File indexing completed on 2022-11-29 12:54:54

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Sebastian Gottfried <sebastiangottfried@web.de>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "keyboardlayoutcommands.h"
0008 
0009 #include <KLocalizedString>
0010 
0011 #include <core/keyboardlayout.h>
0012 #include <core/abstractkey.h>
0013 #include <core/key.h>
0014 
0015 SetKeyboardLayoutTitleCommand::SetKeyboardLayoutTitleCommand(KeyboardLayout* layout, const QString& newTitle, QUndoCommand* parent) :
0016     QUndoCommand(parent),
0017     m_layout(layout),
0018     m_oldTitle(layout->title()),
0019     m_newTitle(newTitle)
0020 {
0021     setText(i18n("Set keyboard layout title"));
0022 }
0023 
0024 void SetKeyboardLayoutTitleCommand::undo()
0025 {
0026     m_layout->setTitle(m_oldTitle);
0027 }
0028 
0029 void SetKeyboardLayoutTitleCommand::redo()
0030 {
0031     m_layout->setTitle(m_newTitle);
0032 }
0033 
0034 int SetKeyboardLayoutTitleCommand::id() const
0035 {
0036     return 0xa7b18eae;
0037 }
0038 
0039 bool SetKeyboardLayoutTitleCommand::mergeWith(const QUndoCommand* other)
0040 {
0041     const SetKeyboardLayoutTitleCommand* setKeyboardLayoutTitleCommand = static_cast<const SetKeyboardLayoutTitleCommand*>(other);
0042 
0043     if (m_layout != setKeyboardLayoutTitleCommand->m_layout)
0044         return false;
0045 
0046     m_newTitle = setKeyboardLayoutTitleCommand->m_newTitle;
0047     return true;
0048 }
0049 
0050 SetKeyboardLayoutNameCommand::SetKeyboardLayoutNameCommand(KeyboardLayout* layout, const QString& newName, QUndoCommand* parent) :
0051     QUndoCommand(parent),
0052     m_layout(layout),
0053     m_oldName(layout->name()),
0054     m_newName(newName)
0055 {
0056     setText(i18n("Set keyboard layout name"));
0057 }
0058 
0059 void SetKeyboardLayoutNameCommand::undo()
0060 {
0061     m_layout->setName(m_oldName);
0062 }
0063 
0064 void SetKeyboardLayoutNameCommand::redo()
0065 {
0066     m_layout->setName(m_newName);
0067 }
0068 
0069 int SetKeyboardLayoutNameCommand::id() const
0070 {
0071     return 0x24c31e8b;
0072 }
0073 
0074 bool SetKeyboardLayoutNameCommand::mergeWith(const QUndoCommand* other)
0075 {
0076     const SetKeyboardLayoutNameCommand* setKeyboardLayoutNameCommand = static_cast<const SetKeyboardLayoutNameCommand*>(other);
0077 
0078     if (m_layout != setKeyboardLayoutNameCommand->m_layout)
0079         return false;
0080 
0081     m_newName = setKeyboardLayoutNameCommand->m_newName;
0082     return true;
0083 }
0084 
0085 SetKeyboardLayoutSizeCommand::SetKeyboardLayoutSizeCommand(KeyboardLayout* layout, const QSize& newSize, QUndoCommand* parent) :
0086     QUndoCommand(parent),
0087     m_layout(layout),
0088     m_oldSize(layout->size()),
0089     m_newSize(newSize)
0090 {
0091     setText(i18n("Set keyboard layout size"));
0092 
0093     for (int i = 0; i < m_layout->keyCount(); i++)
0094     {
0095         AbstractKey* const key = m_layout->key(i);
0096         QRect rect(key->rect());
0097 
0098         if (key->left() + key->width() > newSize.width())
0099         {
0100             rect.moveLeft(newSize.width() - key->width());
0101         }
0102 
0103         if (key->top() + key->height() > newSize.height())
0104         {
0105             rect.moveTop(newSize.height() - key->height());
0106         }
0107 
0108         if (rect != key->rect())
0109         {
0110             new SetKeyGeometryCommand(m_layout, i, rect, this);
0111         }
0112     }
0113 }
0114 
0115 void SetKeyboardLayoutSizeCommand::undo()
0116 {
0117     QUndoCommand::undo();
0118     m_layout->setSize(m_oldSize);
0119 }
0120 
0121 void SetKeyboardLayoutSizeCommand::redo()
0122 {
0123     QUndoCommand::redo();
0124     m_layout->setSize(m_newSize);
0125 }
0126 
0127 int SetKeyboardLayoutSizeCommand::id() const
0128 {
0129     return 0xaad8b7c8;
0130 }
0131 
0132 bool SetKeyboardLayoutSizeCommand::mergeWith(const QUndoCommand* other)
0133 {
0134     Q_UNUSED(other);
0135     return false;
0136 }
0137 
0138 AddKeyCommand::AddKeyCommand(KeyboardLayout *layout, AbstractKey *key, QUndoCommand *parent) :
0139     QUndoCommand(parent),
0140     m_layout(layout),
0141     m_backupKey(key)
0142 {
0143     setText(i18n("Add key"));
0144 }
0145 
0146 AddKeyCommand::~AddKeyCommand()
0147 {
0148     delete m_backupKey;
0149 }
0150 
0151 void AddKeyCommand::undo()
0152 {
0153     const int keyIndex = m_layout->keyCount() - 1;
0154     AbstractKey* abstractKey = m_layout->key(keyIndex);
0155 
0156     if (Key* key = qobject_cast<Key*>(abstractKey))
0157     {
0158         Key* backupKey = new Key();
0159         backupKey->copyFrom(key);
0160         m_backupKey = backupKey;
0161     }
0162     else if (SpecialKey* specialKey = qobject_cast<SpecialKey*>(abstractKey))
0163     {
0164         SpecialKey* specialKeyBackup = new SpecialKey();
0165         specialKey->copyFrom(specialKey);
0166         m_backupKey = specialKeyBackup;
0167     }
0168 
0169     m_layout->removeKey(keyIndex);
0170 }
0171 
0172 void AddKeyCommand::redo()
0173 {
0174     Q_ASSERT(m_backupKey);
0175 
0176     m_layout->addKey(m_backupKey);
0177 
0178     m_backupKey = nullptr;
0179 }
0180 
0181 int AddKeyCommand::id() const
0182 {
0183     return 0xfd2d9a61;
0184 }
0185 
0186 bool AddKeyCommand::mergeWith(const QUndoCommand *other)
0187 {
0188     Q_UNUSED(other);
0189     return false;
0190 }
0191 
0192 RemoveKeyCommand::RemoveKeyCommand(KeyboardLayout* layout, int keyIndex, QUndoCommand* parent) :
0193     QUndoCommand(parent),
0194     m_layout(layout),
0195     m_keyIndex(keyIndex),
0196     m_backupKey(nullptr)
0197 {
0198     setText(i18n("Remove key"));
0199 }
0200 
0201 RemoveKeyCommand::~RemoveKeyCommand()
0202 {
0203     delete m_backupKey;
0204 }
0205 
0206 void RemoveKeyCommand::undo()
0207 {
0208     Q_ASSERT(m_backupKey);
0209 
0210     if (m_keyIndex == m_layout->keyCount())
0211     {
0212         m_layout->addKey(m_backupKey);
0213     }
0214     else
0215     {
0216         m_layout->insertKey(m_keyIndex, m_backupKey);
0217     }
0218 
0219     m_backupKey = nullptr;
0220 }
0221 
0222 void RemoveKeyCommand::redo()
0223 {
0224     AbstractKey* abstractKey = m_layout->key(m_keyIndex);
0225 
0226     if (Key* key = qobject_cast<Key*>(abstractKey))
0227     {
0228         Key* backupKey = new Key();
0229         backupKey->copyFrom(key);
0230         m_backupKey = backupKey;
0231     }
0232     else if (SpecialKey* specialKey = qobject_cast<SpecialKey*>(abstractKey))
0233     {
0234         SpecialKey* specialKeyBackup = new SpecialKey();
0235         specialKeyBackup->copyFrom(specialKey);
0236         m_backupKey = specialKeyBackup;
0237     }
0238 
0239     m_layout->removeKey(m_keyIndex);
0240 }
0241 
0242 int RemoveKeyCommand::id() const
0243 {
0244     return 0xf992f4a7;
0245 }
0246 
0247 bool RemoveKeyCommand::mergeWith(const QUndoCommand* other)
0248 {
0249     Q_UNUSED(other)
0250     return false;
0251 }
0252 
0253 SetKeyGeometryCommand::SetKeyGeometryCommand(KeyboardLayout* layout, int keyIndex, const QRect& newRect, QUndoCommand* parent) :
0254     QUndoCommand(parent),
0255     m_layout(layout),
0256     m_keyIndex(keyIndex),
0257     m_oldRect(layout->key(keyIndex)->rect()),
0258     m_newRect(newRect)
0259 {
0260     setText(i18n("Set key geometry"));
0261 }
0262 
0263 void SetKeyGeometryCommand::undo()
0264 {
0265     m_layout->key(m_keyIndex)->setRect(m_oldRect);
0266 }
0267 
0268 void SetKeyGeometryCommand::redo()
0269 {
0270     m_layout->key(m_keyIndex)->setRect(m_newRect);
0271 }
0272 
0273 int SetKeyGeometryCommand::id() const
0274 {
0275     return 0x7260c67c;
0276 }
0277 
0278 bool SetKeyGeometryCommand::mergeWith(const QUndoCommand* other)
0279 {
0280     const SetKeyGeometryCommand* setKeyGeometryCommand = static_cast<const SetKeyGeometryCommand*>(other);
0281 
0282     if (m_layout != setKeyGeometryCommand->m_layout)
0283         return false;
0284 
0285     if (m_keyIndex != setKeyGeometryCommand->m_keyIndex)
0286         return false;
0287 
0288     m_newRect = setKeyGeometryCommand->m_newRect;
0289     return true;
0290 }
0291 
0292 SetKeyFingerIndexCommand::SetKeyFingerIndexCommand(KeyboardLayout* layout, int keyIndex, int newFingerIndex, QUndoCommand* parent) :
0293     QUndoCommand(parent),
0294     m_layout(layout),
0295     m_keyIndex(keyIndex),
0296     m_newFingerIndex(newFingerIndex)
0297 {
0298     setText(i18n("Set key finger"));
0299 
0300     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0301     Q_ASSERT(key);
0302     m_oldFingerIndex = key->fingerIndex();
0303 }
0304 
0305 void SetKeyFingerIndexCommand::undo()
0306 {
0307     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0308     Q_ASSERT(key);
0309     key->setFingerIndex(m_oldFingerIndex);
0310 }
0311 
0312 void SetKeyFingerIndexCommand::redo()
0313 {
0314     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0315     Q_ASSERT(key);
0316     key->setFingerIndex(m_newFingerIndex);
0317 }
0318 
0319 int SetKeyFingerIndexCommand::id() const
0320 {
0321     return 0xcecb02ad;
0322 }
0323 
0324 bool SetKeyFingerIndexCommand::mergeWith(const QUndoCommand* other)
0325 {
0326     const SetKeyFingerIndexCommand* setKeyFingerIndexCommand = static_cast<const SetKeyFingerIndexCommand*>(other);
0327 
0328     if (m_layout != setKeyFingerIndexCommand->m_layout)
0329         return false;
0330 
0331     if (m_keyIndex != setKeyFingerIndexCommand->m_keyIndex)
0332         return false;
0333 
0334     m_newFingerIndex = setKeyFingerIndexCommand->m_newFingerIndex;
0335     return true;
0336 }
0337 
0338 SetKeyHasHapticMarkerCommand::SetKeyHasHapticMarkerCommand(KeyboardLayout* layout, int keyIndex, bool newHasHapticMarker, QUndoCommand* parent) :
0339     QUndoCommand(parent),
0340     m_layout(layout),
0341     m_keyIndex(keyIndex),
0342     m_newHasHapticMarker(newHasHapticMarker)
0343 {
0344     setText(i18n("Set key haptic marker"));
0345 
0346     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0347     Q_ASSERT(key);
0348     m_oldHasHapticMarker = key->hasHapticMarker();
0349 }
0350 
0351 void SetKeyHasHapticMarkerCommand::undo()
0352 {
0353     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0354     Q_ASSERT(key);
0355     key->setHasHapticMarker(m_oldHasHapticMarker);
0356 }
0357 
0358 void SetKeyHasHapticMarkerCommand::redo()
0359 {
0360     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0361     Q_ASSERT(key);
0362     key->setHasHapticMarker(m_newHasHapticMarker);
0363 }
0364 
0365 int SetKeyHasHapticMarkerCommand::id() const
0366 {
0367     return 0xf436020c;
0368 }
0369 
0370 bool SetKeyHasHapticMarkerCommand::mergeWith(const QUndoCommand* other)
0371 {
0372     const SetKeyHasHapticMarkerCommand* setKeyHasHapticMarkerCommand = static_cast<const SetKeyHasHapticMarkerCommand*>(other);
0373 
0374     if (m_layout != setKeyHasHapticMarkerCommand->m_layout)
0375         return false;
0376 
0377     if (m_keyIndex != setKeyHasHapticMarkerCommand->m_keyIndex)
0378         return false;
0379 
0380     m_newHasHapticMarker = setKeyHasHapticMarkerCommand->m_newHasHapticMarker;
0381     return true;
0382 }
0383 
0384 AddKeyCharCommand::AddKeyCharCommand(KeyboardLayout* layout, int keyIndex, QUndoCommand* parent) :
0385     QUndoCommand(parent),
0386     m_layout(layout),
0387     m_keyIndex(keyIndex)
0388 {
0389     setText(i18n("Add key character"));
0390 }
0391 
0392 void AddKeyCharCommand::undo()
0393 {
0394     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0395 
0396     Q_ASSERT(key);
0397     Q_ASSERT(key->keyCharCount() > 0);
0398 
0399     key->removeKeyChar(key->keyCharCount() - 1);
0400 }
0401 
0402 void AddKeyCharCommand::redo()
0403 {
0404     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0405 
0406     Q_ASSERT(key);
0407 
0408     KeyChar* keyChar = new KeyChar();
0409     key->addKeyChar(keyChar);
0410 }
0411 
0412 int AddKeyCharCommand::id() const
0413 {
0414     return 0x9808f018;
0415 }
0416 
0417 bool AddKeyCharCommand::mergeWith(const QUndoCommand* other)
0418 {
0419     Q_UNUSED(other)
0420     return false;
0421 }
0422 
0423 RemoveKeyCharCommand::RemoveKeyCharCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, QUndoCommand* parent) :
0424     QUndoCommand(parent),
0425     m_layout(layout),
0426     m_keyIndex(keyIndex),
0427     m_keyCharIndex(keyCharIndex),
0428     m_backupKeyChar(nullptr)
0429 {
0430     setText(i18n("Remove key character"));
0431 }
0432 
0433 RemoveKeyCharCommand::~RemoveKeyCharCommand()
0434 {
0435     delete m_backupKeyChar;
0436 }
0437 
0438 void RemoveKeyCharCommand::undo()
0439 {
0440     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0441 
0442     Q_ASSERT(m_backupKeyChar);
0443     Q_ASSERT(key);
0444 
0445     if (m_keyCharIndex == key->keyCharCount())
0446     {
0447         key->addKeyChar(m_backupKeyChar);
0448     }
0449     else
0450     {
0451         key->insertKeyChar(m_keyCharIndex, m_backupKeyChar);
0452     }
0453 
0454     m_backupKeyChar = nullptr;
0455 }
0456 
0457 void RemoveKeyCharCommand::redo()
0458 {
0459     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0460 
0461     Q_ASSERT(key);
0462 
0463     m_backupKeyChar = new KeyChar();
0464     m_backupKeyChar->copyFrom(key->keyChar(m_keyCharIndex));
0465 
0466     key->removeKeyChar(m_keyCharIndex);
0467 }
0468 
0469 int RemoveKeyCharCommand::id() const
0470 {
0471     return 0x4b6252f5;
0472 }
0473 
0474 bool RemoveKeyCharCommand::mergeWith(const QUndoCommand* other)
0475 {
0476     Q_UNUSED(other)
0477     return false;
0478 }
0479 
0480 SetKeyCharValueCommand::SetKeyCharValueCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, QChar newValue, QUndoCommand* parent) :
0481     QUndoCommand(parent),
0482     m_layout(layout),
0483     m_keyIndex(keyIndex),
0484     m_keyCharIndex(keyCharIndex),
0485     m_newValue(newValue)
0486 {
0487     setText(i18n("Set key character value"));
0488 
0489     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0490     m_oldValue = key->keyChar(m_keyCharIndex)->value();
0491 }
0492 
0493 void SetKeyCharValueCommand::undo()
0494 {
0495     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0496     key->keyChar(m_keyCharIndex)->setValue(m_oldValue);
0497 }
0498 
0499 void SetKeyCharValueCommand::redo()
0500 {
0501     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0502     key->keyChar(m_keyCharIndex)->setValue(m_newValue);
0503 }
0504 
0505 int SetKeyCharValueCommand::id() const
0506 {
0507     return 0x7a621de0;
0508 }
0509 
0510 bool SetKeyCharValueCommand::mergeWith(const QUndoCommand* other)
0511 {
0512     const SetKeyCharValueCommand* setKeyCharValueCommand = static_cast<const SetKeyCharValueCommand*>(other);
0513 
0514     if (m_layout != setKeyCharValueCommand->m_layout)
0515         return false;
0516 
0517     if (m_keyIndex != setKeyCharValueCommand->m_keyIndex)
0518         return false;
0519 
0520     if (m_keyCharIndex != setKeyCharValueCommand->m_keyCharIndex)
0521         return false;
0522 
0523     m_newValue = setKeyCharValueCommand->m_newValue;
0524     return true;
0525 }
0526 
0527 SetKeyCharModifierCommand::SetKeyCharModifierCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, const QString& newModifier, QUndoCommand* parent) :
0528     QUndoCommand(parent),
0529     m_layout(layout),
0530     m_keyIndex(keyIndex),
0531     m_keyCharIndex(keyCharIndex),
0532     m_newModifier(newModifier)
0533 {
0534     setText(i18n("Set key character modifier"));
0535 
0536     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0537     m_oldModifier = key->keyChar(m_keyCharIndex)->modifier();
0538 }
0539 
0540 void SetKeyCharModifierCommand::undo()
0541 {
0542     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0543     key->keyChar(m_keyCharIndex)->setModifier(m_oldModifier);
0544 }
0545 
0546 void SetKeyCharModifierCommand::redo()
0547 {
0548     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0549     key->keyChar(m_keyCharIndex)->setModifier(m_newModifier);
0550 }
0551 
0552 int SetKeyCharModifierCommand::id() const
0553 {
0554     return 0xdd9f24d0;
0555 }
0556 
0557 bool SetKeyCharModifierCommand::mergeWith(const QUndoCommand* other)
0558 {
0559     const SetKeyCharModifierCommand* setKeyCharModifierCommand = static_cast<const SetKeyCharModifierCommand*>(other);
0560 
0561     if (m_layout != setKeyCharModifierCommand->m_layout)
0562         return false;
0563 
0564     if (m_keyIndex != setKeyCharModifierCommand->m_keyIndex)
0565         return false;
0566 
0567     if (m_keyCharIndex != setKeyCharModifierCommand->m_keyCharIndex)
0568         return false;
0569 
0570     m_newModifier = setKeyCharModifierCommand->m_newModifier;
0571     return true;
0572 }
0573 
0574 SetKeyCharPositionCommand::SetKeyCharPositionCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, KeyChar::Position newPosition, QUndoCommand* parent) :
0575     QUndoCommand(parent),
0576     m_layout(layout),
0577     m_keyIndex(keyIndex),
0578     m_keyCharIndex(keyCharIndex),
0579     m_newPosition(newPosition)
0580 {
0581     setText(i18n("Set key character position"));
0582 
0583     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0584     m_oldPosition = key->keyChar(m_keyCharIndex)->position();
0585 }
0586 
0587 void SetKeyCharPositionCommand::undo()
0588 {
0589     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0590     key->keyChar(m_keyCharIndex)->setPosition(m_oldPosition);
0591 }
0592 
0593 void SetKeyCharPositionCommand::redo()
0594 {
0595     Key* key = qobject_cast<Key*>(m_layout->key(m_keyIndex));
0596     key->keyChar(m_keyCharIndex)->setPosition(m_newPosition);
0597 }
0598 
0599 int SetKeyCharPositionCommand::id() const
0600 {
0601     return 0x50192aaa;
0602 }
0603 
0604 bool SetKeyCharPositionCommand::mergeWith(const QUndoCommand* other)
0605 {
0606     const SetKeyCharPositionCommand* setKeyCharPositionCommand = static_cast<const SetKeyCharPositionCommand*>(other);
0607 
0608     if (m_layout != setKeyCharPositionCommand->m_layout)
0609         return false;
0610 
0611     if (m_keyIndex != setKeyCharPositionCommand->m_keyIndex)
0612         return false;
0613 
0614     if (m_keyCharIndex != setKeyCharPositionCommand->m_keyCharIndex)
0615         return false;
0616 
0617     m_newPosition = setKeyCharPositionCommand->m_newPosition;
0618     return true;
0619 }
0620 
0621 SetSpecialKeyTypeCommand::SetSpecialKeyTypeCommand(KeyboardLayout* layout, int keyIndex, SpecialKey::Type newType, QUndoCommand* parent) :
0622     QUndoCommand(parent),
0623     m_layout(layout),
0624     m_keyIndex(keyIndex),
0625     m_newType(newType)
0626 {
0627     setText(i18n("Set special key type"));
0628 
0629     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0630     m_oldType = key->type();
0631 }
0632 
0633 void SetSpecialKeyTypeCommand::undo()
0634 {
0635     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0636     key->setType(m_oldType);
0637 }
0638 
0639 void SetSpecialKeyTypeCommand::redo()
0640 {
0641     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0642     key->setType(m_newType);
0643 }
0644 
0645 int SetSpecialKeyTypeCommand::id() const
0646 {
0647     return 0xf1ce4bee;
0648 }
0649 
0650 bool SetSpecialKeyTypeCommand::mergeWith(const QUndoCommand* other)
0651 {
0652     const SetSpecialKeyTypeCommand* setSpecialKeyTypeCommand = static_cast<const SetSpecialKeyTypeCommand*>(other);
0653 
0654     if (m_layout != setSpecialKeyTypeCommand->m_layout)
0655         return false;
0656 
0657     if (m_keyIndex != setSpecialKeyTypeCommand->m_keyIndex)
0658         return false;
0659 
0660     m_newType = setSpecialKeyTypeCommand->m_newType;
0661     return true;
0662 }
0663 
0664 SetSpecialKeyLabelCommand::SetSpecialKeyLabelCommand(KeyboardLayout* layout, int keyIndex, const QString& newLabel, QUndoCommand* parent) :
0665     QUndoCommand(parent),
0666     m_layout(layout),
0667     m_keyIndex(keyIndex),
0668     m_newLabel(newLabel)
0669 {
0670     setText(i18n("Set special key label"));
0671 
0672     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0673     m_oldLabel = key->label();
0674 }
0675 
0676 void SetSpecialKeyLabelCommand::undo()
0677 {
0678     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0679     key->setLabel(m_oldLabel);
0680 }
0681 
0682 void SetSpecialKeyLabelCommand::redo()
0683 {
0684     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0685     key->setLabel(m_newLabel);
0686 }
0687 
0688 int SetSpecialKeyLabelCommand::id() const
0689 {
0690     return 0x6a1ddec9;
0691 }
0692 
0693 bool SetSpecialKeyLabelCommand::mergeWith(const QUndoCommand* other)
0694 {
0695     const SetSpecialKeyLabelCommand* setSpecialKeyLabelCommand = static_cast<const SetSpecialKeyLabelCommand*>(other);
0696 
0697     if (m_layout != setSpecialKeyLabelCommand->m_layout)
0698         return false;
0699 
0700     if (m_keyIndex != setSpecialKeyLabelCommand->m_keyIndex)
0701         return false;
0702 
0703     m_newLabel = setSpecialKeyLabelCommand->m_newLabel;
0704     return true;
0705 }
0706 
0707 SetSpecialKeyModifierIdCommand::SetSpecialKeyModifierIdCommand(KeyboardLayout* layout, int keyIndex, const QString& newModifiewId, QUndoCommand* parent) :
0708     QUndoCommand(parent),
0709     m_layout(layout),
0710     m_keyIndex(keyIndex),
0711     m_newModifierId(newModifiewId)
0712 {
0713     setText(i18n("Set special key modifier ID"));
0714 
0715     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0716     m_oldModifierId = key->modifierId();
0717 }
0718 
0719 void SetSpecialKeyModifierIdCommand::undo()
0720 {
0721     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0722     key->setModifierId(m_oldModifierId);
0723 }
0724 
0725 void SetSpecialKeyModifierIdCommand::redo()
0726 {
0727     SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
0728     key->setModifierId(m_newModifierId);
0729 }
0730 
0731 int SetSpecialKeyModifierIdCommand::id() const
0732 {
0733     return 0xafabebaf;
0734 }
0735 
0736 bool SetSpecialKeyModifierIdCommand::mergeWith(const QUndoCommand* other)
0737 {
0738     const SetSpecialKeyModifierIdCommand* setSpecialKeyModifierIdCommand = static_cast<const SetSpecialKeyModifierIdCommand*>(other);
0739 
0740     if (m_layout != setSpecialKeyModifierIdCommand->m_layout)
0741         return false;
0742 
0743     if (m_keyIndex != setSpecialKeyModifierIdCommand->m_keyIndex)
0744         return false;
0745 
0746     m_newModifierId = setSpecialKeyModifierIdCommand->m_newModifierId;
0747     return true;
0748 }