yolobs-studio/UI/properties-view.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
3.9 KiB
C++
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
#pragma once
#include "vertical-scroll-area.hpp"
#include <obs.hpp>
#include <vector>
#include <memory>
class QFormLayout;
class OBSPropertiesView;
class QLabel;
typedef obs_properties_t *(*PropertiesReloadCallback)(void *obj);
2019-09-22 21:19:10 +00:00
typedef void (*PropertiesUpdateCallback)(void *obj, obs_data_t *settings);
2016-02-23 23:16:51 +00:00
/* ------------------------------------------------------------------------- */
class WidgetInfo : public QObject {
Q_OBJECT
friend class OBSPropertiesView;
private:
OBSPropertiesView *view;
2019-09-22 21:19:10 +00:00
obs_property_t *property;
QWidget *widget;
2016-02-23 23:16:51 +00:00
void BoolChanged(const char *setting);
void IntChanged(const char *setting);
void FloatChanged(const char *setting);
void TextChanged(const char *setting);
bool PathChanged(const char *setting);
void ListChanged(const char *setting);
bool ColorChanged(const char *setting);
bool FontChanged(const char *setting);
2019-07-27 12:47:10 +00:00
void GroupChanged(const char *setting);
2016-02-23 23:16:51 +00:00
void EditableListChanged();
void ButtonClicked();
void TogglePasswordText(bool checked);
public:
inline WidgetInfo(OBSPropertiesView *view_, obs_property_t *prop,
2019-09-22 21:19:10 +00:00
QWidget *widget_)
2016-02-23 23:16:51 +00:00
: view(view_), property(prop), widget(widget_)
2019-09-22 21:19:10 +00:00
{
}
2016-02-23 23:16:51 +00:00
public slots:
void ControlChanged();
/* editable list */
void EditListAdd();
void EditListAddText();
void EditListAddFiles();
2016-08-28 12:07:43 +00:00
void EditListAddDir();
2016-02-23 23:16:51 +00:00
void EditListRemove();
void EditListEdit();
void EditListUp();
void EditListDown();
2020-10-01 20:15:25 +00:00
void EditListReordered(const QModelIndex &parent, int start, int end,
const QModelIndex &destination, int row);
2016-02-23 23:16:51 +00:00
};
/* ------------------------------------------------------------------------- */
class OBSPropertiesView : public VScrollArea {
Q_OBJECT
friend class WidgetInfo;
using properties_delete_t = decltype(&obs_properties_destroy);
using properties_t =
std::unique_ptr<obs_properties_t, properties_delete_t>;
private:
2019-09-22 21:19:10 +00:00
QWidget *widget = nullptr;
properties_t properties;
OBSData settings;
void *obj = nullptr;
std::string type;
PropertiesReloadCallback reloadCallback;
PropertiesUpdateCallback callback = nullptr;
int minSize;
2016-02-23 23:16:51 +00:00
std::vector<std::unique_ptr<WidgetInfo>> children;
2019-09-22 21:19:10 +00:00
std::string lastFocused;
QWidget *lastWidget = nullptr;
bool deferUpdate;
2016-02-23 23:16:51 +00:00
QWidget *NewWidget(obs_property_t *prop, QWidget *widget,
2019-09-22 21:19:10 +00:00
const char *signal);
2016-02-23 23:16:51 +00:00
QWidget *AddCheckbox(obs_property_t *prop);
QWidget *AddText(obs_property_t *prop, QFormLayout *layout,
2019-09-22 21:19:10 +00:00
QLabel *&label);
2016-02-23 23:16:51 +00:00
void AddPath(obs_property_t *prop, QFormLayout *layout, QLabel **label);
void AddInt(obs_property_t *prop, QFormLayout *layout, QLabel **label);
void AddFloat(obs_property_t *prop, QFormLayout *layout,
2019-09-22 21:19:10 +00:00
QLabel **label);
2016-02-23 23:16:51 +00:00
QWidget *AddList(obs_property_t *prop, bool &warning);
void AddEditableList(obs_property_t *prop, QFormLayout *layout,
2019-09-22 21:19:10 +00:00
QLabel *&label);
2016-02-23 23:16:51 +00:00
QWidget *AddButton(obs_property_t *prop);
2019-09-22 21:19:10 +00:00
void AddColor(obs_property_t *prop, QFormLayout *layout,
QLabel *&label);
2016-02-23 23:16:51 +00:00
void AddFont(obs_property_t *prop, QFormLayout *layout, QLabel *&label);
void AddFrameRate(obs_property_t *prop, bool &warning,
2019-09-22 21:19:10 +00:00
QFormLayout *layout, QLabel *&label);
2016-02-23 23:16:51 +00:00
2019-07-27 12:47:10 +00:00
void AddGroup(obs_property_t *prop, QFormLayout *layout);
2016-02-23 23:16:51 +00:00
void AddProperty(obs_property_t *property, QFormLayout *layout);
void resizeEvent(QResizeEvent *event) override;
void GetScrollPos(int &h, int &v);
void SetScrollPos(int h, int v);
public slots:
void ReloadProperties();
void RefreshProperties();
void SignalChanged();
signals:
void PropertiesResized();
void Changed();
2019-07-27 12:47:10 +00:00
void PropertiesRefreshed();
2016-02-23 23:16:51 +00:00
public:
OBSPropertiesView(OBSData settings, void *obj,
2019-09-22 21:19:10 +00:00
PropertiesReloadCallback reloadCallback,
PropertiesUpdateCallback callback, int minSize = 0);
2016-02-23 23:16:51 +00:00
OBSPropertiesView(OBSData settings, const char *type,
2019-09-22 21:19:10 +00:00
PropertiesReloadCallback reloadCallback,
int minSize = 0);
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
inline obs_data_t *GetSettings() const { return settings; }
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
inline void UpdateSettings() { callback(obj, settings); }
inline bool DeferUpdate() const { return deferUpdate; }
2016-02-23 23:16:51 +00:00
};