1
0

OBSHotkeyEdit.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <OBSApp.hpp>
  17. #include <QLineEdit>
  18. class OBSBasicSettings;
  19. class QWidget;
  20. static inline bool operator!=(const obs_key_combination_t &c1, const obs_key_combination_t &c2)
  21. {
  22. return c1.modifiers != c2.modifiers || c1.key != c2.key;
  23. }
  24. static inline bool operator==(const obs_key_combination_t &c1, const obs_key_combination_t &c2)
  25. {
  26. return !(c1 != c2);
  27. }
  28. class OBSHotkeyEdit : public QLineEdit {
  29. Q_OBJECT;
  30. public:
  31. OBSHotkeyEdit(QWidget *parent, obs_key_combination_t original, OBSBasicSettings *settings)
  32. : QLineEdit(parent),
  33. original(original),
  34. settings(settings)
  35. {
  36. setAttribute(Qt::WA_InputMethodEnabled, false);
  37. setAttribute(Qt::WA_MacShowFocusRect, true);
  38. setStyle(App()->GetInvisibleCursorStyle());
  39. InitSignalHandler();
  40. ResetKey();
  41. }
  42. OBSHotkeyEdit(QWidget *parent = nullptr) : QLineEdit(parent), original({}), settings(nullptr)
  43. {
  44. setAttribute(Qt::WA_InputMethodEnabled, false);
  45. setAttribute(Qt::WA_MacShowFocusRect, true);
  46. setStyle(App()->GetInvisibleCursorStyle());
  47. InitSignalHandler();
  48. ResetKey();
  49. }
  50. obs_key_combination_t original;
  51. obs_key_combination_t key;
  52. OBSBasicSettings *settings;
  53. bool changed = false;
  54. void UpdateDuplicationState();
  55. bool hasDuplicate = false;
  56. QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
  57. protected:
  58. OBSSignal layoutChanged;
  59. QAction *dupeIcon = nullptr;
  60. void InitSignalHandler();
  61. void CreateDupeIcon();
  62. void keyPressEvent(QKeyEvent *event) override;
  63. #ifdef __APPLE__
  64. void keyReleaseEvent(QKeyEvent *event) override;
  65. #endif
  66. void mousePressEvent(QMouseEvent *event) override;
  67. void RenderKey();
  68. public slots:
  69. void HandleNewKey(obs_key_combination_t new_key);
  70. void ReloadKeyLayout();
  71. void ResetKey();
  72. void ClearKey();
  73. signals:
  74. void KeyChanged(obs_key_combination_t);
  75. void SearchKey(obs_key_combination_t);
  76. };