another try for dark theme
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user