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
5367c141
Commit
5367c141
authored
Jan 17, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Jan 18, 2021
Browse files
Add basic styling
parent
60f6eca7
Changes
1
Hide whitespace changes
Inline
Side-by-side
kate/katecommandbar.cpp
View file @
5367c141
...
...
@@ -11,6 +11,9 @@
#include <QKeyEvent>
#include <QCoreApplication>
#include <QSortFilterProxyModel>
#include <QPainter>
#include <QStyledItemDelegate>
#include <QTextDocument>
#include <kfts_fuzzy_match.h>
...
...
@@ -54,6 +57,59 @@ private:
QString
m_pattern
;
};
class
CommandBarStyleDelegate
:
public
QStyledItemDelegate
{
public:
CommandBarStyleDelegate
(
QObject
*
parent
=
nullptr
)
:
QStyledItemDelegate
(
parent
)
{
}
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
override
{
QStyleOptionViewItem
options
=
option
;
initStyleOption
(
&
options
,
index
);
QTextDocument
doc
;
QString
str
=
index
.
data
().
toString
();
const
QString
nameColor
=
option
.
palette
.
color
(
QPalette
::
Link
).
name
();
kfts
::
to_fuzzy_matched_display_string
(
m_filterString
,
str
,
QStringLiteral
(
"<b style=
\"
color:%1;
\"
>"
).
arg
(
nameColor
),
QStringLiteral
(
"</b>"
));
doc
.
setHtml
(
QStringLiteral
(
"<span>"
)
+
str
+
QStringLiteral
(
"</span>"
));
doc
.
setDocumentMargin
(
2
);
painter
->
save
();
// paint background
if
(
option
.
state
&
QStyle
::
State_Selected
)
{
painter
->
fillRect
(
option
.
rect
,
option
.
palette
.
highlight
());
}
else
{
painter
->
fillRect
(
option
.
rect
,
option
.
palette
.
base
());
}
options
.
text
=
QString
();
// clear old text
options
.
widget
->
style
()
->
drawControl
(
QStyle
::
CE_ItemViewItem
,
&
options
,
painter
,
options
.
widget
);
// draw text
painter
->
translate
(
option
.
rect
.
x
(),
option
.
rect
.
y
());
// leave space for icon
painter
->
translate
(
25
,
0
);
doc
.
drawContents
(
painter
);
painter
->
restore
();
}
public
Q_SLOTS
:
void
setFilterString
(
const
QString
&
text
)
{
m_filterString
=
text
;
}
private:
QString
m_filterString
;
};
KateCommandBar
::
KateCommandBar
(
QWidget
*
parent
)
:
QMenu
(
parent
)
{
...
...
@@ -74,6 +130,9 @@ KateCommandBar::KateCommandBar(QWidget *parent)
m_model
=
new
CommandModel
(
this
);
CommandBarStyleDelegate
*
delegate
=
new
CommandBarStyleDelegate
(
this
);
m_treeView
->
setItemDelegateForColumn
(
0
,
delegate
);
m_proxyModel
=
new
CommandBarFilterModel
(
this
);
m_proxyModel
->
setFilterRole
(
Qt
::
DisplayRole
);
m_proxyModel
->
setSortRole
(
CommandModel
::
Score
);
...
...
@@ -83,7 +142,12 @@ KateCommandBar::KateCommandBar(QWidget *parent)
connect
(
m_lineEdit
,
&
QLineEdit
::
returnPressed
,
this
,
&
KateCommandBar
::
slotReturnPressed
);
connect
(
m_lineEdit
,
&
QLineEdit
::
textChanged
,
m_proxyModel
,
&
CommandBarFilterModel
::
setFilterString
);
connect
(
m_lineEdit
,
&
QLineEdit
::
textChanged
,
m_proxyModel
,
[
this
](){
reselectFirst
();
});
connect
(
m_lineEdit
,
&
QLineEdit
::
textChanged
,
delegate
,
&
CommandBarStyleDelegate
::
setFilterString
);
connect
(
m_lineEdit
,
&
QLineEdit
::
textChanged
,
this
,
[
this
](){
m_treeView
->
viewport
()
->
update
();
reselectFirst
();
});
connect
(
m_treeView
,
&
QTreeView
::
clicked
,
this
,
&
KateCommandBar
::
slotReturnPressed
);
m_proxyModel
->
setSourceModel
(
m_model
);
m_treeView
->
setSortingEnabled
(
true
);
...
...
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