properties-view.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. #include "vertical-scroll-area.hpp"
  3. #include <obs.hpp>
  4. #include <vector>
  5. #include <memory>
  6. class QFormLayout;
  7. class OBSPropertiesView;
  8. class QLabel;
  9. typedef obs_properties_t *(*PropertiesReloadCallback)(void *obj);
  10. typedef void (*PropertiesUpdateCallback)(void *obj,
  11. obs_data_t *settings);
  12. /* ------------------------------------------------------------------------- */
  13. class WidgetInfo : public QObject {
  14. Q_OBJECT
  15. friend class OBSPropertiesView;
  16. private:
  17. OBSPropertiesView *view;
  18. obs_property_t *property;
  19. QWidget *widget;
  20. void BoolChanged(const char *setting);
  21. void IntChanged(const char *setting);
  22. void FloatChanged(const char *setting);
  23. void TextChanged(const char *setting);
  24. bool PathChanged(const char *setting);
  25. void ListChanged(const char *setting);
  26. bool ColorChanged(const char *setting);
  27. bool FontChanged(const char *setting);
  28. void GroupChanged(const char *setting);
  29. void EditableListChanged();
  30. void ButtonClicked();
  31. void TogglePasswordText(bool checked);
  32. public:
  33. inline WidgetInfo(OBSPropertiesView *view_, obs_property_t *prop,
  34. QWidget *widget_)
  35. : view(view_), property(prop), widget(widget_)
  36. {}
  37. public slots:
  38. void ControlChanged();
  39. /* editable list */
  40. void EditListAdd();
  41. void EditListAddText();
  42. void EditListAddFiles();
  43. void EditListAddDir();
  44. void EditListRemove();
  45. void EditListEdit();
  46. void EditListUp();
  47. void EditListDown();
  48. };
  49. /* ------------------------------------------------------------------------- */
  50. class OBSPropertiesView : public VScrollArea {
  51. Q_OBJECT
  52. friend class WidgetInfo;
  53. using properties_delete_t = decltype(&obs_properties_destroy);
  54. using properties_t =
  55. std::unique_ptr<obs_properties_t, properties_delete_t>;
  56. private:
  57. QWidget *widget = nullptr;
  58. properties_t properties;
  59. OBSData settings;
  60. void *obj = nullptr;
  61. std::string type;
  62. PropertiesReloadCallback reloadCallback;
  63. PropertiesUpdateCallback callback = nullptr;
  64. int minSize;
  65. std::vector<std::unique_ptr<WidgetInfo>> children;
  66. std::string lastFocused;
  67. QWidget *lastWidget = nullptr;
  68. bool deferUpdate;
  69. QWidget *NewWidget(obs_property_t *prop, QWidget *widget,
  70. const char *signal);
  71. QWidget *AddCheckbox(obs_property_t *prop);
  72. QWidget *AddText(obs_property_t *prop, QFormLayout *layout,
  73. QLabel *&label);
  74. void AddPath(obs_property_t *prop, QFormLayout *layout, QLabel **label);
  75. void AddInt(obs_property_t *prop, QFormLayout *layout, QLabel **label);
  76. void AddFloat(obs_property_t *prop, QFormLayout *layout,
  77. QLabel**label);
  78. QWidget *AddList(obs_property_t *prop, bool &warning);
  79. void AddEditableList(obs_property_t *prop, QFormLayout *layout,
  80. QLabel *&label);
  81. QWidget *AddButton(obs_property_t *prop);
  82. void AddColor(obs_property_t *prop, QFormLayout *layout, QLabel *&label);
  83. void AddFont(obs_property_t *prop, QFormLayout *layout, QLabel *&label);
  84. void AddFrameRate(obs_property_t *prop, bool &warning,
  85. QFormLayout *layout, QLabel *&label);
  86. void AddGroup(obs_property_t *prop, QFormLayout *layout);
  87. void AddProperty(obs_property_t *property, QFormLayout *layout);
  88. void resizeEvent(QResizeEvent *event) override;
  89. void GetScrollPos(int &h, int &v);
  90. void SetScrollPos(int h, int v);
  91. public slots:
  92. void ReloadProperties();
  93. void RefreshProperties();
  94. void SignalChanged();
  95. signals:
  96. void PropertiesResized();
  97. void Changed();
  98. public:
  99. OBSPropertiesView(OBSData settings, void *obj,
  100. PropertiesReloadCallback reloadCallback,
  101. PropertiesUpdateCallback callback,
  102. int minSize = 0);
  103. OBSPropertiesView(OBSData settings, const char *type,
  104. PropertiesReloadCallback reloadCallback,
  105. int minSize = 0);
  106. inline obs_data_t *GetSettings() const {return settings;}
  107. inline void UpdateSettings() {callback(obj, settings);}
  108. inline bool DeferUpdate() const {return deferUpdate;}
  109. };