Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tobias Hunger
qt-creator
Commits
18b9bdd4
Commit
18b9bdd4
authored
Dec 01, 2009
by
mae
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some tuning of the overlay search result selection
parent
43f5b466
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
28 deletions
+49
-28
src/plugins/texteditor/basetexteditor.cpp
src/plugins/texteditor/basetexteditor.cpp
+17
-6
src/plugins/texteditor/basetexteditor.h
src/plugins/texteditor/basetexteditor.h
+1
-0
src/plugins/texteditor/texteditoroverlay.cpp
src/plugins/texteditor/texteditoroverlay.cpp
+26
-16
src/plugins/texteditor/texteditoroverlay.h
src/plugins/texteditor/texteditoroverlay.h
+5
-6
No files found.
src/plugins/texteditor/basetexteditor.cpp
View file @
18b9bdd4
...
...
@@ -1871,6 +1871,9 @@ void BaseTextEditorPrivate::highlightSearchResults(const QTextBlock &block,
if
(
m_searchExpr
.
isEmpty
())
return
;
int
blockPosition
=
block
.
position
();
QTextCursor
cursor
=
q
->
textCursor
();
QString
text
=
block
.
text
();
text
.
replace
(
QChar
::
Nbsp
,
QLatin1Char
(
' '
));
int
idx
=
-
1
;
...
...
@@ -1885,8 +1888,8 @@ void BaseTextEditorPrivate::highlightSearchResults(const QTextBlock &block,
continue
;
if
(
m_findScope
.
isNull
()
||
(
block
.
p
osition
()
+
idx
>=
m_findScope
.
selectionStart
()
&&
block
.
p
osition
()
+
idx
+
l
<=
m_findScope
.
selectionEnd
()))
{
||
(
block
P
osition
+
idx
>=
m_findScope
.
selectionStart
()
&&
block
P
osition
+
idx
+
l
<=
m_findScope
.
selectionEnd
()))
{
if
(
selections
)
{
QTextLayout
::
FormatRange
selection
;
selection
.
start
=
idx
;
...
...
@@ -1895,10 +1898,12 @@ void BaseTextEditorPrivate::highlightSearchResults(const QTextBlock &block,
selections
->
append
(
selection
);
}
overlay
->
addOverlaySelection
(
block
.
p
osition
()
+
idx
,
block
.
p
osition
()
+
idx
+
l
,
overlay
->
addOverlaySelection
(
block
P
osition
+
idx
,
block
P
osition
+
idx
+
l
,
m_searchResultFormat
.
background
().
color
().
darker
(
120
),
QColor
());
QColor
(),
false
,
(
idx
==
cursor
.
selectionStart
()
-
blockPosition
&&
idx
+
l
==
cursor
.
selectionEnd
()
-
blockPosition
));
}
}
...
...
@@ -2935,7 +2940,7 @@ void BaseTextEditor::slotCursorPositionChanged()
saveCurrentCursorPositionForNavigation
();
}
if
(
d
->
m_parenthesesMatchingEnabled
)
{
if
(
d
->
m_parenthesesMatchingEnabled
&&
hasFocus
()
)
{
// Delay update when no matching is displayed yet, to avoid flicker
if
(
extraSelections
(
ParenthesesMatchingSelection
).
isEmpty
()
&&
d
->
m_animator
==
0
)
{
...
...
@@ -4268,6 +4273,12 @@ void BaseTextEditor::changeEvent(QEvent *e)
}
}
void
BaseTextEditor
::
focusInEvent
(
QFocusEvent
*
e
)
{
QPlainTextEdit
::
focusInEvent
(
e
);
slotCursorPositionChanged
();
}
void
BaseTextEditor
::
focusOutEvent
(
QFocusEvent
*
e
)
{
QPlainTextEdit
::
focusOutEvent
(
e
);
...
...
src/plugins/texteditor/basetexteditor.h
View file @
18b9bdd4
...
...
@@ -418,6 +418,7 @@ protected:
void
keyPressEvent
(
QKeyEvent
*
e
);
void
wheelEvent
(
QWheelEvent
*
e
);
void
changeEvent
(
QEvent
*
e
);
void
focusInEvent
(
QFocusEvent
*
e
);
void
focusOutEvent
(
QFocusEvent
*
e
);
void
showEvent
(
QShowEvent
*
);
...
...
src/plugins/texteditor/texteditoroverlay.cpp
View file @
18b9bdd4
...
...
@@ -37,7 +37,9 @@ void TextEditorOverlay::clear()
}
void
TextEditorOverlay
::
addOverlaySelection
(
int
begin
,
int
end
,
const
QColor
&
fg
,
const
QColor
&
bg
,
bool
lockSize
)
const
QColor
&
fg
,
const
QColor
&
bg
,
bool
lockSize
,
bool
dropShadow
)
{
if
(
end
<
begin
)
return
;
...
...
@@ -57,6 +59,8 @@ void TextEditorOverlay::addOverlaySelection(int begin, int end,
if
(
lockSize
)
selection
.
m_fixedLength
=
(
end
-
begin
);
selection
.
m_dropShadow
=
dropShadow
;
m_selections
+=
selection
;
update
();
}
...
...
@@ -232,9 +236,16 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co
return
path
;
}
void
TextEditorOverlay
::
paintSelection
(
QPainter
*
painter
,
const
QTextCursor
&
begin
,
const
QTextCursor
&
end
,
const
QColor
&
fg
,
const
QColor
&
bg
)
void
TextEditorOverlay
::
paintSelection
(
QPainter
*
painter
,
const
OverlaySelection
&
selection
)
{
const
QTextCursor
&
begin
=
selection
.
m_cursor_begin
;
const
QTextCursor
&
end
=
selection
.
m_cursor_end
;
const
QColor
&
fg
=
selection
.
m_fg
;
const
QColor
&
bg
=
selection
.
m_bg
;
if
(
begin
.
isNull
()
||
end
.
isNull
()
||
begin
.
position
()
>
end
.
position
())
return
;
...
...
@@ -268,9 +279,12 @@ void TextEditorOverlay::paintSelection(QPainter *painter, const QTextCursor &beg
painter
->
restore
();
}
void
TextEditorOverlay
::
fillSelection
(
QPainter
*
painter
,
const
QTextCursor
&
begin
,
const
QTextCursor
&
end
,
const
QColor
&
color
)
void
TextEditorOverlay
::
fillSelection
(
QPainter
*
painter
,
const
OverlaySelection
&
selection
,
const
QColor
&
color
)
{
const
QTextCursor
&
begin
=
selection
.
m_cursor_begin
;
const
QTextCursor
&
end
=
selection
.
m_cursor_end
;
if
(
begin
.
isNull
()
||
end
.
isNull
()
||
begin
.
position
()
>
end
.
position
())
return
;
...
...
@@ -279,6 +293,11 @@ void TextEditorOverlay::fillSelection(QPainter *painter, const QTextCursor &begi
painter
->
save
();
painter
->
translate
(
-
.5
,
-
.5
);
painter
->
setRenderHint
(
QPainter
::
Antialiasing
);
if
(
selection
.
m_dropShadow
)
{
painter
->
translate
(
2
,
2
);
painter
->
fillPath
(
path
,
QColor
(
0
,
0
,
0
,
100
));
painter
->
translate
(
-
2
,
-
2
);
}
painter
->
fillPath
(
path
,
color
);
painter
->
restore
();
}
...
...
@@ -293,12 +312,7 @@ void TextEditorOverlay::paint(QPainter *painter, const QRect &clip)
!=
selection
.
m_fixedLength
)
continue
;
paintSelection
(
painter
,
selection
.
m_cursor_begin
,
selection
.
m_cursor_end
,
selection
.
m_fg
,
selection
.
m_bg
);
paintSelection
(
painter
,
selection
);
}
}
...
...
@@ -312,11 +326,7 @@ void TextEditorOverlay::fill(QPainter *painter, const QColor &color, const QRect
!=
selection
.
m_fixedLength
)
continue
;
fillSelection
(
painter
,
selection
.
m_cursor_begin
,
selection
.
m_cursor_end
,
color
);
fillSelection
(
painter
,
selection
,
color
);
}
}
...
...
src/plugins/texteditor/texteditoroverlay.h
View file @
18b9bdd4
...
...
@@ -8,12 +8,13 @@ namespace TextEditor {
namespace
Internal
{
struct
TEXTEDITOR_EXPORT
OverlaySelection
{
OverlaySelection
()
:
m_fixedLength
(
-
1
){}
OverlaySelection
()
:
m_fixedLength
(
-
1
)
,
m_dropShadow
(
false
)
{}
QTextCursor
m_cursor_begin
;
QTextCursor
m_cursor_end
;
QColor
m_fg
;
QColor
m_bg
;
int
m_fixedLength
;
bool
m_dropShadow
;
};
class
TEXTEDITOR_EXPORT
TextEditorOverlay
:
public
QObject
...
...
@@ -47,16 +48,14 @@ public:
void
clear
();
void
addOverlaySelection
(
const
QTextCursor
&
cursor
,
const
QColor
&
fg
,
const
QColor
&
bg
,
bool
lockSize
=
false
);
void
addOverlaySelection
(
int
begin
,
int
end
,
const
QColor
&
fg
,
const
QColor
&
bg
,
bool
lockSize
=
false
);
void
addOverlaySelection
(
int
begin
,
int
end
,
const
QColor
&
fg
,
const
QColor
&
bg
,
bool
lockSize
=
false
,
bool
dropShadow
=
false
);
inline
bool
isEmpty
()
const
{
return
m_selections
.
isEmpty
();
}
private:
QPainterPath
createSelectionPath
(
const
QTextCursor
&
begin
,
const
QTextCursor
&
end
,
const
QRect
&
clip
);
void
paintSelection
(
QPainter
*
painter
,
const
QTextCursor
&
begin
,
const
QTextCursor
&
end
,
const
QColor
&
fg
,
const
QColor
&
bg
);
void
fillSelection
(
QPainter
*
painter
,
const
QTextCursor
&
begin
,
const
QTextCursor
&
end
,
const
QColor
&
color
);
void
paintSelection
(
QPainter
*
painter
,
const
OverlaySelection
&
selection
);
void
fillSelection
(
QPainter
*
painter
,
const
OverlaySelection
&
selection
,
const
QColor
&
color
);
};
...
...
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