forked from qt-creator/qt-creator
Editor: visualize indent
Paint a horizontal line every indent size in the whitespace at the start of each block. Fixes: QTCREATORBUG-22756 Change-Id: I044ccb4adefa4c8c9a3a610f0e996a810487fa1e Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
<style name="Comment" foreground="#a8abb0" italic="true"/>
|
||||
<style name="Doxygen.Comment" foreground="#65676a" bold="true" italic="true"/>
|
||||
<style name="Doxygen.Tag" foreground="#66a334"/>
|
||||
<style name="VisualWhitespace" foreground="#bec0c2"/>
|
||||
<style name="VisualWhitespace" foreground="#65676a"/>
|
||||
<style name="QmlLocalId" foreground="#9acfd6" italic="true"/>
|
||||
<style name="QmlExternalId" foreground="#9aa7d6" italic="true"/>
|
||||
<style name="QmlTypeId" foreground="#66a334"/>
|
||||
|
@@ -11,6 +11,7 @@
|
||||
<style name="DiffFile" foreground="#55ff55"/>
|
||||
<style name="DiffLocation" foreground="#ffff55"/>
|
||||
<style name="DisabledCode" foreground="#777777" background="#222222"/>
|
||||
<style name="VisualWhitespace" foreground="#777777"/>
|
||||
<style name="Doxygen.Comment" foreground="#55ffff"/>
|
||||
<style name="Doxygen.Tag" foreground="#00a0a0"/>
|
||||
<style name="Field"/>
|
||||
|
@@ -44,7 +44,7 @@
|
||||
<style name="Comment" foreground="#75715e" italic="true"/>
|
||||
<style name="Doxygen.Comment" foreground="#75715e" bold="true" italic="true"/>
|
||||
<style name="Doxygen.Tag" foreground="#80ff80"/>
|
||||
<style name="VisualWhitespace" foreground="#c0c0c0"/>
|
||||
<style name="VisualWhitespace" foreground="#777777"/>
|
||||
<style name="QmlLocalId" italic="true"/>
|
||||
<style name="QmlExternalId" foreground="#aaaaff" italic="true"/>
|
||||
<style name="QmlTypeId" foreground="#55ff55"/>
|
||||
|
@@ -44,7 +44,7 @@
|
||||
<style name="Comment" foreground="#586e75" italic="true"/>
|
||||
<style name="Doxygen.Comment" foreground="#586e75" italic="true"/>
|
||||
<style name="Doxygen.Tag" foreground="#586e75"/>
|
||||
<style name="VisualWhitespace" foreground="#268bd2"/>
|
||||
<style name="VisualWhitespace" foreground="#586e75"/>
|
||||
<style name="QmlLocalId" foreground="#657b83" italic="true"/>
|
||||
<style name="QmlExternalId" foreground="#2aa198" italic="true"/>
|
||||
<style name="QmlTypeId" foreground="#b58900"/>
|
||||
|
@@ -37,6 +37,7 @@
|
||||
static const char displayLineNumbersKey[] = "DisplayLineNumbers";
|
||||
static const char textWrappingKey[] = "TextWrapping";
|
||||
static const char visualizeWhitespaceKey[] = "VisualizeWhitespace";
|
||||
static const char visualizeIndentKey[] = "VisualizeIndent";
|
||||
static const char displayFoldingMarkersKey[] = "DisplayFoldingMarkers";
|
||||
static const char highlightCurrentLineKey[] = "HighlightCurrentLine2Key";
|
||||
static const char highlightBlocksKey[] = "HighlightBlocksKey";
|
||||
@@ -67,6 +68,7 @@ void DisplaySettings::toSettings(const QString &category, QSettings *s) const
|
||||
s->setValue(QLatin1String(displayLineNumbersKey), m_displayLineNumbers);
|
||||
s->setValue(QLatin1String(textWrappingKey), m_textWrapping);
|
||||
s->setValue(QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace);
|
||||
s->setValue(QLatin1String(visualizeIndentKey), m_visualizeIndent);
|
||||
s->setValue(QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers);
|
||||
s->setValue(QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine);
|
||||
s->setValue(QLatin1String(highlightBlocksKey), m_highlightBlocks);
|
||||
@@ -97,6 +99,7 @@ void DisplaySettings::fromSettings(const QString &category, const QSettings *s)
|
||||
m_displayLineNumbers = s->value(group + QLatin1String(displayLineNumbersKey), m_displayLineNumbers).toBool();
|
||||
m_textWrapping = s->value(group + QLatin1String(textWrappingKey), m_textWrapping).toBool();
|
||||
m_visualizeWhitespace = s->value(group + QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace).toBool();
|
||||
m_visualizeIndent = s->value(group + QLatin1String(visualizeIndentKey), m_visualizeIndent).toBool();
|
||||
m_displayFoldingMarkers = s->value(group + QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers).toBool();
|
||||
m_highlightCurrentLine = s->value(group + QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine).toBool();
|
||||
m_highlightBlocks = s->value(group + QLatin1String(highlightBlocksKey), m_highlightBlocks).toBool();
|
||||
@@ -123,6 +126,7 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const
|
||||
return m_displayLineNumbers == ds.m_displayLineNumbers
|
||||
&& m_textWrapping == ds.m_textWrapping
|
||||
&& m_visualizeWhitespace == ds.m_visualizeWhitespace
|
||||
&& m_visualizeIndent == ds.m_visualizeIndent
|
||||
&& m_displayFoldingMarkers == ds.m_displayFoldingMarkers
|
||||
&& m_highlightCurrentLine == ds.m_highlightCurrentLine
|
||||
&& m_highlightBlocks == ds.m_highlightBlocks
|
||||
|
@@ -58,6 +58,7 @@ public:
|
||||
bool m_displayLineNumbers = true;
|
||||
bool m_textWrapping = false;
|
||||
bool m_visualizeWhitespace = false;
|
||||
bool m_visualizeIndent = true;
|
||||
bool m_displayFoldingMarkers = true;
|
||||
bool m_highlightCurrentLine = false;
|
||||
bool m_highlightBlocks = false;
|
||||
|
@@ -92,6 +92,7 @@ void DisplaySettingsWidget::settingsFromUI(DisplaySettings &displaySettings,
|
||||
marginSettings.m_useIndenter = m_ui.useIndenter->isChecked();
|
||||
marginSettings.m_marginColumn = m_ui.wrapColumn->value();
|
||||
displaySettings.m_visualizeWhitespace = m_ui.visualizeWhitespace->isChecked();
|
||||
displaySettings.m_visualizeIndent = m_ui.visualizeIndent->isChecked();
|
||||
displaySettings.m_displayFoldingMarkers = m_ui.displayFoldingMarkers->isChecked();
|
||||
displaySettings.m_highlightCurrentLine = m_ui.highlightCurrentLine->isChecked();
|
||||
displaySettings.m_highlightBlocks = m_ui.highlightBlocks->isChecked();
|
||||
@@ -126,6 +127,7 @@ void DisplaySettingsWidget::settingsToUI()
|
||||
m_ui.useIndenter->setChecked(marginSettings.m_useIndenter);
|
||||
m_ui.wrapColumn->setValue(marginSettings.m_marginColumn);
|
||||
m_ui.visualizeWhitespace->setChecked(displaySettings.m_visualizeWhitespace);
|
||||
m_ui.visualizeIndent->setChecked(displaySettings.m_visualizeIndent);
|
||||
m_ui.displayFoldingMarkers->setChecked(displaySettings.m_displayFoldingMarkers);
|
||||
m_ui.highlightCurrentLine->setChecked(displaySettings.m_highlightCurrentLine);
|
||||
m_ui.highlightBlocks->setChecked(displaySettings.m_highlightBlocks);
|
||||
|
@@ -90,20 +90,6 @@
|
||||
<string>Display</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="6" column="1">
|
||||
<widget class="QCheckBox" name="displayFileEncoding">
|
||||
<property name="text">
|
||||
<string>Display file encoding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QCheckBox" name="displayFileLineEnding">
|
||||
<property name="text">
|
||||
<string>Display file line ending</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="animateMatchingParentheses">
|
||||
<property name="text">
|
||||
@@ -111,10 +97,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="centerOnScroll">
|
||||
<item row="8" column="0">
|
||||
<widget class="QCheckBox" name="scrollBarHighlights">
|
||||
<property name="text">
|
||||
<string>Center &cursor on scroll</string>
|
||||
<string>Highlight search results on the scrollbar</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -125,27 +111,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="highlightMatchingParentheses">
|
||||
<item row="9" column="0">
|
||||
<widget class="QCheckBox" name="animateNavigationWithinFile">
|
||||
<property name="text">
|
||||
<string>&Highlight matching parentheses</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QCheckBox" name="openLinksInNextSplit">
|
||||
<property name="text">
|
||||
<string>Always open links in another split</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="visualizeWhitespace">
|
||||
<property name="toolTip">
|
||||
<string>Shows tabs and spaces.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Visualize whitespace</string>
|
||||
<string>Animate navigation within file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -156,13 +125,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="autoFoldFirstComment">
|
||||
<property name="text">
|
||||
<string>Auto-fold first &comment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="highlightBlocks">
|
||||
<property name="text">
|
||||
@@ -170,6 +132,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="markTextChanges">
|
||||
<property name="text">
|
||||
<string>Mark &text changes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="autoFoldFirstComment">
|
||||
<property name="text">
|
||||
<string>Auto-fold first &comment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="displayFoldingMarkers">
|
||||
<property name="text">
|
||||
@@ -177,24 +153,55 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QCheckBox" name="animateNavigationWithinFile">
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="centerOnScroll">
|
||||
<property name="text">
|
||||
<string>Animate navigation within file</string>
|
||||
<string>Center &cursor on scroll</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="scrollBarHighlights">
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="visualizeIndent">
|
||||
<property name="text">
|
||||
<string>Highlight search results on the scrollbar</string>
|
||||
<string>Visualize indent</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="markTextChanges">
|
||||
<item row="9" column="1">
|
||||
<widget class="QCheckBox" name="displayFileLineEnding">
|
||||
<property name="text">
|
||||
<string>Mark &text changes</string>
|
||||
<string>Display file line ending</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QCheckBox" name="displayFileEncoding">
|
||||
<property name="text">
|
||||
<string>Display file encoding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QCheckBox" name="openLinksInNextSplit">
|
||||
<property name="text">
|
||||
<string>Always open links in another split</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QCheckBox" name="highlightMatchingParentheses">
|
||||
<property name="text">
|
||||
<string>&Highlight matching parentheses</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="visualizeWhitespace">
|
||||
<property name="toolTip">
|
||||
<string>Shows tabs and spaces.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Visualize whitespace</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -250,6 +257,7 @@
|
||||
<tabstop>enableTextWrapping</tabstop>
|
||||
<tabstop>showWrapColumn</tabstop>
|
||||
<tabstop>wrapColumn</tabstop>
|
||||
<tabstop>useIndenter</tabstop>
|
||||
<tabstop>displayLineNumbers</tabstop>
|
||||
<tabstop>displayFoldingMarkers</tabstop>
|
||||
<tabstop>markTextChanges</tabstop>
|
||||
@@ -257,13 +265,20 @@
|
||||
<tabstop>centerOnScroll</tabstop>
|
||||
<tabstop>autoFoldFirstComment</tabstop>
|
||||
<tabstop>scrollBarHighlights</tabstop>
|
||||
<tabstop>animateNavigationWithinFile</tabstop>
|
||||
<tabstop>highlightCurrentLine</tabstop>
|
||||
<tabstop>highlightBlocks</tabstop>
|
||||
<tabstop>animateMatchingParentheses</tabstop>
|
||||
<tabstop>visualizeIndent</tabstop>
|
||||
<tabstop>highlightMatchingParentheses</tabstop>
|
||||
<tabstop>openLinksInNextSplit</tabstop>
|
||||
<tabstop>displayFileEncoding</tabstop>
|
||||
<tabstop>animateNavigationWithinFile</tabstop>
|
||||
<tabstop>displayFileLineEnding</tabstop>
|
||||
<tabstop>displayAnnotations</tabstop>
|
||||
<tabstop>leftAligned</tabstop>
|
||||
<tabstop>atMargin</tabstop>
|
||||
<tabstop>rightAligned</tabstop>
|
||||
<tabstop>betweenLines</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
@@ -554,6 +554,7 @@ public:
|
||||
void paintCursorAsBlock(const PaintEventData &data, QPainter &painter,
|
||||
PaintEventBlockData &blockData, int cursorPosition) const;
|
||||
void paintAdditionalVisualWhitespaces(PaintEventData &data, QPainter &painter, qreal top) const;
|
||||
void paintIndentDepth(PaintEventData &data, QPainter &painter, const PaintEventBlockData &blockData) const;
|
||||
void paintReplacement(PaintEventData &data, QPainter &painter, qreal top) const;
|
||||
void paintWidgetBackground(const PaintEventData &data, QPainter &painter) const;
|
||||
void paintOverlays(const PaintEventData &data, QPainter &painter) const;
|
||||
@@ -4343,6 +4344,47 @@ void TextEditorWidgetPrivate::paintAdditionalVisualWhitespaces(PaintEventData &d
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorWidgetPrivate::paintIndentDepth(PaintEventData &data,
|
||||
QPainter &painter,
|
||||
const PaintEventBlockData &blockData) const
|
||||
{
|
||||
if (!m_displaySettings.m_visualizeIndent)
|
||||
return;
|
||||
|
||||
const QString text = data.block.text();
|
||||
const TabSettings &tabSettings = m_document->tabSettings();
|
||||
const int currentDepth = tabSettings.indentationColumn(text);
|
||||
|
||||
if (currentDepth <= tabSettings.m_indentSize || blockData.layout->lineCount() < 1)
|
||||
return;
|
||||
|
||||
const qreal horizontalAdvance = QFontMetricsF(q->font()).horizontalAdvance(
|
||||
QString(tabSettings.m_indentSize, QChar(' ')));
|
||||
|
||||
painter.save();
|
||||
painter.setPen(data.visualWhitespaceFormat.foreground().color());
|
||||
|
||||
const QTextLine textLine = blockData.layout->lineAt(0);
|
||||
const QRectF rect = textLine.naturalTextRect();
|
||||
qreal x = textLine.cursorToX(0) + data.offset.x();
|
||||
int paintColumn = tabSettings.m_indentSize;
|
||||
|
||||
while (paintColumn < currentDepth) {
|
||||
x += horizontalAdvance;
|
||||
if (x >= 0) {
|
||||
int paintPosition = tabSettings.positionAtColumn(text, paintColumn);
|
||||
if (blockData.layout->lineForTextPosition(paintPosition).lineNumber() != 0)
|
||||
break;
|
||||
const QPointF top(x, blockData.boundingRect.top());
|
||||
const QPointF bottom(x, blockData.boundingRect.top() + rect.height());
|
||||
const QLineF line(top, bottom);
|
||||
painter.drawLine(line);
|
||||
}
|
||||
paintColumn += tabSettings.m_indentSize;
|
||||
}
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
void TextEditorWidgetPrivate::paintReplacement(PaintEventData &data, QPainter &painter,
|
||||
qreal top) const
|
||||
{
|
||||
@@ -4645,7 +4687,7 @@ void TextEditorWidget::paintEvent(QPaintEvent *e)
|
||||
|
||||
if (drawCursor && !drawCursorAsBlock)
|
||||
d->addCursorsPosition(data, painter, blockData);
|
||||
|
||||
d->paintIndentDepth(data, painter, blockData);
|
||||
d->paintAdditionalVisualWhitespaces(data, painter, blockData.boundingRect.top());
|
||||
d->paintReplacement(data, painter, blockData.boundingRect.top());
|
||||
d->updateLineAnnotation(data, blockData, painter);
|
||||
|
Reference in New Issue
Block a user