File indexing completed on 2023-05-30 09:04:20
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Sebastian Gottfried <sebastiangottfried@web.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KEYBOARDLAYOUTCOMMANDS_H 0008 #define KEYBOARDLAYOUTCOMMANDS_H 0009 0010 #include <QUndoStack> 0011 #include <QRect> 0012 0013 #include "core/specialkey.h" 0014 #include "core/keychar.h" 0015 0016 class KeyboardLayout; 0017 0018 class SetKeyboardLayoutTitleCommand : public QUndoCommand 0019 { 0020 public: 0021 explicit SetKeyboardLayoutTitleCommand(KeyboardLayout* layout, const QString& newTitle, QUndoCommand* parent = nullptr); 0022 void undo() override; 0023 void redo() override; 0024 int id() const override; 0025 bool mergeWith(const QUndoCommand* other) override; 0026 private: 0027 KeyboardLayout* m_layout; 0028 QString m_oldTitle; 0029 QString m_newTitle; 0030 }; 0031 0032 class SetKeyboardLayoutNameCommand : public QUndoCommand 0033 { 0034 public: 0035 explicit SetKeyboardLayoutNameCommand(KeyboardLayout* layout, const QString& newName, QUndoCommand* parent = nullptr); 0036 void undo() override; 0037 void redo() override; 0038 int id() const override; 0039 bool mergeWith(const QUndoCommand* other) override; 0040 private: 0041 KeyboardLayout* m_layout; 0042 QString m_oldName; 0043 QString m_newName; 0044 }; 0045 0046 class SetKeyboardLayoutSizeCommand : public QUndoCommand 0047 { 0048 public: 0049 explicit SetKeyboardLayoutSizeCommand(KeyboardLayout* layout, const QSize& newSize, QUndoCommand* parent = nullptr); 0050 void undo() override; 0051 void redo() override; 0052 int id() const override; 0053 bool mergeWith(const QUndoCommand* other) override; 0054 private: 0055 KeyboardLayout* m_layout; 0056 QSize m_oldSize; 0057 QSize m_newSize; 0058 }; 0059 0060 class AddKeyCommand : public QUndoCommand 0061 { 0062 public: 0063 AddKeyCommand(KeyboardLayout* layout, AbstractKey* key, QUndoCommand* parent = nullptr); 0064 ~AddKeyCommand() override; 0065 void undo() override; 0066 void redo() override; 0067 int id() const override; 0068 bool mergeWith(const QUndoCommand* other) override; 0069 private: 0070 KeyboardLayout* m_layout; 0071 AbstractKey* m_backupKey; 0072 }; 0073 0074 class RemoveKeyCommand : public QUndoCommand 0075 { 0076 public: 0077 RemoveKeyCommand(KeyboardLayout* layout, int keyIndex, QUndoCommand* parent = nullptr); 0078 ~RemoveKeyCommand() override; 0079 void undo() override; 0080 void redo() override; 0081 int id() const override; 0082 bool mergeWith(const QUndoCommand* other) override; 0083 private: 0084 KeyboardLayout* m_layout; 0085 int m_keyIndex; 0086 AbstractKey* m_backupKey; 0087 }; 0088 0089 class SetKeyGeometryCommand : public QUndoCommand 0090 { 0091 public: 0092 explicit SetKeyGeometryCommand(KeyboardLayout* layout, int keyIndex, const QRect& newRect, QUndoCommand* parent = nullptr); 0093 void undo() override; 0094 void redo() override; 0095 int id() const override; 0096 bool mergeWith(const QUndoCommand* other) override; 0097 private: 0098 KeyboardLayout* m_layout; 0099 int m_keyIndex; 0100 QRect m_oldRect; 0101 QRect m_newRect; 0102 }; 0103 0104 class SetKeyFingerIndexCommand : public QUndoCommand 0105 { 0106 public: 0107 explicit SetKeyFingerIndexCommand(KeyboardLayout* layout, int keyIndex, int newFingerIndex, QUndoCommand* parent = nullptr); 0108 void undo() override; 0109 void redo() override; 0110 int id() const override; 0111 bool mergeWith(const QUndoCommand* other) override; 0112 private: 0113 KeyboardLayout* m_layout; 0114 int m_keyIndex; 0115 int m_oldFingerIndex; 0116 int m_newFingerIndex; 0117 }; 0118 0119 class SetKeyHasHapticMarkerCommand : public QUndoCommand 0120 { 0121 public: 0122 explicit SetKeyHasHapticMarkerCommand(KeyboardLayout* layout, int keyIndex, bool newHasHapticMarker, QUndoCommand* parent = nullptr); 0123 void undo() override; 0124 void redo() override; 0125 int id() const override; 0126 bool mergeWith(const QUndoCommand* other) override; 0127 private: 0128 KeyboardLayout* m_layout; 0129 int m_keyIndex; 0130 bool m_oldHasHapticMarker; 0131 bool m_newHasHapticMarker; 0132 }; 0133 0134 class AddKeyCharCommand : public QUndoCommand 0135 { 0136 public: 0137 AddKeyCharCommand(KeyboardLayout* layout, int keyIndex, QUndoCommand* parent = nullptr); 0138 void undo() override; 0139 void redo() override; 0140 int id() const override; 0141 bool mergeWith(const QUndoCommand* other) override; 0142 private: 0143 KeyboardLayout* m_layout; 0144 int m_keyIndex; 0145 }; 0146 0147 class RemoveKeyCharCommand : public QUndoCommand 0148 { 0149 public: 0150 RemoveKeyCharCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, QUndoCommand* parent = nullptr); 0151 ~RemoveKeyCharCommand() override; 0152 void undo() override; 0153 void redo() override; 0154 int id() const override; 0155 bool mergeWith(const QUndoCommand* other) override; 0156 private: 0157 KeyboardLayout* m_layout; 0158 int m_keyIndex; 0159 int m_keyCharIndex; 0160 KeyChar* m_backupKeyChar; 0161 }; 0162 0163 class SetKeyCharValueCommand : public QUndoCommand 0164 { 0165 public: 0166 explicit SetKeyCharValueCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, QChar newValue, QUndoCommand* parent = nullptr); 0167 void undo() override; 0168 void redo() override; 0169 int id() const override; 0170 bool mergeWith(const QUndoCommand* other) override; 0171 private: 0172 KeyboardLayout* m_layout; 0173 int m_keyIndex; 0174 int m_keyCharIndex; 0175 QChar m_oldValue; 0176 QChar m_newValue; 0177 }; 0178 0179 class SetKeyCharModifierCommand : public QUndoCommand 0180 { 0181 public: 0182 explicit SetKeyCharModifierCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, const QString& newModifier, QUndoCommand* parent = nullptr); 0183 void undo() override; 0184 void redo() override; 0185 int id() const override; 0186 bool mergeWith(const QUndoCommand* other) override; 0187 private: 0188 KeyboardLayout* m_layout; 0189 int m_keyIndex; 0190 int m_keyCharIndex; 0191 QString m_oldModifier; 0192 QString m_newModifier; 0193 }; 0194 0195 class SetKeyCharPositionCommand : public QUndoCommand 0196 { 0197 public: 0198 explicit SetKeyCharPositionCommand(KeyboardLayout* layout, int keyIndex, int keyCharIndex, KeyChar::Position newPosition, QUndoCommand* parent = nullptr); 0199 void undo() override; 0200 void redo() override; 0201 int id() const override; 0202 bool mergeWith(const QUndoCommand* other) override; 0203 private: 0204 KeyboardLayout* m_layout; 0205 int m_keyIndex; 0206 int m_keyCharIndex; 0207 KeyChar::Position m_oldPosition; 0208 KeyChar::Position m_newPosition; 0209 }; 0210 0211 class SetSpecialKeyTypeCommand : public QUndoCommand 0212 { 0213 public: 0214 explicit SetSpecialKeyTypeCommand(KeyboardLayout* layout, int keyIndex, SpecialKey::Type newType, QUndoCommand* parent = nullptr); 0215 void undo() override; 0216 void redo() override; 0217 int id() const override; 0218 bool mergeWith(const QUndoCommand* other) override; 0219 private: 0220 KeyboardLayout* m_layout; 0221 int m_keyIndex; 0222 SpecialKey::Type m_oldType; 0223 SpecialKey::Type m_newType; 0224 }; 0225 0226 class SetSpecialKeyLabelCommand : public QUndoCommand 0227 { 0228 public: 0229 explicit SetSpecialKeyLabelCommand(KeyboardLayout* layout, int keyIndex, const QString& newLabel, QUndoCommand* parent = nullptr); 0230 void undo() override; 0231 void redo() override; 0232 int id() const override; 0233 bool mergeWith(const QUndoCommand* other) override; 0234 private: 0235 KeyboardLayout* m_layout; 0236 int m_keyIndex; 0237 QString m_oldLabel; 0238 QString m_newLabel; 0239 }; 0240 0241 class SetSpecialKeyModifierIdCommand : public QUndoCommand 0242 { 0243 public: 0244 explicit SetSpecialKeyModifierIdCommand(KeyboardLayout* layout, int keyIndex, const QString& newModifiewId, QUndoCommand* parent = nullptr); 0245 void undo() override; 0246 void redo() override; 0247 int id() const override; 0248 bool mergeWith(const QUndoCommand* other) override; 0249 private: 0250 KeyboardLayout* m_layout; 0251 int m_keyIndex; 0252 QString m_oldModifierId; 0253 QString m_newModifierId; 0254 }; 0255 0256 #endif // KEYBOARDLAYOUTCOMMANDS_H