From 85e5c3baca8e64d40d2503332e75b97e481cbe4a Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Tue, 2 Jul 2024 18:30:12 +0200 Subject: [PATCH] take color setting out of set model --- GUI/Model/Type/ModelForSet.h | 5 ++--- GUI/Model/Type/PredefinedColors.cpp | 8 ++++++++ GUI/Model/Type/PredefinedColors.h | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/GUI/Model/Type/ModelForSet.h b/GUI/Model/Type/ModelForSet.h index 561e3b6e959..77faf442a4e 100644 --- a/GUI/Model/Type/ModelForSet.h +++ b/GUI/Model/Type/ModelForSet.h @@ -15,8 +15,8 @@ #ifndef BORNAGAIN_GUI_MODEL_TYPE_MODELFORSET_H #define BORNAGAIN_GUI_MODEL_TYPE_MODELFORSET_H +#include "GUI/Model/Type/PredefinedColors.h" #include <QAbstractListModel> -#include <QWidget> template <class T> class SetWithModel; @@ -45,8 +45,7 @@ public: case Qt::ToolTipRole: return t->description(); case Qt::BackgroundRole: - return row == m_set->currentIndex() ? QWidget().palette().color(QPalette::Dark) - : QWidget().palette().color(QPalette::Button); + return GUI::Colors::listBackground(row == m_set->currentIndex()); default: return {}; } diff --git a/GUI/Model/Type/PredefinedColors.cpp b/GUI/Model/Type/PredefinedColors.cpp index 526284de5ef..bd35b5d7e15 100644 --- a/GUI/Model/Type/PredefinedColors.cpp +++ b/GUI/Model/Type/PredefinedColors.cpp @@ -13,6 +13,7 @@ // ************************************************************************************************ #include "GUI/Model/Type/PredefinedColors.h" +#include <QWidget> const QVector<QColor>& GUI::Colors::layerDefaults() { @@ -22,3 +23,10 @@ const QVector<QColor>& GUI::Colors::layerDefaults() return colors; } + +const QColor& GUI::Colors::listBackground(bool isCurrent) +{ + static QVector<QColor> values = {QWidget().palette().color(QPalette::Button), + QWidget().palette().color(QPalette::Dark)}; + return values.at(isCurrent); +} diff --git a/GUI/Model/Type/PredefinedColors.h b/GUI/Model/Type/PredefinedColors.h index 259e172dd1b..5162cdca080 100644 --- a/GUI/Model/Type/PredefinedColors.h +++ b/GUI/Model/Type/PredefinedColors.h @@ -23,6 +23,8 @@ namespace GUI::Colors { const QVector<QColor>& layerDefaults(); +const QColor& listBackground(bool isCurrent); + } // namespace GUI::Colors #endif // BORNAGAIN_GUI_MODEL_TYPE_PREDEFINEDCOLORS_H -- GitLab