mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-07 12:32:26 +00:00
Update highlighting colors in runtime (dark/light) mode change
Until now, this required a restart.
This commit is contained in:
parent
32f89cbbf5
commit
51fd28ed4d
@ -21,7 +21,6 @@
|
||||
#include "GuiIndices.h"
|
||||
#include "GuiView.h"
|
||||
#include "GuiSelectionManager.h"
|
||||
#include "LaTeXHighlighter.h"
|
||||
#include "Validator.h"
|
||||
|
||||
#include "LayoutFile.h"
|
||||
@ -475,12 +474,12 @@ void ModuleSelectionManager::updateDelPB()
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
PreambleModule::PreambleModule(QWidget * parent)
|
||||
: UiWidget<Ui::PreambleUi>(parent), current_id_(nullptr)
|
||||
: UiWidget<Ui::PreambleUi>(parent), current_id_(nullptr),
|
||||
highlighter_(new LaTeXHighlighter(preambleTE->document(), true))
|
||||
{
|
||||
// This is not a memory leak. The object will be destroyed
|
||||
// with this.
|
||||
// @ is letter in the LyX user preamble
|
||||
(void) new LaTeXHighlighter(preambleTE->document(), true);
|
||||
preambleTE->setFont(guiApp->typewriterSystemFont());
|
||||
preambleTE->setWordWrapMode(QTextOption::NoWrap);
|
||||
setFocusProxy(preambleTE);
|
||||
@ -516,6 +515,14 @@ bool PreambleModule::eventFilter(QObject * sender, QEvent * event)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event->type() == QEvent::ApplicationPaletteChange) {
|
||||
// mode switch: colors need to be updated
|
||||
// and the highlighting redone
|
||||
if (highlighter_) {
|
||||
highlighter_->setupColors();
|
||||
highlighter_->rehighlight();
|
||||
}
|
||||
}
|
||||
return QWidget::eventFilter(sender, event);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "GuiDialog.h"
|
||||
#include "GuiIdListModel.h"
|
||||
|
||||
#include "LaTeXHighlighter.h"
|
||||
|
||||
#include "ui_BiblioUi.h"
|
||||
#include "ui_ColorUi.h"
|
||||
#include "ui_ChangeTrackingUi.h"
|
||||
@ -385,6 +387,8 @@ private:
|
||||
Coords preamble_coords_;
|
||||
BufferId current_id_;
|
||||
unique_ptr<support::TempFile> tempfile_;
|
||||
/// LaTeX syntax highlighter
|
||||
LaTeXHighlighter * highlighter_;
|
||||
|
||||
private Q_SLOTS:
|
||||
///
|
||||
|
@ -320,6 +320,15 @@ bool ViewSourceWidget::eventFilter(QObject * obj, QEvent * ev)
|
||||
goToCursor();
|
||||
return true;
|
||||
}
|
||||
if (ev->type() == QEvent::ApplicationPaletteChange) {
|
||||
// mode switch: colors need to be updated
|
||||
// and the highlighting redone
|
||||
if (highlighter_) {
|
||||
highlighter_->setupColors();
|
||||
highlighter_->rehighlight();
|
||||
Q_EMIT needUpdate();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,12 @@ namespace frontend {
|
||||
|
||||
LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent, bool at_letter, bool keyval)
|
||||
: QSyntaxHighlighter(parent), at_letter_(at_letter), keyval_(keyval)
|
||||
{
|
||||
setupColors();
|
||||
}
|
||||
|
||||
|
||||
void LaTeXHighlighter::setupColors()
|
||||
{
|
||||
auto blend = [](QColor color1, QColor color2) {
|
||||
int r = 0.5 * (color1.red() + color2.red());
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
explicit LaTeXHighlighter(QTextDocument * parent,
|
||||
bool at_letter = false,
|
||||
bool keyval = false);
|
||||
void setupColors();
|
||||
|
||||
protected:
|
||||
void highlightBlock(QString const & text) override;
|
||||
|
Loading…
Reference in New Issue
Block a user