diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 7d611193001..d44c789d6f5 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1498,6 +1498,12 @@ QRect BaseTextEditor::collapseBox() return QRect(); QTextBlock begin = document()->findBlockByNumber(d->m_highlightBlocksInfo.open.last()); + + if (!d->m_displaySettings.m_fancyFoldingBar) { + if (TextBlockUserData::hasCollapseAfter(begin.previous())) + begin = begin.previous(); + } + QTextBlock end = document()->findBlockByNumber(d->m_highlightBlocksInfo.close.first()); if (!begin.isValid() || !end.isValid()) return QRect(); @@ -2294,7 +2300,7 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e) } } - if (d->m_codeFoldingVisible) { + if (d->m_codeFoldingVisible && d->m_displaySettings.m_fancyFoldingBar) { QRect r(extraAreaWidth+2, top, collapseBoxWidth-4, bottom - top); bool drawBox = !nextBlock.isVisible(); @@ -2349,6 +2355,86 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e) painter.setRenderHint(QPainter::Antialiasing, false); } + } else if (d->m_codeFoldingVisible) { + + bool collapseThis = false; + bool collapseAfter = false; + bool hasClosingCollapse = false; + + if (TextBlockUserData *userData = static_cast(block.userData())) { + if (!userData->ifdefedOut()) { + collapseAfter = (userData->collapseMode() == TextBlockUserData::CollapseAfter); + collapseThis = (userData->collapseMode() == TextBlockUserData::CollapseThis); + hasClosingCollapse = userData->hasClosingCollapse() && (previousBraceDepth > 0); + } + } + + + int extraAreaHighlightCollapseBlockNumber = -1; + int extraAreaHighlightCollapseEndBlockNumber = -1; + bool endIsVisible = false; + if (!d->m_highlightBlocksInfo.isEmpty()) { + extraAreaHighlightCollapseBlockNumber = d->m_highlightBlocksInfo.open.last(); + extraAreaHighlightCollapseEndBlockNumber = d->m_highlightBlocksInfo.close.first(); + endIsVisible = doc->findBlockByNumber(extraAreaHighlightCollapseEndBlockNumber).isVisible(); + + if (TextBlockUserData::hasCollapseAfter( + doc->findBlockByNumber(extraAreaHighlightCollapseBlockNumber-1))) { + 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->ifdefedOut(); + + bool nextHasClosingCollapse = nextBlockUserData + && nextBlockUserData->hasClosingCollapseInside() + && nextBlockUserData->ifdefedOut(); + + bool drawBox = ((collapseAfter || collapseNext) && !nextHasClosingCollapse); + + 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 (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()); + } + } @@ -2391,20 +2477,11 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e) blockNumber = nextVisibleBlockNumber; } - if (d->m_codeFoldingVisible) { + if (d->m_codeFoldingVisible && d->m_displaySettings.m_fancyFoldingBar) { painter.drawLine(extraAreaWidth, 0, extraAreaWidth, viewport()->height()); painter.drawLine(extraAreaWidth + collapseBoxWidth - 1, 0, extraAreaWidth + collapseBoxWidth - 1, viewport()->height()); -// QRect cb = collapseBox(); -// if (!cb.isEmpty()) { -// QPen pen(baseColor.value() < 128 ? Qt::white : Qt::black); -// pen.setWidth(2); -// painter.setPen(pen); -// painter.setRenderHint(QPainter::Antialiasing, true); -// painter.translate(.5, .5); -// painter.drawRoundedRect(QRect(cb.adjusted(0, 0,-2, -2)), 4, 4); -// } } } @@ -2617,17 +2694,18 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e) d->extraAreaHighlightCollapseBlockNumber = -1; d->extraAreaHighlightCollapseColumn = -1; - if (d->m_displaySettings.m_highlightBlocks) { - QTextCursor cursor = textCursor(); - d->extraAreaHighlightCollapseBlockNumber = cursor.blockNumber(); - d->extraAreaHighlightCollapseColumn = cursor.position() - cursor.block().position(); - } int collapseBoxWidth = fontMetrics().lineSpacing() + 1; if (e->pos().x() > extraArea()->width() - collapseBoxWidth) { d->extraAreaHighlightCollapseBlockNumber = cursor.blockNumber(); if (!TextBlockUserData::hasClosingCollapse(cursor.block())) d->extraAreaHighlightCollapseColumn = cursor.block().length()-1; + if (!d->m_displaySettings.m_fancyFoldingBar + && TextBlockUserData::hasCollapseAfter(cursor.block())) { + d->extraAreaHighlightCollapseBlockNumber++; + if (!TextBlockUserData::hasClosingCollapse(cursor.block().next())) + d->extraAreaHighlightCollapseColumn = cursor.block().next().length()-1; + } } if (highlightBlockNumber != d->extraAreaHighlightCollapseBlockNumber || highlightColumn != d->extraAreaHighlightCollapseColumn) diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 1c02c6ce4a6..ca488ba1c8d 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -38,6 +38,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE class QLabel; @@ -130,7 +131,7 @@ public: inline bool clearIfdefedOut() { bool result = m_ifdefedOut; m_ifdefedOut = false; return result;} inline bool ifdefedOut() const { return m_ifdefedOut; } - inline static TextBlockUserData *canCollapse(const QTextBlock& block) { + inline static TextBlockUserData *canCollapse(const QTextBlock &block) { TextBlockUserData *data = static_cast(block.userData()); if (!data || data->collapseMode() != CollapseAfter) { data = static_cast(block.next().userData()); @@ -140,6 +141,19 @@ public: return data; } + inline static bool hasCollapseAfter(const QTextBlock & block) + { + TextBlockUserData *data = static_cast(block.userData()); + if (data && data->collapseMode() != NoCollapse) { + return (data->collapseMode() == CollapseAfter); + } else if (!data) { + data = static_cast(block.next().userData()); + if (data && data->collapseMode() == TextBlockUserData::CollapseThis && !data->m_ifdefedOut) + return true; + } + return false; + } + inline static bool hasClosingCollapse(const QTextBlock &block) { TextBlockUserData *data = static_cast(block.userData()); return (data && data->hasClosingCollapse()); diff --git a/src/plugins/texteditor/displaysettings.cpp b/src/plugins/texteditor/displaysettings.cpp index b0273a2c887..b16cc1436ea 100644 --- a/src/plugins/texteditor/displaysettings.cpp +++ b/src/plugins/texteditor/displaysettings.cpp @@ -43,6 +43,7 @@ static const char * const displayFoldingMarkersKey = "DisplayFoldingMarkers"; static const char * const highlightCurrentLineKey = "HighlightCurrentLineKeyV2"; static const char * const highlightBlocksKey = "HighlightBlocksKey"; static const char * const animateMatchingParenthesesKey= "AnimateMatchingParenthesesKey"; +static const char * const fancyFoldingBarKey= "FancyFoldingBarKey"; static const char * const groupPostfix = "DisplaySettings"; namespace TextEditor { @@ -56,7 +57,8 @@ DisplaySettings::DisplaySettings() : m_displayFoldingMarkers(true), m_highlightCurrentLine(false), m_highlightBlocks(false), - m_animateMatchingParentheses(true) + m_animateMatchingParentheses(true), + m_fancyFoldingBar(false) { } @@ -75,6 +77,7 @@ void DisplaySettings::toSettings(const QString &category, QSettings *s) const s->setValue(QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine); s->setValue(QLatin1String(highlightBlocksKey), m_highlightBlocks); s->setValue(QLatin1String(animateMatchingParenthesesKey), m_animateMatchingParentheses); + s->setValue(QLatin1String(fancyFoldingBarKey), m_fancyFoldingBar); s->endGroup(); } @@ -96,6 +99,7 @@ void DisplaySettings::fromSettings(const QString &category, const QSettings *s) m_highlightCurrentLine = s->value(group + QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine).toBool(); m_highlightBlocks = s->value(group + QLatin1String(highlightBlocksKey), m_highlightBlocks).toBool(); m_animateMatchingParentheses = s->value(group + QLatin1String(animateMatchingParenthesesKey), m_animateMatchingParentheses).toBool(); + m_fancyFoldingBar = s->value(group + QLatin1String(fancyFoldingBarKey), m_fancyFoldingBar).toBool(); } bool DisplaySettings::equals(const DisplaySettings &ds) const @@ -109,6 +113,7 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const && m_highlightCurrentLine == ds.m_highlightCurrentLine && m_highlightBlocks == ds.m_highlightBlocks && m_animateMatchingParentheses == ds.m_animateMatchingParentheses + && m_fancyFoldingBar == ds.m_fancyFoldingBar ; } diff --git a/src/plugins/texteditor/displaysettings.h b/src/plugins/texteditor/displaysettings.h index 06a7d0fa381..b05cc7a1915 100644 --- a/src/plugins/texteditor/displaysettings.h +++ b/src/plugins/texteditor/displaysettings.h @@ -54,6 +54,7 @@ struct TEXTEDITOR_EXPORT DisplaySettings bool m_highlightCurrentLine; bool m_highlightBlocks; bool m_animateMatchingParentheses; + bool m_fancyFoldingBar; bool equals(const DisplaySettings &ds) const; }; diff --git a/src/plugins/texteditor/displaysettingspage.cpp b/src/plugins/texteditor/displaysettingspage.cpp index ec7ae6a2210..31c7c803d22 100644 --- a/src/plugins/texteditor/displaysettingspage.cpp +++ b/src/plugins/texteditor/displaysettingspage.cpp @@ -124,6 +124,7 @@ void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings) const displaySettings.m_highlightCurrentLine = m_d->m_page.highlightCurrentLine->isChecked(); displaySettings.m_highlightBlocks = m_d->m_page.highlightBlocks->isChecked(); displaySettings.m_animateMatchingParentheses= m_d->m_page.animateMatchingParentheses->isChecked(); + displaySettings.m_fancyFoldingBar = m_d->m_page.fancyFoldingBar->isChecked(); } void DisplaySettingsPage::settingsToUI() @@ -138,6 +139,7 @@ void DisplaySettingsPage::settingsToUI() m_d->m_page.highlightCurrentLine->setChecked(displaySettings.m_highlightCurrentLine); m_d->m_page.highlightBlocks->setChecked(displaySettings.m_highlightBlocks); m_d->m_page.animateMatchingParentheses->setChecked(displaySettings.m_animateMatchingParentheses); + m_d->m_page.fancyFoldingBar->setChecked(displaySettings.m_fancyFoldingBar); } DisplaySettings DisplaySettingsPage::displaySettings() const diff --git a/src/plugins/texteditor/displaysettingspage.ui b/src/plugins/texteditor/displaysettingspage.ui index 5524172fcfb..e6d7eb867a6 100644 --- a/src/plugins/texteditor/displaysettingspage.ui +++ b/src/plugins/texteditor/displaysettingspage.ui @@ -7,7 +7,7 @@ 0 0 381 - 302 + 335 @@ -32,22 +32,52 @@ Display - - + + Display line &numbers - + Display &folding markers - + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + false + + + Use fancy style + + + + + + Show tabs and spaces. @@ -57,21 +87,21 @@ - + Highlight current &line - + Highlight &blocks - + Animate matching parentheses @@ -142,12 +172,28 @@ setEnabled(bool) - 399 - 308 + 238 + 84 - 474 - 308 + 299 + 84 + + + + + displayFoldingMarkers + toggled(bool) + fancyFoldingBar + setEnabled(bool) + + + 60 + 161 + + + 87 + 179 diff --git a/src/plugins/texteditor/textfilewizard.cpp b/src/plugins/texteditor/textfilewizard.cpp index e17e7db1350..32ef28f07d1 100644 --- a/src/plugins/texteditor/textfilewizard.cpp +++ b/src/plugins/texteditor/textfilewizard.cpp @@ -30,6 +30,7 @@ #include "textfilewizard.h" #include "basetexteditor.h" #include "texteditorconstants.h" +#include using namespace TextEditor;