File indexing completed on 2024-05-19 05:08:28
0001 /* 0002 SPDX-FileCopyrightText: 2021 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef TABORDEREDITOR_H 0007 #define TABORDEREDITOR_H 0008 0009 // ---------------------------------------------------------------------------- 0010 // QT Includes 0011 0012 class QPaintEvent; 0013 #include <QDialog> 0014 0015 // ---------------------------------------------------------------------------- 0016 // KDE Includes 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 class TabOrderEditorInterface 0022 { 0023 public: 0024 virtual ~TabOrderEditorInterface() = default; 0025 virtual void setupUi(QWidget* parent) = 0; 0026 virtual void storeTabOrder(const QStringList& tabOrder) = 0; 0027 }; 0028 0029 class TabOrderDialogPrivate; 0030 class TabOrderEditorPrivate; 0031 class TabOrderDialog : public QDialog 0032 { 0033 Q_OBJECT 0034 Q_DECLARE_PRIVATE(TabOrderDialog) 0035 Q_DISABLE_COPY(TabOrderDialog) 0036 friend class TabOrderEditor; 0037 friend class TabOrderEditorPrivate; 0038 0039 public: 0040 explicit TabOrderDialog(QWidget* parent); 0041 ~TabOrderDialog(); 0042 0043 /** 0044 * The widget that contains the edit widgets that 0045 * we want to set the tab order for. 0046 * 0047 * @param targetWidget Pointer to the widget containing the edit widgets 0048 * for which the tab order needs to be set. 0049 * 0050 * @note The widgets themselves are identified by the property 0051 * @c kmm_taborder being @c true. Clears the default tab order. 0052 */ 0053 void setTarget(TabOrderEditorInterface* targetWidget); 0054 0055 /** 0056 * Presets the tab order according to the names 0057 * of the widgets contained in @a widgetNames. 0058 * If called prior to setTarget() it returns immediately. 0059 * 0060 * @param widgetNames QStringList of widget names 0061 * 0062 * @note If @a widgetNames contains names for which no widget 0063 * is found in @c targetWidget or the property @c kmm_taborder is 0064 * not set or false then the entry will be dropped 0065 * without notice. It will be missing when calling tabOrder(). 0066 * 0067 * @sa tabOrder(), setTarget() 0068 */ 0069 void setTabOrder(const QStringList& widgetNames); 0070 0071 /** 0072 * Loads the default tab order of the widget. Is used if 0073 * the user wishes to return to the default. 0074 * 0075 * @param widgetNames QStringList of widget names 0076 * 0077 * @note If @a widgetNames contains names for which no widget 0078 * is found in @c targetWidget or the property @c kmm_taborder is 0079 * not set or false then the entry will be dropped 0080 * without notice. It will be missing when calling tabOrder(). 0081 * 0082 * @sa tabOrder(), setTarget() 0083 */ 0084 void setDefaultTabOrder(const QStringList& widgetNames); 0085 0086 /** 0087 * Returns a list of widget names sorted in the tab order. 0088 * If called prior to setTarget() it returns an empty list. 0089 * If called prior to setDefaultTabOrder() or setTabOrder() 0090 * the order is random. 0091 * 0092 * @returns QStringList of widget names. 0093 */ 0094 QStringList tabOrder() const; 0095 0096 int exec() override; 0097 0098 private: 0099 TabOrderDialogPrivate* d_ptr; 0100 }; 0101 0102 class TabOrderEditor : public QWidget 0103 { 0104 Q_OBJECT 0105 Q_DECLARE_PRIVATE(TabOrderEditor) 0106 Q_DISABLE_COPY(TabOrderEditor) 0107 friend class TabOrderDialog; 0108 friend class TabOrderDialogPrivate; 0109 0110 public: 0111 explicit TabOrderEditor(TabOrderDialog* parent); 0112 ~TabOrderEditor(); 0113 0114 protected: 0115 void mouseMoveEvent(QMouseEvent* event) override; 0116 void mousePressEvent(QMouseEvent* event) override; 0117 void mouseDoubleClickEvent(QMouseEvent* event) override; 0118 void paintEvent(QPaintEvent* e) override; 0119 bool eventFilter(QObject* o, QEvent* e) override; 0120 void keyPressEvent(QKeyEvent* event) override; 0121 void contextMenuEvent(QContextMenuEvent* event) override; 0122 0123 const QFontMetrics& indicatorFontMetrics() const; 0124 0125 Q_SIGNALS: 0126 void geometryUpdated(); 0127 0128 private: 0129 TabOrderEditorPrivate* d_ptr; 0130 }; 0131 0132 #endif // TABORDEREDITOR_H