OBSHotkeyEdit.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /******************************************************************************
  2. Copyright (C) 2014-2015 by Ruwen Hahn <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <obs.hpp>
  16. #include <QLineEdit>
  17. class OBSBasicSettings;
  18. class QWidget;
  19. static inline bool operator!=(const obs_key_combination_t &c1, const obs_key_combination_t &c2)
  20. {
  21. return c1.modifiers != c2.modifiers || c1.key != c2.key;
  22. }
  23. static inline bool operator==(const obs_key_combination_t &c1, const obs_key_combination_t &c2)
  24. {
  25. return !(c1 != c2);
  26. }
  27. class OBSHotkeyEdit : public QLineEdit {
  28. Q_OBJECT;
  29. public:
  30. OBSHotkeyEdit(QWidget *parent, obs_key_combination_t original, OBSBasicSettings *settings)
  31. : QLineEdit(parent),
  32. original(original),
  33. settings(settings)
  34. {
  35. setAttribute(Qt::WA_InputMethodEnabled, false);
  36. setAttribute(Qt::WA_MacShowFocusRect, true);
  37. InitSignalHandler();
  38. ResetKey();
  39. }
  40. OBSHotkeyEdit(QWidget *parent = nullptr) : QLineEdit(parent), original({}), settings(nullptr)
  41. {
  42. setAttribute(Qt::WA_InputMethodEnabled, false);
  43. setAttribute(Qt::WA_MacShowFocusRect, true);
  44. InitSignalHandler();
  45. ResetKey();
  46. }
  47. obs_key_combination_t original;
  48. obs_key_combination_t key;
  49. OBSBasicSettings *settings;
  50. bool changed = false;
  51. void UpdateDuplicationState();
  52. bool hasDuplicate = false;
  53. QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
  54. protected:
  55. OBSSignal layoutChanged;
  56. QAction *dupeIcon = nullptr;
  57. void InitSignalHandler();
  58. void CreateDupeIcon();
  59. void keyPressEvent(QKeyEvent *event) override;
  60. #ifdef __APPLE__
  61. void keyReleaseEvent(QKeyEvent *event) override;
  62. #endif
  63. void mousePressEvent(QMouseEvent *event) override;
  64. void RenderKey();
  65. public slots:
  66. void HandleNewKey(obs_key_combination_t new_key);
  67. void ReloadKeyLayout();
  68. void ResetKey();
  69. void ClearKey();
  70. signals:
  71. void KeyChanged(obs_key_combination_t);
  72. void SearchKey(obs_key_combination_t);
  73. };