1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2013-08-01
7  * Description : Qt model view for Showfoto item - the delegate
8  *
9  * Copyright (C) 2013 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef SHOW_FOTO_ITEM_VIEW_DELEGATE_H
25 #define SHOW_FOTO_ITEM_VIEW_DELEGATE_H
26 
27 // Local includes
28 
29 #include "thumbnailsize.h"
30 #include "ditemdelegate.h"
31 #include "itemdelegateoverlay.h"
32 
33 using namespace Digikam;
34 
35 namespace ShowFoto
36 {
37 
38 class ShowfotoFilterModel;
39 class ShowfotoItemModel;
40 class ShowfotoItemViewDelegatePrivate;
41 
42 class ShowfotoItemViewDelegate : public DItemDelegate,
43                                  public ItemDelegateOverlayContainer
44 {
45     Q_OBJECT
46 
47 public:
48 
49     explicit ShowfotoItemViewDelegate(QObject* const parent = nullptr);
50     ~ShowfotoItemViewDelegate()                                                               override;
51 
52     ThumbnailSize thumbnailSize()                                                       const;
53 
54     int           spacing()                                                             const;
55     QRect         rect()                                                                const;
56 
57     QSize sizeHint(const QStyleOptionViewItem& option,
58                    const QModelIndex& index)                                            const override;
59     QSize gridSize()                                                                    const override;
60 
61     /// reimplemented from DItemDelegate
62     void setThumbnailSize(const ThumbnailSize& thumbSize)                                     override;
63     void setSpacing(int spacing)                                                              override;
64     void setDefaultViewOptions(const QStyleOptionViewItem& option)                            override;
65     bool acceptsToolTip(const QPoint& pos, const QRect& visualRect,
66                         const QModelIndex& index, QRect* tooltipRect = nullptr)         const override;
67     bool acceptsActivation(const QPoint& pos, const QRect& visualRect,
68                            const QModelIndex& index, QRect* activationRect = nullptr)   const override;
69 
70     /**
71      * Returns the area where the pixmap is drawn,
72      * or null if not supported
73      */
74     virtual QRect pixmapRect()                                                          const;
75 
76     /**
77      * Returns the area where the image information is drawn,
78      * or null if empty / not supported.
79      * The image information is textual or graphical information,
80      * but not the pixmap. The ratingRect() will e.g. typically
81      * be contained in this area.
82      */
83     virtual QRect imageInformationRect()                                                const;
84 
85     void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index)        override;
86 
87 protected Q_SLOTS:
88 
89     void slotThemeChanged();
90     void slotSetupChanged();
91 
92     void overlayDestroyed(QObject* o)                                                         override;
93 
94 Q_SIGNALS:
95 
96     void requestNotification(const QModelIndex& index, const QString& message);
97     void hideNotification();
98 
99 protected:
100 
101     /// Use the tool methods for painting in subclasses
102     QRect drawThumbnail(QPainter* p, const QRect& thumbRect,
103                         const QPixmap& background, const QPixmap& thumbnail)            const;
104     void drawName(QPainter* p,const QRect& nameRect, const QString& name)               const;
105     void drawCreationDate(QPainter* p, const QRect& dateRect, const QDateTime& date)    const;
106     void drawImageSize(QPainter* p, const QRect& dimsRect, const QSize& dims)           const;
107     void drawImageFormat(QPainter* p, const QRect& dimsRect, const QString& mime)       const;
108     void drawFileSize(QPainter* p, const QRect& r, qlonglong bytes)                     const;
109     void drawGeolocationIndicator(QPainter* p, const QRect& r)                          const;
110     void drawFocusRect(QPainter* p, const QStyleOptionViewItem& option,
111                        bool isSelected)                                                 const;
112     void drawMouseOverRect(QPainter* p, const QStyleOptionViewItem& option)             const;
113     void prepareFonts();
114     void prepareMetrics(int maxWidth);
115     void prepareBackground();
116 
117     QAbstractItemDelegate* asDelegate()                                                       override;
118 
119     /// reimplement these in subclasses
120     virtual void invalidatePaintingCache();
121     virtual void updateSizeRectsAndPixmaps()                                            = 0;
122 
123 protected:
124 
125     ShowfotoItemViewDelegatePrivate* const d_ptr;
126 
127 protected:
128 
129     ShowfotoItemViewDelegate(ShowfotoItemViewDelegatePrivate& dd, QObject* const parent);
130 
131 private:
132 
133     // Disable.
134     ShowfotoItemViewDelegate(const ShowfotoItemViewDelegate&)            = delete;
135     ShowfotoItemViewDelegate& operator=(const ShowfotoItemViewDelegate&) = delete;
136 
137 private:
138 
139     Q_DECLARE_PRIVATE(ShowfotoItemViewDelegate)
140 };
141 
142 } // namespace ShowFoto
143 
144 #endif // SHOW_FOTO_ITEM_VIEW_DELEGATE_H
145