OBSHotkeyWidget.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "OBSHotkeyEdit.hpp"
  16. #include <QPointer>
  17. #include <QPushButton>
  18. #include <QVBoxLayout>
  19. #include <QWidget>
  20. class OBSBasicSettings;
  21. class OBSHotkeyLabel;
  22. class OBSHotkeyWidget : public QWidget {
  23. Q_OBJECT;
  24. public:
  25. OBSHotkeyWidget(QWidget *parent, obs_hotkey_id id, std::string name, OBSBasicSettings *settings,
  26. const std::vector<obs_key_combination_t> &combos = {})
  27. : QWidget(parent),
  28. id(id),
  29. name(name),
  30. bindingsChanged(obs_get_signal_handler(), "hotkey_bindings_changed",
  31. &OBSHotkeyWidget::BindingsChanged, this),
  32. settings(settings)
  33. {
  34. auto layout = new QVBoxLayout;
  35. layout->setSpacing(0);
  36. layout->setContentsMargins(0, 0, 0, 0);
  37. setLayout(layout);
  38. SetKeyCombinations(combos);
  39. }
  40. void SetKeyCombinations(const std::vector<obs_key_combination_t> &);
  41. obs_hotkey_id id;
  42. std::string name;
  43. bool changed = false;
  44. bool Changed() const;
  45. QPointer<OBSHotkeyLabel> label;
  46. std::vector<QPointer<OBSHotkeyEdit>> edits;
  47. QString toolTip;
  48. void setToolTip(const QString &toolTip_)
  49. {
  50. toolTip = toolTip_;
  51. for (auto &edit : edits)
  52. edit->setToolTip(toolTip_);
  53. }
  54. void Apply();
  55. void GetCombinations(std::vector<obs_key_combination_t> &) const;
  56. void Save();
  57. void Save(std::vector<obs_key_combination_t> &combinations);
  58. void enterEvent(QEnterEvent *event) override;
  59. void leaveEvent(QEvent *event) override;
  60. private:
  61. void AddEdit(obs_key_combination combo, int idx = -1);
  62. void RemoveEdit(size_t idx, bool signal = true);
  63. static void BindingsChanged(void *data, calldata_t *param);
  64. std::vector<QPointer<QPushButton>> removeButtons;
  65. std::vector<QPointer<QPushButton>> revertButtons;
  66. OBSSignal bindingsChanged;
  67. bool ignoreChangedBindings = false;
  68. OBSBasicSettings *settings;
  69. QVBoxLayout *layout() const { return dynamic_cast<QVBoxLayout *>(QWidget::layout()); }
  70. private slots:
  71. void HandleChangedBindings(obs_hotkey_id id_);
  72. signals:
  73. void KeyChanged();
  74. void SearchKey(obs_key_combination_t);
  75. };