digiKam
dcategorizedview_p.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 : 2010-01-16
7  * Description : Item view for listing items in a categorized fashion optionally
8  *
9  * Copyright (C) 2007 by Rafael Fernández López <ereslibre at kde dot org>
10  * Copyright (C) 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  * Copyright (C) 2011-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_DCATEGORIZED_VIEW_PRIVATE_H
27 #define DIGIKAM_DCATEGORIZED_VIEW_PRIVATE_H
28 
29 #include "dcategorizedview.h"
30 
31 // C++ includes
32 
33 #include <cmath>
34 
35 // Qt includes
36 
37 #include <QVector>
38 #include <QPainter>
39 #include <QScrollBar>
40 #include <QPaintEvent>
41 
42 // Local includes
43 
45 #include "dcategorydrawer.h"
46 
53 #define DOLPHIN_DRAGANDDROP
54 
55 class DCategoryDrawer;
56 
57 namespace Digikam
58 {
59 
60 class DCategorizedSortFilterProxyModel;
61 
62 class Q_DECL_HIDDEN SparseModelIndexVector : public QVector<QModelIndex>
63 {
64 public:
65 
66  explicit SparseModelIndexVector(int rowCount, QAbstractItemModel* const model_, int column_)
67  : QVector<QModelIndex>(rowCount),
68  model(model_),
69  column(column_)
70  {
71  }
72 
73  inline QModelIndex& operator[](int i)
74  {
75  QModelIndex& index = QVector<QModelIndex>::operator[](i);
76 
77  if (!index.isValid())
78  {
79  index = model->index(i, column);
80  }
81 
82  return index;
83  }
84 
85 private:
86 
87  // not to be used
88 
89  const QModelIndex& operator[](int i) const
90  {
91  return QVector<QModelIndex>::operator[](i);
92  }
93 
94 private:
95 
96  QAbstractItemModel* model;
97  int column;
98 };
99 
100 // ------------------------------------------------------------------------------------
101 
102 class Q_DECL_HIDDEN DCategorizedView::Private
103 {
104 public:
105 
106  explicit Private(DCategorizedView* const listView);
107  ~Private();
108 
109  // Methods
110 
114  const QModelIndexList& intersectionSet(const QRect& rect);
115 
119  QRect visualRectInViewport(const QModelIndex& index) const;
120 
124  QRect visualCategoryRectInViewport(const QString& category) const;
125 
129  const QRect& cacheIndex(const QModelIndex& index);
130 
134  const QRect& cacheCategory(const QString& category);
135 
140  const QRect& cachedRectIndex(const QModelIndex& index);
141 
146  const QRect& cachedRectCategory(const QString& category);
147 
152  QRect visualRect(const QModelIndex& index);
153 
158  QRect categoryVisualRect(const QString& category);
159 
163  QSize contentsSize();
164 
170  void drawNewCategory(const QModelIndex& index,
171  int sortRole,
172  const QStyleOption& option,
173  QPainter* painter);
174 
179  void updateScrollbars();
180 
184  void drawDraggedItems(QPainter* painter);
185 
190  void drawDraggedItems();
191 
196  int categoryUpperBound(SparseModelIndexVector& modelIndexList, int begin, int averageSize = 0);
197 
201  QItemSelection selectionForRect(const QRect& rect);
202 
203 public:
204 
206  class Q_DECL_HIDDEN ElementInfo
207  {
208  public:
209 
210  explicit ElementInfo()
211  : relativeOffsetToCategory(0)
212  {
213  }
214 
215  QString category;
217  };
218 
219 public:
220 
225 
231  QModelIndex hovered;
236 
242  QVector<ElementInfo> elementsInfo;
243  QHash<int, QRect> elementsPosition;
244  QHash<QString, QVector<int> > categoriesIndexes;
245  QHash<QString, QRect> categoriesPosition;
246  QStringList categories;
247  QModelIndexList intersectedIndexes;
249  QItemSelection lastSelection;
250 
253 };
254 
255 } // namespace Digikam
256 
257 #endif // DIGIKAM_DCATEGORIZED_VIEW_PRIVATE_H
Definition: dcategorizedsortfilterproxymodel.h:53
Attributes.
Definition: dcategorizedview_p.h:207
int relativeOffsetToCategory
Definition: dcategorizedview_p.h:216
QString category
Definition: dcategorizedview_p.h:215
ElementInfo()
Definition: dcategorizedview_p.h:210
Definition: dcategorizedview_p.h:103
QRect lastDraggedItemsRect
Definition: dcategorizedview_p.h:248
bool dragLeftViewport
Definition: dcategorizedview_p.h:229
QPoint initialPressPosition
Definition: dcategorizedview_p.h:233
QHash< QString, QVector< int > > categoriesIndexes
Definition: dcategorizedview_p.h:244
QItemSelection lastSelection
Definition: dcategorizedview_p.h:249
DCategorizedView * listView
Basic data.
Definition: dcategorizedview_p.h:222
QString hoveredCategory
Definition: dcategorizedview_p.h:232
QVector< ElementInfo > elementsInfo
Definition: dcategorizedview_p.h:242
QModelIndexList intersectedIndexes
Definition: dcategorizedview_p.h:247
QHash< int, QRect > elementsPosition
Definition: dcategorizedview_p.h:243
DCategorizedSortFilterProxyModel * proxyModel
Attributes for speed reasons.
Definition: dcategorizedview_p.h:252
int forcedSelectionPosition
Definition: dcategorizedview_p.h:235
bool mouseButtonPressed
Behavior data.
Definition: dcategorizedview_p.h:227
QPoint mousePosition
Definition: dcategorizedview_p.h:234
bool drawItemsWhileDragging
Definition: dcategorizedview_p.h:230
QModelIndex hovered
Definition: dcategorizedview_p.h:231
bool rightMouseButtonPressed
Definition: dcategorizedview_p.h:228
DCategoryDrawer * categoryDrawer
Definition: dcategorizedview_p.h:223
QHash< QString, QRect > categoriesPosition
Definition: dcategorizedview_p.h:245
QSize biggestItemSize
Definition: dcategorizedview_p.h:224
QStringList categories
Definition: dcategorizedview_p.h:246
Item view for listing items.
Definition: dcategorizedview.h:49
Definition: dcategorydrawer.h:52
Definition: dcategorizedview_p.h:63
QModelIndex & operator[](int i)
Definition: dcategorizedview_p.h:73
SparseModelIndexVector(int rowCount, QAbstractItemModel *const model_, int column_)
Definition: dcategorizedview_p.h:66
Definition: datefolderview.cpp:43