MuseScore  3.4
Music composition and notation
textedit.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2014 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __TEXTEDIT_H__
14 #define __TEXTEDIT_H__
15 
16 #include "element.h"
17 #include "text.h"
18 #include "undo.h"
19 
20 namespace Ms {
21 
22 //---------------------------------------------------------
23 // TextEditData
24 //---------------------------------------------------------
25 
26 struct TextEditData : public ElementEditData {
27  QString oldXmlText;
29 
31 
32  TextEditData(TextBase* t) : cursor(t) {}
34  };
35 
36 //---------------------------------------------------------
37 // ChangeText
38 //---------------------------------------------------------
39 
40 class ChangeText : public UndoCommand {
42  QString s;
43 
44  protected:
45  void insertText(EditData*);
46  void removeText(EditData*);
47 
48  public:
49  ChangeText(const TextCursor* tc, const QString& t) : c(*tc), s(t) {}
50  virtual void undo(EditData*) override = 0;
51  virtual void redo(EditData*) override = 0;
52  const TextCursor& cursor() const { return c; }
53  const QString& string() const { return s; }
54  };
55 
56 //---------------------------------------------------------
57 // InsertText
58 //---------------------------------------------------------
59 
60 class InsertText : public ChangeText {
61 
62  public:
63  InsertText(const TextCursor* tc, const QString& t) : ChangeText(tc, t) {}
64  virtual void redo(EditData* ed) override { insertText(ed); }
65  virtual void undo(EditData* ed) override { removeText(ed); }
66  UNDO_NAME("InsertText")
67  };
68 
69 //---------------------------------------------------------
70 // RemoveText
71 //---------------------------------------------------------
72 
73 class RemoveText : public ChangeText {
74 
75  public:
76  RemoveText(const TextCursor* tc, const QString& t) : ChangeText(tc, t) {}
77  virtual void redo(EditData* ed) override { removeText(ed); }
78  virtual void undo(EditData* ed) override { insertText(ed); }
79  UNDO_NAME("InsertText")
80  };
81 
82 //---------------------------------------------------------
83 // SplitJoinText
84 //---------------------------------------------------------
85 
86 class SplitJoinText : public UndoCommand {
87  protected:
89  virtual void split(EditData*);
90  virtual void join(EditData*);
91 
92  public:
93  SplitJoinText(const TextCursor* tc) : c(*tc) {}
94  };
95 
96 //---------------------------------------------------------
97 // SplitText
98 //---------------------------------------------------------
99 
100 class SplitText : public SplitJoinText {
101 
102  virtual void undo(EditData* data) override { join(data); }
103  virtual void redo(EditData* data) override { split(data); }
104 
105  public:
106  SplitText(const TextCursor* tc) : SplitJoinText(tc) {}
107  UNDO_NAME("SplitText");
108  };
109 
110 //---------------------------------------------------------
111 // JoinText
112 //---------------------------------------------------------
113 
114 class JoinText : public SplitJoinText {
115 
116  virtual void undo(EditData* data) override { split(data); }
117  virtual void redo(EditData* data) override { join(data); }
118 
119  public:
120  JoinText(const TextCursor* tc) : SplitJoinText(tc) {}
121  UNDO_NAME("JoinText");
122  };
123 
124 
125 } // namespace Ms
126 
127 #endif
128 
129 
virtual void undo(EditData *ed) override
Definition: textedit.h:65
Definition: textedit.h:73
~TextEditData()
Definition: textedit.h:33
Definition of undo-releated classes and structs.
Definition: textbase.h:102
Definition: textedit.h:60
virtual void redo(EditData *data) override
Definition: textedit.h:103
Definition: textedit.h:26
Definition: element.h:504
TextCursor cursor
Definition: textedit.h:30
TextCursor c
Definition: textedit.h:88
Definition: textedit.h:86
virtual void undo(EditData *data) override
Definition: textedit.h:116
virtual void undo(EditData *ed) override
Definition: textedit.h:78
TextCursor c
Definition: textedit.h:41
virtual void redo(EditData *ed) override
Definition: textedit.h:64
int startUndoIdx
Definition: textedit.h:28
RemoveText(const TextCursor *tc, const QString &t)
Definition: textedit.h:76
const QString & string() const
Definition: textedit.h:53
QString oldXmlText
Definition: textedit.h:27
SplitText(const TextCursor *tc)
Definition: textedit.h:106
Definition: textbase.h:217
#define UNDO_NAME(a)
Definition: undo.h:88
SplitJoinText(const TextCursor *tc)
Definition: textedit.h:93
ChangeText(const TextCursor *tc, const QString &t)
Definition: textedit.h:49
Definition: aeolus.cpp:26
QString s
Definition: textedit.h:42
Definition: textedit.h:114
const TextCursor & cursor() const
Definition: textedit.h:52
Definition: textedit.h:100
Definition: element.h:111
Definition: textedit.h:40
virtual void redo(EditData *ed) override
Definition: textedit.h:77
InsertText(const TextCursor *tc, const QString &t)
Definition: textedit.h:63
TextEditData(TextBase *t)
Definition: textedit.h:32
JoinText(const TextCursor *tc)
Definition: textedit.h:120
virtual void undo(EditData *data) override
Definition: textedit.h:102
virtual void redo(EditData *data) override
Definition: textedit.h:117
Definition: undo.h:96