Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Utilities
Konsole
Commits
1f9ef7e2
Commit
1f9ef7e2
authored
Aug 18, 2020
by
Tomaz Canabrava
Committed by
Kurt Hindenburg
Sep 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix code style
parent
4ebbbb6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
src/delegates/ProfileShortcutDelegate.cpp
src/delegates/ProfileShortcutDelegate.cpp
+18
-15
No files found.
src/delegates/ProfileShortcutDelegate.cpp
View file @
1f9ef7e2
...
@@ -6,23 +6,23 @@
...
@@ -6,23 +6,23 @@
using
namespace
Konsole
;
using
namespace
Konsole
;
ShortcutItemDelegate
::
ShortcutItemDelegate
(
QObject
*
parent
)
ShortcutItemDelegate
::
ShortcutItemDelegate
(
QObject
*
parent
)
:
QStyledItemDelegate
(
parent
),
:
QStyledItemDelegate
(
parent
),
_modifiedEditors
(
QSet
<
QWidget
*>
()),
_modifiedEditors
(
QSet
<
QWidget
*>
()),
_itemsBeingEdited
(
QSet
<
QModelIndex
>
())
_itemsBeingEdited
(
QSet
<
QModelIndex
>
())
{
{
}
}
void
ShortcutItemDelegate
::
editorModified
()
void
ShortcutItemDelegate
::
editorModified
()
{
{
auto
*
editor
=
qobject_cast
<
FilteredKeySequenceEdit
*>
(
sender
());
auto
*
editor
=
qobject_cast
<
FilteredKeySequenceEdit
*>
(
sender
());
Q_ASSERT
(
editor
);
Q_ASSERT
(
editor
);
_modifiedEditors
.
insert
(
editor
);
_modifiedEditors
.
insert
(
editor
);
emit
commitData
(
editor
);
emit
commitData
(
editor
);
emit
closeEditor
(
editor
);
emit
closeEditor
(
editor
);
}
}
void
ShortcutItemDelegate
::
setModelData
(
QWidget
*
editor
,
QAbstractItemModel
*
model
,
void
ShortcutItemDelegate
::
setModelData
(
QWidget
*
editor
,
QAbstractItemModel
*
model
,
const
QModelIndex
&
index
)
const
const
QModelIndex
&
index
)
const
{
{
_itemsBeingEdited
.
remove
(
index
);
_itemsBeingEdited
.
remove
(
index
);
...
@@ -30,25 +30,28 @@ void ShortcutItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* mod
...
@@ -30,25 +30,28 @@ void ShortcutItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* mod
return
;
return
;
}
}
QString
shortcut
=
qobject_cast
<
FilteredKeySequenceEdit
*>
(
editor
)
->
keySequence
().
toString
();
const
auto
shortcut
=
qobject_cast
<
FilteredKeySequenceEdit
*>
(
editor
)
->
keySequence
().
toString
();
model
->
setData
(
index
,
shortcut
,
Qt
::
DisplayRole
);
model
->
setData
(
index
,
shortcut
,
Qt
::
DisplayRole
);
_modifiedEditors
.
remove
(
editor
);
_modifiedEditors
.
remove
(
editor
);
}
}
QWidget
*
ShortcutItemDelegate
::
createEditor
(
QWidget
*
aP
arent
,
const
QStyleOptionViewItem
&
,
const
QModelIndex
&
index
)
const
QWidget
*
ShortcutItemDelegate
::
createEditor
(
QWidget
*
p
arent
,
const
QStyleOptionViewItem
&
,
const
QModelIndex
&
index
)
const
{
{
_itemsBeingEdited
.
insert
(
index
);
_itemsBeingEdited
.
insert
(
index
);
auto
editor
=
new
FilteredKeySequenceEdit
(
aParent
);
auto
editor
=
new
FilteredKeySequenceEdit
(
parent
);
QString
shortcutString
=
index
.
data
(
Qt
::
DisplayRole
).
toString
();
const
auto
shortcutString
=
index
.
data
(
Qt
::
DisplayRole
).
toString
();
editor
->
setKeySequence
(
QKeySequence
::
fromString
(
shortcutString
));
editor
->
setKeySequence
(
QKeySequence
::
fromString
(
shortcutString
));
connect
(
editor
,
&
QKeySequenceEdit
::
editingFinished
,
this
,
&
Konsole
::
ShortcutItemDelegate
::
editorModified
);
editor
->
setFocus
(
Qt
::
FocusReason
::
MouseFocusReason
);
editor
->
setFocus
(
Qt
::
FocusReason
::
MouseFocusReason
);
connect
(
editor
,
&
QKeySequenceEdit
::
editingFinished
,
this
,
&
Konsole
::
ShortcutItemDelegate
::
editorModified
);
return
editor
;
return
editor
;
}
}
void
ShortcutItemDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
void
ShortcutItemDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
const
QModelIndex
&
index
)
const
{
{
if
(
_itemsBeingEdited
.
contains
(
index
))
{
if
(
_itemsBeingEdited
.
contains
(
index
))
{
StyledBackgroundPainter
::
drawBackground
(
painter
,
option
,
index
);
StyledBackgroundPainter
::
drawBackground
(
painter
,
option
,
index
);
...
@@ -59,8 +62,8 @@ void ShortcutItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem&
...
@@ -59,8 +62,8 @@ void ShortcutItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem&
QSize
ShortcutItemDelegate
::
sizeHint
(
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
QSize
ShortcutItemDelegate
::
sizeHint
(
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
{
const
QString
shortcutString
=
index
.
data
(
Qt
::
DisplayRole
).
toString
();
const
auto
shortcutString
=
index
.
data
(
Qt
::
DisplayRole
).
toString
();
QFontMetrics
fm
=
option
.
fontMetrics
;
const
auto
fm
=
option
.
fontMetrics
;
static
const
int
editorMargins
=
16
;
// chosen empirically
static
const
int
editorMargins
=
16
;
// chosen empirically
const
int
width
=
fm
.
boundingRect
(
shortcutString
+
QStringLiteral
(
", ..."
)).
width
()
const
int
width
=
fm
.
boundingRect
(
shortcutString
+
QStringLiteral
(
", ..."
)).
width
()
...
@@ -99,7 +102,7 @@ void FilteredKeySequenceEdit::keyPressEvent(QKeyEvent *event)
...
@@ -99,7 +102,7 @@ void FilteredKeySequenceEdit::keyPressEvent(QKeyEvent *event)
QKeySequenceEdit
::
keyPressEvent
(
event
);
QKeySequenceEdit
::
keyPressEvent
(
event
);
}
}
void
StyledBackgroundPainter
::
drawBackground
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
void
StyledBackgroundPainter
::
drawBackground
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
)
const
QModelIndex
&
)
{
{
const
auto
*
opt
=
qstyleoption_cast
<
const
QStyleOptionViewItem
*>
(
&
option
);
const
auto
*
opt
=
qstyleoption_cast
<
const
QStyleOptionViewItem
*>
(
&
option
);
...
...
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