File indexing completed on 2024-06-23 05:20:47
0001 /* 0002 Copyright (C) 2012, 2013 by Glad Deschrijver <glad.deschrijver@gmail.com> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public License as 0006 published by the Free Software Foundation; either version 2 of 0007 the License or (at your option) version 3 or any later version 0008 accepted by the membership of KDE e.V. (or its successor approved 0009 by the membership of KDE e.V.), which shall act as a proxy 0010 defined in Section 14 of version 3 of the license. 0011 0012 This program is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #ifndef SHORTCUTCONFIGWIDGET_H 0022 #define SHORTCUTCONFIGWIDGET_H 0023 0024 #ifndef QT_NO_SHORTCUT 0025 0026 #include <QWidget> 0027 #include "ui_ShortcutConfigWidget.h" 0028 0029 class QAction; 0030 class QKeySequence; 0031 0032 namespace Gui 0033 { 0034 0035 class ActionDescription; 0036 0037 /** 0038 * Application programmers are not supposed to construct this class directly. 0039 * Use ShortcutHandler::configWidget() instead. 0040 * \see ShortcutHandler 0041 * 0042 * The purpose of this class is to allow program developers to add a shortcut 0043 * editing widget to a configuration dialog (for example as one of its tabs). 0044 */ 0045 class ShortcutConfigWidget : public QWidget 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 explicit ShortcutConfigWidget(QWidget *parent = 0); 0051 ~ShortcutConfigWidget(); 0052 0053 /** 0054 * This function should be called each time the configuration dialog 0055 * to which this widget is added is accepted. This function saves the 0056 * modified shortcuts to disk and makes sure that the modified shortcuts 0057 * can be used in the program. 0058 */ 0059 void accept(); 0060 /** 0061 * This function does not need to be used explicitly. 0062 * This function may be called each time the configuration dialog 0063 * to which this widget is added is rejected. This function discards any 0064 * modification which was done to the shortcuts and which is not yet saved. 0065 * This ensures that when the configuration dialog is shown again, the old 0066 * shortcuts are displayed instead of the not yet saved modifications. 0067 * If this function is not called when the configuration dialog is 0068 * canceled, reject() will be automatically called when this widget is 0069 * shown again. 0070 */ 0071 void reject(); 0072 0073 Q_SIGNALS: 0074 void shortcutsChanged(const QHash<QString, ActionDescription> &actionDescriptions); 0075 0076 protected: 0077 bool eventFilter(QObject *obj, QEvent *event); 0078 void showEvent(QShowEvent *event); 0079 0080 Ui::ShortcutConfigWidget ui; 0081 0082 private Q_SLOTS: 0083 void searchItems(const QString &text); 0084 void clearShortcut(); 0085 void restoreDefaultShortcut(); 0086 0087 private: 0088 QPushButton *clearButton(); // this function needs to be visible to ShortcutConfigDialog 0089 QPushButton *useDefaultButton(); // idem 0090 void setExclusivityGroups(const QList<QStringList> &groups); 0091 void addItem(const QString &actionName, const QString &text, const QString &shortcut, const QIcon &icon, const QString &parentId); 0092 void setActionDescriptions(const QHash<QString, ActionDescription> &actionDescriptions); 0093 void writeSettings(); 0094 0095 friend class ShortcutHandler; 0096 friend class ShortcutConfigDialog; 0097 0098 QHash<QString, ActionDescription> m_actionDescriptions; 0099 QList<QStringList> m_exclusivityGroups; 0100 bool m_shortcutsShouldBeRestored; 0101 }; 0102 0103 } // namespace Gui 0104 0105 #endif // QT_NO_SHORTCUT 0106 0107 #endif // SHORTCUTCONFIGWIDGET_H