properties-view.hpp 3.4 KB

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