properties-view.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 ButtonClicked();
  29. void TogglePasswordText(bool checked);
  30. public:
  31. inline WidgetInfo(OBSPropertiesView *view_, obs_property_t *prop,
  32. QWidget *widget_)
  33. : view(view_), property(prop), widget(widget_)
  34. {}
  35. public slots:
  36. void ControlChanged();
  37. };
  38. /* ------------------------------------------------------------------------- */
  39. class OBSPropertiesView : public VScrollArea {
  40. Q_OBJECT
  41. friend class WidgetInfo;
  42. using properties_delete_t = decltype(&obs_properties_destroy);
  43. using properties_t =
  44. std::unique_ptr<obs_properties_t, properties_delete_t>;
  45. private:
  46. QWidget *widget = nullptr;
  47. properties_t properties;
  48. OBSData settings;
  49. void *obj = nullptr;
  50. std::string type;
  51. PropertiesReloadCallback reloadCallback;
  52. PropertiesUpdateCallback callback = nullptr;
  53. int minSize;
  54. std::vector<std::unique_ptr<WidgetInfo>> children;
  55. std::string lastFocused;
  56. QWidget *lastWidget = nullptr;
  57. bool deferUpdate;
  58. QWidget *NewWidget(obs_property_t *prop, QWidget *widget,
  59. const char *signal);
  60. QWidget *AddCheckbox(obs_property_t *prop);
  61. QWidget *AddText(obs_property_t *prop, QFormLayout *layout,
  62. QLabel *&label);
  63. void AddPath(obs_property_t *prop, QFormLayout *layout, QLabel **label);
  64. void AddInt(obs_property_t *prop, QFormLayout *layout, QLabel **label);
  65. void AddFloat(obs_property_t *prop, QFormLayout *layout,
  66. QLabel**label);
  67. QWidget *AddList(obs_property_t *prop, bool &warning);
  68. QWidget *AddButton(obs_property_t *prop);
  69. void AddColor(obs_property_t *prop, QFormLayout *layout, QLabel *&label);
  70. void AddFont(obs_property_t *prop, QFormLayout *layout, QLabel *&label);
  71. void AddProperty(obs_property_t *property, QFormLayout *layout);
  72. void resizeEvent(QResizeEvent *event) override;
  73. void GetScrollPos(int &h, int &v);
  74. void SetScrollPos(int h, int v);
  75. public slots:
  76. void ReloadProperties();
  77. void RefreshProperties();
  78. void SignalChanged();
  79. signals:
  80. void PropertiesResized();
  81. void Changed();
  82. public:
  83. OBSPropertiesView(OBSData settings, void *obj,
  84. PropertiesReloadCallback reloadCallback,
  85. PropertiesUpdateCallback callback,
  86. int minSize = 0);
  87. OBSPropertiesView(OBSData settings, const char *type,
  88. PropertiesReloadCallback reloadCallback,
  89. int minSize = 0);
  90. inline obs_data_t *GetSettings() const {return settings;}
  91. inline void UpdateSettings() {callback(obj, settings);}
  92. inline bool DeferUpdate() const {return deferUpdate;}
  93. };