浏览代码

UI: Use static function instead of macro to set color

Macros can be hard to read and are usually not very friendly to use in a
debugger. Using a static function instead gives the advantage of better
syntax highlighting in IDEs and better debugger support.
gxalpha 2 年之前
父节点
当前提交
b962daa3c8
共有 1 个文件被更改,包括 15 次插入16 次删除
  1. 15 16
      UI/window-basic-settings-a11y.cpp

+ 15 - 16
UI/window-basic-settings-a11y.cpp

@@ -133,26 +133,25 @@ void OBSBasicSettings::SaveA11ySettings()
 	main->RefreshVolumeColors();
 }
 
-#define SetStyle(label, colorVal)                                             \
-	color = color_from_int(colorVal);                                     \
-	color.setAlpha(255);                                                  \
-	palette = QPalette(color);                                            \
-	label->setFrameStyle(QFrame::Sunken | QFrame::Panel);                 \
-	label->setText(color.name(QColor::HexRgb));                           \
-	label->setPalette(palette);                                           \
-	label->setStyleSheet(QString("background-color: %1; color: %2;")      \
-				     .arg(palette.color(QPalette::Window)     \
-						  .name(QColor::HexRgb))      \
-				     .arg(palette.color(QPalette::WindowText) \
-						  .name(QColor::HexRgb)));    \
-	label->setAutoFillBackground(true);                                   \
+static void SetStyle(QLabel *label, uint32_t colorVal)
+{
+	QColor color = color_from_int(colorVal);
+	color.setAlpha(255);
+	QPalette palette = QPalette(color);
+	label->setFrameStyle(QFrame::Sunken | QFrame::Panel);
+	label->setText(color.name(QColor::HexRgb));
+	label->setPalette(palette);
+	label->setStyleSheet(QString("background-color: %1; color: %2;")
+				     .arg(palette.color(QPalette::Window)
+						  .name(QColor::HexRgb))
+				     .arg(palette.color(QPalette::WindowText)
+						  .name(QColor::HexRgb)));
+	label->setAutoFillBackground(true);
 	label->setAlignment(Qt::AlignCenter);
+}
 
 void OBSBasicSettings::UpdateA11yColors()
 {
-	QPalette palette;
-	QColor color;
-
 	SetStyle(ui->color1, selectRed);
 	SetStyle(ui->color2, selectGreen);
 	SetStyle(ui->color3, selectBlue);