1 #ifndef CSM_PREFS_SHORTCUT_H 2 #define CSM_PREFS_SHORTCUT_H 3 4 #include <string> 5 6 #include <QKeySequence> 7 #include <QObject> 8 #include <QString> 9 10 class QAction; 11 class QWidget; 12 13 namespace CSMPrefs 14 { 15 /// A class similar in purpose to QShortcut, but with the ability to use mouse buttons 16 class Shortcut : public QObject 17 { 18 Q_OBJECT 19 20 public: 21 22 enum ActivationStatus 23 { 24 AS_Regular, 25 AS_Secondary, 26 AS_Inactive 27 }; 28 29 enum SecondaryMode 30 { 31 SM_Replace, ///< The secondary signal replaces the regular signal when the modifier is active 32 SM_Detach, ///< The secondary signal is emitted independent of the regular signal, even if not active 33 SM_Ignore ///< The secondary signal will not ever be emitted 34 }; 35 36 Shortcut(const std::string& name, QWidget* parent); 37 Shortcut(const std::string& name, const std::string& modName, QWidget* parent); 38 Shortcut(const std::string& name, const std::string& modName, SecondaryMode secMode, QWidget* parent); 39 40 ~Shortcut(); 41 42 bool isEnabled() const; 43 44 const std::string& getName() const; 45 const std::string& getModifierName() const; 46 47 SecondaryMode getSecondaryMode() const; 48 49 const QKeySequence& getSequence() const; 50 int getModifier() const; 51 52 /// The position in the sequence 53 int getPosition() const; 54 /// The position in the sequence 55 int getLastPosition() const; 56 57 ActivationStatus getActivationStatus() const; 58 bool getModifierStatus() const; 59 60 void enable(bool state); 61 62 void setSequence(const QKeySequence& sequence); 63 void setModifier(int modifier); 64 65 /// The position in the sequence 66 void setPosition(int pos); 67 68 void setActivationStatus(ActivationStatus status); 69 void setModifierStatus(bool status); 70 71 /// Appends the sequence to the QAction text, also keeps it up to date 72 void associateAction(QAction* action); 73 74 // Workaround for Qt4 signals being "protected" 75 void signalActivated(bool state); 76 void signalActivated(); 77 78 void signalSecondary(bool state); 79 void signalSecondary(); 80 81 QString toString() const; 82 83 private: 84 85 bool mEnabled; 86 87 std::string mName; 88 std::string mModName; 89 SecondaryMode mSecondaryMode; 90 QKeySequence mSequence; 91 int mModifier; 92 93 int mCurrentPos; 94 int mLastPos; 95 96 ActivationStatus mActivationStatus; 97 bool mModifierStatus; 98 99 QAction* mAction; 100 QString mActionText; 101 102 private slots: 103 104 void actionDeleted(); 105 106 signals: 107 108 /// Triggered when the shortcut is activated or deactivated; can be determined from \p state 109 void activated(bool state); 110 111 /// Convenience signal. 112 void activated(); 113 114 /// Triggered depending on SecondaryMode 115 void secondary(bool state); 116 117 /// Convenience signal. 118 void secondary(); 119 }; 120 } 121 122 #endif 123