Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dep/openssl/openssl
Submodule openssl updated 9077 files
8 changes: 6 additions & 2 deletions src/app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -510,3 +509,8 @@ void Application::handleSslErrors(QNetworkReply *reply,
settings.setValue("ssl/ignore", true);
}
}

void Application::applyTheme() {
setStyle(mTheme->style());
setStyleSheet(mTheme->styleSheet());
}
1 change: 1 addition & 0 deletions src/app/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Application : public QApplication {
void autoUpdate();
bool restoreWindows();
bool runSingleInstance();
void applyTheme();

static bool isInTest();
static void setInTest();
Expand Down
177 changes: 98 additions & 79 deletions src/editor/TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "app/Application.h"
#include "conf/Settings.h"
#include <QFocusEvent>
#include <QMainWindow>
#include <QScrollBar>
#include <QStyle>
#include <QWindow>
Expand All @@ -20,6 +19,8 @@

#include "PlatQt.h"

QList<TextEditor*> TextEditor::instances;

using namespace Scintilla;

namespace {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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());
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
6 changes: 6 additions & 0 deletions src/editor/TextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class TextEditor : public Scintilla::ScintillaIFace {
};

TextEditor(QWidget *parent = nullptr);
~TextEditor();

void applySettings();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -179,6 +183,8 @@ class TextEditor : public Scintilla::ScintillaIFace {
QPixmap mUnStagedIcon;

QMap<int, QList<Diagnostic>> mDiagnostics;

static QList<TextEditor*> instances;
};

#endif
17 changes: 17 additions & 0 deletions src/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "git/Config.h"
#include "git/Submodule.h"
#include "qmap.h"
#include "app/Application.h"
#include "editor/TextEditor.h"
#include <QApplication>
#include <QCloseEvent>
#include <QGuiApplication>
Expand Down Expand Up @@ -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<Application *>(QApplication::instance());
if (app)
app->applyTheme();
TextEditor::applyThemeAndSettingsToAllInstances();
}

QMainWindow::changeEvent(event);
}
1 change: 1 addition & 0 deletions src/ui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down