Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 99c9e29f rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Small theme selector at compile time

parent c069b6f1
Branches
Étiquettes
1 requête de fusion!11Change a bit the UI + Add simple scripts support
...@@ -29,13 +29,22 @@ ScriptEditor::LineNumberArea::paintEvent(QPaintEvent *event) noexcept ...@@ -29,13 +29,22 @@ ScriptEditor::LineNumberArea::paintEvent(QPaintEvent *event) noexcept
ScriptEditor::ScriptEditor(QWidget *parent) noexcept ScriptEditor::ScriptEditor(QWidget *parent) noexcept
: QPlainTextEdit(parent) : QPlainTextEdit(parent)
{ {
setStyleSheet(QStringLiteral("* { font-family: \"FiraCode\"; font-size: 10pt}")); setStyleSheet(QStringLiteral("* {"
" background-color: #232629;"
" font-family: \"FiraCode\";"
" font-size: 10pt"
"}"));
lineNumberArea = new LineNumberArea(this); lineNumberArea = new LineNumberArea(this);
setFrameShape(QFrame::NoFrame); setFrameShape(QFrame::NoFrame);
connect(this, &ScriptEditor::blockCountChanged, this, &ScriptEditor::updateLineNumberAreaWidth); connect(this, &ScriptEditor::blockCountChanged, this, &ScriptEditor::updateLineNumberAreaWidth);
connect(this, &ScriptEditor::updateRequest, this, &ScriptEditor::updateLineNumberArea); connect(this, &ScriptEditor::updateRequest, this, &ScriptEditor::updateLineNumberArea);
QTextCharFormat textFormat;
textFormat.setForeground(QBrush(Qt::white));
mergeCurrentCharFormat(textFormat);
setBackgroundVisible(true);
updateLineNumberAreaWidth(0); updateLineNumberAreaWidth(0);
} }
...@@ -99,7 +108,7 @@ void ...@@ -99,7 +108,7 @@ void
ScriptEditor::lineNumberAreaPaintEvent(QPaintEvent *event) noexcept ScriptEditor::lineNumberAreaPaintEvent(QPaintEvent *event) noexcept
{ {
QPainter painter(lineNumberArea); QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), QColor::fromRgb(69, 83, 100)); painter.fillRect(event->rect(), QColor::fromRgb(49, 54, 59));
QTextBlock block = firstVisibleBlock(); QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber(); int blockNumber = block.blockNumber();
int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top()); int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
......
...@@ -12,6 +12,25 @@ VivyApplication::VivyApplication(int &argc, char **argv) ...@@ -12,6 +12,25 @@ VivyApplication::VivyApplication(int &argc, char **argv)
{ {
} }
void
VivyApplication::setTheme(Theme theme) noexcept
{
if (theme == Theme::System)
return;
const QString sheet = theme == Theme::Dark ? QStringLiteral(":qdarkstyle/dark/style.qss")
: QStringLiteral(":qdarkstyle/light/style.qss");
QFile stylesheet(sheet);
if (!stylesheet.exists()) {
qFatal("Missing stylesheet");
} else {
stylesheet.open(QFile::ReadOnly | QFile::Text);
QTextStream stylesheetStream(&stylesheet);
setStyleSheet(stylesheetStream.readAll());
}
}
int int
VivyApplication::exec() noexcept VivyApplication::exec() noexcept
{ {
...@@ -27,13 +46,8 @@ VivyApplication::exec() noexcept ...@@ -27,13 +46,8 @@ VivyApplication::exec() noexcept
setAttribute(Qt::AA_DontShowIconsInMenus, false); setAttribute(Qt::AA_DontShowIconsInMenus, false);
setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false); setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false);
setFont(getApplicationFont(Font::Default)); setFont(getApplicationFont(Font::Default));
QFile stylesheet(":qdarkstyle/dark/style.qss"); setTheme(Theme::Dark); // TODO: Set system theme for now (because we
if (!stylesheet.exists()) { // don't have a central theme provider).
qFatal("Missing stylesheet");
}
stylesheet.open(QFile::ReadOnly | QFile::Text);
QTextStream stylesheetStream(&stylesheet);
setStyleSheet(stylesheetStream.readAll());
// Cursor blinking // Cursor blinking
setCursorFlashTime(0); setCursorFlashTime(0);
......
...@@ -44,6 +44,12 @@ public: ...@@ -44,6 +44,12 @@ public:
DefaultBoldItalic, DefaultBoldItalic,
}; };
enum class Theme {
System,
Dark,
Light,
};
private: private:
int fontIdMonospace; int fontIdMonospace;
int fontIdMonospaceBold; int fontIdMonospaceBold;
...@@ -58,6 +64,7 @@ public: ...@@ -58,6 +64,7 @@ public:
int exec() noexcept; int exec() noexcept;
QFont getApplicationFont(Font) const noexcept; QFont getApplicationFont(Font) const noexcept;
void setTheme(Theme) noexcept;
}; };
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter