Skip to content

Commit

Permalink
Draw layer icons from theme if available and dark/light options
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Feb 11, 2025
1 parent 93ea617 commit bf6b371
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 15 deletions.
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() >
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
18 changes: 12 additions & 6 deletions avogadro/qtgui/qtgui.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<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>
Expand All @@ -11,7 +12,8 @@
<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>
Expand All @@ -31,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/balance@2x.png</file>
Expand Down

0 comments on commit bf6b371

Please sign in to comment.