digiKam
dconfigdlgview_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 : 2009-11-03
7  * Description : A dialog base class which can handle multiple pages.
8  *
9  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2007 by Rafael Fernández López <ereslibre at kde dot org>
11  * Copyright (C) 2006 by Tobias Koenig <tokoe at kde dot org>
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_DCONFIG_DLG_VIEW_PRIVATE_H
27 #define DIGIKAM_DCONFIG_DLG_VIEW_PRIVATE_H
28 
29 #include "dconfigdlgview.h"
30 
31 // Qt includes
32 
33 #include <QAbstractItemDelegate>
34 #include <QGridLayout>
35 #include <QStackedWidget>
36 #include <QAbstractProxyModel>
37 #include <QListView>
38 #include <QTabBar>
39 #include <QTreeView>
40 
41 // Local includes
42 
43 #include "dconfigdlgwidgets.h"
44 
45 namespace Digikam
46 {
47 
48 class Q_DECL_HIDDEN DConfigDlgStackedWidget : public QStackedWidget
49 {
50  Q_OBJECT
51 
52 public:
53 
54  explicit DConfigDlgStackedWidget(QWidget* const parent = nullptr)
55  : QStackedWidget(parent)
56  {
57  }
58 
59  void setMinimumSize(const QSize& size)
60  {
61  mMinimumSize = size;
62  }
63 
64  QSize minimumSizeHint() const override
65  {
66  return mMinimumSize.expandedTo(QStackedWidget::minimumSizeHint());
67  }
68 
69 private:
70 
71  QSize mMinimumSize;
72 };
73 
74 // ---------------------------
75 
76 class Q_DECL_HIDDEN DConfigDlgViewPrivate
77 {
78  Q_DECLARE_PUBLIC(DConfigDlgView)
79 
80 protected:
81 
82  explicit DConfigDlgViewPrivate(DConfigDlgView* const);
83 
84  void updateTitleWidget(const QModelIndex& index);
85 
86  void updateSelection();
87  void cleanupPages();
88  QList<QWidget*> collectPages(const QModelIndex& parent = QModelIndex());
89  DConfigDlgView::FaceType detectAutoFace() const;
90 
91  // private slots
92 
93  void _k_rebuildGui();
94  void _k_modelChanged();
95  void _k_dataChanged(const QModelIndex&, const QModelIndex&);
96  void _k_pageSelected(const QItemSelection&, const QItemSelection&);
97 
98 protected:
99 
101 
102  // data
103 
104  QAbstractItemModel* model;
106 
107  // gui
108 
109  QGridLayout* layout;
112  QWidget* defaultWidget;
113 
114  QAbstractItemView* view;
115 
116 private:
117 
118  // cppcheck-suppress unusedPrivateFunction
119  void init();
120 };
121 
122 // --------------------------------------------------------------------------------------------
123 
124 namespace DConfigDlgInternal
125 {
126 
129 
130 class Q_DECL_HIDDEN DConfigDlgPlainView : public QAbstractItemView
131 {
132  Q_OBJECT
133 
134 public:
135 
136  explicit DConfigDlgPlainView(QWidget* const parent = nullptr);
137 
138  QModelIndex indexAt(const QPoint& point) const override;
139  void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible) override;
140  QRect visualRect(const QModelIndex& index) const override;
141 
142 protected:
143 
144  QModelIndex moveCursor(QAbstractItemView::CursorAction, Qt::KeyboardModifiers) override;
145  int horizontalOffset() const override;
146  int verticalOffset() const override;
147  bool isIndexHidden(const QModelIndex&) const override;
148  void setSelection(const QRect& , QFlags<QItemSelectionModel::SelectionFlag>) override;
149  QRegion visualRegionForSelection(const QItemSelection&) const override;
150 };
151 
152 // ---------------------------
153 
154 class Q_DECL_HIDDEN DConfigDlgListView : public QListView
155 {
156  Q_OBJECT
157 
158 public:
159 
160  explicit DConfigDlgListView(QWidget* const parent = nullptr);
161  ~DConfigDlgListView() override;
162 
163  void setModel(QAbstractItemModel* model) override;
164 
165 private Q_SLOTS:
166 
167  void updateWidth();
168 };
169 
170 // ---------------------------
171 
172 class Q_DECL_HIDDEN DConfigDlgTreeView : public QTreeView
173 {
174  Q_OBJECT
175 
176 public:
177 
178  explicit DConfigDlgTreeView(QWidget* const parent = nullptr);
179 
180  void setModel(QAbstractItemModel* model) override;
181 
182 private Q_SLOTS:
183 
184  void updateWidth();
185 
186 private:
187 
188  void expandItems(const QModelIndex& index = QModelIndex());
189 };
190 
191 // ---------------------------
192 
193 class Q_DECL_HIDDEN DConfigDlgTabbedView : public QAbstractItemView
194 {
195  Q_OBJECT
196 
197 public:
198 
199  explicit DConfigDlgTabbedView(QWidget* const parent = nullptr);
200  ~DConfigDlgTabbedView() override;
201 
202  void setModel(QAbstractItemModel* model) override;
203  QModelIndex indexAt(const QPoint& point) const override;
204  void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible) override;
205  QRect visualRect(const QModelIndex& index) const override;
206  QSize minimumSizeHint() const override;
207 
208 protected:
209 
210  QModelIndex moveCursor(QAbstractItemView::CursorAction, Qt::KeyboardModifiers) override;
211  int horizontalOffset() const override;
212  int verticalOffset() const override;
213  bool isIndexHidden(const QModelIndex&) const override;
214  void setSelection(const QRect& , QFlags<QItemSelectionModel::SelectionFlag>) override;
215  QRegion visualRegionForSelection(const QItemSelection&) const override;
216 
217 private Q_SLOTS:
218 
219  void currentPageChanged(int);
220  void layoutChanged();
221  void dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>& roles) override;
222 
223 private:
224 
225  QTabWidget* mTabWidget;
226 };
227 
228 // ---------------------------
229 
230 class Q_DECL_HIDDEN DConfigDlgListViewDelegate : public QAbstractItemDelegate
231 {
232  Q_OBJECT
233 
234 public:
235 
236  explicit DConfigDlgListViewDelegate(QObject* const parent = nullptr);
237 
238  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
239  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
240 
241 private:
242 
243  void drawFocus(QPainter*, const QStyleOptionViewItem&, const QRect&) const;
244 };
245 
246 // ---------------------------
247 
252 class Q_DECL_HIDDEN DConfigDlgListViewProxy : public QAbstractProxyModel
253 {
254  Q_OBJECT
255 
256 public:
257 
258  explicit DConfigDlgListViewProxy(QObject* const parent = nullptr);
259  ~DConfigDlgListViewProxy() override;
260 
261  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
262  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
263  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
264  QModelIndex parent(const QModelIndex&) const override;
265  QVariant data(const QModelIndex& index, int role) const override;
266  QModelIndex mapFromSource(const QModelIndex& index) const override;
267  QModelIndex mapToSource(const QModelIndex& index) const override;
268 
269 public Q_SLOTS:
270 
271  void rebuildMap();
272 
273 private:
274 
275  void addMapEntry(const QModelIndex&);
276 
277 private:
278 
279  QList<QModelIndex> mList;
280 };
281 
282 // ---------------------------
283 
284 class Q_DECL_HIDDEN SelectionModel : public QItemSelectionModel
285 {
286  Q_OBJECT
287 
288 public:
289 
290  SelectionModel(QAbstractItemModel* const model, QObject* const parent);
291 
292 public Q_SLOTS:
293 
294  void clear() override;
295  void select(const QModelIndex& index, QItemSelectionModel::SelectionFlags command) override;
296  void select(const QItemSelection& selection, QItemSelectionModel::SelectionFlags command) override;
297 };
298 
299 } // namespace DConfigDlgInternal
300 
301 } // namespace Digikam
302 
303 #endif // DIGIKAM_DCONFIG_DLG_VIEW_PRIVATE_H
Definition: dconfigdlgview_p.h:155
Definition: dconfigdlgview_p.h:131
Definition: dconfigdlgview_p.h:194
Definition: dconfigdlgview_p.h:173
Definition: dconfigdlgview_p.h:285
Definition: dconfigdlgview_p.h:49
QSize minimumSizeHint() const override
Definition: dconfigdlgview_p.h:64
void setMinimumSize(const QSize &size)
Definition: dconfigdlgview_p.h:59
DConfigDlgStackedWidget(QWidget *const parent=nullptr)
Definition: dconfigdlgview_p.h:54
Definition: dconfigdlgwidgets.h:185
Definition: dconfigdlgview_p.h:77
DConfigDlgTitle * titleWidget
Definition: dconfigdlgview_p.h:111
QWidget * defaultWidget
Definition: dconfigdlgview_p.h:112
QGridLayout * layout
Definition: dconfigdlgview_p.h:109
QAbstractItemView * view
Definition: dconfigdlgview_p.h:114
DConfigDlgView * q_ptr
Definition: dconfigdlgview_p.h:100
DConfigDlgStackedWidget * stack
Definition: dconfigdlgview_p.h:110
DConfigDlgView::FaceType faceType
Definition: dconfigdlgview_p.h:105
QAbstractItemModel * model
Definition: dconfigdlgview_p.h:104
A base class which can handle multiple pages.
Definition: dconfigdlgview.h:59
FaceType
Definition: dconfigdlgview.h:84
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43