]> git.lyx.org Git - features.git/commitdiff
Also change pdf module highlighting on the fly on mode change
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 5 Sep 2023 09:48:53 +0000 (11:48 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 5 Sep 2023 09:48:53 +0000 (11:48 +0200)
src/frontends/qt/GuiDocument.cpp
src/frontends/qt/GuiDocument.h

index bd7219561c64950fc31ebe0f4b8bcade19b0c4ea..46f2a9c18a2ee2c536437e723075d028af08ea12 100644 (file)
@@ -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
 
index 12f1cd75b0c746dfe7c67f5bf7eea7d726fe4225..c99345cbb8ba38f3b1db49427218db058537dd8a 100644 (file)
@@ -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;
 };