Kaynağa Gözat

UI: Add "Show" button to password text properties

Allows the user to be able to optionally toggle the password text if
they wish.  Mostly useful for troubleshooting purposes.
jp9000 10 yıl önce
ebeveyn
işleme
cce2eb9387
3 değiştirilmiş dosya ile 39 ekleme ve 6 silme
  1. 1 0
      obs/data/locale/en-US.ini
  2. 31 5
      obs/properties-view.cpp
  3. 7 1
      obs/properties-view.hpp

+ 1 - 0
obs/data/locale/en-US.ini

@@ -37,6 +37,7 @@ SceneProjector="Fullscreen Projector (Scene)"
 SourceProjector="Fullscreen Projector (Source)"
 Clear="Clear"
 Revert="Revert"
+Show="Show"
 
 # "name already exists" dialog box
 NameExists.Title="Name already exists"

+ 31 - 5
obs/properties-view.cpp

@@ -184,7 +184,8 @@ QWidget *OBSPropertiesView::AddCheckbox(obs_property_t *prop)
 	return NewWidget(prop, checkbox, SIGNAL(stateChanged(int)));
 }
 
-QWidget *OBSPropertiesView::AddText(obs_property_t *prop)
+QWidget *OBSPropertiesView::AddText(obs_property_t *prop, QFormLayout *layout,
+		QLabel *&label)
 {
 	const char    *name = obs_property_name(prop);
 	const char    *val  = obs_data_get_string(settings, name);
@@ -193,13 +194,32 @@ QWidget *OBSPropertiesView::AddText(obs_property_t *prop)
 	if (type == OBS_TEXT_MULTILINE) {
 		QPlainTextEdit *edit = new QPlainTextEdit(QT_UTF8(val));
 		return NewWidget(prop, edit, SIGNAL(textChanged()));
-	}
 
-	QLineEdit *edit = new QLineEdit();
+	} else if (type == OBS_TEXT_PASSWORD) {
+		QLayout *subLayout = new QHBoxLayout();
+		QLineEdit *edit = new QLineEdit();
+		QPushButton *show = new QPushButton();
 
-	if (type == OBS_TEXT_PASSWORD)
+		show->setText(QTStr("Show"));
+		show->setCheckable(true);
+		edit->setText(QT_UTF8(val));
 		edit->setEchoMode(QLineEdit::Password);
 
+		subLayout->addWidget(edit);
+		subLayout->addWidget(show);
+
+		WidgetInfo *info = new WidgetInfo(this, prop, edit);
+		connect(show, &QAbstractButton::toggled,
+				info, &WidgetInfo::TogglePasswordText);
+		children.emplace_back(info);
+
+		label = new QLabel(QT_UTF8(obs_property_description(prop)));
+		layout->addRow(label, subLayout);
+		return nullptr;
+	}
+
+	QLineEdit *edit = new QLineEdit();
+
 	edit->setText(QT_UTF8(val));
 
 	return NewWidget(prop, edit, SIGNAL(textEdited(const QString &)));
@@ -571,7 +591,7 @@ void OBSPropertiesView::AddProperty(obs_property_t *property,
 		AddFloat(property, layout, &label);
 		break;
 	case OBS_PROPERTY_TEXT:
-		widget = AddText(property);
+		widget = AddText(property, layout, label);
 		break;
 	case OBS_PROPERTY_PATH:
 		AddPath(property, layout, &label);
@@ -794,6 +814,12 @@ void WidgetInfo::ButtonClicked()
 	}
 }
 
+void WidgetInfo::TogglePasswordText(bool show)
+{
+	reinterpret_cast<QLineEdit*>(widget)->setEchoMode(
+			show ? QLineEdit::Normal : QLineEdit::Password);
+}
+
 void WidgetInfo::ControlChanged()
 {
 	const char        *setting = obs_property_name(property);

+ 7 - 1
obs/properties-view.hpp

@@ -18,6 +18,8 @@ typedef void              (*PropertiesUpdateCallback)(void *obj,
 class WidgetInfo : public QObject {
 	Q_OBJECT
 
+	friend class OBSPropertiesView;
+
 private:
 	OBSPropertiesView *view;
 	obs_property_t    *property;
@@ -33,6 +35,8 @@ private:
 	bool FontChanged(const char *setting);
 	void ButtonClicked();
 
+	void TogglePasswordText(bool checked);
+
 public:
 	inline WidgetInfo(OBSPropertiesView *view_, obs_property_t *prop,
 			QWidget *widget_)
@@ -40,6 +44,7 @@ public:
 	{}
 
 public slots:
+
 	void ControlChanged();
 };
 
@@ -72,7 +77,8 @@ private:
 			const char *signal);
 
 	QWidget *AddCheckbox(obs_property_t *prop);
-	QWidget *AddText(obs_property_t *prop);
+	QWidget *AddText(obs_property_t *prop, QFormLayout *layout,
+			QLabel *&label);
 	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,