Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
4d708fa4
Commit
4d708fa4
authored
Apr 22, 2009
by
mae
Browse files
new text editor option "Highlight blocks"
parent
ebfcd35a
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/plugins/texteditor/basetexteditor.cpp
View file @
4d708fa4
...
...
@@ -1199,6 +1199,17 @@ bool BaseTextEditor::lineSeparatorsAllowed() const
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
)
{
...
...
@@ -1262,6 +1273,7 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
m_marksVisible
(
false
),
m_codeFoldingVisible
(
false
),
m_codeFoldingSupported
(
false
),
m_highlightBlocks
(
false
),
m_revisionsVisible
(
false
),
m_lineNumbersVisible
(
true
),
m_highlightCurrentLine
(
true
),
...
...
@@ -1662,6 +1674,24 @@ void BaseTextEditorPrivate::moveCursorVisible(bool ensureVisible)
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
)
{
/*
...
...
@@ -1682,19 +1712,13 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
QRect
viewportRect
=
viewport
()
->
rect
();
const
QColor
baseColor
=
palette
().
base
().
color
();
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
;
const
QColor
blendColor
(
(
blendBase
*
blendFactor
+
baseColor
.
blue
()
*
(
256
-
blendFactor
))
/
256
,
(
blendBase
*
blendFactor
+
baseColor
.
green
()
*
(
256
-
blendFactor
))
/
256
,
(
blendBase
*
blendFactor
+
baseColor
.
blue
()
*
(
256
-
blendFactor
))
/
256
);
const
QColor
blendColor
=
calcBlendColor
(
baseColor
);
if
(
d
->
m_visibleWrapColumn
>
0
)
{
qreal
lineX
=
fontMetrics
().
averageCharWidth
()
*
d
->
m_visibleWrapColumn
+
offset
.
x
()
+
4
;
painter
.
fillRect
(
QRectF
(
lineX
,
0
,
viewportRect
.
width
()
-
lineX
,
viewportRect
.
height
()),
blendColor
);
}
// keep right margin clean from full-width selection
int
maxX
=
offset
.
x
()
+
qMax
((
qreal
)
viewportRect
.
width
(),
documentLayout
->
documentSize
().
width
())
-
doc
->
documentMargin
();
...
...
@@ -1736,12 +1760,24 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
while
(
block
.
isValid
())
{
if
(
!
block
.
isVisible
())
{
block
=
block
.
next
();
continue
;
}
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
();
QTextOption
option
=
layout
->
textOption
();
...
...
@@ -3413,6 +3449,7 @@ void BaseTextEditor::setDisplaySettings(const DisplaySettings &ds)
setVisibleWrapColumn
(
ds
.
m_showWrapColumn
?
ds
.
m_wrapColumn
:
0
);
setCodeFoldingVisible
(
ds
.
m_displayFoldingMarkers
);
setHighlightCurrentLine
(
ds
.
m_highlightCurrentLine
);
setHighlightBlocks
(
ds
.
m_highlightBlocks
);
if
(
d
->
m_displaySettings
.
m_visualizeWhitespace
!=
ds
.
m_visualizeWhitespace
)
{
if
(
QSyntaxHighlighter
*
highlighter
=
baseTextDocument
()
->
syntaxHighlighter
())
...
...
src/plugins/texteditor/basetexteditor.h
View file @
4d708fa4
...
...
@@ -267,9 +267,13 @@ public:
void
setHighlightCurrentLine
(
bool
b
);
bool
highlightCurrentLine
()
const
;
void
setHighlightBlocks
(
bool
b
);
bool
highlightBlocks
()
const
;
void
setLineNumbersVisible
(
bool
b
);
bool
lineNumbersVisible
()
const
;
void
setMarksVisible
(
bool
b
);
bool
marksVisible
()
const
;
...
...
src/plugins/texteditor/basetexteditor_p.h
View file @
4d708fa4
...
...
@@ -183,6 +183,7 @@ public:
uint
m_marksVisible
:
1
;
uint
m_codeFoldingVisible
:
1
;
uint
m_codeFoldingSupported
:
1
;
uint
m_highlightBlocks
:
1
;
uint
m_revisionsVisible
:
1
;
uint
m_lineNumbersVisible
:
1
;
uint
m_highlightCurrentLine
:
1
;
...
...
src/plugins/texteditor/displaysettings.cpp
View file @
4d708fa4
...
...
@@ -41,6 +41,7 @@ static const char * const wrapColumnKey = "WrapColumn";
static
const
char
*
const
visualizeWhitespaceKey
=
"VisualizeWhitespace"
;
static
const
char
*
const
displayFoldingMarkersKey
=
"DisplayFoldingMarkers"
;
static
const
char
*
const
highlightCurrentLineKey
=
"HighlightCurrentLineKey"
;
static
const
char
*
const
highlightBlocksKey
=
"HighlightBlocksKey"
;
static
const
char
*
const
groupPostfix
=
"DisplaySettings"
;
namespace
TextEditor
{
...
...
@@ -52,7 +53,8 @@ DisplaySettings::DisplaySettings() :
m_wrapColumn
(
80
),
m_visualizeWhitespace
(
false
),
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
(
displayFoldingMarkersKey
),
m_displayFoldingMarkers
);
s
->
setValue
(
QLatin1String
(
highlightCurrentLineKey
),
m_highlightCurrentLine
);
s
->
setValue
(
QLatin1String
(
highlightBlocksKey
),
m_highlightBlocks
);
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_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
();
}
bool
DisplaySettings
::
equals
(
const
DisplaySettings
&
ds
)
const
...
...
@@ -99,6 +103,7 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const
&&
m_visualizeWhitespace
==
ds
.
m_visualizeWhitespace
&&
m_displayFoldingMarkers
==
ds
.
m_displayFoldingMarkers
&&
m_highlightCurrentLine
==
ds
.
m_highlightCurrentLine
&&
m_highlightBlocks
==
ds
.
m_highlightBlocks
;
}
...
...
src/plugins/texteditor/displaysettings.h
View file @
4d708fa4
...
...
@@ -52,6 +52,7 @@ struct TEXTEDITOR_EXPORT DisplaySettings
bool
m_visualizeWhitespace
;
bool
m_displayFoldingMarkers
;
bool
m_highlightCurrentLine
;
bool
m_highlightBlocks
;
bool
equals
(
const
DisplaySettings
&
ds
)
const
;
};
...
...
src/plugins/texteditor/displaysettingspage.cpp
View file @
4d708fa4
...
...
@@ -122,6 +122,7 @@ void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings) const
displaySettings
.
m_visualizeWhitespace
=
m_d
->
m_page
.
visualizeWhitespace
->
isChecked
();
displaySettings
.
m_displayFoldingMarkers
=
m_d
->
m_page
.
displayFoldingMarkers
->
isChecked
();
displaySettings
.
m_highlightCurrentLine
=
m_d
->
m_page
.
highlightCurrentLine
->
isChecked
();
displaySettings
.
m_highlightBlocks
=
m_d
->
m_page
.
highlightBlocks
->
isChecked
();
}
void
DisplaySettingsPage
::
settingsToUI
()
...
...
@@ -134,6 +135,7 @@ void DisplaySettingsPage::settingsToUI()
m_d
->
m_page
.
visualizeWhitespace
->
setChecked
(
displaySettings
.
m_visualizeWhitespace
);
m_d
->
m_page
.
displayFoldingMarkers
->
setChecked
(
displaySettings
.
m_displayFoldingMarkers
);
m_d
->
m_page
.
highlightCurrentLine
->
setChecked
(
displaySettings
.
m_highlightCurrentLine
);
m_d
->
m_page
.
highlightBlocks
->
setChecked
(
displaySettings
.
m_highlightBlocks
);
}
DisplaySettings
DisplaySettingsPage
::
displaySettings
()
const
...
...
src/plugins/texteditor/displaysettingspage.ui
View file @
4d708fa4
...
...
@@ -64,6 +64,13 @@
</property>
</widget>
</item>
<item
row=
"4"
column=
"0"
>
<widget
class=
"QCheckBox"
name=
"highlightBlocks"
>
<property
name=
"text"
>
<string>
Highlight
&
blocks
</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment