forked from qt-creator/qt-creator
TextEditor: skip painting overlays with invalid background
Makes it possible to turn of specific overlays by unsetting the color. Such color resulted in a black overlay until now, which is also kind of unexpected. Change-Id: I90732ae496af62b573b2e3b8d8c7fe56632ca8d9 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -323,9 +323,7 @@ void TextEditorOverlay::paintSelection(QPainter *painter,
|
||||
const QColor &bg = selection.m_bg;
|
||||
|
||||
|
||||
if (begin.isNull()
|
||||
|| end.isNull()
|
||||
|| begin.position() > end.position())
|
||||
if (begin.isNull() || end.isNull() || begin.position() > end.position() || !bg.isValid())
|
||||
return;
|
||||
|
||||
QPainterPath path = createSelectionPath(begin, end, m_editor->viewport()->rect());
|
||||
@@ -339,25 +337,21 @@ void TextEditorOverlay::paintSelection(QPainter *painter,
|
||||
|
||||
QRectF pathRect = path.controlPointRect();
|
||||
|
||||
if (bg.isValid()) {
|
||||
if (!m_alpha || begin.blockNumber() != end.blockNumber()) {
|
||||
// gradients are too slow for larger selections :(
|
||||
QColor col = bg;
|
||||
if (m_alpha)
|
||||
col.setAlpha(50);
|
||||
painter->setBrush(col);
|
||||
} else {
|
||||
QLinearGradient linearGrad(pathRect.topLeft(), pathRect.bottomLeft());
|
||||
QColor col1 = fg.lighter(150);
|
||||
col1.setAlpha(20);
|
||||
QColor col2 = fg;
|
||||
col2.setAlpha(80);
|
||||
linearGrad.setColorAt(0, col1);
|
||||
linearGrad.setColorAt(1, col2);
|
||||
painter->setBrush(QBrush(linearGrad));
|
||||
}
|
||||
if (!m_alpha || begin.blockNumber() != end.blockNumber()) {
|
||||
// gradients are too slow for larger selections :(
|
||||
QColor col = bg;
|
||||
if (m_alpha)
|
||||
col.setAlpha(50);
|
||||
painter->setBrush(col);
|
||||
} else {
|
||||
painter->setBrush(QBrush());
|
||||
QLinearGradient linearGrad(pathRect.topLeft(), pathRect.bottomLeft());
|
||||
QColor col1 = fg.lighter(150);
|
||||
col1.setAlpha(20);
|
||||
QColor col2 = fg;
|
||||
col2.setAlpha(80);
|
||||
linearGrad.setColorAt(0, col1);
|
||||
linearGrad.setColorAt(1, col2);
|
||||
painter->setBrush(QBrush(linearGrad));
|
||||
}
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
Reference in New Issue
Block a user