Commit b7e12e23 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Changed classic folding markers

This new look fits better with the new behaviour. Also, the
collapse/expand markers are now drawn by the style.
parent ab47d78c
......@@ -39,7 +39,6 @@
#include "codecselector.h"
#ifndef TEXTEDITOR_STANDALONE
#include <coreplugin/manhattanstyle.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <extensionsystem/pluginmanager.h>
......@@ -2197,6 +2196,34 @@ void BaseTextEditor::slotUpdateExtraAreaWidth()
setViewportMargins(0, 0, extraAreaWidth(), 0);
}
static void drawRectBox(QPainter *painter, const QRect &rect, bool start, bool end,
const QPalette &pal)
{
painter->setRenderHint(QPainter::Antialiasing, false);
const QColor c = pal.highlight().color();
QLinearGradient grad(rect.topRight(), rect.topLeft());
grad.setColorAt(0, c.lighter(110));
grad.setColorAt(1, c);
painter->fillRect(rect, grad);
QColor white = Qt::white;
white.setAlpha(128);
QColor black = Qt::black;
black.setAlpha(32);
painter->setPen(white);
painter->drawLine(rect.topLeft(), rect.bottomLeft());
if (start)
painter->drawLine(rect.topLeft(), rect.topRight());
painter->setPen(black);
painter->drawLine(rect.topRight(), rect.bottomRight());
if (end)
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
}
void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
{
QTextDocument *doc = document();
......@@ -2228,7 +2255,7 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top;
while (block.isValid() && top <= e->rect().bottom()) {
......@@ -2285,7 +2312,6 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
if (d->m_codeFoldingVisible && d->m_displaySettings.m_fancyFoldingBar) {
QRect r(extraAreaWidth+2, top, collapseBoxWidth-4, bottom - top);
bool drawBox = !nextBlock.isVisible();
int extraAreaHighlightCollapseBlockNumber = -1;
int extraAreaHighlightCollapseEndBlockNumber = -1;
......@@ -2306,6 +2332,7 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
color = calcMixColor(pal.highlight().color(), color);
painter.fillRect(r, color);
bool drawBox = !nextBlock.isVisible();
bool drawDown = !d->m_highlightBlocksInfo.isEmpty()
&& blockNumber == extraAreaHighlightCollapseBlockNumber;
bool drawUp = !d->m_highlightBlocksInfo.isEmpty()
......@@ -2361,7 +2388,6 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
}
}
int extraAreaHighlightCollapseBlockNumber = -1;
int extraAreaHighlightCollapseEndBlockNumber = -1;
bool endIsVisible = false;
......@@ -2372,27 +2398,14 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
QTextBlock before = doc->findBlockByNumber(extraAreaHighlightCollapseBlockNumber-1);
if (TextBlockUserData::hasCollapseAfter(before)) {
extraAreaHighlightCollapseBlockNumber--;
extraAreaHighlightCollapseBlockNumber--;
}
}
const QRect box(extraAreaWidth + collapseBoxWidth/4, top + collapseBoxWidth/4,
2 * (collapseBoxWidth/4) + 1, 2 * (collapseBoxWidth/4) + 1);
const QPoint boxCenter = box.center();
QColor textColorInactive = pal.text().color();
textColorInactive.setAlpha(100);
QColor textColor = pal.text().color();
QPen activePen(textColor);
QPen inactivePen(textColorInactive);
TextBlockUserData *nextBlockUserData = TextEditDocumentLayout::testUserData(nextBlock);
bool collapseNext = nextBlockUserData
&& nextBlockUserData->collapseMode()
== TextBlockUserData::CollapseThis
&& nextBlockUserData->collapseMode() == TextBlockUserData::CollapseThis
&& !nextBlockUserData->ifdefedOut();
bool nextHasClosingCollapse = nextBlockUserData
......@@ -2400,36 +2413,25 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
&& nextBlockUserData->ifdefedOut();
bool drawBox = ((collapseAfter || collapseNext) && !nextHasClosingCollapse);
bool active = blockNumber == extraAreaHighlightCollapseBlockNumber;
bool drawStart = drawBox && active;
bool drawEnd = blockNumber == extraAreaHighlightCollapseEndBlockNumber || (drawStart && !endIsVisible);
if (blockNumber > extraAreaHighlightCollapseBlockNumber
&& blockNumber < extraAreaHighlightCollapseEndBlockNumber) {
painter.setPen(activePen);
painter.drawLine(boxCenter.x(), top, boxCenter.x(), bottom - 1);
} else if (blockNumber == extraAreaHighlightCollapseBlockNumber
&& nextVisibleBlockNumber <= extraAreaHighlightCollapseEndBlockNumber) {
painter.setPen(activePen);
painter.drawLine(boxCenter.x(), boxCenter.y(), boxCenter.x(), bottom - 1);
} else if (blockNumber == extraAreaHighlightCollapseEndBlockNumber) {
painter.setPen(activePen);
painter.drawLine(boxCenter.x(), top, boxCenter.x(), boxCenter.y());
if ( blockNumber >= extraAreaHighlightCollapseBlockNumber
&& blockNumber <= extraAreaHighlightCollapseEndBlockNumber) {
QRect box = QRect(extraAreaWidth + 1, top, collapseBoxWidth - 2, collapseBoxWidth);
drawRectBox(&painter, box, drawStart, drawEnd, pal);
}
if (drawBox) {
painter.setPen(blockNumber == extraAreaHighlightCollapseBlockNumber ?
activePen : inactivePen);
painter.setBrush(pal.base());
painter.drawRect(box.adjusted(0, 0, -1, -1));
if (!nextBlock.isVisible())
painter.drawLine(boxCenter.x(), box.top() + 2, boxCenter.x(), box.bottom() - 2);
painter.drawLine(box.left() + 2, boxCenter.y(), box.right() - 2, boxCenter.y());
} else if (blockNumber == extraAreaHighlightCollapseEndBlockNumber) {
painter.setPen(activePen);
painter.drawLine(boxCenter.x() + 1, boxCenter.y(), box.right() - 1, boxCenter.y());
bool expanded = nextBlock.isVisible();
QRect box(extraAreaWidth + collapseBoxWidth/4 + 1, top + collapseBoxWidth/4,
2 * (collapseBoxWidth/4) + 1, 2 * (collapseBoxWidth/4) + 1);
drawFoldingMarker(&painter, box, expanded, active);
}
}
painter.restore();
}
......@@ -2477,6 +2479,24 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e)
}
}
void BaseTextEditor::drawFoldingMarker(QPainter *painter, const QRect &rect,
bool expanded, bool hovered) const
{
QStyleOptionViewItemV2 opt;
opt.rect = QRect(rect.center(), QSize());
opt.state = QStyle::State_Active | QStyle::State_Item | QStyle::State_Children;
if (expanded)
opt.state |= QStyle::State_Open;
else
opt.state |= QStyle::State_Enabled;
if (hovered)
opt.state |= QStyle::State_MouseOver | QStyle::State_Enabled | QStyle::State_Selected;
style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this);
}
void BaseTextEditor::slotModificationChanged(bool m)
{
if (m)
......@@ -2704,7 +2724,7 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e)
}
if (highlightBlockNumber != d->extraAreaHighlightCollapseBlockNumber
|| highlightColumn != d->extraAreaHighlightCollapseColumn)
d->m_highlightBlocksTimer->start(40);
d->m_highlightBlocksTimer->start(d->m_highlightBlocksInfo.isEmpty() ? 40 : 10);
}
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) {
......@@ -3460,12 +3480,12 @@ BaseTextEditorAnimator::BaseTextEditorAnimator(QObject *parent)
void BaseTextEditorAnimator::setData(QFont f, QPalette pal, const QString &text)
{
m_font = f;
m_palette = pal;
m_text = text;
QFontMetrics fm(m_font);
m_size = QSizeF(fm.width(m_text), fm.height());
}
m_font = f;
m_palette = pal;
m_text = text;
QFontMetrics fm(m_font);
m_size = QSizeF(fm.width(m_text), fm.height());
}
void BaseTextEditorAnimator::draw(QPainter *p, const QPointF &pos)
{
......
......@@ -511,6 +511,9 @@ private:
void moveLineUpDown(bool up);
void saveCurrentCursorPositionForNavigation();
void drawFoldingMarker(QPainter *painter, const QRect &rect,
bool expanded, bool hovered) const;
void toggleBlockVisible(const QTextBlock &block);
QRect collapseBox();
......
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