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
Utilities
Kate
Commits
45b950d7
Commit
45b950d7
authored
Jan 21, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Jan 21, 2021
Browse files
Make sure foreground is colored correctly and theme updates are caught correctly
parent
ff1eb3a9
Changes
5
Hide whitespace changes
Inline
Side-by-side
addons/search/MatchModel.cpp
View file @
45b950d7
...
...
@@ -144,12 +144,11 @@ void MatchModel::addMatches(const QUrl &fileUrl, const QVector<KateSearchMatch>
endInsertRows
();
}
void
MatchModel
::
setMatchColors
(
const
Q
Color
&
foreground
,
const
Q
Color
&
background
,
const
Q
Color
&
replaceBackground
,
const
QColor
&
lineNrBackground
)
void
MatchModel
::
setMatchColors
(
const
Q
String
&
foreground
,
const
Q
String
&
background
,
const
Q
String
&
replaceBackground
)
{
m_foregroundColor
=
foreground
;
m_searchBackgroundColor
=
background
;
m_replaceHighlightColor
=
replaceBackground
;
m_lineNumberBackgroundColor
=
lineNrBackground
;
}
KateSearchMatch
*
MatchModel
::
matchFromIndex
(
const
QModelIndex
&
matchIndex
)
...
...
@@ -446,6 +445,7 @@ static QString nbsFormated(int number, int width)
{
QString
str
=
QString
::
number
(
number
);
int
strWidth
=
str
.
size
();
str
.
reserve
(
width
);
while
(
strWidth
<
width
)
{
str
=
QStringLiteral
(
" "
)
+
str
;
strWidth
++
;
...
...
@@ -538,11 +538,11 @@ QString MatchModel::matchToHtmlString(const Match &match) const
matchStr
=
QLatin1String
(
"<i><s>"
)
+
matchStr
+
QLatin1String
(
"</s></i> "
);
}
matchStr
=
QStringLiteral
(
"<span style=
\"
background-color:%1; color:%2;
\"
>%3</span>"
)
.
arg
(
m_searchBackgroundColor
.
name
()
,
m_foregroundColor
.
name
()
,
matchStr
);
.
arg
(
m_searchBackgroundColor
,
m_foregroundColor
,
matchStr
);
if
(
!
replaceStr
.
isEmpty
())
{
matchStr
+=
QStringLiteral
(
"<span style=
\"
background-color:%1; color:%2;
\"
>%3</span>"
)
.
arg
(
m_replaceHighlightColor
.
name
()
,
m_foregroundColor
.
name
()
,
replaceStr
);
.
arg
(
m_replaceHighlightColor
,
m_foregroundColor
,
replaceStr
);
}
matchStr
.
replace
(
QLatin1Char
(
'\n'
),
QStringLiteral
(
"
\\
n"
));
...
...
@@ -559,8 +559,8 @@ QString MatchModel::matchToHtmlString(const Match &match) const
post
=
post
.
toHtmlEscaped
();
// (line:col)[space][space] ...Line text pre [highlighted match] Line text post....
QString
displayText
=
QStringLiteral
(
"<span style=
\"
background-color:%1; color:%2
;
\"
> <b>%
3
:%
4:
</b></span> "
)
.
arg
(
m_lineNumberBackgroundColor
.
name
())
.
arg
(
m_foregroundColor
.
name
()
)
QString
displayText
=
QStringLiteral
(
"<span style=
\"
color:%1
;
\"
> <b>%
2
:%
3
</b></span> "
)
.
arg
(
m_foregroundColor
)
.
arg
(
nbsFormated
(
match
.
range
.
start
().
line
()
+
1
,
3
))
.
arg
(
nbsFormated
(
match
.
range
.
start
().
column
()
+
1
,
3
))
+
pre
+
matchStr
+
post
;
...
...
addons/search/MatchModel.h
View file @
45b950d7
...
...
@@ -83,7 +83,7 @@ public:
void
setDocumentManager
(
KTextEditor
::
Application
*
manager
);
void
setMatchColors
(
const
Q
Color
&
foreground
,
const
Q
Color
&
background
,
const
Q
Color
&
replaceBackground
,
const
QColor
&
lineNrBackground
);
void
setMatchColors
(
const
Q
String
&
foreground
,
const
Q
String
&
background
,
const
Q
String
&
replaceBackground
);
void
setSearchPlace
(
MatchModel
::
SearchPlaces
searchPlace
);
...
...
@@ -169,10 +169,9 @@ private:
QVector
<
MatchFile
>
m_matchFiles
;
QHash
<
QUrl
,
int
>
m_matchFileIndexHash
;
QColor
m_searchBackgroundColor
;
QColor
m_foregroundColor
;
QColor
m_replaceHighlightColor
;
QColor
m_lineNumberBackgroundColor
;
QString
m_searchBackgroundColor
;
QString
m_foregroundColor
;
QString
m_replaceHighlightColor
;
Qt
::
CheckState
m_infoCheckState
=
Qt
::
Checked
;
SearchPlaces
m_searchPlace
=
CurrentFile
;
...
...
addons/search/htmldelegate.cpp
View file @
45b950d7
...
...
@@ -52,6 +52,7 @@ void SPHtmlDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
painter
->
translate
(
clip
.
topLeft
()
-
QPoint
(
0
,
0
));
}
QAbstractTextDocumentLayout
::
PaintContext
pcontext
;
pcontext
.
palette
.
setColor
(
QPalette
::
Text
,
options
.
palette
.
text
().
color
());
doc
.
documentLayout
()
->
draw
(
painter
,
pcontext
);
painter
->
restore
();
...
...
addons/search/plugin_search.cpp
View file @
45b950d7
...
...
@@ -176,17 +176,31 @@ Results::Results(QWidget *parent)
treeView
->
setItemDelegate
(
new
SPHtmlDelegate
(
treeView
));
treeView
->
setModel
(
&
matchModel
);
auto
updateColors
=
[
this
](
KTextEditor
::
Editor
*
e
){
if
(
!
e
)
return
;
const
auto
theme
=
e
->
theme
();
auto
bg
=
QColor
::
fromRgba
(
theme
.
editorColor
(
KSyntaxHighlighting
::
Theme
::
BackgroundColor
));
auto
hl
=
QColor
::
fromRgba
(
theme
.
editorColor
(
KSyntaxHighlighting
::
Theme
::
TextSelection
));
auto
search
=
QColor
::
fromRgba
(
theme
.
editorColor
(
KSyntaxHighlighting
::
Theme
::
SearchHighlight
));
auto
replace
=
QColor
::
fromRgba
(
theme
.
editorColor
(
KSyntaxHighlighting
::
Theme
::
ReplaceHighlight
));
auto
fg
=
QColor
::
fromRgba
(
theme
.
textColor
(
KSyntaxHighlighting
::
Theme
::
Normal
));
auto
pal
=
treeView
->
palette
();
pal
.
setColor
(
QPalette
::
Base
,
bg
);
pal
.
setColor
(
QPalette
::
Highlight
,
hl
);
pal
.
setColor
(
QPalette
::
Text
,
fg
);
matchModel
.
setMatchColors
(
fg
.
name
(),
search
.
name
(),
replace
.
name
());
treeView
->
setPalette
(
pal
);
emit
colorsChanged
();
};
auto
e
=
KTextEditor
::
Editor
::
instance
();
auto
bg
=
QColor
::
fromRgba
(
e
->
theme
().
editorColor
(
KSyntaxHighlighting
::
Theme
::
BackgroundColor
));
auto
fg
=
QColor
::
fromRgba
(
e
->
theme
().
textColor
(
KSyntaxHighlighting
::
Theme
::
Normal
));
auto
hl
=
QColor
::
fromRgba
(
e
->
theme
().
editorColor
(
KSyntaxHighlighting
::
Theme
::
CurrentLine
));
auto
pal
=
treeView
->
palette
();
pal
.
setColor
(
QPalette
::
Base
,
bg
);
pal
.
setColor
(
QPalette
::
Highlight
,
hl
);
pal
.
setColor
(
QPalette
::
Text
,
fg
);
pal
.
setColor
(
QPalette
::
HighlightedText
,
fg
);
treeView
->
setPalette
(
pal
);
connect
(
e
,
&
KTextEditor
::
Editor
::
configChanged
,
this
,
updateColors
);
updateColors
(
e
);
}
K_PLUGIN_FACTORY_WITH_JSON
(
KatePluginSearchFactory
,
"katesearch.json"
,
registerPlugin
<
KatePluginSearch
>
();)
...
...
@@ -791,7 +805,7 @@ void KatePluginSearchView::stopClicked()
* search so that if the user changes the theme, he can see the new colors
* on the next search
*/
void
KatePluginSearchView
::
update
Search
Colors
()
void
KatePluginSearchView
::
update
View
Colors
()
{
auto
*
view
=
m_mainWindow
->
activeView
();
KTextEditor
::
ConfigInterface
*
ciface
=
qobject_cast
<
KTextEditor
::
ConfigInterface
*>
(
view
);
...
...
@@ -800,15 +814,11 @@ void KatePluginSearchView::updateSearchColors()
QColor
searchBackgroundColor
=
ciface
->
configValue
(
QStringLiteral
(
"search-highlight-color"
)).
value
<
QColor
>
();
if
(
!
searchBackgroundColor
.
isValid
())
searchBackgroundColor
=
Qt
::
yellow
;
QColor
replaceHighlightColor
=
ciface
->
configValue
(
QStringLiteral
(
"replace-highlight-color"
)).
value
<
QColor
>
();
if
(
!
replaceHighlightColor
.
isValid
())
replaceHighlightColor
=
Qt
::
green
;
m_
replaceHighlightColor
=
ciface
->
configValue
(
QStringLiteral
(
"replace-highlight-color"
)).
value
<
QColor
>
();
if
(
!
m_
replaceHighlightColor
.
isValid
())
m_
replaceHighlightColor
=
Qt
::
green
;
QColor
foregroundColor
=
view
->
defaultStyleAttribute
(
KTextEditor
::
dsNormal
)
->
foreground
().
color
();
QColor
lineNrBackgroundColor
=
ciface
->
configValue
(
QStringLiteral
(
"icon-border-color"
)).
value
<
QColor
>
();
if
(
!
lineNrBackgroundColor
.
isValid
())
lineNrBackgroundColor
=
view
->
defaultStyleAttribute
(
KTextEditor
::
dsNormal
)
->
background
().
color
();
if
(
!
m_resultAttr
)
m_resultAttr
=
new
KTextEditor
::
Attribute
();
// reset colors at the start of search
...
...
@@ -821,10 +831,6 @@ void KatePluginSearchView::updateSearchColors()
if
(
delegate
)
{
delegate
->
setDisplayFont
(
ciface
->
configValue
(
QStringLiteral
(
"font"
)).
value
<
QFont
>
());
}
m_curResults
->
matchModel
.
setMatchColors
(
foregroundColor
,
searchBackgroundColor
,
replaceHighlightColor
,
lineNrBackgroundColor
);
}
}
}
...
...
@@ -896,7 +902,7 @@ void KatePluginSearchView::startSearch()
return
;
}
update
Search
Colors
();
update
View
Colors
();
m_curResults
->
regExp
=
reg
;
m_curResults
->
useRegExp
=
m_ui
.
useRegExp
->
isChecked
();
...
...
@@ -1020,7 +1026,7 @@ void KatePluginSearchView::startSearchWhileTyping()
if
(
!
m_searchDiskFilesDone
||
!
m_searchOpenFilesDone
)
{
return
;
}
update
Search
Colors
();
update
View
Colors
();
m_isSearchAsYouType
=
true
;
...
...
@@ -1780,6 +1786,9 @@ void KatePluginSearchView::addTab()
}
Results
*
res
=
new
Results
();
connect
(
res
,
&
Results
::
colorsChanged
,
this
,
[
this
](){
updateViewColors
();
});
res
->
treeView
->
setContextMenuPolicy
(
Qt
::
CustomContextMenu
);
res
->
treeView
->
setRootIsDecorated
(
false
);
...
...
addons/search/plugin_search.h
View file @
45b950d7
...
...
@@ -60,6 +60,9 @@ public:
int
searchPlaceIndex
=
0
;
QString
treeRootText
;
MatchModel
matchModel
;
Q_SIGNALS:
void
colorsChanged
();
};
// This class keeps the focus inside the S&R plugin when pressing tab/shift+tab by overriding focusNextPrevChild()
...
...
@@ -176,7 +179,7 @@ protected:
private:
QStringList
filterFiles
(
const
QStringList
&
files
)
const
;
void
update
Search
Colors
();
void
update
View
Colors
();
void
onResize
(
const
QSize
&
size
);
...
...
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