summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/tab-widgets/maintab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'desktop-widgets/tab-widgets/maintab.cpp')
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index ab4b4f28b..6e794f07d 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -47,6 +47,12 @@ struct Completers {
QCompleter *tags;
};
+static bool paletteIsDark(const QPalette &p)
+{
+ // we consider a palette dark if the text color is lighter than the windows background
+ return p.window().color().valueF() < p.windowText().color().valueF();
+}
+
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
editMode(false),
ignoreInput(false),
@@ -72,6 +78,9 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
extraWidgets << new TabDiveComputer(this);
ui.tabWidget->addTab(extraWidgets.last(), tr("Device names"));
+ // make sure we know if this is a light or dark mode
+ isDark = paletteIsDark(palette());
+
// call colorsChanged() for the initial setup now that the extraWidgets are loaded
colorsChanged();
@@ -704,13 +713,24 @@ void MainTab::clearTabs()
widget->clear();
}
+void MainTab::changeEvent(QEvent *ev)
+{
+ if (ev->type() == QEvent::PaletteChange) {
+ // check if this is a light or dark mode
+ bool dark = paletteIsDark(palette());
+ if (dark != isDark) {
+ // things have changed, so setup the colors correctly
+ isDark = dark;
+ colorsChanged();
+ }
+ }
+ QTabWidget::changeEvent(ev);
+}
+
// setup the colors of 'header' elements in the tab widget
void MainTab::colorsChanged()
{
- // Put together appropriate CSS stylesheets: NB: colors below in same order as the enum in prefs.h
- QStringList colors = { "mediumblue", "lightblue", "black" }; // If using dark theme, set color appropriately
- QString colorText = colors[prefs.headerstyle_color];
-
+ QString colorText = isDark ? QStringLiteral("lightblue") : QStringLiteral("mediumblue");
QString lastpart = colorText + " ;}";
// only set the color if the widget is enabled
@@ -731,5 +751,5 @@ void MainTab::colorsChanged()
// finally call the individual updateUi() functions so they can overwrite these style sheets
for (TabBase *widget: extraWidgets)
- widget->updateUi();
+ widget->updateUi(colorText);
}