Browse Source

UI: Add support for property groups

Property groups are implemented in the UI using QGroupBox, which support
both the normal and checkable version of them.
Michael Fabian 'Xaymar' Dirks 6 năm trước cách đây
mục cha
commit
5c0c512fc2
2 tập tin đã thay đổi với 54 bổ sung1 xóa
  1. 51 1
      UI/properties-view.cpp
  2. 3 0
      UI/properties-view.hpp

+ 51 - 1
UI/properties-view.cpp

@@ -19,6 +19,7 @@
 #include <QMenu>
 #include <QStackedWidget>
 #include <QDir>
+#include <QGroupBox>
 #include "double-slider.hpp"
 #include "slider-ignorewheel.hpp"
 #include "spinBox-ignorewheel.hpp"
@@ -1332,6 +1333,44 @@ void OBSPropertiesView::AddFrameRate(obs_property_t *prop, bool &warning,
 	});
 }
 
+void OBSPropertiesView::AddGroup(obs_property_t *prop, QFormLayout *layout)
+{
+	const char *name = obs_property_name(prop);
+	bool val = obs_data_get_bool(settings, name);
+	const char *desc = obs_property_description(prop);
+	enum obs_group_type type = obs_property_group_type(prop);
+
+	// Create GroupBox
+	QGroupBox *groupBox = new QGroupBox(QT_UTF8(desc));
+	groupBox->setCheckable(type == OBS_GROUP_CHECKABLE);
+	groupBox->setChecked(groupBox->isCheckable() ? val : true);
+	groupBox->setAccessibleName("group");
+	groupBox->setEnabled(obs_property_enabled(prop));
+
+	// Create Layout and build content
+	QFormLayout *subLayout = new QFormLayout();
+	subLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
+	groupBox->setLayout(subLayout);
+
+	obs_properties_t *content = obs_property_group_content(prop);
+	obs_property_t *el = obs_properties_first(content);
+	while (el != nullptr) {
+		AddProperty(el, subLayout);
+		obs_property_next(&el);
+	}
+
+	// Insert into UI
+	layout->setWidget(layout->rowCount(),
+			QFormLayout::ItemRole::SpanningRole, groupBox);
+
+	// Register Group Widget
+	WidgetInfo *info = new WidgetInfo(this, prop, groupBox);
+	children.emplace_back(info);
+
+	// Signals
+	connect(groupBox, SIGNAL(toggled()), info, SLOT(ControlChanged()));
+}
+
 void OBSPropertiesView::AddProperty(obs_property_t *property,
 		QFormLayout *layout)
 {
@@ -1381,6 +1420,8 @@ void OBSPropertiesView::AddProperty(obs_property_t *property,
 	case OBS_PROPERTY_FRAME_RATE:
 		AddFrameRate(property, warning, layout, label);
 		break;
+	case OBS_PROPERTY_GROUP:
+		AddGroup(property, layout);
 	}
 
 	if (widget && !obs_property_enabled(property))
@@ -1388,7 +1429,8 @@ void OBSPropertiesView::AddProperty(obs_property_t *property,
 
 	if (!label &&
 	    type != OBS_PROPERTY_BOOL &&
-	    type != OBS_PROPERTY_BUTTON)
+	    type != OBS_PROPERTY_BUTTON &&
+	    type != OBS_PROPERTY_GROUP)
 		label = new QLabel(QT_UTF8(obs_property_description(property)));
 
 	if (warning && label) //TODO: select color based on background color
@@ -1707,6 +1749,13 @@ bool WidgetInfo::FontChanged(const char *setting)
 	return true;
 }
 
+void WidgetInfo::GroupChanged(const char *setting)
+{
+	QGroupBox *groupbox = static_cast<QGroupBox*>(widget);
+	obs_data_set_bool(view->settings, setting,
+		groupbox->isCheckable() ? groupbox->isChecked() : true);
+}
+
 void WidgetInfo::EditableListChanged()
 {
 	const char *setting = obs_property_name(property);
@@ -1776,6 +1825,7 @@ void WidgetInfo::ControlChanged()
 		if (!FrameRateChanged(widget, setting, view->settings))
 			return;
 		break;
+	case OBS_PROPERTY_GROUP:  GroupChanged(setting); return;
 	}
 
 	if (view->callback && !view->deferUpdate)

+ 3 - 0
UI/properties-view.hpp

@@ -33,6 +33,7 @@ private:
 	void ListChanged(const char *setting);
 	bool ColorChanged(const char *setting);
 	bool FontChanged(const char *setting);
+	void GroupChanged(const char *setting);
 	void EditableListChanged();
 	void ButtonClicked();
 
@@ -103,6 +104,8 @@ private:
 	void AddFrameRate(obs_property_t *prop, bool &warning,
 			QFormLayout *layout, QLabel *&label);
 
+	void AddGroup(obs_property_t *prop, QFormLayout *layout);
+
 	void AddProperty(obs_property_t *property, QFormLayout *layout);
 
 	void resizeEvent(QResizeEvent *event) override;