Dark mode support
Centralized all colors, tweaked application paletter in darkmode to make it darker.
This commit is contained in:
parent
aac55b0ed1
commit
86a9a0d709
19 changed files with 335 additions and 73 deletions
|
|
@ -14,6 +14,7 @@
|
|||
CodeEditor::CodeEditor(QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
, gutterArea(new EditorGutter(this))
|
||||
, colorTheme(GetColorTheme())
|
||||
{
|
||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateGutterAreaWidth(int)));
|
||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateGutterArea(QRect,int)));
|
||||
|
|
@ -69,8 +70,7 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
|
|||
void CodeEditor::highlightCurrentLine()
|
||||
{
|
||||
QTextEdit::ExtraSelection selection;
|
||||
QColor lineColor = QColor(Qt::yellow).lighter(160);
|
||||
selection.format.setBackground(lineColor);
|
||||
selection.format.setBackground(colorTheme.currentLine);
|
||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
selection.cursor = textCursor();
|
||||
selection.cursor.clearSelection();
|
||||
|
|
@ -87,8 +87,7 @@ void CodeEditor::onTextChanged()
|
|||
void CodeEditor::addErrorMarker(int position, int length)
|
||||
{
|
||||
QTextEdit::ExtraSelection selection;
|
||||
QColor lineColor = QColor(Qt::red).lighter(160);
|
||||
selection.format.setBackground(lineColor);
|
||||
selection.format.setBackground(colorTheme.errorLine);
|
||||
selection.format.setFontItalic(true);
|
||||
selection.cursor = textCursor();
|
||||
selection.cursor.setPosition(position);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QPlainTextEdit>
|
||||
#include <set>
|
||||
#include "util/Colors.h"
|
||||
|
||||
/** This class adds some capabilities to QPlainTextEdit that are useful
|
||||
* in code editor scenarios.
|
||||
|
|
@ -39,6 +40,7 @@ private:
|
|||
|
||||
QTextEdit::ExtraSelection currentLine;
|
||||
QList<QTextEdit::ExtraSelection> errorMarkers;
|
||||
const ColorTheme &colorTheme;
|
||||
|
||||
std::set<int> errorLines;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,14 @@ GutterPainter::GutterPainter(CodeEditor *editor, QPaintEvent *event)
|
|||
, painter(editor->gutterArea)
|
||||
, event(event)
|
||||
, fontMetrics(editor->fontMetrics())
|
||||
{}
|
||||
, colorTheme(GetColorTheme())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GutterPainter::Paint()
|
||||
{
|
||||
painter.fillRect(event->rect(), Qt::lightGray);
|
||||
painter.fillRect(event->rect(), colorTheme.gutterBackground);
|
||||
|
||||
LoopState loopState(editor);
|
||||
// We will now loop through all visible lines and paint the line numbers in the
|
||||
|
|
@ -37,7 +40,7 @@ void GutterPainter::Paint()
|
|||
void GutterPainter::drawLineNumber(const LoopState &loopState)
|
||||
{
|
||||
QString number = QString::number(loopState.blockNumber() + 1);
|
||||
painter.setPen(Qt::black);
|
||||
painter.setPen(colorTheme.lineNumber);
|
||||
painter.drawText(0, loopState.top, editor->gutterArea->width(), fontMetrics.height(),
|
||||
Qt::AlignRight, number);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <QPainter>
|
||||
#include <QTextBlock>
|
||||
#include "util/Colors.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -13,10 +14,13 @@ public:
|
|||
|
||||
void Paint();
|
||||
private:
|
||||
|
||||
CodeEditor *editor;
|
||||
QPainter painter;
|
||||
QPaintEvent *event;
|
||||
QFontMetrics fontMetrics;
|
||||
const ColorTheme &colorTheme;
|
||||
|
||||
|
||||
struct LoopState {
|
||||
CodeEditor *editor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue