1 // vim: set tabstop=4 shiftwidth=4 expandtab:
2 /*
3 Gwenview: an image viewer
4 Copyright 2008 Aurélien Gâteau <agateau@kde.org>
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
19 
20 */
21 #ifndef PREVIEWITEMDELEGATE_H
22 #define PREVIEWITEMDELEGATE_H
23 
24 #include <lib/gwenviewlib_export.h>
25 
26 // Qt
27 #include <QItemDelegate>
28 
29 // KF
30 
31 // Local
32 
33 class QUrl;
34 
35 namespace Gwenview
36 {
37 class ThumbnailView;
38 
39 struct PreviewItemDelegatePrivate;
40 
41 /**
42  * An ItemDelegate which generates thumbnails for images. It also makes sure
43  * all items are of the same size.
44  */
45 class GWENVIEWLIB_EXPORT PreviewItemDelegate : public QItemDelegate
46 {
47     Q_OBJECT
48 public:
49     PreviewItemDelegate(ThumbnailView *);
50     ~PreviewItemDelegate() override;
51 
52     enum ContextBarAction {
53         NoAction = 0,
54         SelectionAction = 1,
55         FullScreenAction = 2,
56         RotateAction = 4,
57     };
58     Q_DECLARE_FLAGS(ContextBarActions, ContextBarAction)
59 
60     enum ThumbnailDetail {
61         FileNameDetail = 1,
62         DateDetail = 2,
63         RatingDetail = 4,
64         ImageSizeDetail = 8,
65         FileSizeDetail = 16,
66     };
67     // FIXME: Find out why this cause problems with Qt::Alignment in
68     // PreviewItemDelegate!
69     Q_DECLARE_FLAGS(ThumbnailDetails, ThumbnailDetail)
70 
71     /**
72      * Returns which thumbnail details are shown
73      */
74     ThumbnailDetails thumbnailDetails() const;
75 
76     void setThumbnailDetails(ThumbnailDetails);
77 
78     ContextBarActions contextBarActions() const;
79 
80     void setContextBarActions(ContextBarActions);
81 
82     Qt::TextElideMode textElideMode() const;
83 
84     void setTextElideMode(Qt::TextElideMode);
85 
86     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
87     void setEditorData(QWidget *editor, const QModelIndex &index) const override;
88     void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
89     void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
90 
91     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
92     QSize sizeHint(const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/) const override;
93 
94 Q_SIGNALS:
95     void saveDocumentRequested(const QUrl &);
96     void rotateDocumentLeftRequested(const QUrl &);
97     void rotateDocumentRightRequested(const QUrl &);
98     void showDocumentInFullScreenRequested(const QUrl &);
99     void setDocumentRatingRequested(const QUrl &, int rating);
100 
101 private Q_SLOTS:
102     void setThumbnailSize(const QSize &);
103 
104     void slotSaveClicked();
105     void slotRotateLeftClicked();
106     void slotRotateRightClicked();
107     void slotFullScreenClicked();
108     void slotToggleSelectionClicked();
109     void slotRowsChanged();
110 
111 protected:
112     bool eventFilter(QObject *, QEvent *) override;
113 
114 private:
115     PreviewItemDelegatePrivate *const d;
116     friend struct PreviewItemDelegatePrivate;
117 };
118 
119 } // namespace
120 
121 // See upper
122 Q_DECLARE_OPERATORS_FOR_FLAGS(Gwenview::PreviewItemDelegate::ThumbnailDetails)
123 Q_DECLARE_OPERATORS_FOR_FLAGS(Gwenview::PreviewItemDelegate::ContextBarActions)
124 
125 #endif /* PREVIEWITEMDELEGATE_H */
126