26 #include "kshortcutsdialog_p.h"
32 #include <QTreeWidgetItem>
34 KShortcutsEditorItem::KShortcutsEditorItem(QTreeWidgetItem *parent,
KAction *action)
35 : QTreeWidgetItem(parent, ActionItem)
38 , m_oldLocalShortcut(0)
39 , m_oldGlobalShortcut(0)
40 , m_oldShapeGesture(0)
41 , m_oldRockerGesture(0)
44 m_id = m_action->objectName();
46 if (m_actionNameInTable.isEmpty()) {
47 kWarning() <<
"Action without text!" << m_action->objectName();
48 m_actionNameInTable = m_id;
53 KShortcutsEditorItem::~KShortcutsEditorItem()
55 delete m_oldLocalShortcut;
56 delete m_oldGlobalShortcut;
57 delete m_oldShapeGesture;
58 delete m_oldRockerGesture;
62 bool KShortcutsEditorItem::isModified()
const
64 return m_oldLocalShortcut || m_oldGlobalShortcut || m_oldShapeGesture || m_oldRockerGesture;
68 QVariant KShortcutsEditorItem::data(
int column,
int role)
const
74 return m_actionNameInTable;
81 return keySequence(column);
83 return m_action->shapeGesture().shapeName();
85 return m_action->rockerGesture().rockerName();
90 case Qt::DecorationRole:
92 return m_action->icon();
96 case Qt::WhatsThisRole:
97 return m_action->whatsThis();
103 if (column == Name && m_isNameBold) {
104 QFont modifiedFont = treeWidget()->font();
105 modifiedFont.setBold(
true);
115 if (!m_action->isShortcutConfigurable()) {
120 case GlobalAlternate:
121 if (!m_action->isGlobalShortcutEnabled()) {
134 case GlobalAlternate:
135 return keySequence(column);
138 ret.setValue(m_action->shapeGesture());
140 case RockerGesture: {
142 ret.setValue(m_action->rockerGesture());
150 case DefaultShortcutRole:
158 case GlobalAlternate:
164 case RockerGesture: {
174 return qVariantFromValue((
QObject*)m_action);
184 bool KShortcutsEditorItem::operator<(
const QTreeWidgetItem &other)
const
186 const int column = treeWidget() ? treeWidget()->sortColumn() : 0;
191 QKeySequence KShortcutsEditorItem::keySequence(uint column)
const
195 return m_action->shortcut().primary();
197 return m_action->shortcut().alternate();
199 return m_action->globalShortcut().primary();
200 case GlobalAlternate:
201 return m_action->globalShortcut().alternate();
203 return QKeySequence();
208 void KShortcutsEditorItem::setKeySequence(uint column,
const QKeySequence &seq)
211 if (column == GlobalPrimary || column == GlobalAlternate) {
212 ks = m_action->globalShortcut();
213 if (!m_oldGlobalShortcut)
216 ks = m_action->shortcut();
217 if (!m_oldLocalShortcut)
221 if (column == LocalAlternate || column == GlobalAlternate)
227 if (column == GlobalPrimary || column == GlobalAlternate) {
237 void KShortcutsEditorItem::setShapeGesture(
const KShapeGesture &gst)
239 if (!m_oldShapeGesture) {
242 m_action->setShapeGesture(gst);
247 void KShortcutsEditorItem::setRockerGesture(
const KRockerGesture &gst)
249 if (!m_oldRockerGesture) {
252 m_action->setRockerGesture(gst);
258 void KShortcutsEditorItem::updateModified()
260 if (m_oldLocalShortcut && *m_oldLocalShortcut == m_action->shortcut()) {
261 delete m_oldLocalShortcut;
262 m_oldLocalShortcut = 0;
264 if (m_oldGlobalShortcut && *m_oldGlobalShortcut == m_action->globalShortcut()) {
265 delete m_oldGlobalShortcut;
266 m_oldGlobalShortcut = 0;
268 if (m_oldShapeGesture && *m_oldShapeGesture == m_action->shapeGesture()) {
269 delete m_oldShapeGesture;
270 m_oldShapeGesture = 0;
272 if (m_oldRockerGesture && *m_oldRockerGesture == m_action->rockerGesture()) {
273 delete m_oldRockerGesture;
274 m_oldRockerGesture = 0;
279 bool KShortcutsEditorItem::isModified(uint column)
const
286 if (!m_oldLocalShortcut)
288 if (column == LocalPrimary)
289 return m_oldLocalShortcut->primary() != m_action->shortcut().primary();
291 return m_oldLocalShortcut->alternate() != m_action->shortcut().alternate();
293 case GlobalAlternate:
294 if (!m_oldGlobalShortcut)
296 if (column == GlobalPrimary)
297 return m_oldGlobalShortcut->primary() != m_action->globalShortcut().primary();
299 return m_oldGlobalShortcut->alternate() != m_action->globalShortcut().alternate();
301 return static_cast<bool>(m_oldShapeGesture);
303 return static_cast<bool>(m_oldRockerGesture);
314 if (m_oldLocalShortcut || m_oldGlobalShortcut || m_oldShapeGesture || m_oldRockerGesture ) {
315 kDebug(125) <<
"Undoing changes for " << data(Name, Qt::DisplayRole).toString();
318 if (m_oldLocalShortcut) {
323 if (m_oldGlobalShortcut) {
328 if (m_oldShapeGesture) {
329 m_action->setShapeGesture(*m_oldShapeGesture);
332 if (m_oldRockerGesture) {
333 m_action->setRockerGesture(*m_oldRockerGesture);
340 void KShortcutsEditorItem::commit()
343 if (m_oldLocalShortcut || m_oldGlobalShortcut || m_oldShapeGesture || m_oldRockerGesture ) {
344 kDebug(125) <<
"Committing changes for " << data(Name, Qt::DisplayRole).toString();
348 delete m_oldLocalShortcut;
349 m_oldLocalShortcut = 0;
350 delete m_oldGlobalShortcut;
351 m_oldGlobalShortcut = 0;
352 delete m_oldShapeGesture;
353 m_oldShapeGesture = 0;
354 delete m_oldRockerGesture;
355 m_oldRockerGesture = 0;
KAction * undo(const QObject *recvr, const char *slot, QObject *parent)
Undo the last operation.
int naturalCompare(const QString &a, const QString &b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
The shortcut is a default shortcut - it becomes active when somebody decides to reset shortcuts to de...
QString removeAcceleratorMarker(const QString &label_)
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QString i18nc(const char *ctxt, const char *text)
Represents a keyboard shortcut.
A wrapper around QIcon that provides KDE icon features.
The shortcut will immediately become active but may be reset to "default".
void setAlternate(const QKeySequence &keySeq)
Set the alternate key sequence of this shortcut to the given key sequence.
Class to encapsulate user-driven action or event.
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void setPrimary(const QKeySequence &keySeq)
Set the primary key sequence of this shortcut to the given key sequence.
Prevent autoloading of saved global shortcut for action.