From 812b6f7d69e691a04ba22477d4e443d3fb4f8757 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Thu, 4 Mar 2021 12:35:38 +0100 Subject: [PATCH] Allow for runtime (dark/light) mode switch --- src/frontends/qt/GuiToolbar.cpp | 8 ++++++++ src/frontends/qt/GuiToolbar.h | 3 +++ src/frontends/qt/GuiView.cpp | 13 +++++++++++++ src/frontends/qt/GuiView.h | 2 ++ 4 files changed, 26 insertions(+) diff --git a/src/frontends/qt/GuiToolbar.cpp b/src/frontends/qt/GuiToolbar.cpp index 5600f4a74f..8057d84a70 100644 --- a/src/frontends/qt/GuiToolbar.cpp +++ b/src/frontends/qt/GuiToolbar.cpp @@ -116,6 +116,14 @@ void GuiToolbar::fill() } +void GuiToolbar::refill() +{ + filled_ = false; + clear(); + fill(); +} + + void GuiToolbar::showEvent(QShowEvent * ev) { fill(); diff --git a/src/frontends/qt/GuiToolbar.h b/src/frontends/qt/GuiToolbar.h index 262b09ef07..d658f3f51b 100644 --- a/src/frontends/qt/GuiToolbar.h +++ b/src/frontends/qt/GuiToolbar.h @@ -152,6 +152,9 @@ public: /// void toggle(); + /// + void refill(); + /// toggles movability void movable(bool silent = false); diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index a48540d28c..c226968c5c 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -1470,6 +1470,12 @@ bool GuiView::event(QEvent * e) return QMainWindow::event(e); } + case QEvent::ApplicationPaletteChange: { + // runtime switch from/to dark mode + refillToolbars(); + return QMainWindow::event(e); + } + default: return QMainWindow::event(e); } @@ -1739,6 +1745,13 @@ void GuiView::updateToolbars() } +void GuiView::refillToolbars() +{ + for (auto const & tb_p : d.toolbars_) + tb_p.second->refill(); +} + + void GuiView::setBuffer(Buffer * newBuffer, bool switch_to) { LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << endl); diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h index 4c610e0ef9..f5024e5ef4 100644 --- a/src/frontends/qt/GuiView.h +++ b/src/frontends/qt/GuiView.h @@ -149,6 +149,8 @@ public: /// updates the possible layouts selectable void updateLayoutList(); void updateToolbars(); + /// refill the toolbars (dark mode switch) + void refillToolbars(); /// LayoutBox * getLayoutDialog() const; -- 2.39.5