qhotkey_p.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef QHOTKEY_P_H
  2. #define QHOTKEY_P_H
  3. #include "qhotkey.h"
  4. #include <QAbstractNativeEventFilter>
  5. #include <QGlobalStatic>
  6. #include <QMultiHash>
  7. #include <QMutex>
  8. class QHOTKEY_SHARED_EXPORT QHotkeyPrivate
  9. : public QObject
  10. , public QAbstractNativeEventFilter
  11. {
  12. Q_OBJECT
  13. public:
  14. QHotkeyPrivate(); // singleton!!!
  15. ~QHotkeyPrivate();
  16. static QHotkeyPrivate* instance();
  17. static bool isPlatformSupported();
  18. QHotkey::NativeShortcut nativeShortcut(Qt::Key keycode,
  19. Qt::KeyboardModifiers modifiers);
  20. bool addShortcut(QHotkey* hotkey);
  21. bool removeShortcut(QHotkey* hotkey);
  22. protected:
  23. void activateShortcut(QHotkey::NativeShortcut shortcut);
  24. void releaseShortcut(QHotkey::NativeShortcut shortcut);
  25. virtual quint32 nativeKeycode(Qt::Key keycode,
  26. bool& ok) = 0; // platform implement
  27. virtual quint32 nativeModifiers(Qt::KeyboardModifiers modifiers,
  28. bool& ok) = 0; // platform implement
  29. virtual bool registerShortcut(
  30. QHotkey::NativeShortcut shortcut) = 0; // platform implement
  31. virtual bool unregisterShortcut(
  32. QHotkey::NativeShortcut shortcut) = 0; // platform implement
  33. QString error;
  34. private:
  35. QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut>
  36. mapping;
  37. QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
  38. Q_INVOKABLE void addMappingInvoked(Qt::Key keycode,
  39. Qt::KeyboardModifiers modifiers,
  40. QHotkey::NativeShortcut nativeShortcut);
  41. Q_INVOKABLE bool addShortcutInvoked(QHotkey* hotkey);
  42. Q_INVOKABLE bool removeShortcutInvoked(QHotkey* hotkey);
  43. Q_INVOKABLE QHotkey::NativeShortcut nativeShortcutInvoked(
  44. Qt::Key keycode,
  45. Qt::KeyboardModifiers modifiers);
  46. };
  47. #define NATIVE_INSTANCE(ClassName) \
  48. Q_GLOBAL_STATIC(ClassName, hotkeyPrivate) \
  49. \
  50. QHotkeyPrivate* QHotkeyPrivate::instance() { return hotkeyPrivate; }
  51. Q_DECLARE_METATYPE(Qt::Key)
  52. Q_DECLARE_METATYPE(Qt::KeyboardModifiers)
  53. #endif // QHOTKEY_P_H