From 1f4c7cc22b2e152919f5f9e748ad718254d795c7 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 19 Jul 2020 09:30:00 -0400 Subject: [PATCH] Improve Password Generator Widget UI/UX * Fix #5098 - Ensure advanced mode settings are saved distinctly from simple mode settings * Make selected character groups pop out in the UI * Improve layout of character options --- src/gui/PasswordGeneratorWidget.cpp | 149 ++-- src/gui/PasswordGeneratorWidget.h | 4 +- src/gui/PasswordGeneratorWidget.ui | 1141 +++++++++++---------------- src/gui/styles/base/basestyle.qss | 5 + 4 files changed, 527 insertions(+), 772 deletions(-) diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index e1c15310f..78b65b400 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "core/Config.h" #include "core/PasswordGenerator.h" @@ -134,26 +135,25 @@ void PasswordGeneratorWidget::loadSettings() { // Password config m_ui->checkBoxLower->setChecked(config()->get(Config::PasswordGenerator_LowerCase).toBool()); - m_ui->checkBoxLowerAdv->setChecked(config()->get(Config::PasswordGenerator_LowerCase).toBool()); m_ui->checkBoxUpper->setChecked(config()->get(Config::PasswordGenerator_UpperCase).toBool()); - m_ui->checkBoxUpperAdv->setChecked(config()->get(Config::PasswordGenerator_UpperCase).toBool()); m_ui->checkBoxNumbers->setChecked(config()->get(Config::PasswordGenerator_Numbers).toBool()); - m_ui->checkBoxSpecialChars->setChecked(config()->get(Config::PasswordGenerator_SpecialChars).toBool()); - m_ui->checkBoxNumbersAdv->setChecked(config()->get(Config::PasswordGenerator_Numbers).toBool()); m_ui->editAdditionalChars->setText(config()->get(Config::PasswordGenerator_AdditionalChars).toString()); m_ui->editExcludedChars->setText(config()->get(Config::PasswordGenerator_ExcludedChars).toString()); - m_ui->buttonAdvancedMode->setChecked(config()->get(Config::PasswordGenerator_AdvancedMode).toBool()); - setAdvancedMode(m_ui->buttonAdvancedMode->isChecked()); + bool advanced = config()->get(Config::PasswordGenerator_AdvancedMode).toBool(); + if (advanced) { + m_ui->checkBoxSpecialChars->setChecked(config()->get(Config::PasswordGenerator_Logograms).toBool()); + } else { + m_ui->checkBoxSpecialChars->setChecked(config()->get(Config::PasswordGenerator_SpecialChars).toBool()); + } m_ui->checkBoxBraces->setChecked(config()->get(Config::PasswordGenerator_Braces).toBool()); m_ui->checkBoxQuotes->setChecked(config()->get(Config::PasswordGenerator_Quotes).toBool()); m_ui->checkBoxPunctuation->setChecked(config()->get(Config::PasswordGenerator_Punctuation).toBool()); m_ui->checkBoxDashes->setChecked(config()->get(Config::PasswordGenerator_Dashes).toBool()); m_ui->checkBoxMath->setChecked(config()->get(Config::PasswordGenerator_Math).toBool()); - m_ui->checkBoxLogograms->setChecked(config()->get(Config::PasswordGenerator_Logograms).toBool()); + m_ui->checkBoxExtASCII->setChecked(config()->get(Config::PasswordGenerator_EASCII).toBool()); - m_ui->checkBoxExtASCIIAdv->setChecked(config()->get(Config::PasswordGenerator_EASCII).toBool()); m_ui->checkBoxExcludeAlike->setChecked(config()->get(Config::PasswordGenerator_ExcludeAlike).toBool()); m_ui->checkBoxEnsureEvery->setChecked(config()->get(Config::PasswordGenerator_EnsureEvery).toBool()); m_ui->spinBoxLength->setValue(config()->get(Config::PasswordGenerator_Length).toInt()); @@ -166,30 +166,32 @@ void PasswordGeneratorWidget::loadSettings() // Password or diceware? m_ui->tabWidget->setCurrentIndex(config()->get(Config::PasswordGenerator_Type).toInt()); + + // Set advanced mode + m_ui->buttonAdvancedMode->setChecked(advanced); + setAdvancedMode(advanced); } void PasswordGeneratorWidget::saveSettings() { // Password config - if (m_ui->simpleBar->isVisible()) { - config()->set(Config::PasswordGenerator_LowerCase, m_ui->checkBoxLower->isChecked()); - config()->set(Config::PasswordGenerator_UpperCase, m_ui->checkBoxUpper->isChecked()); - config()->set(Config::PasswordGenerator_Numbers, m_ui->checkBoxNumbers->isChecked()); - config()->set(Config::PasswordGenerator_EASCII, m_ui->checkBoxExtASCII->isChecked()); - } else { - config()->set(Config::PasswordGenerator_LowerCase, m_ui->checkBoxLowerAdv->isChecked()); - config()->set(Config::PasswordGenerator_UpperCase, m_ui->checkBoxUpperAdv->isChecked()); - config()->set(Config::PasswordGenerator_Numbers, m_ui->checkBoxNumbersAdv->isChecked()); - config()->set(Config::PasswordGenerator_EASCII, m_ui->checkBoxExtASCIIAdv->isChecked()); - } + config()->set(Config::PasswordGenerator_LowerCase, m_ui->checkBoxLower->isChecked()); + config()->set(Config::PasswordGenerator_UpperCase, m_ui->checkBoxUpper->isChecked()); + config()->set(Config::PasswordGenerator_Numbers, m_ui->checkBoxNumbers->isChecked()); + config()->set(Config::PasswordGenerator_EASCII, m_ui->checkBoxExtASCII->isChecked()); + config()->set(Config::PasswordGenerator_AdvancedMode, m_ui->buttonAdvancedMode->isChecked()); - config()->set(Config::PasswordGenerator_SpecialChars, m_ui->checkBoxSpecialChars->isChecked()); + if (m_ui->buttonAdvancedMode->isChecked()) { + config()->set(Config::PasswordGenerator_SpecialChars, m_ui->checkBoxSpecialChars->isChecked()); + } else { + config()->set(Config::PasswordGenerator_Logograms, m_ui->checkBoxSpecialChars->isChecked()); + } config()->set(Config::PasswordGenerator_Braces, m_ui->checkBoxBraces->isChecked()); config()->set(Config::PasswordGenerator_Punctuation, m_ui->checkBoxPunctuation->isChecked()); config()->set(Config::PasswordGenerator_Quotes, m_ui->checkBoxQuotes->isChecked()); config()->set(Config::PasswordGenerator_Dashes, m_ui->checkBoxDashes->isChecked()); config()->set(Config::PasswordGenerator_Math, m_ui->checkBoxMath->isChecked()); - config()->set(Config::PasswordGenerator_Logograms, m_ui->checkBoxLogograms->isChecked()); + config()->set(Config::PasswordGenerator_AdditionalChars, m_ui->editAdditionalChars->text()); config()->set(Config::PasswordGenerator_ExcludedChars, m_ui->editExcludedChars->text()); config()->set(Config::PasswordGenerator_ExcludeAlike, m_ui->checkBoxExcludeAlike->isChecked()); @@ -321,41 +323,48 @@ bool PasswordGeneratorWidget::isPasswordVisible() const return m_ui->editNewPassword->isPasswordVisible(); } -void PasswordGeneratorWidget::setAdvancedMode(bool state) +void PasswordGeneratorWidget::setAdvancedMode(bool advanced) { - if (state) { - m_ui->simpleBar->hide(); - m_ui->advancedContainer->show(); - m_ui->checkBoxUpperAdv->setChecked(m_ui->checkBoxUpper->isChecked()); - m_ui->checkBoxLowerAdv->setChecked(m_ui->checkBoxLower->isChecked()); - m_ui->checkBoxNumbersAdv->setChecked(m_ui->checkBoxNumbers->isChecked()); - m_ui->checkBoxBraces->setChecked(m_ui->checkBoxSpecialChars->isChecked()); - m_ui->checkBoxPunctuation->setChecked(m_ui->checkBoxSpecialChars->isChecked()); - m_ui->checkBoxQuotes->setChecked(m_ui->checkBoxSpecialChars->isChecked()); - m_ui->checkBoxMath->setChecked(m_ui->checkBoxSpecialChars->isChecked()); - m_ui->checkBoxDashes->setChecked(m_ui->checkBoxSpecialChars->isChecked()); - m_ui->checkBoxLogograms->setChecked(m_ui->checkBoxSpecialChars->isChecked()); - m_ui->checkBoxExtASCIIAdv->setChecked(m_ui->checkBoxExtASCII->isChecked()); + saveSettings(); + + if (advanced) { + m_ui->checkBoxSpecialChars->setText("# $ % && @ ^ ` ~"); + m_ui->checkBoxSpecialChars->setToolTip(tr("Logograms")); + m_ui->checkBoxSpecialChars->setChecked(config()->get(Config::PasswordGenerator_Logograms).toBool()); } else { - m_ui->simpleBar->show(); - m_ui->advancedContainer->hide(); - m_ui->checkBoxUpper->setChecked(m_ui->checkBoxUpperAdv->isChecked()); - m_ui->checkBoxLower->setChecked(m_ui->checkBoxLowerAdv->isChecked()); - m_ui->checkBoxNumbers->setChecked(m_ui->checkBoxNumbersAdv->isChecked()); - m_ui->checkBoxSpecialChars->setChecked( - m_ui->checkBoxBraces->isChecked() | m_ui->checkBoxPunctuation->isChecked() - | m_ui->checkBoxQuotes->isChecked() | m_ui->checkBoxMath->isChecked() | m_ui->checkBoxDashes->isChecked() - | m_ui->checkBoxLogograms->isChecked()); - m_ui->checkBoxExtASCII->setChecked(m_ui->checkBoxExtASCIIAdv->isChecked()); + m_ui->checkBoxSpecialChars->setText("/ * + && …"); + m_ui->checkBoxSpecialChars->setToolTip(tr("Special Characters")); + m_ui->checkBoxSpecialChars->setChecked(config()->get(Config::PasswordGenerator_SpecialChars).toBool()); } - QApplication::processEvents(); - adjustSize(); + m_ui->advancedContainer->setVisible(advanced); + m_ui->checkBoxBraces->setVisible(advanced); + m_ui->checkBoxPunctuation->setVisible(advanced); + m_ui->checkBoxQuotes->setVisible(advanced); + m_ui->checkBoxMath->setVisible(advanced); + m_ui->checkBoxDashes->setVisible(advanced); + + if (!m_standalone) { + QTimer::singleShot(50, this, [this] { adjustSize(); }); + } } void PasswordGeneratorWidget::excludeHexChars() { m_ui->editExcludedChars->setText("GHIJKLMNOPQRSTUVWXYZghijklmnopqrstuvwxyz"); + m_ui->checkBoxNumbers->setChecked(true); + m_ui->checkBoxUpper->setChecked(true); + + m_ui->checkBoxLower->setChecked(false); + m_ui->checkBoxSpecialChars->setChecked(false); + m_ui->checkBoxExtASCII->setChecked(false); + m_ui->checkBoxPunctuation->setChecked(false); + m_ui->checkBoxQuotes->setChecked(false); + m_ui->checkBoxDashes->setChecked(false); + m_ui->checkBoxMath->setChecked(false); + m_ui->checkBoxBraces->setChecked(false); + + updateGenerator(); } void PasswordGeneratorWidget::colorStrengthIndicator(const PasswordHealth& health) @@ -397,39 +406,27 @@ PasswordGenerator::CharClasses PasswordGeneratorWidget::charClasses() { PasswordGenerator::CharClasses classes; - if (m_ui->simpleBar->isVisible()) { - if (m_ui->checkBoxLower->isChecked()) { - classes |= PasswordGenerator::LowerLetters; - } + if (m_ui->checkBoxLower->isChecked()) { + classes |= PasswordGenerator::LowerLetters; + } - if (m_ui->checkBoxUpper->isChecked()) { - classes |= PasswordGenerator::UpperLetters; - } + if (m_ui->checkBoxUpper->isChecked()) { + classes |= PasswordGenerator::UpperLetters; + } - if (m_ui->checkBoxNumbers->isChecked()) { - classes |= PasswordGenerator::Numbers; - } + if (m_ui->checkBoxNumbers->isChecked()) { + classes |= PasswordGenerator::Numbers; + } + if (m_ui->checkBoxExtASCII->isChecked()) { + classes |= PasswordGenerator::EASCII; + } + + if (!m_ui->buttonAdvancedMode->isChecked()) { if (m_ui->checkBoxSpecialChars->isChecked()) { classes |= PasswordGenerator::SpecialCharacters; } - - if (m_ui->checkBoxExtASCII->isChecked()) { - classes |= PasswordGenerator::EASCII; - } } else { - if (m_ui->checkBoxLowerAdv->isChecked()) { - classes |= PasswordGenerator::LowerLetters; - } - - if (m_ui->checkBoxUpperAdv->isChecked()) { - classes |= PasswordGenerator::UpperLetters; - } - - if (m_ui->checkBoxNumbersAdv->isChecked()) { - classes |= PasswordGenerator::Numbers; - } - if (m_ui->checkBoxBraces->isChecked()) { classes |= PasswordGenerator::Braces; } @@ -450,13 +447,9 @@ PasswordGenerator::CharClasses PasswordGeneratorWidget::charClasses() classes |= PasswordGenerator::Math; } - if (m_ui->checkBoxLogograms->isChecked()) { + if (m_ui->checkBoxSpecialChars->isChecked()) { classes |= PasswordGenerator::Logograms; } - - if (m_ui->checkBoxExtASCIIAdv->isChecked()) { - classes |= PasswordGenerator::EASCII; - } } return classes; diff --git a/src/gui/PasswordGeneratorWidget.h b/src/gui/PasswordGeneratorWidget.h index 08409ed22..036ea7706 100644 --- a/src/gui/PasswordGeneratorWidget.h +++ b/src/gui/PasswordGeneratorWidget.h @@ -45,8 +45,10 @@ public: Password = 0, Diceware = 1 }; + explicit PasswordGeneratorWidget(QWidget* parent = nullptr); ~PasswordGeneratorWidget(); + void loadSettings(); void saveSettings(); void setPasswordLength(int length); @@ -69,7 +71,7 @@ signals: private slots: void updateButtonsEnabled(const QString& password); void updatePasswordStrength(const QString& password); - void setAdvancedMode(bool state); + void setAdvancedMode(bool advanced); void excludeHexChars(); void passwordLengthChanged(int length); diff --git a/src/gui/PasswordGeneratorWidget.ui b/src/gui/PasswordGeneratorWidget.ui index 17b2432e5..65018cbda 100644 --- a/src/gui/PasswordGeneratorWidget.ui +++ b/src/gui/PasswordGeneratorWidget.ui @@ -6,8 +6,8 @@ 0 0 - 622 - 455 + 729 + 427 @@ -156,7 +156,7 @@ QProgressBar::chunk { - + Qt::TabFocus @@ -169,7 +169,7 @@ QProgressBar::chunk { - + Qt::TabFocus @@ -299,672 +299,404 @@ QProgressBar::chunk { Character Types - + QLayout::SetMinimumSize - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 40 - 25 - - - - Upper-case letters - - - Upper-case letters - - - - - - A-Z - - - true - - - optionButtons - - - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Lower-case letters - - - Lower-case letters - - - - - - a-z - - - true - - - optionButtons - - - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Numbers - - - Numbers - - - - - - 0-9 - - - true - - - optionButtons - - - - - - - true - - - - 60 - 25 - - - - Qt::TabFocus - - - Special characters - - - Special characters - - - /*_& ... - - - true - - - optionButtons - - - - - - - - 105 - 25 - - - - Qt::TabFocus - - - Extended ASCII - - - Extended ASCII - - - ExtendedASCII - - - true - - - optionButtons - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - + + + Qt::Horizontal + + + + 40 + 20 + + + - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - true + + + + + 6 + + + + + true + + + Qt::TabFocus + + + Special characters + + + Special characters + + + / * + && … + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Quotes + + + Quotes + + + " ' + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Punctuation + + + Punctuation + + + . , : ; + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Dashes and Slashes + + + Dashes and Slashes + + + \ / | _ - + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Upper-case letters + + + Upper-case letters + + + A-Z + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Numbers + + + Numbers + + + 0-9 + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Lower-case letters + + + Lower-case letters + + + a-z + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Math Symbols + + + Math Symbols + + + < * + ! ? = + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Extended ASCII + + + Extended ASCII + + + Extended ASCII + + + true + + + optionButtons + + + + + + + Qt::TabFocus + + + Braces + + + Braces + + + { [ ( ) ] } + + + true + + + optionButtons + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + + + 0 + + + 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QLayout::SetMinimumSize - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Upper-case letters - - - Upper-case letters - - - A-Z - - - true - - - optionButtons - - - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Lower-case letters - - - Lower-case letters - - - a-z - - - true - - - optionButtons - - - - - - - - - QLayout::SetMinimumSize - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Numbers - - - 0-9 - - - true - - - optionButtons - - - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Braces - - - Braces - - - {[( - - - true - - - optionButtons - - - - - - - - - QLayout::SetMinimumSize - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Punctuation - - - Punctuation - - - .,:; - - - true - - - optionButtons - - - - - - - - 40 - 25 - - - - Qt::TabFocus - - - Quotes - - - " ' - - - true - - - optionButtons - - - - - - - - - QLayout::SetMinimumSize - - - - - - 60 - 25 - - - - Qt::TabFocus - - - Math Symbols - - - Math Symbols - - - <*+!?= - - - true - - - optionButtons - - - - - - - - 60 - 25 - - - - Qt::TabFocus - - - Dashes and Slashes - - - Dashes and Slashes - - - \_|-/ - - - true - - - optionButtons - - - - - - - - - QLayout::SetMinimumSize - - - - - - 105 - 25 - - - - Qt::TabFocus - - - Logograms - - - Logograms - - - #$%&&@^`~ - - - true - - - optionButtons - - - - - - - - 105 - 25 - - - - Qt::TabFocus - - - Extended ASCII - - - ExtendedASCII - - - true - - - optionButtons - - - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - 0 - - - - Also choose from: + + + + 6 - + + + + Do not include: + + + + + + + + 0 + 0 + + + + + 375 + 0 + + + + Additional characters to use for the generated password + + + Additional characters + + + + + + + Qt::TabFocus + + + Add non-hex letters to "do not include" list + + + Hex Passwords + + + Hex + + + + + + + + 0 + 0 + + + + + 375 + 0 + + + + Character set to exclude from generated password + + + Excluded characters + + + + + + + Also choose from: + + + + - - - - - 0 - 0 - - - - - 200 - 0 - - + + - Additional characters to use for the generated password - - - Additional characters - - - - - - - - 0 - 0 - - - - - 200 - 0 - - - - Character set to exclude from generated password - - - Excluded characters - - - - - - - Do not include: - - - - - - - Qt::TabFocus - - - Add non-hex letters to "do not include" list - - - Hex Passwords + Excluded characters: "0", "1", "l", "I", "O", "|", "﹒" - Hex + Exclude look-alike characters + + optionButtons + + + + + + + Pick characters from every group + + + optionButtons + - - - - - Excluded characters: "0", "1", "l", "I", "O", "|", "﹒" - - - Exclude look-alike characters - - - optionButtons - - - - - - - Pick characters from every group - - - optionButtons - - - - - + + + - - - true + + + Qt::Horizontal - - - 0 - - - 0 - - - 0 - - - 0 - - - + + + 40 + 20 + + + @@ -980,13 +712,6 @@ QProgressBar::chunk { - - - - Word Case: - - - @@ -997,23 +722,13 @@ QProgressBar::chunk { - - + + - Word Separator: + Word Count: - - - - - - - 0 - 0 - - - - Wordlist: + + spinBoxLength @@ -1030,6 +745,33 @@ QProgressBar::chunk { + + + + Word Separator: + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -1075,30 +817,49 @@ QProgressBar::chunk { - - + + - Word Count: + Word Case: - - spinBoxLength + + + + + + + 0 + 0 + + + + Wordlist: - - - - - - - - + - + + + + 0 + 0 + + + + + 20 + 0 + + + + + + - + Qt::Horizontal @@ -1216,22 +977,16 @@ QProgressBar::chunk { sliderLength spinBoxLength buttonAdvancedMode - groupBox checkBoxUpper checkBoxLower checkBoxNumbers checkBoxSpecialChars checkBoxExtASCII - checkBoxUpperAdv - checkBoxNumbersAdv checkBoxPunctuation - checkBoxMath - checkBoxLogograms - checkBoxLowerAdv - checkBoxBraces checkBoxQuotes checkBoxDashes - checkBoxExtASCIIAdv + checkBoxMath + checkBoxBraces editAdditionalChars editExcludedChars buttonAddHex diff --git a/src/gui/styles/base/basestyle.qss b/src/gui/styles/base/basestyle.qss index ce47ee4f0..9bfc6a605 100644 --- a/src/gui/styles/base/basestyle.qss +++ b/src/gui/styles/base/basestyle.qss @@ -8,6 +8,11 @@ QPushButton:!default:hover { background: palette(mid); } +PasswordGeneratorWidget QPushButton:checked { + background: palette(highlight); + color: palette(highlighted-text); +} + QSpinBox { min-width: 90px; }