提交 cce2eb93 编写于 作者: J jp9000

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.
上级 5cb89165
......@@ -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"
......
......@@ -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);
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册