File indexing completed on 2024-04-14 03:57:12

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     explicit 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 Q_SIGNALS:
0056     void shortcutChanged(const QList<QKeySequence> &cut);
0057 
0058 public Q_SLOTS:
0059     void setShortcut(const QList<QKeySequence> &cut);
0060     void clearShortcut();
0061 
0062     /**
0063      * Actually remove the shortcut that the user wanted to steal, from the
0064      * action that was using it.
0065      *
0066      * To be called before you apply your changes.
0067      * No shortcuts are stolen until this function is called.
0068      */
0069     void applyStealShortcut();
0070 
0071 private:
0072     friend class KShortcutWidgetPrivate;
0073     std::unique_ptr<KShortcutWidgetPrivate> const d;
0074 };
0075 
0076 #endif // KSHORTCUTWIDGET_H