From 82e3c0dd6a40459b1a3739661b209d4df6781a84 Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Tue, 17 Jan 2023 19:23:14 +0100 Subject: [PATCH 01/12] Adds macOS theme switch listening --- src/app/Application.cpp | 10 +++++++--- src/app/Application.h | 1 + src/ui/MainWindow.cpp | 14 ++++++++++++++ src/ui/MainWindow.h | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 64216bec9..174d07aae 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -142,8 +142,7 @@ Application::Application(int &argc, char **argv, bool haltOnParseError) // Initialize theme. mTheme.reset(Theme::create(parser.value("theme"))); - setStyle(mTheme->style()); - setStyleSheet(mTheme->styleSheet()); + applyTheme(); #if defined(Q_OS_WIN) // Set default font style and hinting. @@ -488,4 +487,9 @@ void Application::handleSslErrors(QNetworkReply *reply, reply->ignoreSslErrors(errors); settings.setValue("ssl/ignore", true); } -} \ No newline at end of file +} + +void Application::applyTheme() { + setStyle(mTheme->style()); + setStyleSheet(mTheme->styleSheet()); +} diff --git a/src/app/Application.h b/src/app/Application.h index bd2282de2..3aee52bc9 100644 --- a/src/app/Application.h +++ b/src/app/Application.h @@ -27,6 +27,7 @@ class Application : public QApplication { void autoUpdate(); bool restoreWindows(); bool runSingleInstance(); + void applyTheme(); static bool isInTest(); static void setInTest(); diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 4e0d53bd4..c2e917699 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -21,6 +21,7 @@ #include "git/Repository.h" #include "git/Config.h" #include "git/Submodule.h" +#include "app/Application.h" #include #include #include @@ -589,3 +590,16 @@ QString MainWindow::windowGroup() const { QByteArray hash = QCryptographicHash::hash(group, QCryptographicHash::Md5); return QString::fromUtf8(hash.toHex()); } + +void MainWindow::changeEvent(QEvent* e) +{ +#ifdef Q_OS_MACX + if ( e->type() == QEvent::PaletteChange ) + { + Application *app = qobject_cast(QApplication::instance()); + if (app) + app->applyTheme(); + } +#endif + QMainWindow::changeEvent( e ); +} \ No newline at end of file diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 65d0be713..970c8ff80 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -62,6 +62,7 @@ class MainWindow : public QMainWindow { void closeEvent(QCloseEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; + void changeEvent(QEvent *event) override; private: void updateTabNames(); From 7579e2530b2959c371047eb9b78f58f15ace96bb Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Tue, 17 Jan 2023 20:35:32 +0100 Subject: [PATCH 02/12] Fixes formatting --- src/ui/MainWindow.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index c2e917699..a3a5b92b7 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -591,15 +591,14 @@ QString MainWindow::windowGroup() const { return QString::fromUtf8(hash.toHex()); } -void MainWindow::changeEvent(QEvent* e) +void MainWindow::changeEvent(QEvent *e) { #ifdef Q_OS_MACX - if ( e->type() == QEvent::PaletteChange ) - { - Application *app = qobject_cast(QApplication::instance()); + if (e->type() == QEvent::PaletteChange) { + Application *app = qobject_cast(QApplication::instance()); if (app) app->applyTheme(); } #endif - QMainWindow::changeEvent( e ); + QMainWindow::changeEvent(e); } \ No newline at end of file From 8d179c6a1a81becfdc306fdfb1f4e919939a11dd Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Wed, 18 Jan 2023 09:18:33 +0100 Subject: [PATCH 03/12] Fix formatting --- src/ui/MainWindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index a3a5b92b7..bc91e222f 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -591,8 +591,7 @@ QString MainWindow::windowGroup() const { return QString::fromUtf8(hash.toHex()); } -void MainWindow::changeEvent(QEvent *e) -{ +void MainWindow::changeEvent(QEvent *e) { #ifdef Q_OS_MACX if (e->type() == QEvent::PaletteChange) { Application *app = qobject_cast(QApplication::instance()); From adb2c49dbdfc95355679f982f23356cff2889e43 Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Fri, 20 Jan 2023 19:58:40 +0100 Subject: [PATCH 04/12] Remove ifdefs temporarily --- src/ui/MainWindow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index bc91e222f..1b15dd12a 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -592,12 +592,11 @@ QString MainWindow::windowGroup() const { } void MainWindow::changeEvent(QEvent *e) { -#ifdef Q_OS_MACX if (e->type() == QEvent::PaletteChange) { Application *app = qobject_cast(QApplication::instance()); if (app) app->applyTheme(); } -#endif + QMainWindow::changeEvent(e); -} \ No newline at end of file +} From a7fecbfdbd6219f4fb3d660e223602ef6381014d Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Mon, 23 Jan 2023 23:27:50 +0100 Subject: [PATCH 05/12] Test TextEditor theme update --- src/editor/TextEditor.cpp | 142 +++++++++++++++++++++----------------- src/editor/TextEditor.h | 6 ++ src/ui/MainWindow.cpp | 12 +++- 3 files changed, 94 insertions(+), 66 deletions(-) diff --git a/src/editor/TextEditor.cpp b/src/editor/TextEditor.cpp index c53c0bb5c..fbca495e0 100644 --- a/src/editor/TextEditor.cpp +++ b/src/editor/TextEditor.cpp @@ -11,7 +11,6 @@ #include "app/Application.h" #include "conf/Settings.h" #include -#include #include #include #include @@ -20,6 +19,8 @@ #include "PlatQt.h" +QList TextEditor::instances; + using namespace Scintilla; namespace { @@ -50,18 +51,7 @@ const float textHeightFactorCheckBoxSize = 2.0; extern LexerModule lmLPeg; TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) { - // Load colors. - Theme *theme = Application::theme(); - mOursColor = theme->diff(Theme::Diff::Ours); - mTheirsColor = theme->diff(Theme::Diff::Theirs); - mAdditionColor = theme->diff(Theme::Diff::Addition); - mDeletionColor = theme->diff(Theme::Diff::Deletion); - - // Load icons. - QStyle *style = this->style(); - mNoteIcon = style->standardIcon(QStyle::SP_MessageBoxInformation); - mWarningIcon = style->standardIcon(QStyle::SP_MessageBoxWarning); - mErrorIcon = style->standardIcon(QStyle::SP_MessageBoxCritical); + instances.append(this); // Register the LPeg lexer. static bool initialized = false; @@ -101,57 +91,8 @@ TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) { clearCmdKey(SCK_ADD + (SCI_CTRL << 16)); clearCmdKey(SCK_SUBTRACT + (SCI_CTRL << 16)); - // Set find indicators. - indicSetStyle(FindAll, INDIC_STRAIGHTBOX); - indicSetFore(FindAll, Qt::white); - indicSetAlpha(FindAll, 255); - indicSetUnder(FindAll, true); - - indicSetStyle(FindCurrent, INDIC_STRAIGHTBOX); - indicSetFore(FindCurrent, Qt::yellow); - indicSetAlpha(FindCurrent, 255); - indicSetUnder(FindCurrent, true); - - // Set word diff indicators. - indicSetStyle(WordAddition, INDIC_STRAIGHTBOX); - indicSetFore(WordAddition, theme->diff(Theme::Diff::WordAddition)); - indicSetAlpha(WordAddition, 255); - indicSetUnder(WordAddition, true); - - indicSetStyle(WordDeletion, INDIC_STRAIGHTBOX); - indicSetFore(WordDeletion, theme->diff(Theme::Diff::WordDeletion)); - indicSetAlpha(WordDeletion, 255); - indicSetUnder(WordDeletion, true); - - indicSetStyle(NoteIndicator, INDIC_SQUIGGLE); - indicSetFore(NoteIndicator, theme->diff(Theme::Diff::Note)); - indicSetAlpha(NoteIndicator, 255); - indicSetUnder(NoteIndicator, true); + applyThemeAndSettings(); - indicSetStyle(WarningIndicator, INDIC_STRAIGHTBOX); - indicSetFore(WarningIndicator, theme->diff(Theme::Diff::Warning)); - indicSetAlpha(WarningIndicator, 255); - indicSetUnder(WarningIndicator, true); - - indicSetStyle(ErrorIndicator, INDIC_STRAIGHTBOX); - indicSetFore(ErrorIndicator, theme->diff(Theme::Diff::Error)); - indicSetAlpha(ErrorIndicator, 255); - indicSetUnder(ErrorIndicator, true); - - // Initialize LPeg lexer. - QColor base = palette().color(QPalette::Base); - QColor text = palette().color(QPalette::Text); - bool dark = (text.lightnessF() > base.lightnessF()); - - setLexerLanguage("lpeg"); - setProperty("lexer.lpeg.home", Settings::lexerDir().path()); - setProperty("lexer.lpeg.themes", theme->dir().path()); - setProperty("lexer.lpeg.theme", theme->name()); - setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light"); - setCaretFore(text); - - // Apply default settings. - applySettings(); connect(Settings::instance(), &Settings::settingsChanged, this, &TextEditor::applySettings); @@ -160,6 +101,10 @@ TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) { &TextEditor::updateGeometry); } +TextEditor::~TextEditor() { + instances.removeOne(this); +} + void TextEditor::contextMenuEvent(QContextMenuEvent *event) { Point pos = PointFromQPoint(event->globalPos()); Point pt = PointFromQPoint(event->pos()); @@ -619,3 +564,74 @@ void TextEditor::keyPressEvent(QKeyEvent *ke) { ScintillaIFace::keyPressEvent(ke); } +void TextEditor::applyThemeAndSettingsToAllInstances() { + for (const auto& instance : instances) + instance->applyThemeAndSettings(); +} + +void TextEditor::applyThemeAndSettings() { + // Load colors. + Theme *theme = Application::theme(); + mOursColor = theme->diff(Theme::Diff::Ours); + mTheirsColor = theme->diff(Theme::Diff::Theirs); + mAdditionColor = theme->diff(Theme::Diff::Addition); + mDeletionColor = theme->diff(Theme::Diff::Deletion); + + // Load icons. + QStyle *style = this->style(); + mNoteIcon = style->standardIcon(QStyle::SP_MessageBoxInformation); + mWarningIcon = style->standardIcon(QStyle::SP_MessageBoxWarning); + mErrorIcon = style->standardIcon(QStyle::SP_MessageBoxCritical); + + // Set find indicators. + indicSetStyle(FindAll, INDIC_STRAIGHTBOX); + indicSetFore(FindAll, Qt::white); + indicSetAlpha(FindAll, 255); + indicSetUnder(FindAll, true); + + indicSetStyle(FindCurrent, INDIC_STRAIGHTBOX); + indicSetFore(FindCurrent, Qt::yellow); + indicSetAlpha(FindCurrent, 255); + indicSetUnder(FindCurrent, true); + + // Set word diff indicators. + indicSetStyle(WordAddition, INDIC_STRAIGHTBOX); + indicSetFore(WordAddition, theme->diff(Theme::Diff::WordAddition)); + indicSetAlpha(WordAddition, 255); + indicSetUnder(WordAddition, true); + + indicSetStyle(WordDeletion, INDIC_STRAIGHTBOX); + indicSetFore(WordDeletion, theme->diff(Theme::Diff::WordDeletion)); + indicSetAlpha(WordDeletion, 255); + indicSetUnder(WordDeletion, true); + + indicSetStyle(NoteIndicator, INDIC_SQUIGGLE); + indicSetFore(NoteIndicator, theme->diff(Theme::Diff::Note)); + indicSetAlpha(NoteIndicator, 255); + indicSetUnder(NoteIndicator, true); + + indicSetStyle(WarningIndicator, INDIC_STRAIGHTBOX); + indicSetFore(WarningIndicator, theme->diff(Theme::Diff::Warning)); + indicSetAlpha(WarningIndicator, 255); + indicSetUnder(WarningIndicator, true); + + indicSetStyle(ErrorIndicator, INDIC_STRAIGHTBOX); + indicSetFore(ErrorIndicator, theme->diff(Theme::Diff::Error)); + indicSetAlpha(ErrorIndicator, 255); + indicSetUnder(ErrorIndicator, true); + + // Initialize LPeg lexer. + QColor base = palette().color(QPalette::Base); + QColor text = palette().color(QPalette::Text); + bool dark = (text.lightnessF() > base.lightnessF()); + + setLexerLanguage("lpeg"); + setProperty("lexer.lpeg.home", Settings::lexerDir().path()); + setProperty("lexer.lpeg.themes", theme->dir().path()); + setProperty("lexer.lpeg.theme", theme->name()); + setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light"); + setCaretFore(text); + + // Apply default settings. + applySettings(); +} diff --git a/src/editor/TextEditor.h b/src/editor/TextEditor.h index 6d45dfb5a..041633a0f 100644 --- a/src/editor/TextEditor.h +++ b/src/editor/TextEditor.h @@ -84,6 +84,7 @@ class TextEditor : public Scintilla::ScintillaIFace { }; TextEditor(QWidget *parent = nullptr); + ~TextEditor(); void applySettings(); @@ -119,6 +120,8 @@ class TextEditor : public Scintilla::ScintillaIFace { return QRect(pr.left, pr.top, pr.Width(), pr.Height()); } + static void applyThemeAndSettingsToAllInstances(); + signals: void settingsChanged(); void highlightActivated(bool active); @@ -156,6 +159,7 @@ class TextEditor : public Scintilla::ScintillaIFace { void loadMarkerPixmap(Marker marker, const QPixmap &pixmap); void AddToPopUp(const char *label, int cmd = 0, bool enabled = true); void ContextMenu(Scintilla::Point pt); + void applyThemeAndSettings(); QString mPath; int mLineCount = -1; @@ -179,6 +183,8 @@ class TextEditor : public Scintilla::ScintillaIFace { QPixmap mUnStagedIcon; QMap> mDiagnostics; + + static QList instances; }; #endif diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 1b15dd12a..88e3e97be 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -22,6 +22,7 @@ #include "git/Config.h" #include "git/Submodule.h" #include "app/Application.h" +#include "editor/TextEditor.h" #include #include #include @@ -591,12 +592,17 @@ QString MainWindow::windowGroup() const { return QString::fromUtf8(hash.toHex()); } -void MainWindow::changeEvent(QEvent *e) { - if (e->type() == QEvent::PaletteChange) { +void MainWindow::changeEvent(QEvent *event) { +#ifdef Q_OS_MAC + if (event->type() == QEvent::PaletteChange) { +#else + if (event->type() == QEvent::ThemeChange) { +#endif Application *app = qobject_cast(QApplication::instance()); if (app) app->applyTheme(); + TextEditor::applyThemeAndSettingsToAllInstances(); } - QMainWindow::changeEvent(e); + QMainWindow::changeEvent(event); } From deb12f08db800fc9bb4fcf13b949ca027abbeda0 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Fri, 27 Jan 2023 14:19:00 +0100 Subject: [PATCH 06/12] Description: forgotten to set style --- src/editor/TextEditor.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/editor/TextEditor.cpp b/src/editor/TextEditor.cpp index fbca495e0..305fd04bf 100644 --- a/src/editor/TextEditor.cpp +++ b/src/editor/TextEditor.cpp @@ -180,22 +180,6 @@ void TextEditor::applySettings() { // Missing newline style. styleSetFont(EofNewline, italic); - // Remote comment styles - Theme *theme = Application::theme(); - styleSetFont(CommentBody, regular); - styleSetFore(CommentBody, theme->remoteComment(Theme::Comment::Body)); - styleSetBack(CommentBody, theme->remoteComment(Theme::Comment::Background)); - - styleSetFont(CommentAuthor, bold); - styleSetFore(CommentAuthor, theme->remoteComment(Theme::Comment::Author)); - styleSetBack(CommentAuthor, theme->remoteComment(Theme::Comment::Background)); - - styleSetFont(CommentTimestamp, regular); - styleSetFore(CommentTimestamp, - theme->remoteComment(Theme::Comment::Timestamp)); - styleSetBack(CommentTimestamp, - theme->remoteComment(Theme::Comment::Background)); - // Emit own signal. emit settingsChanged(); @@ -632,6 +616,25 @@ void TextEditor::applyThemeAndSettings() { setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light"); setCaretFore(text); + QFont regular = font(); + QFont bold = regular; + bold.setBold(true); + + // Remote comment styles + styleSetFont(CommentBody, regular); + styleSetFore(CommentBody, theme->remoteComment(Theme::Comment::Body)); + styleSetBack(CommentBody, theme->remoteComment(Theme::Comment::Background)); + + styleSetFont(CommentAuthor, bold); + styleSetFore(CommentAuthor, theme->remoteComment(Theme::Comment::Author)); + styleSetBack(CommentAuthor, theme->remoteComment(Theme::Comment::Background)); + + styleSetFont(CommentTimestamp, regular); + styleSetFore(CommentTimestamp, + theme->remoteComment(Theme::Comment::Timestamp)); + styleSetBack(CommentTimestamp, + theme->remoteComment(Theme::Comment::Background)); + // Apply default settings. applySettings(); } From 7144b86e81c485648dbf09c96297a577564aee26 Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Tue, 17 Jan 2023 19:23:14 +0100 Subject: [PATCH 07/12] Adds macOS theme switch listening --- dep/openssl/openssl | 2 +- src/app/Application.cpp | 8 ++++++-- src/app/Application.h | 1 + src/ui/MainWindow.cpp | 14 ++++++++++++++ src/ui/MainWindow.h | 1 + 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dep/openssl/openssl b/dep/openssl/openssl index 1c01dbcbe..29708a562 160000 --- a/dep/openssl/openssl +++ b/dep/openssl/openssl @@ -1 +1 @@ -Subproject commit 1c01dbcbebc08d629d02326d941b8491ae99597d +Subproject commit 29708a562a1887a91de0fa6ca668c71871accde9 diff --git a/src/app/Application.cpp b/src/app/Application.cpp index dac82df53..04a332b8a 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -157,8 +157,7 @@ Application::Application(int &argc, char **argv, bool haltOnParseError) // Initialize theme. mTheme.reset(Theme::create(parser.value("theme"))); - setStyle(mTheme->style()); - setStyleSheet(mTheme->styleSheet()); + applyTheme(); #if defined(Q_OS_WIN) // Set default font style and hinting. @@ -510,3 +509,8 @@ void Application::handleSslErrors(QNetworkReply *reply, settings.setValue("ssl/ignore", true); } } + +void Application::applyTheme() { + setStyle(mTheme->style()); + setStyleSheet(mTheme->styleSheet()); +} diff --git a/src/app/Application.h b/src/app/Application.h index bd2282de2..3aee52bc9 100644 --- a/src/app/Application.h +++ b/src/app/Application.h @@ -27,6 +27,7 @@ class Application : public QApplication { void autoUpdate(); bool restoreWindows(); bool runSingleInstance(); + void applyTheme(); static bool isInTest(); static void setInTest(); diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 91b825e18..f83e31731 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -22,6 +22,7 @@ #include "git/Config.h" #include "git/Submodule.h" #include "qmap.h" +#include "app/Application.h" #include #include #include @@ -594,3 +595,16 @@ QString MainWindow::windowGroup() const { QByteArray hash = QCryptographicHash::hash(group, QCryptographicHash::Md5); return QString::fromUtf8(hash.toHex()); } + +void MainWindow::changeEvent(QEvent* e) +{ +#ifdef Q_OS_MACX + if ( e->type() == QEvent::PaletteChange ) + { + Application *app = qobject_cast(QApplication::instance()); + if (app) + app->applyTheme(); + } +#endif + QMainWindow::changeEvent( e ); +} \ No newline at end of file diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 65d0be713..970c8ff80 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -62,6 +62,7 @@ class MainWindow : public QMainWindow { void closeEvent(QCloseEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; + void changeEvent(QEvent *event) override; private: void updateTabNames(); From 2d4be0306f895c9adb3b8c77d6223e907289d735 Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Tue, 17 Jan 2023 20:35:32 +0100 Subject: [PATCH 08/12] Fixes formatting --- src/ui/MainWindow.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index f83e31731..e2eb2b1f2 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -596,15 +596,14 @@ QString MainWindow::windowGroup() const { return QString::fromUtf8(hash.toHex()); } -void MainWindow::changeEvent(QEvent* e) +void MainWindow::changeEvent(QEvent *e) { #ifdef Q_OS_MACX - if ( e->type() == QEvent::PaletteChange ) - { - Application *app = qobject_cast(QApplication::instance()); + if (e->type() == QEvent::PaletteChange) { + Application *app = qobject_cast(QApplication::instance()); if (app) app->applyTheme(); } #endif - QMainWindow::changeEvent( e ); + QMainWindow::changeEvent(e); } \ No newline at end of file From dc3004a2875dbcd60006e16c9980a32236bcb04a Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Wed, 18 Jan 2023 09:18:33 +0100 Subject: [PATCH 09/12] Fix formatting --- src/ui/MainWindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index e2eb2b1f2..294b24198 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -596,8 +596,7 @@ QString MainWindow::windowGroup() const { return QString::fromUtf8(hash.toHex()); } -void MainWindow::changeEvent(QEvent *e) -{ +void MainWindow::changeEvent(QEvent *e) { #ifdef Q_OS_MACX if (e->type() == QEvent::PaletteChange) { Application *app = qobject_cast(QApplication::instance()); From 0671ebcea056a118a449176ccaaa5ccaf6dc672f Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Fri, 20 Jan 2023 19:58:40 +0100 Subject: [PATCH 10/12] Remove ifdefs temporarily --- src/ui/MainWindow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 294b24198..a2115bec2 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -597,12 +597,11 @@ QString MainWindow::windowGroup() const { } void MainWindow::changeEvent(QEvent *e) { -#ifdef Q_OS_MACX if (e->type() == QEvent::PaletteChange) { Application *app = qobject_cast(QApplication::instance()); if (app) app->applyTheme(); } -#endif + QMainWindow::changeEvent(e); -} \ No newline at end of file +} From aea59ef7b7b3cb31c67eb051a377a394995faf0f Mon Sep 17 00:00:00 2001 From: 0verEngineer Date: Mon, 23 Jan 2023 23:27:50 +0100 Subject: [PATCH 11/12] Test TextEditor theme update --- src/editor/TextEditor.cpp | 142 +++++++++++++++++++++----------------- src/editor/TextEditor.h | 6 ++ src/ui/MainWindow.cpp | 12 +++- 3 files changed, 94 insertions(+), 66 deletions(-) diff --git a/src/editor/TextEditor.cpp b/src/editor/TextEditor.cpp index 1a4b87731..ccd2a507f 100644 --- a/src/editor/TextEditor.cpp +++ b/src/editor/TextEditor.cpp @@ -11,7 +11,6 @@ #include "app/Application.h" #include "conf/Settings.h" #include -#include #include #include #include @@ -20,6 +19,8 @@ #include "PlatQt.h" +QList TextEditor::instances; + using namespace Scintilla; namespace { @@ -52,18 +53,7 @@ const float textHeightFactorCheckBoxSize = 2.0; extern LexerModule lmLPeg; TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) { - // Load colors. - Theme *theme = Application::theme(); - mOursColor = theme->diff(Theme::Diff::Ours); - mTheirsColor = theme->diff(Theme::Diff::Theirs); - mAdditionColor = theme->diff(Theme::Diff::Addition); - mDeletionColor = theme->diff(Theme::Diff::Deletion); - - // Load icons. - QStyle *style = this->style(); - mNoteIcon = style->standardIcon(QStyle::SP_MessageBoxInformation); - mWarningIcon = style->standardIcon(QStyle::SP_MessageBoxWarning); - mErrorIcon = style->standardIcon(QStyle::SP_MessageBoxCritical); + instances.append(this); // Register the LPeg lexer. static bool initialized = false; @@ -103,57 +93,8 @@ TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) { clearCmdKey(SCK_ADD + (SCI_CTRL << 16)); clearCmdKey(SCK_SUBTRACT + (SCI_CTRL << 16)); - // Set find indicators. - indicSetStyle(FindAll, INDIC_STRAIGHTBOX); - indicSetFore(FindAll, Qt::white); - indicSetAlpha(FindAll, 255); - indicSetUnder(FindAll, true); - - indicSetStyle(FindCurrent, INDIC_STRAIGHTBOX); - indicSetFore(FindCurrent, Qt::yellow); - indicSetAlpha(FindCurrent, 255); - indicSetUnder(FindCurrent, true); - - // Set word diff indicators. - indicSetStyle(WordAddition, INDIC_STRAIGHTBOX); - indicSetFore(WordAddition, theme->diff(Theme::Diff::WordAddition)); - indicSetAlpha(WordAddition, 255); - indicSetUnder(WordAddition, true); - - indicSetStyle(WordDeletion, INDIC_STRAIGHTBOX); - indicSetFore(WordDeletion, theme->diff(Theme::Diff::WordDeletion)); - indicSetAlpha(WordDeletion, 255); - indicSetUnder(WordDeletion, true); - - indicSetStyle(NoteIndicator, INDIC_SQUIGGLE); - indicSetFore(NoteIndicator, theme->diff(Theme::Diff::Note)); - indicSetAlpha(NoteIndicator, 255); - indicSetUnder(NoteIndicator, true); + applyThemeAndSettings(); - indicSetStyle(WarningIndicator, INDIC_STRAIGHTBOX); - indicSetFore(WarningIndicator, theme->diff(Theme::Diff::Warning)); - indicSetAlpha(WarningIndicator, 255); - indicSetUnder(WarningIndicator, true); - - indicSetStyle(ErrorIndicator, INDIC_STRAIGHTBOX); - indicSetFore(ErrorIndicator, theme->diff(Theme::Diff::Error)); - indicSetAlpha(ErrorIndicator, 255); - indicSetUnder(ErrorIndicator, true); - - // Initialize LPeg lexer. - QColor base = palette().color(QPalette::Base); - QColor text = palette().color(QPalette::Text); - bool dark = (text.lightnessF() > base.lightnessF()); - - setLexerLanguage("lpeg"); - setProperty("lexer.lpeg.home", Settings::lexerDir().path()); - setProperty("lexer.lpeg.themes", theme->dir().path()); - setProperty("lexer.lpeg.theme", theme->name()); - setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light"); - setCaretFore(text); - - // Apply default settings. - applySettings(); connect(Settings::instance(), &Settings::settingsChanged, this, &TextEditor::applySettings); @@ -162,6 +103,10 @@ TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) { &TextEditor::updateGeometry); } +TextEditor::~TextEditor() { + instances.removeOne(this); +} + void TextEditor::contextMenuEvent(QContextMenuEvent *event) { Point pos = PointFromQPoint(event->globalPos()); Point pt = PointFromQPoint(event->pos()); @@ -621,3 +566,74 @@ void TextEditor::keyPressEvent(QKeyEvent *ke) { ScintillaIFace::keyPressEvent(ke); } +void TextEditor::applyThemeAndSettingsToAllInstances() { + for (const auto& instance : instances) + instance->applyThemeAndSettings(); +} + +void TextEditor::applyThemeAndSettings() { + // Load colors. + Theme *theme = Application::theme(); + mOursColor = theme->diff(Theme::Diff::Ours); + mTheirsColor = theme->diff(Theme::Diff::Theirs); + mAdditionColor = theme->diff(Theme::Diff::Addition); + mDeletionColor = theme->diff(Theme::Diff::Deletion); + + // Load icons. + QStyle *style = this->style(); + mNoteIcon = style->standardIcon(QStyle::SP_MessageBoxInformation); + mWarningIcon = style->standardIcon(QStyle::SP_MessageBoxWarning); + mErrorIcon = style->standardIcon(QStyle::SP_MessageBoxCritical); + + // Set find indicators. + indicSetStyle(FindAll, INDIC_STRAIGHTBOX); + indicSetFore(FindAll, Qt::white); + indicSetAlpha(FindAll, 255); + indicSetUnder(FindAll, true); + + indicSetStyle(FindCurrent, INDIC_STRAIGHTBOX); + indicSetFore(FindCurrent, Qt::yellow); + indicSetAlpha(FindCurrent, 255); + indicSetUnder(FindCurrent, true); + + // Set word diff indicators. + indicSetStyle(WordAddition, INDIC_STRAIGHTBOX); + indicSetFore(WordAddition, theme->diff(Theme::Diff::WordAddition)); + indicSetAlpha(WordAddition, 255); + indicSetUnder(WordAddition, true); + + indicSetStyle(WordDeletion, INDIC_STRAIGHTBOX); + indicSetFore(WordDeletion, theme->diff(Theme::Diff::WordDeletion)); + indicSetAlpha(WordDeletion, 255); + indicSetUnder(WordDeletion, true); + + indicSetStyle(NoteIndicator, INDIC_SQUIGGLE); + indicSetFore(NoteIndicator, theme->diff(Theme::Diff::Note)); + indicSetAlpha(NoteIndicator, 255); + indicSetUnder(NoteIndicator, true); + + indicSetStyle(WarningIndicator, INDIC_STRAIGHTBOX); + indicSetFore(WarningIndicator, theme->diff(Theme::Diff::Warning)); + indicSetAlpha(WarningIndicator, 255); + indicSetUnder(WarningIndicator, true); + + indicSetStyle(ErrorIndicator, INDIC_STRAIGHTBOX); + indicSetFore(ErrorIndicator, theme->diff(Theme::Diff::Error)); + indicSetAlpha(ErrorIndicator, 255); + indicSetUnder(ErrorIndicator, true); + + // Initialize LPeg lexer. + QColor base = palette().color(QPalette::Base); + QColor text = palette().color(QPalette::Text); + bool dark = (text.lightnessF() > base.lightnessF()); + + setLexerLanguage("lpeg"); + setProperty("lexer.lpeg.home", Settings::lexerDir().path()); + setProperty("lexer.lpeg.themes", theme->dir().path()); + setProperty("lexer.lpeg.theme", theme->name()); + setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light"); + setCaretFore(text); + + // Apply default settings. + applySettings(); +} diff --git a/src/editor/TextEditor.h b/src/editor/TextEditor.h index 0ae8b7b43..498d6d09f 100644 --- a/src/editor/TextEditor.h +++ b/src/editor/TextEditor.h @@ -84,6 +84,7 @@ class TextEditor : public Scintilla::ScintillaIFace { }; TextEditor(QWidget *parent = nullptr); + ~TextEditor(); void applySettings(); @@ -119,6 +120,8 @@ class TextEditor : public Scintilla::ScintillaIFace { return QRect(pr.left, pr.top, pr.Width(), pr.Height()); } + static void applyThemeAndSettingsToAllInstances(); + signals: void settingsChanged(); void highlightActivated(bool active); @@ -156,6 +159,7 @@ class TextEditor : public Scintilla::ScintillaIFace { void loadMarkerPixmap(Marker marker, const QPixmap &pixmap); void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) override; void ContextMenu(Scintilla::Point pt); + void applyThemeAndSettings(); QString mPath; int mLineCount = -1; @@ -179,6 +183,8 @@ class TextEditor : public Scintilla::ScintillaIFace { QPixmap mUnStagedIcon; QMap> mDiagnostics; + + static QList instances; }; #endif diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index a2115bec2..ba12f0912 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -23,6 +23,7 @@ #include "git/Submodule.h" #include "qmap.h" #include "app/Application.h" +#include "editor/TextEditor.h" #include #include #include @@ -596,12 +597,17 @@ QString MainWindow::windowGroup() const { return QString::fromUtf8(hash.toHex()); } -void MainWindow::changeEvent(QEvent *e) { - if (e->type() == QEvent::PaletteChange) { +void MainWindow::changeEvent(QEvent *event) { +#ifdef Q_OS_MAC + if (event->type() == QEvent::PaletteChange) { +#else + if (event->type() == QEvent::ThemeChange) { +#endif Application *app = qobject_cast(QApplication::instance()); if (app) app->applyTheme(); + TextEditor::applyThemeAndSettingsToAllInstances(); } - QMainWindow::changeEvent(e); + QMainWindow::changeEvent(event); } From f1d9eeb3796455257a9d48ca499b79db4ebc6fc4 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Fri, 27 Jan 2023 14:19:00 +0100 Subject: [PATCH 12/12] Description: forgotten to set style --- src/editor/TextEditor.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/editor/TextEditor.cpp b/src/editor/TextEditor.cpp index ccd2a507f..209332d3a 100644 --- a/src/editor/TextEditor.cpp +++ b/src/editor/TextEditor.cpp @@ -182,22 +182,6 @@ void TextEditor::applySettings() { // Missing newline style. styleSetFont(EofNewline, italic); - // Remote comment styles - Theme *theme = Application::theme(); - styleSetFont(CommentBody, regular); - styleSetFore(CommentBody, theme->remoteComment(Theme::Comment::Body)); - styleSetBack(CommentBody, theme->remoteComment(Theme::Comment::Background)); - - styleSetFont(CommentAuthor, bold); - styleSetFore(CommentAuthor, theme->remoteComment(Theme::Comment::Author)); - styleSetBack(CommentAuthor, theme->remoteComment(Theme::Comment::Background)); - - styleSetFont(CommentTimestamp, regular); - styleSetFore(CommentTimestamp, - theme->remoteComment(Theme::Comment::Timestamp)); - styleSetBack(CommentTimestamp, - theme->remoteComment(Theme::Comment::Background)); - // Emit own signal. emit settingsChanged(); @@ -634,6 +618,25 @@ void TextEditor::applyThemeAndSettings() { setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light"); setCaretFore(text); + QFont regular = font(); + QFont bold = regular; + bold.setBold(true); + + // Remote comment styles + styleSetFont(CommentBody, regular); + styleSetFore(CommentBody, theme->remoteComment(Theme::Comment::Body)); + styleSetBack(CommentBody, theme->remoteComment(Theme::Comment::Background)); + + styleSetFont(CommentAuthor, bold); + styleSetFore(CommentAuthor, theme->remoteComment(Theme::Comment::Author)); + styleSetBack(CommentAuthor, theme->remoteComment(Theme::Comment::Background)); + + styleSetFont(CommentTimestamp, regular); + styleSetFore(CommentTimestamp, + theme->remoteComment(Theme::Comment::Timestamp)); + styleSetBack(CommentTimestamp, + theme->remoteComment(Theme::Comment::Background)); + // Apply default settings. applySettings(); }