forked from qt-creator/qt-creator
new text editor option "Highlight blocks"
This commit is contained in:
@@ -1199,6 +1199,17 @@ bool BaseTextEditor::lineSeparatorsAllowed() const
|
|||||||
return d->m_lineSeparatorsAllowed;
|
return d->m_lineSeparatorsAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::setHighlightBlocks(bool b)
|
||||||
|
{
|
||||||
|
d->m_highlightBlocks = b & d->m_codeFoldingSupported;
|
||||||
|
viewport()->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseTextEditor::highlightBlocks() const
|
||||||
|
{
|
||||||
|
return d->m_highlightBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BaseTextEditor::setCodeFoldingVisible(bool b)
|
void BaseTextEditor::setCodeFoldingVisible(bool b)
|
||||||
{
|
{
|
||||||
@@ -1262,6 +1273,7 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
|
|||||||
m_marksVisible(false),
|
m_marksVisible(false),
|
||||||
m_codeFoldingVisible(false),
|
m_codeFoldingVisible(false),
|
||||||
m_codeFoldingSupported(false),
|
m_codeFoldingSupported(false),
|
||||||
|
m_highlightBlocks(false),
|
||||||
m_revisionsVisible(false),
|
m_revisionsVisible(false),
|
||||||
m_lineNumbersVisible(true),
|
m_lineNumbersVisible(true),
|
||||||
m_highlightCurrentLine(true),
|
m_highlightCurrentLine(true),
|
||||||
@@ -1662,6 +1674,24 @@ void BaseTextEditorPrivate::moveCursorVisible(bool ensureVisible)
|
|||||||
q->ensureCursorVisible();
|
q->ensureCursorVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QColor calcBlendColor(const QColor &baseColor, int factor = 1)
|
||||||
|
{
|
||||||
|
const int blendBase = (baseColor.value() > 128) ? 0 : 255;
|
||||||
|
// Darker backgrounds may need a bit more contrast
|
||||||
|
// (this calculation is temporary solution until we have a setting for this color)
|
||||||
|
const int blendFactor = (baseColor.value() > 128) ? 8 : 16;
|
||||||
|
|
||||||
|
QColor blendColor = baseColor;
|
||||||
|
|
||||||
|
while (factor--) {
|
||||||
|
blendColor = QColor(
|
||||||
|
(blendBase * blendFactor + blendColor.blue() * (256 - blendFactor)) / 256,
|
||||||
|
(blendBase * blendFactor + blendColor.green() * (256 - blendFactor)) / 256,
|
||||||
|
(blendBase * blendFactor + blendColor.blue() * (256 - blendFactor)) / 256);
|
||||||
|
}
|
||||||
|
return blendColor;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditor::paintEvent(QPaintEvent *e)
|
void BaseTextEditor::paintEvent(QPaintEvent *e)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -1682,19 +1712,13 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
|
|||||||
QRect viewportRect = viewport()->rect();
|
QRect viewportRect = viewport()->rect();
|
||||||
|
|
||||||
const QColor baseColor = palette().base().color();
|
const QColor baseColor = palette().base().color();
|
||||||
const int blendBase = (baseColor.value() > 128) ? 0 : 255;
|
const QColor blendColor = calcBlendColor(baseColor);
|
||||||
// Darker backgrounds may need a bit more contrast
|
|
||||||
// (this calculation is temporary solution until we have a setting for this color)
|
|
||||||
const int blendFactor = (baseColor.value() > 128) ? 8 : 16;
|
|
||||||
const QColor blendColor(
|
|
||||||
(blendBase * blendFactor + baseColor.blue() * (256 - blendFactor)) / 256,
|
|
||||||
(blendBase * blendFactor + baseColor.green() * (256 - blendFactor)) / 256,
|
|
||||||
(blendBase * blendFactor + baseColor.blue() * (256 - blendFactor)) / 256);
|
|
||||||
if (d->m_visibleWrapColumn > 0) {
|
if (d->m_visibleWrapColumn > 0) {
|
||||||
qreal lineX = fontMetrics().averageCharWidth() * d->m_visibleWrapColumn + offset.x() + 4;
|
qreal lineX = fontMetrics().averageCharWidth() * d->m_visibleWrapColumn + offset.x() + 4;
|
||||||
painter.fillRect(QRectF(lineX, 0, viewportRect.width() - lineX, viewportRect.height()), blendColor);
|
painter.fillRect(QRectF(lineX, 0, viewportRect.width() - lineX, viewportRect.height()), blendColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep right margin clean from full-width selection
|
// keep right margin clean from full-width selection
|
||||||
int maxX = offset.x() + qMax((qreal)viewportRect.width(), documentLayout->documentSize().width())
|
int maxX = offset.x() + qMax((qreal)viewportRect.width(), documentLayout->documentSize().width())
|
||||||
- doc->documentMargin();
|
- doc->documentMargin();
|
||||||
@@ -1736,12 +1760,24 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
|
|||||||
|
|
||||||
while (block.isValid()) {
|
while (block.isValid()) {
|
||||||
|
|
||||||
if (!block.isVisible()) {
|
|
||||||
block = block.next();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF r = blockBoundingRect(block).translated(offset);
|
QRectF r = blockBoundingRect(block).translated(offset);
|
||||||
|
|
||||||
|
if (d->m_highlightBlocks) {
|
||||||
|
QTextBlock previousBlock = block.previous();
|
||||||
|
if (previousBlock.isValid()){
|
||||||
|
int thisBraceDepth = block.userState();
|
||||||
|
if (thisBraceDepth >= 0)
|
||||||
|
thisBraceDepth >>= 8;
|
||||||
|
int braceDepth = block.previous().userState();
|
||||||
|
if (braceDepth >= 0)
|
||||||
|
braceDepth >>= 8;
|
||||||
|
int minBraceDepth = qMin(thisBraceDepth, braceDepth);
|
||||||
|
if (minBraceDepth > 0) {
|
||||||
|
painter.fillRect(r, calcBlendColor(baseColor, minBraceDepth));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTextLayout *layout = block.layout();
|
QTextLayout *layout = block.layout();
|
||||||
|
|
||||||
QTextOption option = layout->textOption();
|
QTextOption option = layout->textOption();
|
||||||
@@ -3413,6 +3449,7 @@ void BaseTextEditor::setDisplaySettings(const DisplaySettings &ds)
|
|||||||
setVisibleWrapColumn(ds.m_showWrapColumn ? ds.m_wrapColumn : 0);
|
setVisibleWrapColumn(ds.m_showWrapColumn ? ds.m_wrapColumn : 0);
|
||||||
setCodeFoldingVisible(ds.m_displayFoldingMarkers);
|
setCodeFoldingVisible(ds.m_displayFoldingMarkers);
|
||||||
setHighlightCurrentLine(ds.m_highlightCurrentLine);
|
setHighlightCurrentLine(ds.m_highlightCurrentLine);
|
||||||
|
setHighlightBlocks(ds.m_highlightBlocks);
|
||||||
|
|
||||||
if (d->m_displaySettings.m_visualizeWhitespace != ds.m_visualizeWhitespace) {
|
if (d->m_displaySettings.m_visualizeWhitespace != ds.m_visualizeWhitespace) {
|
||||||
if (QSyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter())
|
if (QSyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter())
|
||||||
|
|||||||
@@ -267,9 +267,13 @@ public:
|
|||||||
void setHighlightCurrentLine(bool b);
|
void setHighlightCurrentLine(bool b);
|
||||||
bool highlightCurrentLine() const;
|
bool highlightCurrentLine() const;
|
||||||
|
|
||||||
|
void setHighlightBlocks(bool b);
|
||||||
|
bool highlightBlocks() const;
|
||||||
|
|
||||||
void setLineNumbersVisible(bool b);
|
void setLineNumbersVisible(bool b);
|
||||||
bool lineNumbersVisible() const;
|
bool lineNumbersVisible() const;
|
||||||
|
|
||||||
|
|
||||||
void setMarksVisible(bool b);
|
void setMarksVisible(bool b);
|
||||||
bool marksVisible() const;
|
bool marksVisible() const;
|
||||||
|
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ public:
|
|||||||
uint m_marksVisible : 1;
|
uint m_marksVisible : 1;
|
||||||
uint m_codeFoldingVisible : 1;
|
uint m_codeFoldingVisible : 1;
|
||||||
uint m_codeFoldingSupported : 1;
|
uint m_codeFoldingSupported : 1;
|
||||||
|
uint m_highlightBlocks : 1;
|
||||||
uint m_revisionsVisible : 1;
|
uint m_revisionsVisible : 1;
|
||||||
uint m_lineNumbersVisible : 1;
|
uint m_lineNumbersVisible : 1;
|
||||||
uint m_highlightCurrentLine : 1;
|
uint m_highlightCurrentLine : 1;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ static const char * const wrapColumnKey = "WrapColumn";
|
|||||||
static const char * const visualizeWhitespaceKey = "VisualizeWhitespace";
|
static const char * const visualizeWhitespaceKey = "VisualizeWhitespace";
|
||||||
static const char * const displayFoldingMarkersKey = "DisplayFoldingMarkers";
|
static const char * const displayFoldingMarkersKey = "DisplayFoldingMarkers";
|
||||||
static const char * const highlightCurrentLineKey = "HighlightCurrentLineKey";
|
static const char * const highlightCurrentLineKey = "HighlightCurrentLineKey";
|
||||||
|
static const char * const highlightBlocksKey = "HighlightBlocksKey";
|
||||||
static const char * const groupPostfix = "DisplaySettings";
|
static const char * const groupPostfix = "DisplaySettings";
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
@@ -52,7 +53,8 @@ DisplaySettings::DisplaySettings() :
|
|||||||
m_wrapColumn(80),
|
m_wrapColumn(80),
|
||||||
m_visualizeWhitespace(false),
|
m_visualizeWhitespace(false),
|
||||||
m_displayFoldingMarkers(true),
|
m_displayFoldingMarkers(true),
|
||||||
m_highlightCurrentLine(true)
|
m_highlightCurrentLine(true),
|
||||||
|
m_highlightBlocks(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +71,7 @@ void DisplaySettings::toSettings(const QString &category, QSettings *s) const
|
|||||||
s->setValue(QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace);
|
s->setValue(QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace);
|
||||||
s->setValue(QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers);
|
s->setValue(QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers);
|
||||||
s->setValue(QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine);
|
s->setValue(QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine);
|
||||||
|
s->setValue(QLatin1String(highlightBlocksKey), m_highlightBlocks);
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +91,7 @@ void DisplaySettings::fromSettings(const QString &category, const QSettings *s)
|
|||||||
m_visualizeWhitespace = s->value(group + QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace).toBool();
|
m_visualizeWhitespace = s->value(group + QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace).toBool();
|
||||||
m_displayFoldingMarkers = s->value(group + QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers).toBool();
|
m_displayFoldingMarkers = s->value(group + QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers).toBool();
|
||||||
m_highlightCurrentLine = s->value(group + QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine).toBool();
|
m_highlightCurrentLine = s->value(group + QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine).toBool();
|
||||||
|
m_highlightBlocks = s->value(group + QLatin1String(highlightBlocksKey), m_highlightBlocks).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisplaySettings::equals(const DisplaySettings &ds) const
|
bool DisplaySettings::equals(const DisplaySettings &ds) const
|
||||||
@@ -99,6 +103,7 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const
|
|||||||
&& m_visualizeWhitespace == ds.m_visualizeWhitespace
|
&& m_visualizeWhitespace == ds.m_visualizeWhitespace
|
||||||
&& m_displayFoldingMarkers == ds.m_displayFoldingMarkers
|
&& m_displayFoldingMarkers == ds.m_displayFoldingMarkers
|
||||||
&& m_highlightCurrentLine == ds.m_highlightCurrentLine
|
&& m_highlightCurrentLine == ds.m_highlightCurrentLine
|
||||||
|
&& m_highlightBlocks == ds.m_highlightBlocks
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ struct TEXTEDITOR_EXPORT DisplaySettings
|
|||||||
bool m_visualizeWhitespace;
|
bool m_visualizeWhitespace;
|
||||||
bool m_displayFoldingMarkers;
|
bool m_displayFoldingMarkers;
|
||||||
bool m_highlightCurrentLine;
|
bool m_highlightCurrentLine;
|
||||||
|
bool m_highlightBlocks;
|
||||||
|
|
||||||
bool equals(const DisplaySettings &ds) const;
|
bool equals(const DisplaySettings &ds) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings) const
|
|||||||
displaySettings.m_visualizeWhitespace = m_d->m_page.visualizeWhitespace->isChecked();
|
displaySettings.m_visualizeWhitespace = m_d->m_page.visualizeWhitespace->isChecked();
|
||||||
displaySettings.m_displayFoldingMarkers = m_d->m_page.displayFoldingMarkers->isChecked();
|
displaySettings.m_displayFoldingMarkers = m_d->m_page.displayFoldingMarkers->isChecked();
|
||||||
displaySettings.m_highlightCurrentLine = m_d->m_page.highlightCurrentLine->isChecked();
|
displaySettings.m_highlightCurrentLine = m_d->m_page.highlightCurrentLine->isChecked();
|
||||||
|
displaySettings.m_highlightBlocks = m_d->m_page.highlightBlocks->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplaySettingsPage::settingsToUI()
|
void DisplaySettingsPage::settingsToUI()
|
||||||
@@ -134,6 +135,7 @@ void DisplaySettingsPage::settingsToUI()
|
|||||||
m_d->m_page.visualizeWhitespace->setChecked(displaySettings.m_visualizeWhitespace);
|
m_d->m_page.visualizeWhitespace->setChecked(displaySettings.m_visualizeWhitespace);
|
||||||
m_d->m_page.displayFoldingMarkers->setChecked(displaySettings.m_displayFoldingMarkers);
|
m_d->m_page.displayFoldingMarkers->setChecked(displaySettings.m_displayFoldingMarkers);
|
||||||
m_d->m_page.highlightCurrentLine->setChecked(displaySettings.m_highlightCurrentLine);
|
m_d->m_page.highlightCurrentLine->setChecked(displaySettings.m_highlightCurrentLine);
|
||||||
|
m_d->m_page.highlightBlocks->setChecked(displaySettings.m_highlightBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplaySettings DisplaySettingsPage::displaySettings() const
|
DisplaySettings DisplaySettingsPage::displaySettings() const
|
||||||
|
|||||||
@@ -64,6 +64,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QCheckBox" name="highlightBlocks">
|
||||||
|
<property name="text">
|
||||||
|
<string>Highlight &blocks</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user