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/editor/TextEditor.cpp b/src/editor/TextEditor.cpp index 1a4b87731..209332d3a 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); - - 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); + applyThemeAndSettings(); - // 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()); @@ -237,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(); @@ -621,3 +550,93 @@ 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); + + 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(); +} 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 91b825e18..ba12f0912 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -22,6 +22,8 @@ #include "git/Config.h" #include "git/Submodule.h" #include "qmap.h" +#include "app/Application.h" +#include "editor/TextEditor.h" #include #include #include @@ -594,3 +596,18 @@ QString MainWindow::windowGroup() const { QByteArray hash = QCryptographicHash::hash(group, QCryptographicHash::Md5); return QString::fromUtf8(hash.toHex()); } + +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(event); +} 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();