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
c95c9f12
Commit
c95c9f12
authored
Jan 29, 2021
by
Waqar Ahmed
Browse files
Clean up command bar code and fix styling
parent
4fdbe6f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
kate/katecommandbar.cpp
View file @
c95c9f12
...
...
@@ -112,10 +112,11 @@ public:
if
(
rtl
)
{
auto
r
=
options
.
widget
->
style
()
->
subElementRect
(
QStyle
::
SE_ItemViewItemText
,
&
options
,
options
.
widget
);
auto
hasIcon
=
index
.
data
(
Qt
::
DecorationRole
).
value
<
QIcon
>
().
isNull
();
if
(
hasIcon
)
if
(
hasIcon
)
{
doc
.
setTextWidth
(
r
.
width
()
-
25
);
else
}
else
{
doc
.
setTextWidth
(
r
.
width
());
}
}
// draw text
...
...
@@ -152,15 +153,10 @@ public:
{
QStyleOptionViewItem
options
=
option
;
initStyleOption
(
&
options
,
index
);
QTextDocument
doc
;
const
auto
strs
=
index
.
data
().
toString
();
doc
.
setDocumentMargin
(
2
);
doc
.
setHtml
(
strs
);
painter
->
save
();
const
auto
shortcutString
=
index
.
data
().
toString
();
// paint background
if
(
option
.
state
&
QStyle
::
State_Selected
)
{
painter
->
fillRect
(
option
.
rect
,
option
.
palette
.
highlight
());
...
...
@@ -171,48 +167,50 @@ public:
options
.
text
=
QString
();
// clear old text
options
.
widget
->
style
()
->
drawControl
(
QStyle
::
CE_ItemViewItem
,
&
options
,
painter
,
options
.
widget
);
if
(
!
s
trs
.
isEmpty
())
{
// collect
button-style pixmaps
QVector
<
QPair
<
QRect
,
QString
>>
btn
Rect
s
;
auto
list
=
s
trs
.
split
(
QLatin1Char
(
'+'
));
for
(
auto
text
:
list
)
{
auto
r
=
option
.
fontMetrics
.
boundingRect
(
text
);
if
(
!
s
hortcutString
.
isEmpty
())
{
// collect
rects for each word
QVector
<
QPair
<
QRect
,
QString
>>
btns
;
const
auto
list
=
s
hortcutString
.
split
(
QLatin1Char
(
'+'
));
for
(
const
QString
&
text
:
list
)
{
QRect
r
=
option
.
fontMetrics
.
boundingRect
(
text
);
r
.
setWidth
(
r
.
width
()
+
8
);
r
.
setHeight
(
r
.
height
()
+
4
);
btn
Rect
s
.
append
({
r
,
text
});
btns
.
append
({
r
,
text
});
}
auto
plusRect
=
option
.
fontMetrics
.
boundingRect
(
QLatin1Char
(
'+'
));
const
auto
plusRect
=
option
.
fontMetrics
.
boundingRect
(
QLatin1Char
(
'+'
));
// draw them
int
d
x
=
option
.
rect
.
x
();
int
y
=
option
.
rect
.
y
();
int
p
y
=
option
.
rect
.
y
()
+
plusRect
.
height
()
/
2
;
int
total
=
btn
Rect
s
.
size
();
int
x
=
option
.
rect
.
x
();
const
int
y
=
option
.
rect
.
y
();
const
int
p
lusY
=
option
.
rect
.
y
()
+
plusRect
.
height
()
/
2
;
const
int
total
=
btns
.
size
();
int
i
=
0
;
painter
->
setRenderHint
(
QPainter
::
Antialiasing
);
// :)
for
(
const
auto
&
pxm
:
btnRects
)
{
// draw rounded rect shadown
painter
->
setRenderHint
(
QPainter
::
Antialiasing
);
for
(
const
auto
&
btn
:
btns
)
{
painter
->
setPen
(
Qt
::
NoPen
);
QRect
r
(
dx
,
y
,
pxm
.
first
.
width
(),
pxm
.
first
.
height
());
auto
shadow
=
r
.
translated
(
0
,
1
);
const
QRect
&
rect
=
btn
.
first
;
QRect
buttonRect
(
x
,
y
,
rect
.
width
(),
rect
.
height
());
// draw rounded rect shadow
auto
shadowRect
=
buttonRect
.
translated
(
0
,
1
);
painter
->
setBrush
(
option
.
palette
.
shadow
());
painter
->
drawRoundedRect
(
shadow
,
3
,
3
);
painter
->
drawRoundedRect
(
shadow
Rect
,
3
,
3
);
// draw rounded rect itself
painter
->
setBrush
(
option
.
palette
.
button
());
painter
->
drawRoundedRect
(
r
,
3
,
3
);
painter
->
drawRoundedRect
(
buttonRect
,
3
,
3
);
// draw text inside rounded rect
painter
->
setPen
(
option
.
palette
.
buttonText
().
color
());
painter
->
drawText
(
r
,
Qt
::
AlignCenter
,
pxm
.
second
);
painter
->
drawText
(
buttonRect
,
Qt
::
AlignCenter
,
btn
.
second
);
// draw '+'
if
(
i
+
1
<
total
)
{
d
x
+=
pxm
.
firs
t
.
width
()
+
8
;
painter
->
drawText
(
QPoint
(
d
x
,
p
y
+
(
pxm
.
firs
t
.
height
()
/
2
)),
QStringLiteral
(
"+"
));
d
x
+=
plusRect
.
width
()
+
8
;
x
+=
rec
t
.
width
()
+
8
;
painter
->
drawText
(
QPoint
(
x
,
p
lusY
+
(
rec
t
.
height
()
/
2
)),
QStringLiteral
(
"+"
));
x
+=
plusRect
.
width
()
+
8
;
}
i
++
;
}
...
...
@@ -280,7 +278,8 @@ void KateCommandBar::updateBar(const QList<KActionCollection *> &actionCollectio
{
QVector
<
QPair
<
QString
,
QAction
*>>
actionList
;
for
(
const
auto
collection
:
actionCollections
)
{
for
(
const
auto
action
:
collection
->
actions
())
{
const
QList
<
QAction
*>
collectionActions
=
collection
->
actions
();
for
(
const
auto
action
:
collectionActions
)
{
// sanity + empty check ensures displayable actions and removes ourself
// from the action list
if
(
action
&&
!
action
->
text
().
isEmpty
())
{
...
...
kate/katemainwindow.cpp
View file @
c95c9f12
...
...
@@ -1221,11 +1221,13 @@ void KateMainWindow::slotCommandBarOpen()
QList
<
KActionCollection
*>
actionCollections
;
auto
clients
=
guiFactory
()
->
clients
();
for
(
auto
c
:
clients
)
{
if
(
!
c
)
for
(
const
KXMLGUIClient
*
c
:
clients
)
{
if
(
!
c
)
{
continue
;
if
(
!
c
->
actionCollection
())
}
if
(
!
c
->
actionCollection
())
{
continue
;
}
actionCollections
.
append
(
c
->
actionCollection
());
}
...
...
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