File indexing completed on 2024-03-24 17:14:01
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Ben Cooksley <bcooksley@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef SIDEBARMODE_H 0008 #define SIDEBARMODE_H 0009 0010 #include "BaseMode.h" 0011 #include <KSelectionProxyModel> 0012 #include <QIcon> 0013 #include <QWidget> 0014 0015 class ModuleView; 0016 class KAboutData; 0017 class QModelIndex; 0018 class QAbstractItemView; 0019 class QAbstractItemModel; 0020 class QAction; 0021 class SidebarMode; 0022 class MenuItem; 0023 0024 class FocusHackWidget : public QWidget 0025 { 0026 Q_OBJECT 0027 public: 0028 explicit FocusHackWidget(QWidget *parent = nullptr); 0029 ~FocusHackWidget() override; 0030 0031 public Q_SLOTS: 0032 void focusNext(); 0033 void focusPrevious(); 0034 }; 0035 0036 class SubcategoryModel : public KSelectionProxyModel 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(QString title READ title NOTIFY titleChanged) 0040 Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged) 0041 Q_PROPERTY(bool categoryOwnedByKCM READ categoryOwnedByKCM NOTIFY categoryOwnedByKCMChanged) 0042 0043 public: 0044 explicit SubcategoryModel(QAbstractItemModel *parentModel, SidebarMode *parent = nullptr); 0045 0046 QString title() const; 0047 QIcon icon() const; 0048 bool categoryOwnedByKCM() const; 0049 0050 void setParentIndex(const QModelIndex &activeModule); 0051 0052 Q_INVOKABLE void loadParentCategoryModule(); 0053 0054 Q_SIGNALS: 0055 void titleChanged(); 0056 void iconChanged(); 0057 void categoryOwnedByKCMChanged(); 0058 0059 private: 0060 QAbstractItemModel *m_parentModel; 0061 SidebarMode *m_sidebarMode; 0062 QPersistentModelIndex m_activeModuleIndex; 0063 }; 0064 0065 class SidebarMode : public BaseMode 0066 { 0067 Q_OBJECT 0068 0069 Q_PROPERTY(QAbstractItemModel *categoryModel READ categoryModel CONSTANT) 0070 Q_PROPERTY(QAbstractItemModel *searchModel READ searchModel CONSTANT) 0071 Q_PROPERTY(QAbstractItemModel *subCategoryModel READ subCategoryModel CONSTANT) 0072 Q_PROPERTY(int activeCategoryRow READ activeCategoryRow NOTIFY activeCategoryRowChanged) 0073 Q_PROPERTY(int activeSearchRow READ activeSearchRow NOTIFY activeSearchRowChanged) 0074 Q_PROPERTY(int activeSubCategoryRow READ activeSubCategoryRow NOTIFY activeSubCategoryRowChanged) 0075 Q_PROPERTY(int width READ width NOTIFY widthChanged) 0076 Q_PROPERTY(bool actionMenuVisible READ actionMenuVisible NOTIFY actionMenuVisibleChanged) 0077 Q_PROPERTY(bool introPageVisible READ introPageVisible WRITE setIntroPageVisible NOTIFY introPageVisibleChanged) 0078 Q_PROPERTY(bool defaultsIndicatorsVisible READ defaultsIndicatorsVisible NOTIFY defaultsIndicatorsVisibleChanged) 0079 Q_PROPERTY(qreal headerHeight READ headerHeight WRITE setHeaderHeight NOTIFY headerHeightChanged) 0080 0081 public: 0082 SidebarMode(QObject *parent, const QVariantList &args); 0083 ~SidebarMode() override; 0084 QWidget *mainWidget() override; 0085 void initEvent() override; 0086 void giveFocus() override; 0087 KAboutData *aboutData() override; 0088 ModuleView *moduleView() const override; 0089 void reloadStartupModule() override; 0090 0091 QAbstractItemModel *categoryModel() const; 0092 QAbstractItemModel *searchModel() const; 0093 QAbstractItemModel *subCategoryModel() const; 0094 0095 int activeCategoryRow() const; 0096 int activeSubCategoryRow() const; 0097 int activeSearchRow() const; 0098 0099 int width() const; 0100 0101 bool actionMenuVisible() const; 0102 0103 bool introPageVisible() const; 0104 void setIntroPageVisible(const bool &introPageVisible); 0105 0106 qreal headerHeight() const; 0107 void setHeaderHeight(qreal height); 0108 0109 bool defaultsIndicatorsVisible() const override; 0110 void toggleDefaultsIndicatorsVisibility() override; 0111 0112 Q_INVOKABLE QAction *action(const QString &name) const; 0113 // QML doesn't understand QIcon, otherwise we could get it from the QAction itself 0114 Q_INVOKABLE QString actionIconName(const QString &name) const; 0115 Q_INVOKABLE void showActionMenu(const QPoint &position); 0116 0117 Q_INVOKABLE void loadModule(const QModelIndex &activeModule, const QStringList &args = QStringList()); 0118 0119 protected: 0120 QList<QAbstractItemView *> views() const override; 0121 bool eventFilter(QObject *watched, QEvent *event) override; 0122 0123 private Q_SLOTS: 0124 void moduleLoaded(); 0125 void updateDefaults(); 0126 void initWidget(); 0127 0128 private: 0129 void initPlaceHolderWidget(); 0130 void updateModelMenuItem(MenuItem *item); 0131 void updateCategoryModel(const QModelIndex &categoryIdx); 0132 void refreshDefaults(); 0133 0134 Q_SIGNALS: 0135 void activeCategoryRowChanged(); 0136 void activeSubCategoryRowChanged(); 0137 void activeSearchRowChanged(); 0138 void widthChanged(); 0139 void actionMenuVisibleChanged(); 0140 void introPageVisibleChanged(); 0141 void headerHeightChanged(); 0142 void defaultsIndicatorsVisibleChanged(); 0143 0144 private: 0145 class Private; 0146 Private *const d; 0147 }; 0148 0149 #endif