From 209f0086629b4f39518e8f0787702d53a26d2655 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 23 Sep 2014 18:38:36 +0200 Subject: [PATCH] TextEditor: Draw background first. Task-number: QTCREATORBUG-13028 Change-Id: I14ae1794c920b3877f9eca468e1180042b51fb3f Reviewed-by: Jarek Kobus Reviewed-by: David Schulz --- .../diffeditor/selectabletexteditorwidget.cpp | 8 +--- .../diffeditor/selectabletexteditorwidget.h | 5 +-- src/plugins/texteditor/basetexteditor.cpp | 37 +++++++++++-------- src/plugins/texteditor/basetexteditor.h | 1 + 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/plugins/diffeditor/selectabletexteditorwidget.cpp b/src/plugins/diffeditor/selectabletexteditorwidget.cpp index 95a48bc56a9..29fad396f0e 100644 --- a/src/plugins/diffeditor/selectabletexteditorwidget.cpp +++ b/src/plugins/diffeditor/selectabletexteditorwidget.cpp @@ -46,13 +46,7 @@ SelectableTextEditorWidget::~SelectableTextEditorWidget() { } -void SelectableTextEditorWidget::paintEvent(QPaintEvent *e) -{ - paintSelections(e); - BaseTextEditorWidget::paintEvent(e); -} - -void SelectableTextEditorWidget::paintSelections(QPaintEvent *e) +void SelectableTextEditorWidget::innerPaintEvent(QPaintEvent *e) { QPainter painter(viewport()); diff --git a/src/plugins/diffeditor/selectabletexteditorwidget.h b/src/plugins/diffeditor/selectabletexteditorwidget.h index 2b60323b38a..bb80934b0d6 100644 --- a/src/plugins/diffeditor/selectabletexteditorwidget.h +++ b/src/plugins/diffeditor/selectabletexteditorwidget.h @@ -58,11 +58,8 @@ public: m_selections = selections; } -protected: - virtual void paintEvent(QPaintEvent *e); - private: - void paintSelections(QPaintEvent *e); + void innerPaintEvent(QPaintEvent *e); void paintSelections(QPainter &painter, const QList &selections, const QTextBlock &block, diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 1179561bce9..0180d5e9386 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -3435,6 +3435,27 @@ static QTextLayout::FormatRange createBlockCursorCharFormatRange(int pos, const void BaseTextEditorWidget::paintEvent(QPaintEvent *e) { + // draw backgrond to the right of the wrap column before everything else + qreal lineX = 0; + QPointF offset(contentOffset()); + QRect viewportRect = viewport()->rect(); + QRect er = e->rect(); + + const FontSettings &fs = textDocument()->fontSettings(); + const QTextCharFormat &searchScopeFormat = fs.toTextCharFormat(C_SEARCH_SCOPE); + const QTextCharFormat &ifdefedOutFormat = fs.toTextCharFormat(C_DISABLED_CODE); + + if (d->m_visibleWrapColumn > 0) { + QPainter painter(viewport()); + // Don't use QFontMetricsF::averageCharWidth here, due to it returning + // a fractional size even when this is not supported by the platform. + lineX = QFontMetricsF(font()).width(QLatin1Char('x')) * d->m_visibleWrapColumn + offset.x() + 4; + if (lineX < viewportRect.width()) + painter.fillRect(QRectF(lineX, er.top(), viewportRect.width() - lineX, er.height()), + ifdefedOutFormat.background()); + } + + innerPaintEvent(e); /* Here comes an almost verbatim copy of QPlainTextEdit::paintEvent() so we can adjust the extra @@ -3446,22 +3467,13 @@ void BaseTextEditorWidget::paintEvent(QPaintEvent *e) QTextDocument *doc = document(); BaseTextDocumentLayout *documentLayout = qobject_cast(doc->documentLayout()); QTC_ASSERT(documentLayout, return); - const FontSettings &fs = textDocument()->fontSettings(); - const QTextCharFormat &searchScopeFormat = fs.toTextCharFormat(C_SEARCH_SCOPE); - const QTextCharFormat &ifdefedOutFormat = fs.toTextCharFormat(C_DISABLED_CODE); - QPointF offset(contentOffset()); QTextBlock textCursorBlock = textCursor().block(); bool hasMainSelection = textCursor().hasSelection(); bool suppressSyntaxInIfdefedOutBlock = (ifdefedOutFormat.foreground() != palette().foreground()); - QRect er = e->rect(); - QRect viewportRect = viewport()->rect(); - - qreal lineX = 0; - // Set a brush origin so that the WaveUnderline knows where the wave started painter.setBrushOrigin(offset); @@ -3607,15 +3619,8 @@ void BaseTextEditorWidget::paintEvent(QPaintEvent *e) // draw wrap column after ifdefed out blocks if (d->m_visibleWrapColumn > 0) { - // Don't use QFontMetricsF::averageCharWidth here, due to it returning - // a fractional size even when this is not supported by the platform. - lineX = QFontMetricsF(font()).width(QLatin1Char('x')) * d->m_visibleWrapColumn + offset.x() + 4; - if (lineX < viewportRect.width()) { const QBrush background = ifdefedOutFormat.background(); - painter.fillRect(QRectF(lineX, er.top(), viewportRect.width() - lineX, er.height()), - background); - const QColor col = (palette().base().color().value() > 128) ? Qt::black : Qt::white; const QPen pen = painter.pen(); painter.setPen(blendColors(background.isOpaque() ? background.color() : palette().base().color(), diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 93e394dc267..cdd4cd284a6 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -495,6 +495,7 @@ protected: bool viewportEvent(QEvent *event); void resizeEvent(QResizeEvent *); void paintEvent(QPaintEvent *); + virtual void innerPaintEvent(QPaintEvent *) {} void timerEvent(QTimerEvent *); void mouseMoveEvent(QMouseEvent *); void mousePressEvent(QMouseEvent *);