21
21
#ifndef KFORMULACOMMAND_H
22
22
#define KFORMULACOMMAND_H
26
#include <qvaluevector.h>
26
28
#include <kcommand.h>
30
#include "fontstyle.h"
29
31
#include "kformulacontainer.h"
30
32
#include "formulacursor.h"
32
34
KFORMULA_NAMESPACE_BEGIN
35
38
* Base for all kformula commands.
56
59
* you can use the @ref KMacroCommand .
58
61
* @param name a description to be used as menu entry.
59
* @param document the container we are working for.
61
KFormulaCommand(const QString& name, KFormulaContainer* document);
62
virtual ~KFormulaCommand();
65
* Executes the command using the KFormulaContainer's active
68
virtual void execute() = 0;
71
* Undoes the command using the KFormulaContainer's active
74
virtual void unexecute() = 0;
77
* A command might have no effect.
78
* @returns true if nothing happened.
80
virtual bool isSenseless() { return false; }
63
PlainCommand(const QString& name);
64
virtual ~PlainCommand();
85
69
static int getEvilDestructionCount() { return evilDestructionCount; }
74
static int evilDestructionCount;
78
class Command : public PlainCommand
83
* Sets up the command. Be careful not to change the cursor in
84
* the constructor of any command. Each command must use the selection
85
* it finds when it is executed for the first time. This way
86
* you can use the @ref KMacroCommand .
88
* @param name a description to be used as menu entry.
89
* @param document the container we are working for.
91
Command(const QString& name, Container* document);
110
117
* @returns the cursor that is active. It will be used to @ref execute
113
FormulaCursor* getActiveCursor() { return doc->getActiveCursor(); }
120
FormulaCursor* getActiveCursor() { return doc->activeCursor(); }
116
123
* Tells the document to check if the formula changed.
146
153
* The container we belong to.
148
KFormulaContainer* doc;
151
static int evilDestructionCount;
156
160
* Base for all commands that want to add a simple element.
158
class KFCAdd : public KFormulaCommand
162
class KFCAdd : public Command
162
KFCAdd(const QString &name, KFormulaContainer* document);
166
KFCAdd(const QString &name, Container* document);
164
168
virtual void execute();
165
169
virtual void unexecute();
183
187
* Command that is used to remove the current selection
184
188
* if we want to replace it with another element.
186
class KFCRemoveSelection : public KFormulaCommand
190
class KFCRemoveSelection : public Command
191
195
* generic add command, default implementation do nothing
193
KFCRemoveSelection(KFormulaContainer* document,
194
BasicElement::Direction dir = BasicElement::beforeCursor);
197
KFCRemoveSelection(Container* document,
198
Direction dir = beforeCursor);
196
200
virtual void execute();
197
201
virtual void unexecute();
202
206
* the list where all elements are stored that are removed
205
QList<BasicElement> removedList;
209
QPtrList<BasicElement> removedList;
207
BasicElement::Direction dir;
212
* Removes the current selection and adds the any new elements
216
* Removes the current selection and adds any new elements
215
219
class KFCReplace : public KFCAdd
219
KFCReplace(const QString &name, KFormulaContainer* document);
223
KFCReplace(const QString &name, Container* document);
222
226
virtual void execute();
235
239
* Command that is used to remove the currently
236
240
* selected element.
238
class KFCRemove : public KFormulaCommand
242
class KFCRemove : public Command
243
247
* generic add command, default implementation do nothing
245
KFCRemove(KFormulaContainer* document, BasicElement::Direction dir);
249
KFCRemove(Container* document, Direction dir);
248
252
virtual void execute();
275
279
FormulaCursor::CursorData* simpleRemoveCursor;
277
BasicElement::Direction dir;
282
286
* Command to remove the parent element.
284
class KFCRemoveEnclosing : public KFormulaCommand
288
class KFCRemoveEnclosing : public Command
287
KFCRemoveEnclosing(KFormulaContainer* document, BasicElement::Direction dir);
291
KFCRemoveEnclosing(Container* document, Direction dir);
288
292
~KFCRemoveEnclosing();
290
294
virtual void execute();
291
295
virtual void unexecute();
293
virtual bool isSenseless() { return element == 0; }
296
298
BasicElement* element;
298
BasicElement::Direction direction;
303
305
* The command that takes the main child out of the selected
304
306
* element and replaces the element with it.
306
class KFCAddReplacing : public KFormulaCommand
308
class KFCAddReplacing : public Command
309
KFCAddReplacing(const QString &name, KFormulaContainer* document);
311
KFCAddReplacing(const QString &name, Container* document);
310
312
~KFCAddReplacing();
312
314
virtual void execute();
359
361
KFCAddGenericIndex addIndex;
365
class FormulaElement;
367
class KFCChangeBaseSize : public PlainCommand {
369
KFCChangeBaseSize( const QString& name, Container* document, FormulaElement* formula, int size );
375
Container* m_document;
376
FormulaElement* m_formula;
383
* Base for all font commands that act on the current selection.
384
* Implements the visitor pattern. (Really?)
386
class FontCommand : public Command {
388
FontCommand( const QString& name, Container* document );
391
* Collects all elements that are to be modified.
393
void addTextElement( TextElement* element ) { list.append(element); }
396
* Collects all parent elements those children are to be changend.
398
void addElement( BasicElement* element ) { elementList.append( element ); }
402
QPtrList<TextElement>& childrenList() { return list; }
404
void collectChildren();
406
void parseSequences( const QMap<SequenceElement*, int>& parents );
411
* the list where all elements are stored that are removed
414
QPtrList<TextElement> list;
416
QPtrList<BasicElement> elementList;
421
* Changes the char style of a number of elements an their children.
423
class CharStyleCommand : public FontCommand {
425
CharStyleCommand( CharStyle cs, const QString& name, Container* document );
427
virtual void execute();
428
virtual void unexecute();
432
typedef QValueVector<CharStyle> StyleList;
440
* Changes the char family of a number of elements an their children.
442
class CharFamilyCommand : public FontCommand {
444
CharFamilyCommand( CharFamily cf, const QString& name, Container* document );
446
virtual void execute();
447
virtual void unexecute();
451
typedef QValueVector<CharFamily> FamilyList;
453
FamilyList familyList;
454
CharFamily charFamily;
362
458
KFORMULA_NAMESPACE_END
364
460
#endif // KFORMULACOMMAND_H