diff --git a/lib/legacy/scene-group.cpp b/lib/legacy/scene-group.cpp index 4004e4f7..c2c0429a 100644 --- a/lib/legacy/scene-group.cpp +++ b/lib/legacy/scene-group.cpp @@ -141,7 +141,7 @@ void AdvSceneSwitcher::on_sceneGroupAdd_clicked() placeHolderText = format.arg(++i); } - bool accepted = AdvSSNameDialog::AskForName( + bool accepted = NameDialog::AskForName( this, obs_module_text("AdvSceneSwitcher.sceneGroupTab.add"), obs_module_text("AdvSceneSwitcher.sceneGroupTab.add"), name, placeHolderText); diff --git a/lib/macro/macro-tab.cpp b/lib/macro/macro-tab.cpp index 5e193987..2615c5fa 100644 --- a/lib/macro/macro-tab.cpp +++ b/lib/macro/macro-tab.cpp @@ -67,7 +67,7 @@ bool AdvSceneSwitcher::AddNewMacro(std::shared_ptr &res, placeHolderText = fmt.arg(++i); } - bool accepted = AdvSSNameDialog::AskForName( + bool accepted = NameDialog::AskForName( this, obs_module_text("AdvSceneSwitcher.macroTab.add"), obs_module_text("AdvSceneSwitcher.macroTab.name"), name, placeHolderText); @@ -199,7 +199,7 @@ void AdvSceneSwitcher::RenameSelectedMacro() std::string oldName = macro->Name(); std::string name; - if (!AdvSSNameDialog::AskForName( + if (!NameDialog::AskForName( this, obs_module_text("AdvSceneSwitcher.windowTitle"), obs_module_text("AdvSceneSwitcher.item.newName"), name, QString::fromStdString(oldName))) { @@ -370,7 +370,7 @@ bool AdvSceneSwitcher::ResolveMacroImportNameConflict( } std::string newName; - bool accepted = AdvSSNameDialog::AskForName( + bool accepted = NameDialog::AskForName( this, obs_module_text(macro->IsGroup() ? "AdvSceneSwitcher.macroTab.addGroup" @@ -956,7 +956,7 @@ static void handleCustomLabelChange(MacroSegmentEdit *segmentEdit, } std::string label; - bool accepted = AdvSSNameDialog::AskForName( + bool accepted = NameDialog::AskForName( GetSettingsWindow(), obs_module_text( "AdvSceneSwitcher.macroTab.segment.setCustomLabel"), diff --git a/lib/utils/item-selection-helpers.cpp b/lib/utils/item-selection-helpers.cpp index 49f50017..10400bbd 100644 --- a/lib/utils/item-selection-helpers.cpp +++ b/lib/utils/item-selection-helpers.cpp @@ -177,7 +177,7 @@ void ItemSelection::RenameItem() Item *item = variant.value(); std::string name; - bool accepted = AdvSSNameDialog::AskForName( + bool accepted = NameDialog::AskForName( this, obs_module_text("AdvSceneSwitcher.windowTitle"), obs_module_text("AdvSceneSwitcher.item.newName"), name, QString::fromStdString(item->Name())); diff --git a/lib/utils/name-dialog.cpp b/lib/utils/name-dialog.cpp index 8d3993b9..0fac5614 100644 --- a/lib/utils/name-dialog.cpp +++ b/lib/utils/name-dialog.cpp @@ -5,22 +5,22 @@ namespace advss { -AdvSSNameDialog::AdvSSNameDialog(QWidget *parent) : QDialog(parent) +NameDialog::NameDialog(QWidget *parent) + : QDialog(parent), + _label(new QLabel(this)), + _userText(new QLineEdit(this)) + { setModal(true); setWindowModality(Qt::WindowModality::WindowModal); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setFixedWidth(555); setMinimumHeight(100); - QVBoxLayout *layout = new QVBoxLayout; + auto layout = new QVBoxLayout; setLayout(layout); - label = new QLabel(this); - layout->addWidget(label); - label->setText("Set Text"); - - userText = new QLineEdit(this); - layout->addWidget(userText); + layout->addWidget(_label); + layout->addWidget(_userText); QDialogButtonBox *buttonbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel); @@ -30,43 +30,44 @@ AdvSSNameDialog::AdvSSNameDialog(QWidget *parent) : QDialog(parent) connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject); } -static bool IsWhitespace(char ch) +static bool isWhitespace(char ch) { return ch == ' ' || ch == '\t'; } -static void CleanWhitespace(std::string &str) +static void cleanWhitespace(std::string &str) { - while (str.size() && IsWhitespace(str.back())) + while (str.size() && isWhitespace(str.back())) { str.erase(str.end() - 1); - while (str.size() && IsWhitespace(str.front())) + } + while (str.size() && isWhitespace(str.front())) { str.erase(str.begin()); + } } -bool AdvSSNameDialog::AskForName(QWidget *parent, const QString &title, - const QString &text, - std::string &userTextInput, - const QString &placeHolder, int maxSize, - bool clean) +bool NameDialog::AskForName(QWidget *parent, const QString &title, + const QString &prompt, std::string &userTextInput, + const QString &placeHolder, int maxSize, bool clean) { if (maxSize <= 0 || maxSize > 32767) { maxSize = 170; } - AdvSSNameDialog dialog(parent); + NameDialog dialog(parent); dialog.setWindowTitle(title); - dialog.label->setText(text); - dialog.userText->setMaxLength(maxSize); - dialog.userText->setText(placeHolder); - dialog.userText->selectAll(); + dialog._label->setVisible(!prompt.isEmpty()); + dialog._label->setText(prompt); + dialog._userText->setMaxLength(maxSize); + dialog._userText->setText(placeHolder); + dialog._userText->selectAll(); if (dialog.exec() != DialogCode::Accepted) { return false; } - userTextInput = dialog.userText->text().toUtf8().constData(); + userTextInput = dialog._userText->text().toUtf8().constData(); if (clean) { - CleanWhitespace(userTextInput); + cleanWhitespace(userTextInput); } return true; } diff --git a/lib/utils/name-dialog.hpp b/lib/utils/name-dialog.hpp index 67570cd4..f53ecbd2 100644 --- a/lib/utils/name-dialog.hpp +++ b/lib/utils/name-dialog.hpp @@ -8,23 +8,23 @@ namespace advss { // Based on OBS's NameDialog -class AdvSSNameDialog : public QDialog { +class NameDialog : public QDialog { Q_OBJECT public: - AdvSSNameDialog(QWidget *parent); + NameDialog(QWidget *parent); // Returns true if user clicks OK, false otherwise // userTextInput returns string that user typed into dialog EXPORT static bool AskForName(QWidget *parent, const QString &title, - const QString &text, + const QString &prompt, std::string &userTextInput, const QString &placeHolder = QString(""), int maxSize = 170, bool clean = true); private: - QLabel *label; - QLineEdit *userText; + QLabel *_label; + QLineEdit *_userText; }; } // namespace advss diff --git a/plugins/base/utils/string-list.cpp b/plugins/base/utils/string-list.cpp index fdc29ba0..3885ca8e 100644 --- a/plugins/base/utils/string-list.cpp +++ b/plugins/base/utils/string-list.cpp @@ -137,9 +137,9 @@ void StringListEdit::showEvent(QShowEvent *e) void StringListEdit::Add() { std::string name; - bool accepted = AdvSSNameDialog::AskForName(this, _addString, - _addStringDescription, name, - "", _maxStringSize, false); + bool accepted = NameDialog::AskForName(this, _addString, + _addStringDescription, name, "", + _maxStringSize, false); if (!accepted || (!_allowEmpty && name.empty())) { return; @@ -205,10 +205,10 @@ void StringListEdit::Down() void StringListEdit::Clicked(QListWidgetItem *item) { std::string name; - bool accepted = AdvSSNameDialog::AskForName(this, _addString, - _addStringDescription, name, - item->text(), - _maxStringSize, false); + bool accepted = NameDialog::AskForName(this, _addString, + _addStringDescription, name, + item->text(), _maxStringSize, + false); if (!accepted || (!_allowEmpty && name.empty())) { return; diff --git a/plugins/twitch/category-selection.cpp b/plugins/twitch/category-selection.cpp index b6a195f0..61eaf705 100644 --- a/plugins/twitch/category-selection.cpp +++ b/plugins/twitch/category-selection.cpp @@ -314,7 +314,7 @@ void TwitchCategorySearchButton::SetToken( void TwitchCategorySearchButton::StartManualCategorySearch() { std::string category; - bool accepted = AdvSSNameDialog::AskForName( + bool accepted = NameDialog::AskForName( this, obs_module_text("AdvSceneSwitcher.twitchCategories.search"), obs_module_text("AdvSceneSwitcher.twitchCategories.name"),