diff --git a/libs/widgets/qcodeedit.cpp b/libs/widgets/qcodeedit.cpp index 64d5035..e23cd48 100644 --- a/libs/widgets/qcodeedit.cpp +++ b/libs/widgets/qcodeedit.cpp @@ -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 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; diff --git a/libs/widgets/qcodeedit.h b/libs/widgets/qcodeedit.h index 7caa9aa..1946bbc 100644 --- a/libs/widgets/qcodeedit.h +++ b/libs/widgets/qcodeedit.h @@ -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 StringsPair; typedef QPair> ACSection; // section, ACClass.id -> list of entries