Debian Codegraph @

BambooTracker/gui/command/pattern/pattern_editor_common_qt_command.hpp

raw
1 /*
2 * Copyright (C) 2020 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #ifndef PATTERN_EDITOR_COMMON_QT_COMMAND_HPP
27 #define PATTERN_EDITOR_COMMON_QT_COMMAND_HPP
28
29 #include <QUndoCommand>
30 #include "command/command_id.hpp"
31 #include "gui/pattern_editor/pattern_position.hpp"
32
33 class PatternEditorPanel;
34
35 namespace gui_command_impl
36 {
37 class PatternEditorCommonQtCommand : public QUndoCommand
38 {
39 public:
40 virtual void redo() override;
41 virtual void undo() override;
42 int id() const override final;
43
44 protected:
45 PatternEditorPanel* panel_;
46 PatternEditorCommonQtCommand(CommandId id, PatternEditorPanel* panel,
47 bool redrawAll, QUndoCommand* parent);
48
49 private:
50 CommandId id_;
51 bool redrawAll_;
52 };
53
54 template<CommandId comId, bool redrawAll>
55 class PatternEditorCommonQtCommandRedraw final : public PatternEditorCommonQtCommand
56 {
57 public:
58 PatternEditorCommonQtCommandRedraw(PatternEditorPanel* panel, QUndoCommand* parent = nullptr)
59 : PatternEditorCommonQtCommand(comId, panel, redrawAll, parent) {}
60 };
61
62 template<CommandId id>
63 using PatternEditorCommonQtCommandRedrawAll = PatternEditorCommonQtCommandRedraw<id, true>;
64
65 template<CommandId id>
66 using PatternEditorCommonQtCommandRedrawText = PatternEditorCommonQtCommandRedraw<id, false>;
67
68 class PatternEditorEntryQtCommand : public PatternEditorCommonQtCommand
69 {
70 public:
71 void undo() override;
72 bool mergeWith(const QUndoCommand* other) override;
73
74 protected:
75 PatternEditorEntryQtCommand(CommandId id, PatternEditorPanel* panel, bool redrawAll,
76 const PatternPosition& pos, bool secondEntry, QUndoCommand* parent);
77
78 private:
79 const PatternPosition pos_;
80 bool isSecondEntry_;
81 };
82
83 template<CommandId comId, bool redrawAll>
84 class PatternEditorEntryQtCommandRedraw final : public PatternEditorEntryQtCommand
85 {
86 public:
87 PatternEditorEntryQtCommandRedraw(PatternEditorPanel* panel, const PatternPosition& pos,
88 bool secondEntry, QUndoCommand* parent = nullptr)
89 : PatternEditorEntryQtCommand(comId, panel, redrawAll, pos, secondEntry, parent) {}
90 };
91
92 template<CommandId id>
93 using PatternEditorEntryQtCommandRedrawAll = PatternEditorEntryQtCommandRedraw<id, true>;
94
95 template<CommandId id>
96 using PatternEditorEntryQtCommandRedrawText = PatternEditorEntryQtCommandRedraw<id, false>;
97 }
98
99 #endif // PATTERN_EDITOR_COMMON_QT_COMMAND_HPP