From: Juergen Spitzmueller Date: Tue, 5 Sep 2023 09:48:53 +0000 (+0200) Subject: Also change pdf module highlighting on the fly on mode change X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7c8c3657fdebf38d35a44c0e7e50a092d106addf;p=features.git Also change pdf module highlighting on the fly on mode change --- diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp index bd7219561c..46f2a9c18a 100644 --- a/src/frontends/qt/GuiDocument.cpp +++ b/src/frontends/qt/GuiDocument.cpp @@ -1782,8 +1782,11 @@ GuiDocument::GuiDocument(GuiView & lv) pdfSupportModule->subjectLE)); pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator( pdfSupportModule->keywordsLE)); - (void) new LaTeXHighlighter(pdfSupportModule->optionsTE->document(), true, true); - (void) new LaTeXHighlighter(pdfSupportModule->metadataTE->document(), true, true); + + pdf_options_highlighter_ = new LaTeXHighlighter( + pdfSupportModule->optionsTE->document(), true, true); + pdf_metadata_highlighter_ = new LaTeXHighlighter( + pdfSupportModule->metadataTE->document(), true, true); for (int i = 0; backref_opts[i][0]; ++i) pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i])); @@ -1840,6 +1843,9 @@ GuiDocument::GuiDocument(GuiView & lv) docPS->addPanel(outputModule, N_("Output")); docPS->addPanel(preambleModule, N_("LaTeX Preamble")); docPS->setCurrentPanel("Document Class"); + + // Filter out (dark/light) mode changes + installEventFilter(this); } @@ -5391,6 +5397,24 @@ void GuiDocument::setOutputSync(bool on) } +bool GuiDocument::eventFilter(QObject * sender, QEvent * event) +{ + if (event->type() == QEvent::ApplicationPaletteChange) { + // mode switch: colors need to be updated + // and the highlighting redone + if (pdf_options_highlighter_) { + pdf_options_highlighter_->setupColors(); + pdf_options_highlighter_->rehighlight(); + } + if (pdf_metadata_highlighter_) { + pdf_metadata_highlighter_->setupColors(); + pdf_metadata_highlighter_->rehighlight(); + } + } + return QWidget::eventFilter(sender, event); +} + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt/GuiDocument.h b/src/frontends/qt/GuiDocument.h index 12f1cd75b0..c99345cbb8 100644 --- a/src/frontends/qt/GuiDocument.h +++ b/src/frontends/qt/GuiDocument.h @@ -360,6 +360,12 @@ private: /// Track whether we prompted the user about unapplied /// changes bool prompted_; + + /// LaTeX syntax highlighter + LaTeXHighlighter * pdf_options_highlighter_; + LaTeXHighlighter * pdf_metadata_highlighter_; +protected: + bool eventFilter(QObject * sender, QEvent * event) override; };