Improve the properties API so that it can actually respond somewhat to user input. Maybe later this might be further improved or replaced with something script-based. When creating a property, you can now add a callback to that property that notifies when the property has been changed in the user interface. Return true if you want the properties to be refreshed, or false if not. Though now that I think about it I doubt there would ever be a case where you would have this callback and *not* refresh the properties. Regardless, this allows functions to change the values of properties or settings, or enable/disable/hide other property controls from view dynamically.
80 lines
2.0 KiB
C++
80 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <QScrollArea>
|
|
#include <obs.hpp>
|
|
#include <vector>
|
|
#include <memory>
|
|
|
|
class QFormLayout;
|
|
class OBSPropertiesView;
|
|
|
|
typedef void (*PropertiesUpdateCallback)(void *obj, obs_data_t settings);
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
class WidgetInfo : public QObject {
|
|
Q_OBJECT
|
|
|
|
private:
|
|
OBSPropertiesView *view;
|
|
obs_property_t property;
|
|
QWidget *widget;
|
|
|
|
void BoolChanged(const char *setting);
|
|
void IntChanged(const char *setting);
|
|
void FloatChanged(const char *setting);
|
|
void TextChanged(const char *setting);
|
|
void PathChanged(const char *setting);
|
|
void ListChanged(const char *setting);
|
|
void ColorChanged(const char *setting);
|
|
|
|
public:
|
|
inline WidgetInfo(OBSPropertiesView *view_, obs_property_t prop,
|
|
QWidget *widget_)
|
|
: view(view_), property(prop), widget(widget_)
|
|
{}
|
|
|
|
public slots:
|
|
void ControlChanged();
|
|
};
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
class OBSPropertiesView : public QScrollArea {
|
|
Q_OBJECT
|
|
|
|
friend class WidgetInfo;
|
|
|
|
private:
|
|
QWidget *widget;
|
|
obs_properties_t properties;
|
|
OBSData settings;
|
|
void *obj;
|
|
PropertiesUpdateCallback callback;
|
|
std::vector<std::unique_ptr<WidgetInfo>> children;
|
|
|
|
void RefreshProperties();
|
|
|
|
QWidget *NewWidget(obs_property_t prop, QWidget *widget,
|
|
const char *signal);
|
|
|
|
QWidget *AddCheckbox(obs_property_t prop);
|
|
QWidget *AddText(obs_property_t prop);
|
|
QWidget *AddPath(obs_property_t prop, QFormLayout *layout);
|
|
QWidget *AddInt(obs_property_t prop);
|
|
QWidget *AddFloat(obs_property_t prop);
|
|
QWidget *AddList(obs_property_t prop);
|
|
|
|
void AddProperty(obs_property_t property, QFormLayout *layout);
|
|
|
|
public:
|
|
OBSPropertiesView(OBSData settings,
|
|
obs_properties_t properties,
|
|
void *obj, PropertiesUpdateCallback callback);
|
|
|
|
inline ~OBSPropertiesView()
|
|
{
|
|
obs_properties_destroy(properties);
|
|
}
|
|
};
|