Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfram Rösler <wolfram@roesler-ac.de>2022-10-02 16:44:50 +0300
committerJonathan White <support@dmapps.us>2022-10-04 05:03:36 +0300
commitb1e7c34b82452773e0a7291462fef60a40a4ea72 (patch)
tree2750b03803a9679e4778ec99cc49640157f94f66
parent54f9b25b5213550c3185477f09b34a1b412395ff (diff)
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.
-rw-r--r--share/translations/keepassxc_en.ts4
-rw-r--r--src/core/Config.cpp1
-rw-r--r--src/core/Config.h1
-rw-r--r--src/gui/Application.cpp5
-rw-r--r--src/gui/ApplicationSettingsWidget.cpp2
-rw-r--r--src/gui/ApplicationSettingsWidgetGeneral.ui7
-rw-r--r--src/gui/EntryPreviewWidget.cpp31
-rw-r--r--src/gui/EntryPreviewWidget.ui30
8 files changed, 68 insertions, 13 deletions
diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts
index ac5d43f56..7c4521579 100644
--- a/share/translations/keepassxc_en.ts
+++ b/share/translations/keepassxc_en.ts
@@ -503,6 +503,10 @@
<source> recent files</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>Show passwords in color</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
<context>
<name>ApplicationSettingsWidgetSecurity</name>
diff --git a/src/core/Config.cpp b/src/core/Config.cpp
index 8808abd75..44896bc1c 100644
--- a/src/core/Config.cpp
+++ b/src/core/Config.cpp
@@ -105,6 +105,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::GUI_HideUsernames, {QS("GUI/HideUsernames"), Roaming, false}},
{Config::GUI_HidePasswords, {QS("GUI/HidePasswords"), Roaming, true}},
{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_ApplicationTheme, {QS("GUI/ApplicationTheme"), Roaming, QS("auto")}},
{Config::GUI_CompactMode, {QS("GUI/CompactMode"), Roaming, false}},
diff --git a/src/core/Config.h b/src/core/Config.h
index a48cb4c59..e0b42b35c 100644
--- a/src/core/Config.h
+++ b/src/core/Config.h
@@ -86,6 +86,7 @@ public:
GUI_HideUsernames,
GUI_HidePasswords,
GUI_AdvancedSettings,
+ GUI_ColorPasswords,
GUI_MonospaceNotes,
GUI_ApplicationTheme,
GUI_CompactMode,
diff --git a/src/gui/Application.cpp b/src/gui/Application.cpp
index cfe29cf96..8e8f4ca5b 100644
--- a/src/gui/Application.cpp
+++ b/src/gui/Application.cpp
@@ -183,6 +183,7 @@ void Application::applyTheme()
auto* s = new LightStyle;
setPalette(s->standardPalette());
setStyle(s);
+ m_darkTheme = false;
} else if (appTheme == "dark") {
auto* s = new DarkStyle;
setPalette(s->standardPalette());
@@ -191,7 +192,9 @@ void Application::applyTheme()
} else {
// Classic mode, don't check for dark theme on Windows
// 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();
#endif
QFile stylesheetFile(":/styles/base/classicstyle.qss");
diff --git a/src/gui/ApplicationSettingsWidget.cpp b/src/gui/ApplicationSettingsWidget.cpp
index be925c770..7972e8e0c 100644
--- a/src/gui/ApplicationSettingsWidget.cpp
+++ b/src/gui/ApplicationSettingsWidget.cpp
@@ -239,6 +239,7 @@ void ApplicationSettingsWidget::loadSettings()
m_generalUi->toolbarMovableCheckBox->setChecked(config()->get(Config::GUI_MovableToolbar).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->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_MonospaceNotes, m_generalUi->monospaceNotesCheckBox->isChecked());
+ config()->set(Config::GUI_ColorPasswords, m_generalUi->colorPasswordsCheckBox->isChecked());
config()->set(Config::GUI_ToolButtonStyle, m_generalUi->toolButtonStyleComboBox->currentData().toString());
diff --git a/src/gui/ApplicationSettingsWidgetGeneral.ui b/src/gui/ApplicationSettingsWidgetGeneral.ui
index 0a67c57b7..53bf9f724 100644
--- a/src/gui/ApplicationSettingsWidgetGeneral.ui
+++ b/src/gui/ApplicationSettingsWidgetGeneral.ui
@@ -767,6 +767,13 @@
</layout>
</item>
<item>
+ <widget class="QCheckBox" name="colorPasswordsCheckBox">
+ <property name="text">
+ <string>Show passwords in color</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QCheckBox" name="monospaceNotesCheckBox">
<property name="text">
<string>Use monospaced font for notes</string>
diff --git a/src/gui/EntryPreviewWidget.cpp b/src/gui/EntryPreviewWidget.cpp
index 304fc733f..0e2e18ee9 100644
--- a/src/gui/EntryPreviewWidget.cpp
+++ b/src/gui/EntryPreviewWidget.cpp
@@ -19,6 +19,8 @@
#include "EntryPreviewWidget.h"
#include "ui_EntryPreviewWidget.h"
+#include "Application.h"
+#include "core/Config.h"
#include "gui/Clipboard.h"
#include "gui/Font.h"
#include "gui/Icons.h"
@@ -232,14 +234,31 @@ void EntryPreviewWidget::setPasswordVisible(bool state)
{
const QString password = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password());
if (state) {
- m_ui->entryPasswordLabel->setText(password);
- m_ui->entryPasswordLabel->setCursorPosition(0);
- m_ui->entryPasswordLabel->setFont(Font::fixedFont());
+ if (config()->get(Config::GUI_ColorPasswords).toBool()) {
+ // Show the password in color
+ // 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()) {
- m_ui->entryPasswordLabel->setText("");
+ m_ui->entryPasswordLabel->setPlainText("");
} 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));
}
@@ -280,7 +299,7 @@ void EntryPreviewWidget::updateEntryGeneralTab()
// Hide password
setPasswordVisible(false);
// 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);
} else {
// Show password
diff --git a/src/gui/EntryPreviewWidget.ui b/src/gui/EntryPreviewWidget.ui
index df7196a27..89d072059 100644
--- a/src/gui/EntryPreviewWidget.ui
+++ b/src/gui/EntryPreviewWidget.ui
@@ -315,25 +315,43 @@
</widget>
</item>
<item>
- <widget class="QLineEdit" name="entryPasswordLabel">
+ <widget class="QTextEdit" name="entryPasswordLabel">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>30</height>
+ </size>
+ </property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
- <property name="text">
- <string notr="true">password</string>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
</property>
- <property name="frame">
- <bool>false</bool>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
</property>
- <property name="dragEnabled">
+ <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>
+ </property>
+ <property name="lineWrapMode">
+ <enum>QTextEdit::NoWrap</enum>
+ </property>
<property name="readOnly">
<bool>true</bool>
</property>