digiKam
showfotodelegate.h
Go to the documentation of this file.
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  * Copyright (C) 2013-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef SHOW_FOTO_DELEGATE_H
26 #define SHOW_FOTO_DELEGATE_H
27 
28 // Qt includes
29 
30 #include <QListView>
31 
32 // Local includes
33 
35 #include "showfotothumbnailmodel.h"
36 
37 namespace ShowFoto
38 {
39 
40 class ShowfotoThumbnailBar;
41 class ShowfotoThumbnailDelegatePrivate;
42 class ShowfotoNormalDelegatePrivate;
43 class ShowfotoFilterModel;
44 
46 {
47  Q_OBJECT
48 
49 public:
50 
51  explicit ShowfotoDelegate(QObject* const parent = nullptr);
52  ~ShowfotoDelegate() override;
53 
54  void setView(ShowfotoThumbnailBar* view);
55 
56  QRect actualPixmapRect(const QModelIndex& index) const;
57  QRect groupIndicatorRect() const;
58  QRect coordinatesIndicatorRect() const;
59 
60  int calculatethumbSizeToFit(int ws);
61 
62  void setSpacing(int spacing) override;
63  void setDefaultViewOptions(const QStyleOptionViewItem& option) override;
64  bool acceptsToolTip(const QPoint& pos, const QRect& visualRect,
65  const QModelIndex& index, QRect* tooltipRect = nullptr) const override;
66  bool acceptsActivation(const QPoint& pos, const QRect& visualRect,
67  const QModelIndex& index, QRect* activationRect = nullptr) const override;
68 
69  QRect pixmapRect() const override;
70  QRect imageInformationRect() const override;
71 
72  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
73  QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const override;
74 
79  static QPixmap retrieveThumbnailPixmap(const QModelIndex& index, int thumbnailSize);
80 
81 public:
82 
85 
86 protected:
87 
88  bool onActualPixmapRect(const QPoint& pos, const QRect& visualRect,
89  const QModelIndex& index, QRect* actualRect) const;
90  void updateActualPixmapRect(const QModelIndex& index, const QRect& rect);
91 
92  void setModel(QAbstractItemModel* model);
93 
95 
100  virtual void updateContentWidth();
101 
106  virtual void updateRects() = 0;
107 
108  void clearCaches() override;
109 
114  virtual void clearModelDataCaches();
115 
116  virtual QPixmap thumbnailPixmap(const QModelIndex& index) const;
117 
118  void invalidatePaintingCache() override;
119  void updateSizeRectsAndPixmaps() override;
120 
121 protected Q_SLOTS:
122 
123  void modelChanged();
124  void modelContentsChanged();
125 
126 private:
127 
128  Q_DECLARE_PRIVATE(ShowfotoDelegate)
129 };
130 
131 // -------------- ShowfotoThumbnailDelegate ---------------------
132 
134 {
135  Q_OBJECT
136 
137 public:
138 
139  explicit ShowfotoThumbnailDelegate(ShowfotoThumbnailBar* const parent);
140  ~ShowfotoThumbnailDelegate() override;
141 
142  void setFlow(QListView::Flow flow);
143 
148  int maximumSize() const;
149  int minimumSize() const;
150 
151  void setDefaultViewOptions(const QStyleOptionViewItem& option) override;
152  bool acceptsActivation(const QPoint& pos,
153  const QRect& visualRect,
154  const QModelIndex& index,
155  QRect* activationRect) const override;
156 
157 protected:
158 
159  void updateContentWidth() override;
160  void updateRects() override;
161  int thumbnailPixmapSize(bool withHighlight, int size);
162 
163 private:
164 
165  // Disable
166  explicit ShowfotoThumbnailDelegate(QObject*) = delete;
167 
168 private:
169 
170  Q_DECLARE_PRIVATE(ShowfotoThumbnailDelegate)
171 };
172 
173 // ------------------- ShowfotoNormalDelegate ------------------
174 
176 {
177  Q_OBJECT
178 
179 public:
180 
181  explicit ShowfotoNormalDelegate(ShowfotoThumbnailBar* const bar,
182  QObject* const parent = nullptr);
183  ~ShowfotoNormalDelegate() override;
184 
185 protected:
186 
188  ShowfotoThumbnailBar* const bar,
189  QObject* const parent = nullptr);
190 
191  void updateRects() override;
192 
193 private:
194 
195  Q_DECLARE_PRIVATE(ShowfotoNormalDelegate)
196 };
197 
198 } // namespace ShowFoto
199 
200 #endif // SHOW_FOTO_DELEGATE_H
Definition: showfotodelegate_p.h:56
Definition: showfotodelegate.h:46
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: showfotodelegate.cpp:175
virtual void updateContentWidth()
Definition: showfotodelegate.cpp:314
bool acceptsActivation(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *activationRect=nullptr) const override
Definition: showfotodelegate.cpp:277
void updateActualPixmapRect(const QModelIndex &index, const QRect &rect)
Definition: showfotodelegate.cpp:390
void modelChanged()
Definition: showfotodelegate.cpp:360
void modelContentsChanged()
Definition: showfotodelegate.cpp:367
void clearCaches() override
Definition: showfotodelegate.cpp:347
void setSpacing(int spacing) override
Definition: showfotodelegate.cpp:118
bool onActualPixmapRect(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *actualRect) const
Definition: showfotodelegate.cpp:283
~ShowfotoDelegate() override
Definition: showfotodelegate.cpp:52
virtual QPixmap thumbnailPixmap(const QModelIndex &index) const
Definition: showfotodelegate.cpp:168
virtual void updateRects()=0
static QPixmap retrieveThumbnailPixmap(const QModelIndex &index, int thumbnailSize)
Definition: showfotodelegate.cpp:151
void invalidatePaintingCache() override
reimplement these in subclasses
Definition: showfotodelegate.cpp:309
void updateSizeRectsAndPixmaps() override
Definition: showfotodelegate.cpp:320
QRect imageInformationRect() const override
Definition: showfotodelegate.cpp:130
ShowfotoDelegate(QObject *const parent=nullptr)
Definition: showfotodelegate.cpp:42
QRect coordinatesIndicatorRect() const
Definition: showfotodelegate.cpp:144
void setDefaultViewOptions(const QStyleOptionViewItem &option) override
Definition: showfotodelegate.cpp:303
QRect pixmapRect() const override
Definition: showfotodelegate.cpp:123
void setModel(QAbstractItemModel *model)
Definition: showfotodelegate.cpp:80
int calculatethumbSizeToFit(int ws)
Definition: showfotodelegate.cpp:401
QPixmap pixmapForDrag(const QStyleOptionViewItem &option, const QList< QModelIndex > &indexes) const override
Definition: showfotodelegate.cpp:258
void setView(ShowfotoThumbnailBar *view)
Definition: showfotodelegate.cpp:58
bool acceptsToolTip(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *tooltipRect=nullptr) const override
Definition: showfotodelegate.cpp:271
QRect actualPixmapRect(const QModelIndex &index) const
Definition: showfotodelegate.cpp:372
virtual void clearModelDataCaches()
Definition: showfotodelegate.cpp:354
QRect groupIndicatorRect() const
Definition: showfotodelegate.cpp:137
Definition: showfotoitemviewdelegate.h:44
QRect rect() const
Definition: showfotoitemviewdelegate.cpp:114
int spacing() const
Definition: showfotoitemviewdelegate.cpp:107
ThumbnailSize thumbnailSize() const
Definition: showfotoitemviewdelegate.cpp:76
Definition: showfotodelegate_p.h:121
Definition: showfotodelegate.h:176
void updateRects() override
Definition: showfotodelegate.cpp:603
~ShowfotoNormalDelegate() override
Definition: showfotodelegate.cpp:599
ShowfotoNormalDelegate(ShowfotoThumbnailBar *const bar, QObject *const parent=nullptr)
Definition: showfotodelegate.cpp:580
Definition: showfotothumbnailbar.h:38
Definition: showfotodelegate.h:134
void setFlow(QListView::Flow flow)
Definition: showfotodelegate.cpp:481
void updateContentWidth() override
Definition: showfotodelegate.cpp:519
int maximumSize() const
Definition: showfotodelegate.cpp:497
~ShowfotoThumbnailDelegate() override
Definition: showfotodelegate.cpp:477
int minimumSize() const
Definition: showfotodelegate.cpp:504
bool acceptsActivation(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *activationRect) const override
Definition: showfotodelegate.cpp:511
void updateRects() override
Definition: showfotodelegate.cpp:549
int thumbnailPixmapSize(bool withHighlight, int size)
Definition: showfotodelegate.cpp:539
ShowfotoThumbnailDelegate(ShowfotoThumbnailBar *const parent)
Definition: showfotodelegate.cpp:470
void setDefaultViewOptions(const QStyleOptionViewItem &option) override
Definition: showfotodelegate.cpp:487
Definition: showfotofolderviewbar.cpp:52