| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | #ifndef KSHORTCUTWIDGET_H |
| 8 | #define KSHORTCUTWIDGET_H |
| 9 | |
| 10 | #include <kxmlgui_export.h> |
| 11 | |
| 12 | #include <QKeySequence> |
| 13 | #include <QList> |
| 14 | #include <QWidget> |
| 15 | #include <memory> |
| 16 | |
| 17 | class KActionCollection; |
| 18 | class KShortcutWidgetPrivate; |
| 19 | |
| 20 | /*! |
| 21 | * \class KShortcutWidget |
| 22 | * \inmodule KXmlGui |
| 23 | * |
| 24 | * Provides a widget that lets the user assign a main shortcut |
| 25 | * and an alternate shortcut for a certain action. |
| 26 | * |
| 27 | * \image kshortcutwidget.png "KShortcutWidget" |
| 28 | */ |
| 29 | class KXMLGUI_EXPORT KShortcutWidget : public QWidget |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | |
| 33 | /*! |
| 34 | * \property KShortcutWidget::modifierlessAllowed |
| 35 | */ |
| 36 | Q_PROPERTY(bool modifierlessAllowed READ isModifierlessAllowed WRITE setModifierlessAllowed) |
| 37 | public: |
| 38 | /*! |
| 39 | * \brief Creates a new shortcut widget as a child of \a parent. |
| 40 | */ |
| 41 | explicit KShortcutWidget(QWidget *parent = nullptr); |
| 42 | /*! |
| 43 | * \brief Destructs the shortcut widget. |
| 44 | */ |
| 45 | ~KShortcutWidget() override; |
| 46 | |
| 47 | /*! |
| 48 | * \brief Sets whether to \a allow a shortcut |
| 49 | * that doesn't include a modifier key. |
| 50 | */ |
| 51 | void setModifierlessAllowed(bool allow); |
| 52 | |
| 53 | /*! |
| 54 | * \brief Returns whether the set widget shortcut |
| 55 | * can be set without including a modifier key. |
| 56 | */ |
| 57 | bool isModifierlessAllowed(); |
| 58 | |
| 59 | /*! |
| 60 | * \brief Sets whether to \a show the clear buttons next to the |
| 61 | * main and alternate shortcuts of the widget. |
| 62 | */ |
| 63 | void setClearButtonsShown(bool show); |
| 64 | |
| 65 | /*! |
| 66 | * \brief Returns the set shortcut. |
| 67 | */ |
| 68 | QList<QKeySequence> shortcut() const; |
| 69 | |
| 70 | /*! |
| 71 | * \brief Sets a list of \a actionCollections to check against |
| 72 | * for a conflictuous shortcut. |
| 73 | * |
| 74 | * If there is a conflictuous shortcut with a QAction, |
| 75 | * and that this shortcut can be configured |
| 76 | * (that is, KActionCollection::isShortcutConfigurable() returns \c true) |
| 77 | * the user will be prompted to eventually steal the shortcut from this action. |
| 78 | * |
| 79 | * Global shortcuts are automatically checked for conflicts. |
| 80 | * |
| 81 | * Don't forget to call applyStealShortcut() to actually steal the shortcut. |
| 82 | * |
| 83 | * \since 4.1 |
| 84 | */ |
| 85 | void setCheckActionCollections(const QList<KActionCollection *> &actionCollections); |
| 86 | |
| 87 | Q_SIGNALS: |
| 88 | /*! |
| 89 | * \brief Emitted when the given shortcut \a cut has changed. |
| 90 | */ |
| 91 | void shortcutChanged(const QList<QKeySequence> &cut); |
| 92 | |
| 93 | public Q_SLOTS: |
| 94 | /*! |
| 95 | * \brief Sets the given shortcut \a cut to the widget. |
| 96 | */ |
| 97 | void setShortcut(const QList<QKeySequence> &cut); |
| 98 | /*! |
| 99 | * \brief Unassigns the widget's shortcut. |
| 100 | */ |
| 101 | void clearShortcut(); |
| 102 | |
| 103 | /*! |
| 104 | * \brief Actually remove the shortcut that the user wanted to steal, |
| 105 | * from the action that was using it. |
| 106 | * |
| 107 | * To be called before you apply your changes. |
| 108 | * No shortcuts are stolen until this function is called. |
| 109 | */ |
| 110 | void applyStealShortcut(); |
| 111 | |
| 112 | private: |
| 113 | friend class KShortcutWidgetPrivate; |
| 114 | std::unique_ptr<KShortcutWidgetPrivate> const d; |
| 115 | }; |
| 116 | |
| 117 | #endif // KSHORTCUTWIDGET_H |
| 118 | |