File indexing completed on 2024-09-08 12:23:24
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 #ifndef KSHORTCUTWIDGET_H 0008 #define KSHORTCUTWIDGET_H 0009 0010 #include <kxmlgui_export.h> 0011 0012 #include <QKeySequence> 0013 #include <QList> 0014 #include <QWidget> 0015 #include <memory> 0016 0017 class KActionCollection; 0018 class KShortcutWidgetPrivate; 0019 0020 /** 0021 * @class KShortcutWidget kshortcutwidget.h KShortcutWidget 0022 * 0023 * \image html kshortcutwidget.png "KShortcutWidget" 0024 */ 0025 class KXMLGUI_EXPORT KShortcutWidget : public QWidget 0026 { 0027 Q_OBJECT 0028 Q_PROPERTY(bool modifierlessAllowed READ isModifierlessAllowed WRITE setModifierlessAllowed) 0029 public: 0030 KShortcutWidget(QWidget *parent = nullptr); 0031 ~KShortcutWidget() override; 0032 0033 void setModifierlessAllowed(bool allow); 0034 bool isModifierlessAllowed(); 0035 0036 void setClearButtonsShown(bool show); 0037 0038 QList<QKeySequence> shortcut() const; 0039 0040 /** 0041 * Set a list of action collections to check against for conflictuous shortcut. 0042 * 0043 * If there is a conflictuous shortcut with a QAction, and that his shortcut can be configured 0044 * (KActionCollection::isShortcutConfigurable() returns true) the user will be prompted for eventually steal 0045 * the shortcut from this action 0046 * 0047 * Global shortcuts are automatically checked for conflicts 0048 * 0049 * Don't forget to call applyStealShortcut to actually steal the shortcut. 0050 * 0051 * @since 4.1 0052 */ 0053 void setCheckActionCollections(const QList<KActionCollection *> &actionCollections); 0054 0055 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(4, 1) 0056 /** 0057 * @deprecated since 4.1 0058 * Use setCheckActionCollections so that KShortcutWidget knows 0059 * in which action collection to call the writeSettings method after stealing 0060 * a shortcut from an action. 0061 */ 0062 KXMLGUI_DEPRECATED_VERSION(4, 1, "Use KShortcutWidget::setCheckActionCollections(const QList<KActionCollection *> &)") 0063 void setCheckActionList(const QList<QAction *> &checkList); 0064 #endif 0065 0066 Q_SIGNALS: 0067 void shortcutChanged(const QList<QKeySequence> &cut); 0068 0069 public Q_SLOTS: 0070 void setShortcut(const QList<QKeySequence> &cut); 0071 void clearShortcut(); 0072 0073 /** 0074 * Actually remove the shortcut that the user wanted to steal, from the 0075 * action that was using it. 0076 * 0077 * To be called before you apply your changes. 0078 * No shortcuts are stolen until this function is called. 0079 */ 0080 void applyStealShortcut(); 0081 0082 private: 0083 friend class KShortcutWidgetPrivate; 0084 std::unique_ptr<KShortcutWidgetPrivate> const d; 0085 }; 0086 0087 #endif // KSHORTCUTWIDGET_H