QCodeEdit dark theme test
This commit is contained in:
@@ -584,6 +584,7 @@ void QCodeEdit::changeEvent(QEvent * e) {
|
||||
ui->retranslateUi(this);
|
||||
lbl_help[lhF1]->setText(tr("Press F1 for details"));
|
||||
break;
|
||||
case QEvent::PaletteChange: is_dark_theme = palette().color(QPalette::Window).valueF() < 0.5; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -876,8 +877,21 @@ void QCodeEdit::highlightBrackets() {
|
||||
|
||||
|
||||
void QCodeEdit::applyExtraSelection() {
|
||||
ui->textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected << es_custom << es_brackets
|
||||
<< es_search_list << es_cursor << es_link << es_blockselection);
|
||||
auto inverseColorValue = [](const QColor & c) {
|
||||
qreal hsv[4];
|
||||
c.getHsvF(&hsv[0], &hsv[1], &hsv[2], &hsv[3]);
|
||||
return QColor::fromHsvF(hsv[0], hsv[1], 1. - 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()));
|
||||
}
|
||||
}
|
||||
esl << es_blockselection;
|
||||
ui->textCode->setExtraSelections(esl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user