Pārlūkot izejas kodu

Highlight label in properties-view when a disabled list item is selected

Palana 11 gadi atpakaļ
vecāks
revīzija
b5f56ff579
2 mainītis faili ar 11 papildinājumiem un 3 dzēšanām
  1. 10 2
      obs/properties-view.cpp
  2. 1 1
      obs/properties-view.hpp

+ 10 - 2
obs/properties-view.cpp

@@ -172,7 +172,7 @@ static void AddComboItem(QComboBox *combo, obs_property_t prop,
 	item->setFlags(Qt::NoItemFlags);
 }
 
-QWidget *OBSPropertiesView::AddList(obs_property_t prop)
+QWidget *OBSPropertiesView::AddList(obs_property_t prop, bool &warning)
 {
 	const char       *name  = obs_property_name(prop);
 	QComboBox        *combo = new QComboBox();
@@ -213,6 +213,10 @@ QWidget *OBSPropertiesView::AddList(obs_property_t prop)
 	if (idx != -1)
 		combo->setCurrentIndex(idx);
 
+	QAbstractItemModel *model = combo->model();
+	warning = idx != -1 &&
+		model->flags(model->index(idx, 0)) == Qt::NoItemFlags;
+
 	WidgetInfo *info = new WidgetInfo(this, prop, combo);
 	connect(combo, SIGNAL(currentIndexChanged(int)), info,
 				SLOT(ControlChanged()));
@@ -244,6 +248,7 @@ void OBSPropertiesView::AddProperty(obs_property_t property,
 		return;
 
 	QWidget *widget = nullptr;
+	bool    warning = false;
 
 	switch (type) {
 	case OBS_PROPERTY_INVALID:
@@ -264,7 +269,7 @@ void OBSPropertiesView::AddProperty(obs_property_t property,
 		AddPath(property, layout);
 		break;
 	case OBS_PROPERTY_LIST:
-		widget = AddList(property);
+		widget = AddList(property, warning);
 		break;
 	case OBS_PROPERTY_COLOR:
 		/* TODO */
@@ -285,6 +290,9 @@ void OBSPropertiesView::AddProperty(obs_property_t property,
 	    type != OBS_PROPERTY_BUTTON)
 		label = new QLabel(QT_UTF8(obs_property_description(property)));
 
+	if (warning && label) //TODO: select color based on background color
+		label->setStyleSheet("QLabel { color: red; }");
+
 	if (label && minSize) {
 		label->setMinimumWidth(minSize);
 		label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

+ 1 - 1
obs/properties-view.hpp

@@ -65,7 +65,7 @@ private:
 	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);
+	QWidget *AddList(obs_property_t prop, bool &warning);
 	QWidget *AddButton(obs_property_t prop);
 
 	void AddProperty(obs_property_t property, QFormLayout *layout);