14#include "config-xmlgui.h"
17#include "kshortcutsdialog_p.h"
20#include <QTreeWidgetItem>
23#include <KGlobalAccel>
30 , m_oldLocalShortcut(nullptr)
31 , m_oldGlobalShortcut(nullptr)
34 m_id = m_action->objectName();
36 if (m_actionNameInTable.isEmpty()) {
37 qCWarning(DEBUG_KXMLGUI) <<
"Action without text!" << m_action->objectName();
38 m_actionNameInTable = m_id;
41 m_collator.setNumericMode(
true);
45KShortcutsEditorItem::~KShortcutsEditorItem()
47 delete m_oldLocalShortcut;
48 delete m_oldGlobalShortcut;
51bool KShortcutsEditorItem::isModified()
const
53 return m_oldLocalShortcut || m_oldGlobalShortcut;
56QVariant KShortcutsEditorItem::data(
int column,
int role)
const
62 return m_actionNameInTable;
76 return m_action->icon();
81 return m_action->whatsThis();
87 if (column == Name && m_isNameBold) {
88 QFont modifiedFont = treeWidget()->font();
93 case KExtendableItemDelegate::ShowExtensionIndicatorRole:
99 return !m_action->property(
"isShortcutConfigurable").isValid()
100 || m_action->property(
"isShortcutConfigurable").toBool();
103 case GlobalAlternate:
118 case GlobalAlternate:
126 case DefaultShortcutRole: {
134 return primarySequence(defaultShortcuts);
136 return alternateSequence(defaultShortcuts);
139 return primarySequence(defaultGlobalShortcuts);
140 case GlobalAlternate:
141 return alternateSequence(defaultGlobalShortcuts);
159bool KShortcutsEditorItem::operator<(
const QTreeWidgetItem &other)
const
161 const int column = treeWidget() ? treeWidget()->sortColumn() : 0;
162 return m_collator.compare(text(column), other.
text(column)) < 0;
165QKeySequence KShortcutsEditorItem::keySequence(uint column)
const
167 auto shortcuts = [
this]() {
168 return m_action->shortcuts();
172 auto globalShortcuts = [
this]() {
179 return primarySequence(shortcuts());
181 return alternateSequence(shortcuts());
184 return primarySequence(globalShortcuts());
185 case GlobalAlternate:
186 return alternateSequence(globalShortcuts());
193void KShortcutsEditorItem::setKeySequence(uint column,
const QKeySequence &seq)
197 if (column == GlobalPrimary || column == GlobalAlternate) {
199 if (!m_oldGlobalShortcut) {
205 ks = m_action->shortcuts();
206 if (!m_oldLocalShortcut) {
211 if (column == LocalAlternate || column == GlobalAlternate) {
216 if (ks.
size() <= 1) {
231 if (column == GlobalPrimary || column == GlobalAlternate) {
237 m_action->setShortcuts(ks);
244void KShortcutsEditorItem::updateModified()
246 if (m_oldLocalShortcut && *m_oldLocalShortcut == m_action->shortcuts()) {
247 delete m_oldLocalShortcut;
248 m_oldLocalShortcut =
nullptr;
252 delete m_oldGlobalShortcut;
253 m_oldGlobalShortcut =
nullptr;
258bool KShortcutsEditorItem::isModified(uint column)
const
265 if (!m_oldLocalShortcut) {
268 if (column == LocalPrimary) {
269 return primarySequence(*m_oldLocalShortcut) != primarySequence(m_action->shortcuts());
271 return alternateSequence(*m_oldLocalShortcut) != alternateSequence(m_action->shortcuts());
275 case GlobalAlternate:
276 if (!m_oldGlobalShortcut) {
279 if (column == GlobalPrimary) {
290void KShortcutsEditorItem::undo()
292 if (m_oldLocalShortcut) {
294 m_action->setShortcuts(*m_oldLocalShortcut);
298 if (m_oldGlobalShortcut) {
306void KShortcutsEditorItem::commit()
308 delete m_oldLocalShortcut;
309 m_oldLocalShortcut =
nullptr;
310 delete m_oldGlobalShortcut;
311 m_oldGlobalShortcut =
nullptr;
static KGlobalAccel * self()
bool setShortcut(QAction *action, const QList< QKeySequence > &shortcut, GlobalShortcutLoading loadFlag=Autoloading)
QList< QKeySequence > shortcut(const QAction *action) const
QList< QKeySequence > defaultShortcut(const QAction *action) const
static QString removeAcceleratorMarker(const QString &label)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
const QList< QKeySequence > & shortcut(StandardShortcut id)
void setBold(bool enable)
bool isEmpty() const const
qsizetype size() const const
T value(qsizetype i) const const
void keySequence(QWidget *widget, const QKeySequence &keySequence)
QString text(int column) const const
QVariant fromValue(T &&value)