浏览代码

shared/properties-view: Use IconLabel for help icon

Changes the icon rendering for the properties view "question mark" icon
from Qt label HTML to use the IconLabel widget. This makes the label
high DPI.
Unfortunately the properties view code is a complete nightmare and in a
way, this PR makes this worse by adding the "leftWidget" widget as a
placeholder for what the "normal" label used to be, but you can't easily
replace that label with the icon label (while retaining prior
modifications from other nightmare code) so here we are. The entire
thing needs to be burnt to the ground and be rebuilt from the ground up
but that's a task for another day.
gxalpha 1 年之前
父节点
当前提交
270cebe581
共有 2 个文件被更改,包括 54 次插入40 次删除
  1. 5 0
      shared/properties-view/CMakeLists.txt
  2. 49 40
      shared/properties-view/properties-view.cpp

+ 5 - 0
shared/properties-view/CMakeLists.txt

@@ -24,6 +24,10 @@ if(NOT TARGET OBS::qt-slider-ignorewheel)
   )
 endif()
 
+if(NOT TARGET OBS::qt-icon-label)
+  add_subdirectory("${CMAKE_SOURCE_DIR}/shared/qt/icon-label" "${CMAKE_BINARY_DIR}/shared/qt/icon-label")
+endif()
+
 add_library(properties-view INTERFACE)
 add_library(OBS::properties-view ALIAS properties-view)
 
@@ -53,6 +57,7 @@ target_link_libraries(
     OBS::qt-plain-text-edit
     OBS::qt-vertical-scroll-area
     OBS::qt-slider-ignorewheel
+    OBS::qt-icon-label
     Qt::Core
     Qt::Widgets
 )

+ 49 - 40
shared/properties-view/properties-view.cpp

@@ -33,6 +33,7 @@
 #include <qt-wrappers.hpp>
 #include <plain-text-edit.hpp>
 #include <slider-ignorewheel.hpp>
+#include <icon-label.hpp>
 #include <cstdlib>
 #include <initializer_list>
 #include <obs-data.h>
@@ -277,15 +278,46 @@ QWidget *OBSPropertiesView::AddCheckbox(obs_property_t *prop)
 {
 	const char *name = obs_property_name(prop);
 	const char *desc = obs_property_description(prop);
+	const char *long_desc = obs_property_long_description(prop);
 	bool val = obs_data_get_bool(settings, name);
 
 	QCheckBox *checkbox = new QCheckBox(QT_UTF8(desc));
 	checkbox->setCheckState(val ? Qt::Checked : Qt::Unchecked);
+
 #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
-	return NewWidget(prop, checkbox, &QCheckBox::checkStateChanged);
+	QWidget *widget =
+		NewWidget(prop, checkbox, &QCheckBox::checkStateChanged);
 #else
-	return NewWidget(prop, checkbox, &QCheckBox::stateChanged);
+	QWidget *widget = NewWidget(prop, checkbox, &QCheckBox::stateChanged);
 #endif
+
+	if (!long_desc) {
+		return widget;
+	}
+
+	QString file = !obs_frontend_is_theme_dark()
+			       ? ":/res/images/help.svg"
+			       : ":/res/images/help_light.svg";
+
+	IconLabel *help = new IconLabel(checkbox);
+	help->setIcon(QIcon(file));
+	help->setToolTip(long_desc);
+
+#ifdef __APPLE__
+	checkbox->setAttribute(Qt::WA_LayoutUsesWidgetRect);
+#endif
+
+	widget = new QWidget();
+	QHBoxLayout *layout = new QHBoxLayout(widget);
+	layout->setContentsMargins(0, 0, 0, 0);
+	layout->setAlignment(Qt::AlignLeft);
+	layout->setSpacing(0);
+
+	layout->addWidget(checkbox);
+	layout->addWidget(help);
+	widget->setLayout(layout);
+
+	return widget;
 }
 
 QWidget *OBSPropertiesView::AddText(obs_property_t *prop, QFormLayout *layout,
@@ -1625,53 +1657,30 @@ void OBSPropertiesView::AddProperty(obs_property_t *property,
 	if (!obs_property_enabled(property))
 		widget->setEnabled(false);
 
-	if (obs_property_long_description(property)) {
+	QWidget *leftWidget = label;
+	if (obs_property_long_description(property) && label) {
 		QString file = !obs_frontend_is_theme_dark()
 				       ? ":/res/images/help.svg"
 				       : ":/res/images/help_light.svg";
-		if (label) {
-			QString lStr = "<html>%1 <img src='%2' style=' \
-				vertical-align: bottom;  \
-				' /></html>";
-
-			label->setText(lStr.arg(label->text(), file));
-			label->setToolTip(
-				obs_property_long_description(property));
-		} else if (type == OBS_PROPERTY_BOOL) {
-
-			QString bStr = "<html> <img src='%1' style=' \
-				vertical-align: bottom;  \
-				' /></html>";
 
-			const char *desc = obs_property_description(property);
+		QWidget *newWidget = new QWidget();
+		newWidget->setToolTip(obs_property_long_description(property));
 
-			QWidget *newWidget = new QWidget();
+		QHBoxLayout *boxLayout = new QHBoxLayout(newWidget);
+		boxLayout->setContentsMargins(0, 0, 0, 0);
+		boxLayout->setAlignment(Qt::AlignLeft);
+		boxLayout->setSpacing(0);
 
-			QHBoxLayout *boxLayout = new QHBoxLayout(newWidget);
-			boxLayout->setContentsMargins(0, 0, 0, 0);
-			boxLayout->setAlignment(Qt::AlignLeft);
-			boxLayout->setSpacing(0);
+		IconLabel *help = new IconLabel(newWidget);
+		help->setIcon(QIcon(file));
+		help->setToolTip(obs_property_long_description(property));
 
-			QCheckBox *check = qobject_cast<QCheckBox *>(widget);
-			check->setText(desc);
-			check->setToolTip(
-				obs_property_long_description(property));
-#ifdef __APPLE__
-			check->setAttribute(Qt::WA_LayoutUsesWidgetRect);
-#endif
-
-			QLabel *help = new QLabel(check);
-			help->setText(bStr.arg(file));
-			help->setToolTip(
-				obs_property_long_description(property));
-
-			boxLayout->addWidget(check);
-			boxLayout->addWidget(help);
-			widget = newWidget;
-		}
+		boxLayout->addWidget(label);
+		boxLayout->addWidget(help);
+		leftWidget = newWidget;
 	}
 
-	layout->addRow(label, widget);
+	layout->addRow(leftWidget, widget);
 
 	if (!lastFocused.empty())
 		if (lastFocused.compare(name) == 0)