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.
This commit is contained in:
Jonathan White 2020-10-07 21:14:32 -04:00
parent a09acc86d0
commit b0e038e789
17 changed files with 44 additions and 192 deletions

View File

@ -140,7 +140,9 @@ Files: share/icons/badges/2_Expired.svg
Copyright: 2020 KeePassXC Team <team@keepassxc.org>
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

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M16.59,5.59L18,7L12,13L6,7L7.41,5.59L12,10.17L16.59,5.59M16.59,11.59L18,13L12,19L6,13L7.41,11.59L12,16.17L16.59,11.59Z" /></svg>

After

Width:  |  Height:  |  Size: 413 B

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M5.59,7.41L7,6L13,12L7,18L5.59,16.59L10.17,12L5.59,7.41M11.59,7.41L13,6L19,12L13,18L11.59,16.59L16.17,12L11.59,7.41Z" /></svg>

After

Width:  |  Height:  |  Size: 411 B

View File

@ -8,6 +8,8 @@
<file>application/scalable/actions/application-exit.svg</file>
<file>application/scalable/actions/auto-type.svg</file>
<file>application/scalable/actions/bugreport.svg</file>
<file>application/scalable/actions/chevron-double-down.svg</file>
<file>application/scalable/actions/chevron-double-right.svg</file>
<file>application/scalable/actions/chronometer.svg</file>
<file>application/scalable/actions/clipboard-text.svg</file>
<file>application/scalable/actions/configure.svg</file>

View File

@ -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

View File

@ -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) {

View File

@ -66,7 +66,6 @@ protected slots:
private slots:
void browseKeyFile();
void clearKeyFileText();
void keyFileTextChanged();
void pollHardwareKey();
void hardwareKeyResponse(bool found);
void openHardwareKeyHelp();

View File

@ -416,6 +416,9 @@
<property name="accessibleName">
<string>Key file to unlock the database</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
@ -575,16 +578,14 @@
</spacer>
</item>
</layout>
<action name="keyFileClearIcon">
<property name="text">
<string>Clear</string>
</property>
<property name="toolTip">
<string>Clear Key File</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>PasswordEdit</class>
<extends>QLineEdit</extends>
<header>gui/PasswordEdit.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>MessageWidget</class>
<extends>QWidget</extends>
@ -596,11 +597,6 @@
<extends>QLabel</extends>
<header>gui/widgets/ElidedLabel.h</header>
</customwidget>
<customwidget>
<class>PasswordEdit</class>
<extends>QLineEdit</extends>
<header>gui/PasswordEdit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>editPassword</tabstop>

View File

@ -1,70 +0,0 @@
/*
* Copyright (C) 2007 Trolltech ASA <info@trolltech.com>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2012 Florian Geyer <blueice@fobos.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "LineEdit.h"
#include <QStyle>
#include <QToolButton>
#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());
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (C) 2007 Trolltech ASA <info@trolltech.com>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2012 Florian Geyer <blueice@fobos.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_LINEEDIT_H
#define KEEPASSX_LINEEDIT_H
#include <QLineEdit>
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

View File

@ -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<PassphraseGenerator::PassphraseWordCase>(m_ui->wordCaseComboBox->currentData().toInt()));

View File

@ -608,6 +608,9 @@ QProgressBar::chunk {
<property name="accessibleName">
<string>Additional characters</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
@ -646,6 +649,9 @@ QProgressBar::chunk {
<property name="accessibleName">
<string>Excluded characters</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
@ -944,22 +950,6 @@ QProgressBar::chunk {
</spacer>
</item>
</layout>
<action name="clearInclude">
<property name="text">
<string>Clear</string>
</property>
<property name="toolTip">
<string>Clear</string>
</property>
</action>
<action name="clearExclude">
<property name="text">
<string>Clear</string>
</property>
<property name="toolTip">
<string>Clear</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -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<QToolButton*>()) {
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());
}

View File

@ -41,7 +41,7 @@
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@ -51,11 +51,6 @@
<string>Search</string>
</property>
</action>
<action name="clearIcon">
<property name="text">
<string>Clear</string>
</property>
</action>
<action name="helpIcon">
<property name="text">
<string>Search Help</string>

View File

@ -54,6 +54,8 @@
#include <cmath>
#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,

View File

@ -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,

View File

@ -855,8 +855,7 @@ void TestGui::testSearch()
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
QVERIFY(entryView->isVisible());
auto* clearButton = searchWidget->findChild<QAction*>("clearIcon");
QVERIFY(!clearButton->isVisible());
QVERIFY(searchTextEdit->isClearButtonEnabled());
auto* helpButton = searchWidget->findChild<QAction*>("helpIcon");
auto* helpPanel = searchWidget->findChild<QWidget*>("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);