From b0e038e7891efbcab073ff66c72932aeb09cf687 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Wed, 7 Oct 2020 21:14:32 -0400 Subject: [PATCH] Improve default Qt widget icons * Include new icons for toolbar overflow to ensure they are tinted correctly and fit in with the rest of the UI. * Replace custom code for clearing line edits by including a proper icon for the default action. --- COPYING | 4 +- .../scalable/actions/chevron-double-down.svg | 1 + .../scalable/actions/chevron-double-right.svg | 1 + share/icons/icons.qrc | 2 + src/CMakeLists.txt | 1 - src/gui/DatabaseOpenWidget.cpp | 13 ---- src/gui/DatabaseOpenWidget.h | 1 - src/gui/DatabaseOpenWidget.ui | 22 +++--- src/gui/LineEdit.cpp | 70 ------------------- src/gui/LineEdit.h | 44 ------------ src/gui/PasswordGeneratorWidget.cpp | 13 ---- src/gui/PasswordGeneratorWidget.ui | 22 ++---- src/gui/SearchWidget.cpp | 8 --- src/gui/SearchWidget.ui | 7 +- src/gui/styles/base/BaseStyle.cpp | 17 +++++ src/gui/styles/base/BaseStyle.h | 2 + tests/gui/TestGui.cpp | 8 +-- 17 files changed, 44 insertions(+), 192 deletions(-) create mode 100644 share/icons/application/scalable/actions/chevron-double-down.svg create mode 100644 share/icons/application/scalable/actions/chevron-double-right.svg delete mode 100644 src/gui/LineEdit.cpp delete mode 100644 src/gui/LineEdit.h diff --git a/COPYING b/COPYING index 174848e46..aa11b14fa 100644 --- a/COPYING +++ b/COPYING @@ -140,7 +140,9 @@ Files: share/icons/badges/2_Expired.svg Copyright: 2020 KeePassXC Team License: MIT -Files: share/icons/application/scalable/actions/document-close.svg +Files: share/icons/application/scalable/actions/chevron-double-down.svg + share/icons/application/scalable/actions/chevron-double-right.svg + share/icons/application/scalable/actions/document-close.svg share/icons/application/scalable/actions/document-edit.svg share/icons/application/scalable/actions/document-export.svg share/icons/application/scalable/actions/document-import.svg diff --git a/share/icons/application/scalable/actions/chevron-double-down.svg b/share/icons/application/scalable/actions/chevron-double-down.svg new file mode 100644 index 000000000..edcf11814 --- /dev/null +++ b/share/icons/application/scalable/actions/chevron-double-down.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/share/icons/application/scalable/actions/chevron-double-right.svg b/share/icons/application/scalable/actions/chevron-double-right.svg new file mode 100644 index 000000000..3f2a06b4f --- /dev/null +++ b/share/icons/application/scalable/actions/chevron-double-right.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/share/icons/icons.qrc b/share/icons/icons.qrc index cb11f9068..cf73b4958 100644 --- a/share/icons/icons.qrc +++ b/share/icons/icons.qrc @@ -8,6 +8,8 @@ application/scalable/actions/application-exit.svg application/scalable/actions/auto-type.svg application/scalable/actions/bugreport.svg + application/scalable/actions/chevron-double-down.svg + application/scalable/actions/chevron-double-right.svg application/scalable/actions/chronometer.svg application/scalable/actions/clipboard-text.svg application/scalable/actions/configure.svg diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f8c3b156..0ceccdd9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -120,7 +120,6 @@ set(keepassx_SOURCES gui/IconModels.cpp gui/KeePass1OpenWidget.cpp gui/KMessageWidget.cpp - gui/LineEdit.cpp gui/MainWindow.cpp gui/MessageBox.cpp gui/MessageWidget.cpp diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index 4dbe9dc9d..b48f86365 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -76,12 +76,6 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent) m_ui->keyFileLabelHelp->setIcon(resources()->icon("system-help").pixmap(QSize(12, 12))); connect(m_ui->keyFileLabelHelp, SIGNAL(clicked(bool)), SLOT(openKeyFileHelp())); - connect(m_ui->keyFileLineEdit, SIGNAL(textChanged(QString)), SLOT(keyFileTextChanged())); - m_ui->keyFileLineEdit->addAction(m_ui->keyFileClearIcon, QLineEdit::TrailingPosition); - m_ui->keyFileClearIcon->setIcon(resources()->icon("edit-clear-locationbar-rtl")); - m_ui->keyFileClearIcon->setVisible(false); - connect(m_ui->keyFileClearIcon, SIGNAL(triggered(bool)), SLOT(clearKeyFileText())); - #ifdef WITH_XC_YUBIKEY m_ui->hardwareKeyProgress->setVisible(false); QSizePolicy sp = m_ui->hardwareKeyProgress->sizePolicy(); @@ -145,8 +139,6 @@ void DatabaseOpenWidget::load(const QString& filename) m_filename = filename; m_ui->fileNameLabel->setRawText(m_filename); - m_ui->keyFileClearIcon->setVisible(false); - if (config()->get(Config::RememberLastKeyFiles).toBool()) { auto lastKeyFiles = config()->get(Config::LastKeyFiles).toHash(); if (lastKeyFiles.contains(m_filename)) { @@ -388,11 +380,6 @@ void DatabaseOpenWidget::clearKeyFileText() m_ui->keyFileLineEdit->clear(); } -void DatabaseOpenWidget::keyFileTextChanged() -{ - m_ui->keyFileClearIcon->setVisible(!m_ui->keyFileLineEdit->text().isEmpty()); -} - void DatabaseOpenWidget::pollHardwareKey() { if (m_pollingHardwareKey) { diff --git a/src/gui/DatabaseOpenWidget.h b/src/gui/DatabaseOpenWidget.h index 6d2b688ca..fffdf8a7a 100644 --- a/src/gui/DatabaseOpenWidget.h +++ b/src/gui/DatabaseOpenWidget.h @@ -66,7 +66,6 @@ protected slots: private slots: void browseKeyFile(); void clearKeyFileText(); - void keyFileTextChanged(); void pollHardwareKey(); void hardwareKeyResponse(bool found); void openHardwareKeyHelp(); diff --git a/src/gui/DatabaseOpenWidget.ui b/src/gui/DatabaseOpenWidget.ui index a7510baba..eef4a2ed2 100644 --- a/src/gui/DatabaseOpenWidget.ui +++ b/src/gui/DatabaseOpenWidget.ui @@ -416,6 +416,9 @@ Key file to unlock the database + + true + @@ -575,16 +578,14 @@ - - - Clear - - - Clear Key File - - + + PasswordEdit + QLineEdit +
gui/PasswordEdit.h
+ 1 +
MessageWidget QWidget @@ -596,11 +597,6 @@ QLabel
gui/widgets/ElidedLabel.h
- - PasswordEdit - QLineEdit -
gui/PasswordEdit.h
-
editPassword diff --git a/src/gui/LineEdit.cpp b/src/gui/LineEdit.cpp deleted file mode 100644 index ec5cb7f9c..000000000 --- a/src/gui/LineEdit.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2007 Trolltech ASA - * Copyright (C) 2012 Felix Geyer - * Copyright (C) 2012 Florian Geyer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 or (at your option) - * version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "LineEdit.h" - -#include -#include - -#include "core/Resources.h" - -LineEdit::LineEdit(QWidget* parent) - : QLineEdit(parent) - , m_clearButton(new QToolButton(this)) -{ - m_clearButton->setObjectName("clearButton"); - - QString iconNameDirected = - QString("edit-clear-locationbar-").append((layoutDirection() == Qt::LeftToRight) ? "rtl" : "ltr"); - - const auto icon = resources()->icon(iconNameDirected); - - m_clearButton->setIcon(icon); - m_clearButton->setCursor(Qt::ArrowCursor); - m_clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); - m_clearButton->hide(); - connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear())); - connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateCloseButton(QString))); - int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - setStyleSheet( - QString("QLineEdit { padding-right: %1px; } ").arg(m_clearButton->sizeHint().width() + frameWidth + 1)); - QSize msz = minimumSizeHint(); - setMinimumSize(qMax(msz.width(), m_clearButton->sizeHint().height() + frameWidth * 2 + 2), - qMax(msz.height(), m_clearButton->sizeHint().height() + frameWidth * 2 + 2)); -} - -void LineEdit::resizeEvent(QResizeEvent* event) -{ - QSize sz = m_clearButton->sizeHint(); - int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - int y = (rect().bottom() + 1 - sz.height()) / 2; - - if (layoutDirection() == Qt::LeftToRight) { - m_clearButton->move(rect().right() - frameWidth - sz.width(), y); - } else { - m_clearButton->move(rect().left() + frameWidth, y); - } - - QLineEdit::resizeEvent(event); -} - -void LineEdit::updateCloseButton(const QString& text) -{ - m_clearButton->setVisible(!text.isEmpty()); -} diff --git a/src/gui/LineEdit.h b/src/gui/LineEdit.h deleted file mode 100644 index 1695e8551..000000000 --- a/src/gui/LineEdit.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2007 Trolltech ASA - * Copyright (C) 2012 Felix Geyer - * Copyright (C) 2012 Florian Geyer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 or (at your option) - * version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef KEEPASSX_LINEEDIT_H -#define KEEPASSX_LINEEDIT_H - -#include - -class QToolButton; - -class LineEdit : public QLineEdit -{ - Q_OBJECT - -public: - explicit LineEdit(QWidget* parent = nullptr); - -protected: - void resizeEvent(QResizeEvent* event) override; - -private slots: - void updateCloseButton(const QString& text); - -private: - QToolButton* const m_clearButton; -}; - -#endif // KEEPASSX_LINEEDIT_H diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index 07dda651b..2dc643df2 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -45,14 +45,6 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) m_ui->buttonCopy->setIcon(resources()->icon("clipboard-text")); m_ui->buttonClose->setShortcut(Qt::Key_Escape); - m_ui->clearInclude->setIcon(resources()->icon("edit-clear-locationbar-rtl")); - m_ui->editAdditionalChars->addAction(m_ui->clearInclude, QLineEdit::TrailingPosition); - m_ui->clearInclude->setVisible(false); - - m_ui->clearExclude->setIcon(resources()->icon("edit-clear-locationbar-rtl")); - m_ui->editExcludedChars->addAction(m_ui->clearExclude, QLineEdit::TrailingPosition); - m_ui->clearExclude->setVisible(false); - connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updateButtonsEnabled(QString))); connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updatePasswordStrength(QString))); connect(m_ui->buttonAdvancedMode, SIGNAL(toggled(bool)), SLOT(setAdvancedMode(bool))); @@ -63,8 +55,6 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) connect(m_ui->buttonCopy, SIGNAL(clicked()), SLOT(copyPassword())); connect(m_ui->buttonGenerate, SIGNAL(clicked()), SLOT(regeneratePassword())); connect(m_ui->buttonClose, SIGNAL(clicked()), SIGNAL(closed())); - connect(m_ui->clearInclude, SIGNAL(triggered(bool)), m_ui->editAdditionalChars, SLOT(clear())); - connect(m_ui->clearExclude, SIGNAL(triggered(bool)), m_ui->editExcludedChars, SLOT(clear())); connect(m_ui->sliderLength, SIGNAL(valueChanged(int)), SLOT(passwordLengthChanged(int))); connect(m_ui->spinBoxLength, SIGNAL(valueChanged(int)), SLOT(passwordLengthChanged(int))); @@ -530,9 +520,6 @@ void PasswordGeneratorWidget::updateGenerator() } else { m_ui->buttonGenerate->setEnabled(false); } - - m_ui->clearInclude->setVisible(!m_ui->editAdditionalChars->text().isEmpty()); - m_ui->clearExclude->setVisible(!m_ui->editExcludedChars->text().isEmpty()); } else { m_dicewareGenerator->setWordCase( static_cast(m_ui->wordCaseComboBox->currentData().toInt())); diff --git a/src/gui/PasswordGeneratorWidget.ui b/src/gui/PasswordGeneratorWidget.ui index 65018cbda..81964a517 100644 --- a/src/gui/PasswordGeneratorWidget.ui +++ b/src/gui/PasswordGeneratorWidget.ui @@ -608,6 +608,9 @@ QProgressBar::chunk { Additional characters + + true + @@ -646,6 +649,9 @@ QProgressBar::chunk { Excluded characters + + true + @@ -944,22 +950,6 @@ QProgressBar::chunk { - - - Clear - - - Clear - - - - - Clear - - - Clear - - diff --git a/src/gui/SearchWidget.cpp b/src/gui/SearchWidget.cpp index 1c7b683c1..6ade47e2e 100644 --- a/src/gui/SearchWidget.cpp +++ b/src/gui/SearchWidget.cpp @@ -45,7 +45,6 @@ SearchWidget::SearchWidget(QWidget* parent) m_clearSearchTimer->setSingleShot(true); connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), SLOT(startSearchTimer())); - connect(m_ui->clearIcon, SIGNAL(triggered(bool)), m_ui->searchEdit, SLOT(clear())); connect(m_ui->helpIcon, SIGNAL(triggered()), SLOT(toggleHelp())); connect(m_ui->searchIcon, SIGNAL(triggered()), SLOT(showSearchMenu())); connect(m_searchTimer, SIGNAL(timeout()), SLOT(startSearch())); @@ -75,10 +74,6 @@ SearchWidget::SearchWidget(QWidget* parent) m_ui->helpIcon->setIcon(resources()->icon("system-help")); m_ui->searchEdit->addAction(m_ui->helpIcon, QLineEdit::TrailingPosition); - m_ui->clearIcon->setIcon(resources()->icon("edit-clear-locationbar-rtl")); - m_ui->clearIcon->setVisible(false); - m_ui->searchEdit->addAction(m_ui->clearIcon, QLineEdit::TrailingPosition); - // Fix initial visibility of actions (bug in Qt) for (QToolButton* toolButton : m_ui->searchEdit->findChildren()) { toolButton->setVisible(toolButton->defaultAction()->isVisible()); @@ -172,9 +167,6 @@ void SearchWidget::startSearch() m_searchTimer->stop(); } - bool hasText = m_ui->searchEdit->text().length() > 0; - m_ui->clearIcon->setVisible(hasText); - search(m_ui->searchEdit->text()); } diff --git a/src/gui/SearchWidget.ui b/src/gui/SearchWidget.ui index 74cc468cf..c924b4076 100644 --- a/src/gui/SearchWidget.ui +++ b/src/gui/SearchWidget.ui @@ -41,7 +41,7 @@ - false + true @@ -51,11 +51,6 @@ Search - - - Clear - - Search Help diff --git a/src/gui/styles/base/BaseStyle.cpp b/src/gui/styles/base/BaseStyle.cpp index aac9daf1c..2c72f9bcc 100644 --- a/src/gui/styles/base/BaseStyle.cpp +++ b/src/gui/styles/base/BaseStyle.cpp @@ -54,6 +54,8 @@ #include +#include "core/Resources.h" + QT_BEGIN_NAMESPACE Q_GUI_EXPORT int qt_defaultDpiX(); QT_END_NAMESPACE @@ -3036,6 +3038,21 @@ QPalette BaseStyle::standardPalette() const return QCommonStyle::standardPalette(); } +QIcon BaseStyle::standardIcon(StandardPixmap sp, const QStyleOption* opt, const QWidget* widget) const +{ + switch (sp) { + case SP_ToolBarHorizontalExtensionButton: + return resources()->icon("chevron-double-down"); + case SP_ToolBarVerticalExtensionButton: + return resources()->icon("chevron-double-right"); + case SP_LineEditClearButton: + return resources()->icon( + QString("edit-clear-locationbar-").append((opt->direction == Qt::LeftToRight) ? "rtl" : "ltr")); + default: + return QCommonStyle::standardIcon(sp, opt, widget); + } +} + void BaseStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, diff --git a/src/gui/styles/base/BaseStyle.h b/src/gui/styles/base/BaseStyle.h index d6269fad7..86d81b44b 100644 --- a/src/gui/styles/base/BaseStyle.h +++ b/src/gui/styles/base/BaseStyle.h @@ -42,6 +42,8 @@ public: }; QPalette standardPalette() const override; + QIcon + standardIcon(StandardPixmap sp, const QStyleOption* opt = nullptr, const QWidget* widget = nullptr) const override; void drawPrimitive(PrimitiveElement elem, const QStyleOption* option, QPainter* painter, diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index d323744b6..060a29520 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -855,8 +855,7 @@ void TestGui::testSearch() auto* entryView = m_dbWidget->findChild("entryView"); QVERIFY(entryView->isVisible()); - auto* clearButton = searchWidget->findChild("clearIcon"); - QVERIFY(!clearButton->isVisible()); + QVERIFY(searchTextEdit->isClearButtonEnabled()); auto* helpButton = searchWidget->findChild("helpIcon"); auto* helpPanel = searchWidget->findChild("SearchHelpWidget"); @@ -866,7 +865,6 @@ void TestGui::testSearch() // Enter search QTest::mouseClick(searchTextEdit, Qt::LeftButton); QTRY_VERIFY(searchTextEdit->hasFocus()); - QTRY_VERIFY(!clearButton->isVisible()); // Show/Hide search help helpButton->trigger(); QTRY_VERIFY(helpPanel->isVisible()); @@ -877,14 +875,12 @@ void TestGui::testSearch() // Search for "ZZZ" QTest::keyClicks(searchTextEdit, "ZZZ"); QTRY_COMPARE(searchTextEdit->text(), QString("ZZZ")); - QTRY_VERIFY(clearButton->isVisible()); QTRY_VERIFY(m_dbWidget->isSearchActive()); QTRY_COMPARE(entryView->model()->rowCount(), 0); // Press the search clear button - clearButton->trigger(); + searchTextEdit->clear(); QTRY_VERIFY(searchTextEdit->text().isEmpty()); QTRY_VERIFY(searchTextEdit->hasFocus()); - QTRY_VERIFY(!clearButton->isVisible()); // Escape clears searchedit and retains focus QTest::keyClicks(searchTextEdit, "ZZZ"); QTest::keyClick(searchTextEdit, Qt::Key_Escape);