Skip to content

Commit

Permalink
Use better static icons for widgets in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Mar 7, 2024
1 parent 1ff8834 commit 0d17b09
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/appsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <QSize>
#include <QDir>
#include <QLockFile>
#include <QPalette>
#include <QIcon>

#define RECENT_FILES 10
#define RECENT_SEARCHES 20
Expand Down Expand Up @@ -266,3 +268,13 @@ void QTextPadSettings::addRecentSearchReplacement(const QString &text)
replacements.removeLast();
m_settings.setValue(QStringLiteral("Search/RecentReplace"), replacements);
}

QIcon QTextPadSettings::staticIcon(const QString &iconName, const QPalette &palette)
{
const bool darkTheme = palette.color(QPalette::Window).lightness() < 128;
qDebug("Lightness = %d", palette.color(QPalette::Window).lightness());
const QString iconPattern = darkTheme
? QStringLiteral(":/icons/qtextpad-dark/16x16/actions/%1.png")
: QStringLiteral(":/icons/qtextpad/16x16/actions/%1.png");
return QIcon(iconPattern.arg(iconName));
}
3 changes: 2 additions & 1 deletion src/appsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ class QTextPadSettings
SIMPLE_SETTING(bool, "Search/Escapes", searchEscapes, setSearchEscapes, false)
SIMPLE_SETTING(bool, "Search/Wrap", searchWrap, setSearchWrap, true)

static QIcon staticIcon(const QString &iconName, const QPalette &palette);

private:
QSettings m_settings;
};

/* Helper for loading theme icons */
#define ICON(name) QIcon::fromTheme(QStringLiteral(name))
#define ICON_S16(name) QIcon(QStringLiteral(":/icons/qtextpad/16x16/actions/" name ".png"))

#endif // QTEXTPAD_APPSETTINGS_H
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/qtextpad-dark/16x16/actions/go-down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/qtextpad-dark/16x16/actions/go-up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/icons/qtextpad-dark/index.theme
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Icon Theme]
Name=qtextpad-dark
Comment=Default qtextpad dark theme, based on Breeze-dark

Directories=16x16/actions,22x22/actions

[16x16/actions]
Size=16
Context=Actions
Type=Fixed

[22x22/actions]
Size=22
Context=Actions
Type=Fixed
File renamed without changes
13 changes: 9 additions & 4 deletions src/qtextpad.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
<file>icons/qtextpad-64.png</file>
<file>icons/qtextpad-128.png</file>

<!-- Used by the filter widgets -->
<file>icons/search-filter.png</file>

<!-- Oxygen icons for Win/Mac and Unixes that don't have a usable theme -->
<!-- Fallback icon themes for Win/Mac and Unixes that don't have a usable
theme, plus icons for widgets that don't use themes -->
<file>icons/qtextpad/index.theme</file>
<file>icons/qtextpad/16x16/actions/application-menu.png</file>
<file>icons/qtextpad/16x16/actions/document-new.png</file>
Expand All @@ -33,6 +31,7 @@
<file>icons/qtextpad/16x16/actions/go-jump.png</file>
<file>icons/qtextpad/16x16/actions/go-up.png</file>
<file>icons/qtextpad/16x16/actions/help-about.png</file>
<file>icons/qtextpad/16x16/actions/search-filter.png</file>
<file>icons/qtextpad/16x16/actions/view-fullscreen.png</file>
<file>icons/qtextpad/16x16/actions/view-refresh.png</file>
<file>icons/qtextpad/16x16/actions/view-restore.png</file>
Expand Down Expand Up @@ -64,5 +63,11 @@
<file>icons/qtextpad/22x22/actions/zoom-in.png</file>
<file>icons/qtextpad/22x22/actions/zoom-original.png</file>
<file>icons/qtextpad/22x22/actions/zoom-out.png</file>

<file>icons/qtextpad-dark/index.theme</file>
<file>icons/qtextpad-dark/16x16/actions/application-menu.png</file>
<file>icons/qtextpad-dark/16x16/actions/go-down.png</file>
<file>icons/qtextpad-dark/16x16/actions/go-up.png</file>
<file>icons/qtextpad-dark/16x16/actions/search-filter.png</file>
</qresource>
</RCC>
10 changes: 4 additions & 6 deletions src/searchdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ SearchWidget::SearchWidget(QTextPadWindow *parent)
: QWidget(parent), m_editor(parent->editor())
{
auto tbMenu = new QToolButton(this);
const QPalette &pal = palette();
tbMenu->setAutoRaise(true);
tbMenu->setIconSize(QSize(16, 16));
tbMenu->setIcon(ICON_S16("application-menu"));
tbMenu->setIcon(QTextPadSettings::staticIcon(QStringLiteral("application-menu"), pal));
tbMenu->setToolTip(tr("Search Settings"));
tbMenu->setStyleSheet(QStringLiteral("QToolButton::menu-indicator { image: none; }"));

Expand Down Expand Up @@ -82,14 +82,12 @@ SearchWidget::SearchWidget(QTextPadWindow *parent)

auto tbNext = new QToolButton(this);
tbNext->setAutoRaise(true);
tbNext->setIconSize(QSize(16, 16));
tbNext->setIcon(ICON_S16("go-down"));
tbNext->setIcon(QTextPadSettings::staticIcon(QStringLiteral("go-down"), pal));
tbNext->setToolTip(tr("Find Next"));

auto tbPrev = new QToolButton(this);
tbPrev->setAutoRaise(true);
tbPrev->setIconSize(QSize(16, 16));
tbPrev->setIcon(ICON_S16("go-up"));
tbPrev->setIcon(QTextPadSettings::staticIcon(QStringLiteral("go-up"), pal));
tbPrev->setToolTip(tr("Find Previous"));

auto layout = new QHBoxLayout(this);
Expand Down
3 changes: 2 additions & 1 deletion src/settingspopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@

#include <KSyntaxHighlighting/Repository>

#include "appsettings.h"
#include "syntaxtextedit.h"
#include "charsets.h"

TreeFilterEdit::TreeFilterEdit(QWidget *parent)
: QLineEdit(parent)
{
m_searchIcon = QIcon(QStringLiteral(":/icons/search-filter.png"));
m_searchIcon = QTextPadSettings::staticIcon(QStringLiteral("search-filter"), palette());
setClearButtonEnabled(true);
resizeEvent(Q_NULLPTR);
}
Expand Down

0 comments on commit 0d17b09

Please sign in to comment.