File indexing completed on 2025-03-16 13:13:02
0001 /******************************************************************************** 0002 * Copyright (C) 2011-2015 by Stephen Allewell * 0003 * steve.allewell@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ********************************************************************************/ 0010 0011 0012 /** 0013 * @file 0014 * Header file for the QUndoCommand derived classes. 0015 */ 0016 0017 0018 #ifndef Commands_H 0019 #define Commands_H 0020 0021 0022 #include <QUndoCommand> 0023 #include <QWidget> 0024 0025 #include "SymbolLibrary.h" 0026 0027 0028 class QMimeData; 0029 0030 class Editor; 0031 0032 0033 /** 0034 * @brief Move to command class. 0035 * 0036 * Implement a move to operation on the QPainterPath for the current symbol. 0037 * If this is the first operation it updates the start position of the path, otherwise 0038 * it ends the current sub path and starts a new sub path at the specified point. 0039 * 0040 * The original path is stored for a possible undo. 0041 */ 0042 class MoveToCommand : public QUndoCommand 0043 { 0044 public: 0045 MoveToCommand(Editor *editor, const QPointF &to); 0046 virtual ~MoveToCommand(); 0047 0048 virtual void undo(); 0049 virtual void redo(); 0050 0051 private: 0052 Editor *m_editor; /**< pointer to the editor */ 0053 QPointF m_to; /**< point to move to */ 0054 QPainterPath m_path; /**< original path to be restored on undo */ 0055 }; 0056 0057 0058 /** 0059 * @brief Line to command class. 0060 * 0061 * Implement a line to operation on the QPainterPath for the current symbol. 0062 * The line is added to the current sub path. 0063 * 0064 * The original path is stored for a possible undo. 0065 */ 0066 class LineToCommand : public QUndoCommand 0067 { 0068 public: 0069 LineToCommand(Editor *editor, const QPointF &to); 0070 virtual ~LineToCommand(); 0071 0072 virtual void undo(); 0073 virtual void redo(); 0074 0075 private: 0076 Editor *m_editor; /**< pointer to the editor */ 0077 QPointF m_to; /**< point to draw to */ 0078 QPainterPath m_path; /**< original path to be restored on undo */ 0079 }; 0080 0081 0082 /** 0083 * @brief Cubic to command class. 0084 * 0085 * Implement a cubic to operation on the QPainterPath for the current symbol. 0086 * The cubic is added to the current sub path. 0087 * 0088 * The original path is stored for a possible undo. 0089 */ 0090 class CubicToCommand : public QUndoCommand 0091 { 0092 public: 0093 CubicToCommand(Editor *editor, const QPointF &control1, const QPointF &control2, const QPointF &to); 0094 virtual ~CubicToCommand(); 0095 0096 virtual void undo(); 0097 virtual void redo(); 0098 0099 private: 0100 Editor *m_editor; /**< pointer to the editor */ 0101 QPointF m_control1; /**< first control point */ 0102 QPointF m_control2; /**< second control point */ 0103 QPointF m_to; /**< end point */ 0104 QPainterPath m_path; /**< original path to be restored on undo */ 0105 }; 0106 0107 0108 /** 0109 * @brief Rectangle command class. 0110 * 0111 * Implement a rectangle operation on the QPainterPath for the current symbol. 0112 * The current sub path is closed and the rectangle is added as a new sub path as a 0113 * series of line to operations. 0114 * 0115 * The original path is stored for a possible undo. 0116 */ 0117 class RectangleCommand : public QUndoCommand 0118 { 0119 public: 0120 RectangleCommand(Editor *editor, const QPointF &from, const QPointF &to); 0121 virtual ~RectangleCommand(); 0122 0123 virtual void undo(); 0124 virtual void redo(); 0125 0126 private: 0127 Editor *m_editor; /**< pointer to the editor */ 0128 QPointF m_from; /**< first corner */ 0129 QPointF m_to; /**< second corner */ 0130 QPainterPath m_path; /**< original path to be restored on undo */ 0131 }; 0132 0133 0134 /** 0135 * @brief Ellipse command class. 0136 * 0137 * Implement an ellipse operation on the QPainterPath for the current symbol. 0138 * The current sub path is closed and the ellipse is added as a new sub path as a 0139 * series of cubic to operations. 0140 * 0141 * The original path is stored for a possible undo. 0142 */ 0143 class EllipseCommand : public QUndoCommand 0144 { 0145 public: 0146 EllipseCommand(Editor *editor, const QPointF &from, const QPointF &to); 0147 virtual ~EllipseCommand(); 0148 0149 virtual void undo(); 0150 virtual void redo(); 0151 0152 private: 0153 Editor *m_editor; /**< pointer to the editor */ 0154 QPointF m_from; /**< first corner */ 0155 QPointF m_to; /**< second corner */ 0156 QPainterPath m_path; /**< original path to be restored on undo */ 0157 }; 0158 0159 0160 /** 0161 * @brief Move point command class. 0162 * 0163 * Implement moving a control point in the m_points list from one position to 0164 * another. The Editor QPainterPath needs to be reconstructed with the moved position. 0165 * 0166 * The original position is stored for a possible undo. 0167 */ 0168 class MovePointCommand : public QUndoCommand 0169 { 0170 public: 0171 MovePointCommand(Editor *editor, int index, const QPointF &from, const QPointF &to); 0172 virtual ~MovePointCommand(); 0173 0174 virtual void undo(); 0175 virtual void redo(); 0176 0177 private: 0178 Editor *m_editor; /**< pointer to the editor */ 0179 int m_index; /**< index of the point in m_editor->m_points */ 0180 QPointF m_from; /**< original position */ 0181 QPointF m_to; /**< destination position */ 0182 }; 0183 0184 0185 /** 0186 * @brief Update symbol command class; 0187 * 0188 * Implement updating a symbol in the library using the index specified. The index may 0189 * be 0 for new symbols and a new index will be generated by the library. 0190 * 0191 * The original Symbol is stored for a possible undo. 0192 */ 0193 class UpdateSymbolCommand : public QUndoCommand 0194 { 0195 public: 0196 UpdateSymbolCommand(SymbolLibrary *library, qint16 index, const Symbol &symbol); 0197 virtual ~UpdateSymbolCommand(); 0198 0199 virtual void undo(); 0200 virtual void redo(); 0201 0202 private: 0203 SymbolLibrary *m_symbolLibrary; /**< pointer to the symbol library */ 0204 qint16 m_index; /**< index of the symbol in the library */ 0205 Symbol m_symbol; /**< the updated symbol */ 0206 Symbol m_originalSymbol; /**< original symbol to be restored on undo */ 0207 }; 0208 0209 0210 /** 0211 * @brief Import library command class. 0212 * 0213 * Implement importing the symbols from one library into the current library. The indexes 0214 * from the import library are ignored and new indexes are generated by the current library. 0215 * 0216 * The list of generated indexes is stored for a possible undo. 0217 */ 0218 class ImportLibraryCommand : public QUndoCommand 0219 { 0220 public: 0221 ImportLibraryCommand(SymbolLibrary *library, SymbolLibrary *imported); 0222 virtual ~ImportLibraryCommand(); 0223 0224 virtual void undo(); 0225 virtual void redo(); 0226 0227 private: 0228 SymbolLibrary *m_symbolLibrary; /**< pointer to the symbol library */ 0229 SymbolLibrary *m_imported; /**< pointer to the imported library */ 0230 QList<qint16> m_addedIndexes; /**< indexes of the symbols imported to be removed on undo */ 0231 }; 0232 0233 0234 /** 0235 * @brief Rotate left command class. 0236 * 0237 * Implement the rotation of the QPainterPath for the current symbol left (counter clockwise). 0238 * 0239 * Nothing is stored for undo as this is implemented as a rotate right. 0240 */ 0241 class RotateLeftCommand : public QUndoCommand 0242 { 0243 public: 0244 explicit RotateLeftCommand(Editor *editor); 0245 ~RotateLeftCommand(); 0246 0247 virtual void undo(); 0248 virtual void redo(); 0249 0250 private: 0251 Editor *m_editor; /**< pointer to the editor */ 0252 }; 0253 0254 0255 /** 0256 * @brief Rotate right command class. 0257 * 0258 * Implement the rotation of the QPainterPath for the current symbol right (clockwise). 0259 * 0260 * Nothing is stored for undo as this is implemented as a rotate left. 0261 */ 0262 class RotateRightCommand : public QUndoCommand 0263 { 0264 public: 0265 explicit RotateRightCommand(Editor *editor); 0266 ~RotateRightCommand(); 0267 0268 virtual void undo(); 0269 virtual void redo(); 0270 0271 private: 0272 Editor *m_editor; /**< pointer to the editor */ 0273 }; 0274 0275 0276 /** 0277 * @brief Flip horizontal command class. 0278 * 0279 * Implement the flipping of the QPainterPath for the current symbol horizontally about 0280 * the vertical axis passing through the center line of the symbol. 0281 * 0282 * Nothing is stored for undo as this implemented by another flip horizontal. 0283 */ 0284 class FlipHorizontalCommand : public QUndoCommand 0285 { 0286 public: 0287 explicit FlipHorizontalCommand(Editor *editor); 0288 ~FlipHorizontalCommand(); 0289 0290 virtual void undo(); 0291 virtual void redo(); 0292 0293 private: 0294 Editor *m_editor; /**< pointer to the editor */ 0295 }; 0296 0297 0298 /** 0299 * @brief Flip vertical command class. 0300 * 0301 * Implement the flipping of the QPainterPath for the current symbol vertically about 0302 * the horizontal axis passing through the center line of the symbol. 0303 * 0304 * Nothing is stored for undo as this is implemented by another flip vertical. 0305 */ 0306 class FlipVerticalCommand : public QUndoCommand 0307 { 0308 public: 0309 explicit FlipVerticalCommand(Editor *editor); 0310 ~FlipVerticalCommand(); 0311 0312 virtual void undo(); 0313 virtual void redo(); 0314 0315 private: 0316 Editor *m_editor; /**< pointer to the editor */ 0317 }; 0318 0319 0320 /** 0321 * @brief Scale to preferred size class. 0322 * 0323 * Implement scaling of the current symbol so that it fits within the preferred size rectangle. 0324 * No changes are made to symbols that are already inside it. 0325 */ 0326 class ScalePreferredCommand : public QUndoCommand 0327 { 0328 public: 0329 ScalePreferredCommand(Editor *editor, const QPainterPath &originlSymbol, int gridElements, int borderSize); 0330 ~ScalePreferredCommand(); 0331 0332 virtual void undo(); 0333 virtual void redo(); 0334 0335 private: 0336 Editor *m_editor; /**< pointer to the editor */ 0337 QPainterPath m_originalSymbol; /**< original symbol path used for undo */ 0338 int m_gridElements; /**< the number of elements in a grid side */ 0339 int m_borderSize; /**< the number of elements in a border */ 0340 }; 0341 0342 0343 /** 0344 * @brief Change the fill state command class. 0345 * 0346 * Implement changing the fill state of the current symbol. 0347 * 0348 * The original state is stored for a possible undo. 0349 */ 0350 class ChangeFilledCommand : public QUndoCommand 0351 { 0352 public: 0353 ChangeFilledCommand(Editor *editor, bool from, bool to); 0354 virtual ~ChangeFilledCommand(); 0355 0356 virtual void undo(); 0357 virtual void redo(); 0358 0359 private: 0360 Editor *m_editor; /**< pointer to the editor */ 0361 bool m_from; /**< original setting */ 0362 bool m_to; /**< new setting */ 0363 }; 0364 0365 0366 /** 0367 * @brief Change the fill rule command class. 0368 * 0369 * Implement changing the fill rule of the QPainterPath for the current symbol. 0370 * 0371 * The original fill rule is stored for a possible undo. 0372 */ 0373 class ChangeFillRuleCommand : public QUndoCommand 0374 { 0375 public: 0376 ChangeFillRuleCommand(Editor *editor, Qt::FillRule from, Qt::FillRule to); 0377 virtual ~ChangeFillRuleCommand(); 0378 0379 virtual void undo(); 0380 virtual void redo(); 0381 0382 private: 0383 Editor *m_editor; /**< pointer to the Editor */ 0384 Qt::FillRule m_from; /**< original setting */ 0385 Qt::FillRule m_to; /**< new setting */ 0386 }; 0387 0388 0389 /** 0390 * @brief Change the pen cap style command. 0391 * 0392 * Implement changing the line cap style for the current symbol. 0393 * 0394 * The original style is stored for a possible undo. 0395 */ 0396 class ChangeCapStyleCommand : public QUndoCommand 0397 { 0398 public: 0399 ChangeCapStyleCommand(Editor *editor, Qt::PenCapStyle from, Qt::PenCapStyle to); 0400 virtual ~ChangeCapStyleCommand(); 0401 0402 virtual void undo(); 0403 virtual void redo(); 0404 0405 private: 0406 Editor *m_editor; /**< pointer to the Editor */ 0407 Qt::PenCapStyle m_from; /**< original setting */ 0408 Qt::PenCapStyle m_to; /**< new setting */ 0409 }; 0410 0411 0412 /** 0413 * @brief Change the pen join style command. 0414 * 0415 * Implement changing the line join style for the current symbol. 0416 * 0417 * The original style is stored for a possible undo. 0418 */ 0419 class ChangeJoinStyleCommand : public QUndoCommand 0420 { 0421 public: 0422 ChangeJoinStyleCommand(Editor *editor, Qt::PenJoinStyle from, Qt::PenJoinStyle to); 0423 virtual ~ChangeJoinStyleCommand(); 0424 0425 virtual void undo(); 0426 virtual void redo(); 0427 0428 private: 0429 Editor *m_editor; /**< pointer to the Editor */ 0430 Qt::PenJoinStyle m_from; /**< original setting */ 0431 Qt::PenJoinStyle m_to; /**< new setting */ 0432 }; 0433 0434 0435 /** 0436 * @brief Delete a symbol from the library command. 0437 * 0438 * Implement deleting a symbol from the library using the index specified. 0439 * 0440 * The index and the symbol removed are stored for a possible undo. 0441 */ 0442 class DeleteSymbolCommand : public QUndoCommand 0443 { 0444 public: 0445 DeleteSymbolCommand(SymbolLibrary *library, qint16 index); 0446 virtual ~DeleteSymbolCommand(); 0447 0448 virtual void undo(); 0449 virtual void redo(); 0450 0451 private: 0452 SymbolLibrary *m_symbolLibrary; /**< pointer to the SymbolLibrary */ 0453 qint16 m_index; /**< index of the symbol */ 0454 Symbol m_symbol; /**< the symbol deleted, stored for undo */ 0455 }; 0456 0457 0458 /** 0459 * @brief Increase the line width of the path. 0460 * 0461 * Implement increasing the line width for the current symbol. Multiple increases 0462 * of the width are merged together to allow for a single undo or redo operation. 0463 * 0464 * The original width is stored for a possible undo. 0465 */ 0466 class IncreaseLineWidthCommand : public QUndoCommand 0467 { 0468 public: 0469 IncreaseLineWidthCommand(Editor *editor, qreal from, qreal to); 0470 virtual ~IncreaseLineWidthCommand(); 0471 0472 virtual void redo(); 0473 virtual void undo(); 0474 0475 virtual int id() const; 0476 virtual bool mergeWith(const QUndoCommand *command); 0477 0478 private: 0479 Editor *m_editor; /**< pointer to the Editor */ 0480 qreal m_from; /**< the original setting */ 0481 qreal m_to; /**< the new setting, this may be changed by merging commands */ 0482 }; 0483 0484 0485 /** 0486 * @brief Decrease the line width of the path. 0487 * 0488 * Implement decreasing the line width for the current symbol. Multiple decreases 0489 * of the width are merged together to allow for a single undo or redo operation. 0490 * 0491 * The original width is stored for a possible undo. 0492 */ 0493 class DecreaseLineWidthCommand : public QUndoCommand 0494 { 0495 public: 0496 DecreaseLineWidthCommand(Editor *editor, qreal from, qreal to); 0497 virtual ~DecreaseLineWidthCommand(); 0498 0499 virtual void redo(); 0500 virtual void undo(); 0501 0502 virtual int id() const; 0503 virtual bool mergeWith(const QUndoCommand *command); 0504 0505 private: 0506 Editor *m_editor; /**< pointer to the Editor */ 0507 qreal m_from; /**< the original setting */ 0508 qreal m_to; /**< the new setting, this may be changed by merging commands */ 0509 }; 0510 0511 0512 /** 0513 * @brief Add new symbols dragged from another instance of the SymbolEditor. 0514 * 0515 * Allows copying of symbols from one symbol library to another using drag and drop. 0516 */ 0517 class DragAndDropCommand : public QUndoCommand 0518 { 0519 public: 0520 DragAndDropCommand(SymbolLibrary *library, const QMimeData *mimeData); 0521 0522 virtual void redo(); 0523 virtual void undo(); 0524 0525 private: 0526 SymbolLibrary *m_library; 0527 QList<Symbol> m_symbols; 0528 QList<qint16> m_indexes; 0529 }; 0530 0531 0532 /** 0533 * @brief Add a fonted character as a symbol. 0534 * 0535 * Allows a character to be added after selection from the KCharSelect dialog. 0536 */ 0537 class AddCharacterCommand : public QUndoCommand 0538 { 0539 public: 0540 AddCharacterCommand(Editor *editor, const QPainterPath &path); 0541 0542 virtual void redo(); 0543 virtual void undo(); 0544 0545 private: 0546 Editor *m_editor; 0547 QPainterPath m_path; 0548 }; 0549 0550 0551 #endif 0552