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
Marco Bubke
flatpak-qt-creator
Commits
ffe9fe58
Commit
ffe9fe58
authored
Apr 29, 2009
by
mae
Browse files
support old-fashioned +/- folding bar, but improved
parent
918cac90
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/plugins/texteditor/basetexteditor.cpp
View file @
ffe9fe58
...
...
@@ -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
<
TextBlockUserData
*>
(
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
)
...
...
src/plugins/texteditor/basetexteditor.h
View file @
ffe9fe58
...
...
@@ -38,6 +38,7 @@
#include <QtGui/QLabel>
#include <QtGui/QKeyEvent>
#include <QtCore/QTimeLine>
#include <QtCore/QDebug>
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
<
TextBlockUserData
*>
(
block
.
userData
());
if
(
!
data
||
data
->
collapseMode
()
!=
CollapseAfter
)
{
data
=
static_cast
<
TextBlockUserData
*>
(
block
.
next
().
userData
());
...
...
@@ -140,6 +141,19 @@ public:
return
data
;
}
inline
static
bool
hasCollapseAfter
(
const
QTextBlock
&
block
)
{
TextBlockUserData
*
data
=
static_cast
<
TextBlockUserData
*>
(
block
.
userData
());
if
(
data
&&
data
->
collapseMode
()
!=
NoCollapse
)
{
return
(
data
->
collapseMode
()
==
CollapseAfter
);
}
else
if
(
!
data
)
{
data
=
static_cast
<
TextBlockUserData
*>
(
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
<
TextBlockUserData
*>
(
block
.
userData
());
return
(
data
&&
data
->
hasClosingCollapse
());
...
...
src/plugins/texteditor/displaysettings.cpp
View file @
ffe9fe58
...
...
@@ -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
;
}
...
...
src/plugins/texteditor/displaysettings.h
View file @
ffe9fe58
...
...
@@ -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
;
};
...
...
src/plugins/texteditor/displaysettingspage.cpp
View file @
ffe9fe58
...
...
@@ -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
...
...
src/plugins/texteditor/displaysettingspage.ui
View file @
ffe9fe58
...
...
@@ -7,7 +7,7 @@
<x>
0
</x>
<y>
0
</y>
<width>
381
</width>
<height>
3
02
</height>
<height>
3
35
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
...
...
@@ -32,22 +32,52 @@
<property
name=
"title"
>
<string>
Display
</string>
</property>
<layout
class=
"Q
Grid
Layout"
name=
"
grid
Layout
_2
"
>
<item
row=
"0"
column=
"0"
>
<layout
class=
"Q
VBox
Layout"
name=
"
vertical
Layout"
>
<item>
<widget
class=
"QCheckBox"
name=
"displayLineNumbers"
>
<property
name=
"text"
>
<string>
Display line
&
numbers
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
>
<item>
<widget
class=
"QCheckBox"
name=
"displayFoldingMarkers"
>
<property
name=
"text"
>
<string>
Display
&
folding markers
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"0"
>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout_2"
>
<item>
<spacer
name=
"horizontalSpacer_2"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeType"
>
<enum>
QSizePolicy::Fixed
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"fancyFoldingBar"
>
<property
name=
"enabled"
>
<bool>
false
</bool>
</property>
<property
name=
"text"
>
<string>
Use fancy style
</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"visualizeWhitespace"
>
<property
name=
"toolTip"
>
<string>
Show tabs and spaces.
</string>
...
...
@@ -57,21 +87,21 @@
</property>
</widget>
</item>
<item
row=
"3"
column=
"0"
>
<item>
<widget
class=
"QCheckBox"
name=
"highlightCurrentLine"
>
<property
name=
"text"
>
<string>
Highlight current
&
line
</string>
</property>
</widget>
</item>
<item
row=
"4"
column=
"0"
>
<item>
<widget
class=
"QCheckBox"
name=
"highlightBlocks"
>
<property
name=
"text"
>
<string>
Highlight
&
blocks
</string>
</property>
</widget>
</item>
<item
row=
"5"
column=
"0"
>
<item>
<widget
class=
"QCheckBox"
name=
"animateMatchingParentheses"
>
<property
name=
"text"
>
<string>
Animate matching parentheses
</string>
...
...
@@ -142,12 +172,28 @@
<slot>
setEnabled(bool)
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
399
</x>
<y>
308
</y>
<x>
238
</x>
<y>
84
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
299
</x>
<y>
84
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
displayFoldingMarkers
</sender>
<signal>
toggled(bool)
</signal>
<receiver>
fancyFoldingBar
</receiver>
<slot>
setEnabled(bool)
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
60
</x>
<y>
161
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
474
</x>
<y>
308
</y>
<x>
87
</x>
<y>
179
</y>
</hint>
</hints>
</connection>
...
...
src/plugins/texteditor/textfilewizard.cpp
View file @
ffe9fe58
...
...
@@ -30,6 +30,7 @@
#include "textfilewizard.h"
#include "basetexteditor.h"
#include "texteditorconstants.h"
#include <QDebug>
using
namespace
TextEditor
;
...
...
Write
Preview
Supports
Markdown
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