Skip to content

Fix dark theme - make sure to use default text and document-close icons #1967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Binary file added avogadro/qtgui/icons/fallback/32x32/dots-dark.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 avogadro/qtgui/icons/fallback/32x32/lock-dark.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.
Binary file added avogadro/qtgui/icons/fallback/32x32/plus-dark.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 avogadro/qtgui/icons/fallback/32x32/preview-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 43 additions & 9 deletions avogadro/qtgui/layermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QtCore/QFileInfo>
#include <QtGui/QColor>
#include <QtGui/QIcon>
#include <QtGui/QPalette>

namespace Avogadro::QtGui {

Expand All @@ -22,13 +23,44 @@ const int QTTY_COLUMNS = 6;

LayerModel::LayerModel(QObject* p) : QAbstractItemModel(p), m_item(0)
{
m_plusIcon = QIcon(":/icons/fallback/32x32/plus.png");
m_dotsIcon = QIcon(":/icons/fallback/32x32/dots.png");
m_previewIcon = QIcon(":/icons/fallback/32x32/preview.png");
m_previewDashedIcon = QIcon(":/icons/fallback/32x32/dashed-preview.png");
m_lockIcon = QIcon(":/icons/fallback/32x32/lock.png");
m_openLockIcon = QIcon(":/icons/fallback/32x32/lock-open.png");
m_removeIcon = QIcon(":/icons/fallback/32x32/cross.png");
// determine if need dark mode or light mode icons
// e.g. https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5
const QPalette defaultPalette;
// i.e., the text is lighter than the background
bool darkMode = (defaultPalette.color(QPalette::WindowText).lightness() >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Qt 6.5 onwards there's a much easier way to find out whether the system is light mode or dark mode: using QStyleHints::colorScheme()

defaultPalette.color(QPalette::Window).lightness());
loadIcons(darkMode);
}

void LayerModel::loadIcons(bool darkMode)
{
QString iconPath = ":icons/fallback/32x32/";

QString dashedPreviewIconPath = iconPath + "dashed-preview-light.png";
QString dotsIconPath = iconPath + "dots-light.png";
QString lockIconPath = iconPath + "lock-light.png";
QString openLockIconPath = iconPath + "lock-open-light.png";
QString plusIconPath = iconPath + "plus-light.png";
QString previewIconPath = iconPath + "preview-light.png";

if (darkMode) {
dashedPreviewIconPath = iconPath + "dashed-preview-dark.png";
dotsIconPath = iconPath + "dots-dark.png";
lockIconPath = iconPath + "lock-dark.png";
openLockIconPath = iconPath + "lock-open-dark.png";
plusIconPath = iconPath + "plus-dark.png";
previewIconPath = iconPath + "preview-dark.png";
}

m_plusIcon = QIcon::fromTheme("list-add", QIcon(plusIconPath));
m_removeIcon = QIcon::fromTheme(
"list-remove", QIcon(":/icons/fallback/32x32/edit-delete.png"));
m_dotsIcon = QIcon::fromTheme("view-more", QIcon(dotsIconPath));
m_previewIcon = QIcon::fromTheme("view-visible", QIcon(previewIconPath));
m_previewDashedIcon =
QIcon::fromTheme("view-hidden", QIcon(dashedPreviewIconPath));
m_lockIcon = QIcon::fromTheme("lock", QIcon(lockIconPath));
m_openLockIcon = QIcon::fromTheme("unlock", QIcon(openLockIconPath));
}

QModelIndex LayerModel::parent(const QModelIndex&) const
Expand Down Expand Up @@ -88,8 +120,10 @@ QVariant LayerModel::data(const QModelIndex& idx, int role) const
case Qt::ForegroundRole:
if (layer == getMoleculeLayer().activeLayer())
return QVariant(QColor(Qt::red));
else
return QVariant(QColor(Qt::black));
else {
const QPalette defaultPalette;
return QVariant(defaultPalette.color(QPalette::WindowText));
}
default:
return QVariant();
}
Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtgui/layermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AVOGADROQTGUI_EXPORT LayerModel : public QAbstractItemModel,

explicit LayerModel(QObject* p = 0);

void loadIcons(bool darkMode);

QModelIndex parent(const QModelIndex& child) const override;
int rowCount(const QModelIndex& parent) const override;
int columnCount(const QModelIndex& parent) const override;
Expand Down
16 changes: 10 additions & 6 deletions avogadro/qtgui/moleculemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#include "molecule.h"
#include "moleculemodel.h"
#include "molecule.h"

#include <QtCore/QFileInfo>
#include <QtGui/QColor>
#include <QtGui/QIcon>
#include <QtGui/QPalette>

namespace Avogadro::QtGui {

MoleculeModel::MoleculeModel(QObject* p)
: QAbstractItemModel(p), m_activeMolecule(nullptr)
{}
{
}

QModelIndex MoleculeModel::parent(const QModelIndex&) const
{
Expand Down Expand Up @@ -115,14 +117,16 @@ QVariant MoleculeModel::data(const QModelIndex& idx, int role) const
case Qt::ForegroundRole:
if (mol == m_activeMolecule)
return QVariant(QColor(Qt::red));
else
return QVariant(QColor(Qt::black));
else {
const QPalette defaultPalette;
return QVariant(defaultPalette.color(QPalette::WindowText));
}
default:
return QVariant();
}
} else if (idx.column() == 1) {
if (role == Qt::DecorationRole)
return QIcon(":/icons/fallback/32x32/edit-delete.png");
return QIcon::fromTheme("document-close");
}
return QVariant();
}
Expand Down Expand Up @@ -197,4 +201,4 @@ void MoleculeModel::itemChanged()
}
}

} // namespace Avogadro
} // namespace Avogadro::QtGui
20 changes: 14 additions & 6 deletions avogadro/qtgui/qtgui.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<RCC>
<qresource prefix="/">
<file>icons/fallback/32x32/cross.png</file>
<file>icons/fallback/32x32/dashed-preview.png</file>
<file>icons/fallback/32x32/dashed-preview-light.png</file>
<file>icons/fallback/32x32/dashed-preview-dark.png</file>
<file>icons/fallback/32x32/document-close.png</file>
<file>icons/fallback/32x32/document-export.png</file>
<file>icons/fallback/32x32/document-import.png</file>
<file>icons/fallback/32x32/document-new.png</file>
Expand All @@ -10,13 +12,15 @@
<file>icons/fallback/32x32/document-save-all.png</file>
<file>icons/fallback/32x32/document-save-as.png</file>
<file>icons/fallback/32x32/document-save.png</file>
<file>icons/fallback/32x32/dots.png</file>
<file>icons/fallback/32x32/dots-light.png</file>
<file>icons/fallback/32x32/dots-dark.png</file>
<file>icons/fallback/32x32/edit-add.png</file>
<file>icons/fallback/32x32/edit-copy.png</file>
<file>icons/fallback/32x32/edit-cut.png</file>
<file>icons/fallback/32x32/edit-paste.png</file>
<file>icons/fallback/32x32/edit-delete.png</file>
<file>icons/fallback/32x32/help-about.png</file>
<file>icons/fallback/64x64/document-close.png</file>
<file>icons/fallback/64x64/document-export.png</file>
<file>icons/fallback/64x64/document-import.png</file>
<file>icons/fallback/64x64/document-new.png</file>
Expand All @@ -29,10 +33,14 @@
<file>icons/fallback/64x64/edit-cut.png</file>
<file>icons/fallback/64x64/edit-paste.png</file>
<file>icons/fallback/64x64/help-about.png</file>
<file>icons/fallback/32x32/lock-open.png</file>
<file>icons/fallback/32x32/lock.png</file>
<file>icons/fallback/32x32/plus.png</file>
<file>icons/fallback/32x32/preview.png</file>
<file>icons/fallback/32x32/lock-open-light.png</file>
<file>icons/fallback/32x32/lock-open-dark.png</file>
<file>icons/fallback/32x32/lock-light.png</file>
<file>icons/fallback/32x32/lock-dark.png</file>
<file>icons/fallback/32x32/plus-light.png</file>
<file>icons/fallback/32x32/plus-dark.png</file>
<file>icons/fallback/32x32/preview-light.png</file>
<file>icons/fallback/32x32/preview-dark.png</file>
<file>icons/fallback/index.theme</file>
<file>icons/colormap/balance.png</file>
<file>icons/colormap/[email protected]</file>
Expand Down
Loading