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
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!11Change a bit the UI + Add simple scripts support
......@@ -29,13 +29,22 @@ ScriptEditor::LineNumberArea::paintEvent(QPaintEvent *event) noexcept
ScriptEditor::ScriptEditor(QWidget *parent) noexcept
: 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);
setFrameShape(QFrame::NoFrame);
connect(this, &ScriptEditor::blockCountChanged, this, &ScriptEditor::updateLineNumberAreaWidth);
connect(this, &ScriptEditor::updateRequest, this, &ScriptEditor::updateLineNumberArea);
QTextCharFormat textFormat;
textFormat.setForeground(QBrush(Qt::white));
mergeCurrentCharFormat(textFormat);
setBackgroundVisible(true);
updateLineNumberAreaWidth(0);
}
......@@ -99,7 +108,7 @@ void
ScriptEditor::lineNumberAreaPaintEvent(QPaintEvent *event) noexcept
{
QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), QColor::fromRgb(69, 83, 100));
painter.fillRect(event->rect(), QColor::fromRgb(49, 54, 59));
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
......
......@@ -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
VivyApplication::exec() noexcept
{
......@@ -27,13 +46,8 @@ VivyApplication::exec() noexcept
setAttribute(Qt::AA_DontShowIconsInMenus, false);
setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false);
setFont(getApplicationFont(Font::Default));
QFile stylesheet(":qdarkstyle/dark/style.qss");
if (!stylesheet.exists()) {
qFatal("Missing stylesheet");
}
stylesheet.open(QFile::ReadOnly | QFile::Text);
QTextStream stylesheetStream(&stylesheet);
setStyleSheet(stylesheetStream.readAll());
setTheme(Theme::Dark); // TODO: Set system theme for now (because we
// don't have a central theme provider).
// Cursor blinking
setCursorFlashTime(0);
......
......@@ -44,6 +44,12 @@ public:
DefaultBoldItalic,
};
enum class Theme {
System,
Dark,
Light,
};
private:
int fontIdMonospace;
int fontIdMonospaceBold;
......@@ -58,6 +64,7 @@ public:
int exec() 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