another try for dark theme

This commit is contained in:
2024-01-18 18:04:02 +03:00
parent 2739cc53ec
commit 071a73f5ba
2 changed files with 24 additions and 7 deletions

View File

@@ -877,18 +877,32 @@ void QCodeEdit::highlightBrackets() {
}
QColor inverseColorValue(const QColor & c) {
int hsv[4];
c.getHsv(&hsv[0], &hsv[1], &hsv[2], &hsv[3]);
return QColor::fromHsv(hsv[0], hsv[1], 255 - hsv[2], hsv[3]);
}
QBrush QCodeEdit::invertedBrush(const QBrush & b) {
auto ret = b;
ret.setColor(inverseColorValue(b.color()));
return ret;
}
QTextCharFormat QCodeEdit::invertedFormat(const QTextCharFormat & f) {
auto ret = f;
ret.setForeground(invertedBrush(ret.foreground()));
ret.setBackground(invertedBrush(ret.background()));
return ret;
}
void QCodeEdit::applyExtraSelection() {
auto inverseColorValue = [](const QColor & c) {
int hsv[4];
c.getHsv(&hsv[0], &hsv[1], &hsv[2], &hsv[3]);
return QColor::fromHsv(hsv[0], hsv[1], 255 - hsv[2], hsv[3]);
};
QList<QTextEdit::ExtraSelection> esl;
esl << es_line << es_selected << es_custom << es_brackets << es_search_list << es_cursor << es_link;
if (is_dark_theme) {
for (auto & e: esl) {
e.format.foreground().setColor(inverseColorValue(e.format.foreground().color()));
e.format.background().setColor(inverseColorValue(e.format.background().color()));
e.format = invertedFormat(e.format);
}
}
esl << es_blockselection;

View File

@@ -111,6 +111,9 @@ public:
void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon());
bool wordCompletitionEnabled() const { return word_complete; }
static QBrush invertedBrush(const QBrush & b);
static QTextCharFormat invertedFormat(const QTextCharFormat & f);
protected:
typedef QPair<QString, QString> StringsPair;
typedef QPair<int, QList<ACEntry>> ACSection; // section, ACClass.id -> list of entries