Add option to display passwords in color in preview panel

Closes #4099

* Fixed bug in Application that did not set the dark theme flag when the theme was changed from dark to light.
This commit is contained in:
Wolfram Rösler 2022-10-02 09:44:50 -04:00 committed by Jonathan White
parent dc07f01418
commit 14d0732e1d
8 changed files with 68 additions and 13 deletions

View File

@ -503,6 +503,10 @@
<source> recent files</source> <source> recent files</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Show passwords in color</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ApplicationSettingsWidgetSecurity</name> <name>ApplicationSettingsWidgetSecurity</name>

View File

@ -105,6 +105,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::GUI_HideUsernames, {QS("GUI/HideUsernames"), Roaming, false}}, {Config::GUI_HideUsernames, {QS("GUI/HideUsernames"), Roaming, false}},
{Config::GUI_HidePasswords, {QS("GUI/HidePasswords"), Roaming, true}}, {Config::GUI_HidePasswords, {QS("GUI/HidePasswords"), Roaming, true}},
{Config::GUI_AdvancedSettings, {QS("GUI/AdvancedSettings"), Roaming, false}}, {Config::GUI_AdvancedSettings, {QS("GUI/AdvancedSettings"), Roaming, false}},
{Config::GUI_ColorPasswords, {QS("GUI/ColorPasswords"), Roaming, false}},
{Config::GUI_MonospaceNotes, {QS("GUI/MonospaceNotes"), Roaming, false}}, {Config::GUI_MonospaceNotes, {QS("GUI/MonospaceNotes"), Roaming, false}},
{Config::GUI_ApplicationTheme, {QS("GUI/ApplicationTheme"), Roaming, QS("auto")}}, {Config::GUI_ApplicationTheme, {QS("GUI/ApplicationTheme"), Roaming, QS("auto")}},
{Config::GUI_CompactMode, {QS("GUI/CompactMode"), Roaming, false}}, {Config::GUI_CompactMode, {QS("GUI/CompactMode"), Roaming, false}},

View File

@ -86,6 +86,7 @@ public:
GUI_HideUsernames, GUI_HideUsernames,
GUI_HidePasswords, GUI_HidePasswords,
GUI_AdvancedSettings, GUI_AdvancedSettings,
GUI_ColorPasswords,
GUI_MonospaceNotes, GUI_MonospaceNotes,
GUI_ApplicationTheme, GUI_ApplicationTheme,
GUI_CompactMode, GUI_CompactMode,

View File

@ -183,6 +183,7 @@ void Application::applyTheme()
auto* s = new LightStyle; auto* s = new LightStyle;
setPalette(s->standardPalette()); setPalette(s->standardPalette());
setStyle(s); setStyle(s);
m_darkTheme = false;
} else if (appTheme == "dark") { } else if (appTheme == "dark") {
auto* s = new DarkStyle; auto* s = new DarkStyle;
setPalette(s->standardPalette()); setPalette(s->standardPalette());
@ -191,7 +192,9 @@ void Application::applyTheme()
} else { } else {
// Classic mode, don't check for dark theme on Windows // Classic mode, don't check for dark theme on Windows
// because Qt 5.x does not support it // because Qt 5.x does not support it
#ifndef Q_OS_WIN #if defined(Q_OS_WIN)
m_darkTheme = false;
#else
m_darkTheme = osUtils->isDarkMode(); m_darkTheme = osUtils->isDarkMode();
#endif #endif
QFile stylesheetFile(":/styles/base/classicstyle.qss"); QFile stylesheetFile(":/styles/base/classicstyle.qss");

View File

@ -239,6 +239,7 @@ void ApplicationSettingsWidget::loadSettings()
m_generalUi->toolbarMovableCheckBox->setChecked(config()->get(Config::GUI_MovableToolbar).toBool()); m_generalUi->toolbarMovableCheckBox->setChecked(config()->get(Config::GUI_MovableToolbar).toBool());
m_generalUi->monospaceNotesCheckBox->setChecked(config()->get(Config::GUI_MonospaceNotes).toBool()); m_generalUi->monospaceNotesCheckBox->setChecked(config()->get(Config::GUI_MonospaceNotes).toBool());
m_generalUi->colorPasswordsCheckBox->setChecked(config()->get(Config::GUI_ColorPasswords).toBool());
m_generalUi->toolButtonStyleComboBox->clear(); m_generalUi->toolButtonStyleComboBox->clear();
m_generalUi->toolButtonStyleComboBox->addItem(tr("Icon only"), Qt::ToolButtonIconOnly); m_generalUi->toolButtonStyleComboBox->addItem(tr("Icon only"), Qt::ToolButtonIconOnly);
@ -383,6 +384,7 @@ void ApplicationSettingsWidget::saveSettings()
config()->set(Config::GUI_MovableToolbar, m_generalUi->toolbarMovableCheckBox->isChecked()); config()->set(Config::GUI_MovableToolbar, m_generalUi->toolbarMovableCheckBox->isChecked());
config()->set(Config::GUI_MonospaceNotes, m_generalUi->monospaceNotesCheckBox->isChecked()); config()->set(Config::GUI_MonospaceNotes, m_generalUi->monospaceNotesCheckBox->isChecked());
config()->set(Config::GUI_ColorPasswords, m_generalUi->colorPasswordsCheckBox->isChecked());
config()->set(Config::GUI_ToolButtonStyle, m_generalUi->toolButtonStyleComboBox->currentData().toString()); config()->set(Config::GUI_ToolButtonStyle, m_generalUi->toolButtonStyleComboBox->currentData().toString());

View File

@ -766,6 +766,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="colorPasswordsCheckBox">
<property name="text">
<string>Show passwords in color</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="monospaceNotesCheckBox"> <widget class="QCheckBox" name="monospaceNotesCheckBox">
<property name="text"> <property name="text">

View File

@ -19,6 +19,8 @@
#include "EntryPreviewWidget.h" #include "EntryPreviewWidget.h"
#include "ui_EntryPreviewWidget.h" #include "ui_EntryPreviewWidget.h"
#include "Application.h"
#include "core/Config.h"
#include "gui/Clipboard.h" #include "gui/Clipboard.h"
#include "gui/Font.h" #include "gui/Font.h"
#include "gui/Icons.h" #include "gui/Icons.h"
@ -232,14 +234,31 @@ void EntryPreviewWidget::setPasswordVisible(bool state)
{ {
const QString password = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password()); const QString password = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password());
if (state) { if (state) {
m_ui->entryPasswordLabel->setText(password); if (config()->get(Config::GUI_ColorPasswords).toBool()) {
m_ui->entryPasswordLabel->setCursorPosition(0); // Show the password in color
m_ui->entryPasswordLabel->setFont(Font::fixedFont()); // clang-format off
QString html;
const auto dark = kpxcApp->isDarkTheme();
for (const auto c : password) {
const auto color = c.isDigit() ? (dark ? "lightblue" : "blue")
: c.isUpper() ? (dark ? "lightgreen" : "darkgreen")
: c.isLower() ? (dark ? "yellow" : "red")
: (dark ? "white" : "black");
html += "<span style=\"color: " + QString(color) + ";\">" + QString(c).toHtmlEscaped() + "</span>";
}
// clang-format on
m_ui->entryPasswordLabel->setHtml(html);
} else {
// No color
m_ui->entryPasswordLabel->setPlainText(password.toHtmlEscaped());
}
} else if (password.isEmpty() && !config()->get(Config::Security_PasswordEmptyPlaceholder).toBool()) { } else if (password.isEmpty() && !config()->get(Config::Security_PasswordEmptyPlaceholder).toBool()) {
m_ui->entryPasswordLabel->setText(""); m_ui->entryPasswordLabel->setPlainText("");
} else { } else {
m_ui->entryPasswordLabel->setText(QString("\u25cf").repeated(6)); m_ui->entryPasswordLabel->setPlainText(QString("\u25cf").repeated(6));
} }
m_ui->entryPasswordLabel->setFont(Font::fixedFont());
m_ui->togglePasswordButton->setIcon(icons()->onOffIcon("password-show", state)); m_ui->togglePasswordButton->setIcon(icons()->onOffIcon("password-show", state));
} }
@ -280,7 +299,7 @@ void EntryPreviewWidget::updateEntryGeneralTab()
// Hide password // Hide password
setPasswordVisible(false); setPasswordVisible(false);
// Show the password toggle button if there are dots in the label // Show the password toggle button if there are dots in the label
m_ui->togglePasswordButton->setVisible(!m_ui->entryPasswordLabel->text().isEmpty()); m_ui->togglePasswordButton->setVisible(!m_currentEntry->password().isEmpty());
m_ui->togglePasswordButton->setChecked(false); m_ui->togglePasswordButton->setChecked(false);
} else { } else {
// Show password // Show password

View File

@ -315,24 +315,42 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="entryPasswordLabel"> <widget class="QTextEdit" name="entryPasswordLabel">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>150</width> <width>150</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::ClickFocus</enum> <enum>Qt::ClickFocus</enum>
</property> </property>
<property name="text"> <property name="frameShape">
<string notr="true">password</string> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frame"> <property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="dragEnabled"> <property name="lineWrapMode">
<bool>true</bool> <enum>QTextEdit::NoWrap</enum>
</property> </property>
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>