File indexing completed on 2025-01-19 03:53:51
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-11-03 0007 * Description : A dialog base class which can handle multiple pages. 0008 * 0009 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2007 by Rafael Fernández López <ereslibre at kde dot org> 0011 * SPDX-FileCopyrightText: 2006 by Tobias Koenig <tokoe at kde dot org> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #ifndef DIGIKAM_DCONFIG_DLG_VIEW_PRIVATE_H 0018 #define DIGIKAM_DCONFIG_DLG_VIEW_PRIVATE_H 0019 0020 #include "dconfigdlgview.h" 0021 0022 // Qt includes 0023 0024 #include <QAbstractItemDelegate> 0025 #include <QGridLayout> 0026 #include <QStackedWidget> 0027 #include <QAbstractProxyModel> 0028 #include <QListView> 0029 #include <QTabBar> 0030 #include <QTreeView> 0031 0032 // Local includes 0033 0034 #include "dconfigdlgwidgets.h" 0035 0036 namespace Digikam 0037 { 0038 0039 class Q_DECL_HIDDEN DConfigDlgStackedWidget : public QStackedWidget 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 0045 explicit DConfigDlgStackedWidget(QWidget* const parent = nullptr) 0046 : QStackedWidget(parent) 0047 { 0048 } 0049 0050 void setMinimumSize(const QSize& size) 0051 { 0052 mMinimumSize = size; 0053 } 0054 0055 QSize minimumSizeHint() const override 0056 { 0057 return mMinimumSize.expandedTo(QStackedWidget::minimumSizeHint()); 0058 } 0059 0060 private: 0061 0062 QSize mMinimumSize; 0063 }; 0064 0065 // --------------------------- 0066 0067 class Q_DECL_HIDDEN DConfigDlgViewPrivate 0068 { 0069 Q_DECLARE_PUBLIC(DConfigDlgView) 0070 0071 protected: 0072 0073 explicit DConfigDlgViewPrivate(DConfigDlgView* const); 0074 0075 void updateTitleWidget(const QModelIndex& index); 0076 0077 void updateSelection(); 0078 void cleanupPages(); 0079 QList<QWidget*> collectPages(const QModelIndex& parent = QModelIndex()); 0080 DConfigDlgView::FaceType detectAutoFace() const; 0081 0082 // private slots 0083 0084 void _k_rebuildGui(); 0085 void _k_modelChanged(); 0086 void _k_dataChanged(const QModelIndex&, const QModelIndex&); 0087 void _k_pageSelected(const QItemSelection&, const QItemSelection&); 0088 0089 protected: 0090 0091 DConfigDlgView* q_ptr; 0092 0093 // data 0094 0095 QAbstractItemModel* model; 0096 DConfigDlgView::FaceType faceType; 0097 0098 // gui 0099 0100 QGridLayout* layout; 0101 DConfigDlgStackedWidget* stack; 0102 DConfigDlgTitle* titleWidget; 0103 QWidget* defaultWidget; 0104 0105 QAbstractItemView* view; 0106 0107 private: 0108 0109 // cppcheck-suppress unusedPrivateFunction 0110 void init(); 0111 }; 0112 0113 // -------------------------------------------------------------------------------------------- 0114 0115 namespace DConfigDlgInternal 0116 { 0117 0118 class DConfigDlgListViewDelegate; 0119 class DConfigDlgListViewProxy; 0120 0121 class Q_DECL_HIDDEN DConfigDlgPlainView : public QAbstractItemView 0122 { 0123 Q_OBJECT 0124 0125 public: 0126 0127 explicit DConfigDlgPlainView(QWidget* const parent = nullptr); 0128 0129 QModelIndex indexAt(const QPoint& point) const override; 0130 void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible) override; 0131 QRect visualRect(const QModelIndex& index) const override; 0132 0133 protected: 0134 0135 QModelIndex moveCursor(QAbstractItemView::CursorAction, Qt::KeyboardModifiers) override; 0136 int horizontalOffset() const override; 0137 int verticalOffset() const override; 0138 bool isIndexHidden(const QModelIndex&) const override; 0139 void setSelection(const QRect& , QFlags<QItemSelectionModel::SelectionFlag>) override; 0140 QRegion visualRegionForSelection(const QItemSelection&) const override; 0141 }; 0142 0143 // --------------------------- 0144 0145 class Q_DECL_HIDDEN DConfigDlgListView : public QListView 0146 { 0147 Q_OBJECT 0148 0149 public: 0150 0151 explicit DConfigDlgListView(QWidget* const parent = nullptr); 0152 ~DConfigDlgListView() override; 0153 0154 void setModel(QAbstractItemModel* model) override; 0155 0156 private Q_SLOTS: 0157 0158 void updateWidth(); 0159 }; 0160 0161 // --------------------------- 0162 0163 class Q_DECL_HIDDEN DConfigDlgTreeView : public QTreeView 0164 { 0165 Q_OBJECT 0166 0167 public: 0168 0169 explicit DConfigDlgTreeView(QWidget* const parent = nullptr); 0170 0171 void setModel(QAbstractItemModel* model) override; 0172 0173 private Q_SLOTS: 0174 0175 void updateWidth(); 0176 0177 private: 0178 0179 void expandItems(const QModelIndex& index = QModelIndex()); 0180 }; 0181 0182 // --------------------------- 0183 0184 class Q_DECL_HIDDEN DConfigDlgTabbedView : public QAbstractItemView 0185 { 0186 Q_OBJECT 0187 0188 public: 0189 0190 explicit DConfigDlgTabbedView(QWidget* const parent = nullptr); 0191 ~DConfigDlgTabbedView() override; 0192 0193 void setModel(QAbstractItemModel* model) override; 0194 QModelIndex indexAt(const QPoint& point) const override; 0195 void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible) override; 0196 QRect visualRect(const QModelIndex& index) const override; 0197 QSize minimumSizeHint() const override; 0198 0199 protected: 0200 0201 QModelIndex moveCursor(QAbstractItemView::CursorAction, Qt::KeyboardModifiers) override; 0202 int horizontalOffset() const override; 0203 int verticalOffset() const override; 0204 bool isIndexHidden(const QModelIndex&) const override; 0205 void setSelection(const QRect& , QFlags<QItemSelectionModel::SelectionFlag>) override; 0206 QRegion visualRegionForSelection(const QItemSelection&) const override; 0207 0208 private Q_SLOTS: 0209 0210 void currentPageChanged(int); 0211 void layoutChanged(); 0212 void dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>& roles) override; 0213 0214 private: 0215 0216 QTabWidget* mTabWidget; 0217 }; 0218 0219 // --------------------------- 0220 0221 class Q_DECL_HIDDEN DConfigDlgListViewDelegate : public QAbstractItemDelegate 0222 { 0223 Q_OBJECT 0224 0225 public: 0226 0227 explicit DConfigDlgListViewDelegate(QObject* const parent = nullptr); 0228 0229 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0230 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0231 0232 private: 0233 0234 void drawFocus(QPainter*, const QStyleOptionViewItem&, const QRect&) const; 0235 }; 0236 0237 // --------------------------- 0238 0239 /** 0240 * We need this proxy model to map the leaves of a tree-like model 0241 * to a one-level list model. 0242 */ 0243 class Q_DECL_HIDDEN DConfigDlgListViewProxy : public QAbstractProxyModel 0244 { 0245 Q_OBJECT 0246 0247 public: 0248 0249 explicit DConfigDlgListViewProxy(QObject* const parent = nullptr); 0250 ~DConfigDlgListViewProxy() override; 0251 0252 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0253 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0254 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 0255 QModelIndex parent(const QModelIndex&) const override; 0256 QVariant data(const QModelIndex& index, int role) const override; 0257 QModelIndex mapFromSource(const QModelIndex& index) const override; 0258 QModelIndex mapToSource(const QModelIndex& index) const override; 0259 0260 public Q_SLOTS: 0261 0262 void rebuildMap(); 0263 0264 private: 0265 0266 void addMapEntry(const QModelIndex&); 0267 0268 private: 0269 0270 QList<QModelIndex> mList; 0271 }; 0272 0273 // --------------------------- 0274 0275 class Q_DECL_HIDDEN SelectionModel : public QItemSelectionModel 0276 { 0277 Q_OBJECT 0278 0279 public: 0280 0281 SelectionModel(QAbstractItemModel* const model, QObject* const parent); 0282 0283 public Q_SLOTS: 0284 0285 void clear() override; 0286 void select(const QModelIndex& index, QItemSelectionModel::SelectionFlags command) override; 0287 void select(const QItemSelection& selection, QItemSelectionModel::SelectionFlags command) override; 0288 }; 0289 0290 } // namespace DConfigDlgInternal 0291 0292 } // namespace Digikam 0293 0294 #endif // DIGIKAM_DCONFIG_DLG_VIEW_PRIVATE_H