File indexing completed on 2024-10-06 13:19:08
0001 /* 0002 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #ifndef SHORTCUTSHANDLER_H 0007 #define SHORTCUTSHANDLER_H 0008 0009 #include <KActionCollection> 0010 0011 #include <X11/X.h> 0012 #include <fixx11h.h> 0013 0014 class KAction; 0015 class QKeySequence; 0016 0017 namespace KHotKeys 0018 { 0019 /** 0020 * @author Michael Jansen <kde@michael-jansen.biz> 0021 */ 0022 class ShortcutsHandler : public QObject 0023 { 0024 Q_OBJECT 0025 0026 public: 0027 enum HandlerType { 0028 Active, //!< Create real actions 0029 Configuration, 0030 }; //!< Create configuration actions ( not active ) 0031 0032 /** 0033 * Default constructor 0034 * 0035 * \param Should 0036 */ 0037 ShortcutsHandler(HandlerType type = Active, QObject *parent = nullptr); 0038 0039 /** 0040 * Destructor 0041 */ 0042 ~ShortcutsHandler() override; 0043 0044 /** 0045 * Create a action. 0046 * 0047 * The action stays in the ownership of this class. Do not delete. 0048 * 0049 * \param id Persistent id for the action 0050 * \param name Name for the action. Is used in the global shortcut 0051 * configuration dialog 0052 * \param shortcut Shortcut that triggers the action 0053 * 0054 * \return The new action or 0 if an error occurred. 0055 * 0056 * \see KAction::registerGlobalShortcut() 0057 */ 0058 QAction *addAction(const QString &id, const QString &text, const QKeySequence &shortcut); 0059 0060 /** 0061 * Remove a action from the collection. 0062 * 0063 * \param id Persistent id for the action 0064 * 0065 * \return The action or 0 if not found. 0066 */ 0067 QAction *getAction(const QString &id); 0068 0069 /** 0070 * Remove a action from the collection. 0071 * 0072 * \param id Persistent id for the action 0073 * 0074 * \return true if the action was removed. 0075 */ 0076 bool removeAction(const QString &id); 0077 0078 /** 0079 * From Kbd. 0080 * 0081 * \warning Does nothing, returns false 0082 */ 0083 bool send_macro_key(const QKeySequence &key, Window window_P); 0084 0085 Q_SIGNALS: 0086 0087 /** 0088 * One of the actions shortcuts was changed. 0089 */ 0090 void shortcutChanged() const; 0091 0092 private: 0093 HandlerType _type; 0094 0095 KActionCollection *_actions; 0096 }; 0097 0098 } // namespace KHotKeys 0099 0100 #endif /* #ifndef SHORTCUTSHANDLER_H */