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
684fea48
Commit
684fea48
authored
Apr 01, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Apr 04, 2021
Browse files
Fix shortcut display for multi-key shortcuts
Signed-off-by:
Waqar Ahmed
<
waqar.17a@gmail.com
>
parent
ae37e978
Changes
1
Hide whitespace changes
Inline
Side-by-side
kate/katecommandbar.cpp
View file @
684fea48
...
...
@@ -142,12 +142,22 @@ private:
class
ShortcutStyleDelegate
:
public
QStyledItemDelegate
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
static
constexpr
auto
SkipEmptyParts
=
QString
::
SkipEmptyParts
;
#else
static
constexpr
auto
SkipEmptyParts
=
Qt
::
SkipEmptyParts
;
#endif
public:
ShortcutStyleDelegate
(
QObject
*
parent
=
nullptr
)
:
QStyledItemDelegate
(
parent
)
{
}
static
QStringList
splitShortcutString
(
const
QString
&
shortcutString
)
{
return
shortcutString
.
split
(
QLatin1String
(
", "
),
SkipEmptyParts
);
}
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
override
{
QStyleOptionViewItem
options
=
option
;
...
...
@@ -167,19 +177,42 @@ public:
options
.
widget
->
style
()
->
drawControl
(
QStyle
::
CE_ItemViewItem
,
&
options
,
painter
,
options
.
widget
);
if
(
!
shortcutString
.
isEmpty
())
{
// collect rects for each word
QVector
<
QPair
<
QRect
,
QString
>>
btns
;
const
auto
list
=
[
&
shortcutString
]
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
auto
list
=
shortcutString
.
split
(
QLatin1Char
(
'+'
),
QString
::
SkipEmptyParts
);
#else
auto
list
=
shortcutString
.
split
(
QLatin1Char
(
'+'
),
Qt
::
SkipEmptyParts
);
#endif
if
(
shortcutString
.
endsWith
(
QLatin1String
(
"+"
)))
{
list
.
append
(
QStringLiteral
(
"+"
));
/**
* Shortcut string splitting
*
* We do it in two steps
* 1. Split on ", " so that if we have multi modifier shortcuts they are nicely
* splitted into strings.
* 2. Split each shortcut from step 1 into individual string.
*
* Example:
*
* "Ctrl+,, Alt+:"
* Step 1: [ "Ctrl+," , "Alt+:"]
* Step 2: [ "Ctrl", ",", "Alt", ":"]
*/
const
auto
spaceSplitted
=
splitShortcutString
(
shortcutString
);
const
auto
list
=
[
spaceSplitted
]
{
QStringList
shortcutList
;
shortcutList
.
reserve
(
spaceSplitted
.
size
()
*
2
);
for
(
const
QString
&
shortcut
:
spaceSplitted
)
{
QStringList
list
=
shortcut
.
split
(
QLatin1Char
(
'+'
),
SkipEmptyParts
);
if
(
shortcut
.
endsWith
(
QLatin1String
(
"+"
)))
{
list
.
append
(
QStringLiteral
(
"+"
));
}
}
return
l
ist
;
return
shortcutL
ist
;
}();
/**
* Create rects for each string from the previous step
*
* @todo boundingRect may give issues here, use horizontalAdvance
* @todo We probably dont need the full rect, just the width so the
* "btns" vector can just be vector<pair<int, string>>
*/
QVector
<
QPair
<
QRect
,
QString
>>
btns
;
btns
.
reserve
(
list
.
size
());
const
int
height
=
options
.
rect
.
height
();
for
(
const
QString
&
text
:
list
)
{
...
...
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