Commit 209f0086 authored by hjk's avatar hjk
Browse files

TextEditor: Draw background first.



Task-number: QTCREATORBUG-13028
Change-Id: I14ae1794c920b3877f9eca468e1180042b51fb3f
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@digia.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 2b8e8189
......@@ -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());
......
......@@ -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<DiffSelection> &selections,
const QTextBlock &block,
......
......@@ -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<BaseTextDocumentLayout*>(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(),
......
......@@ -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 *);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment