~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to lib/kformula/kformulacommand.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef KFORMULACOMMAND_H
22
22
#define KFORMULACOMMAND_H
23
23
 
24
 
#include <qlist.h>
 
24
#include <qmap.h>
 
25
#include <qptrlist.h>
 
26
#include <qvaluevector.h>
25
27
 
26
28
#include <kcommand.h>
27
29
 
28
 
#include "artwork.h"
 
30
#include "fontstyle.h"
29
31
#include "kformulacontainer.h"
30
32
#include "formulacursor.h"
31
33
 
32
34
KFORMULA_NAMESPACE_BEGIN
33
35
 
 
36
 
34
37
/**
35
38
 * Base for all kformula commands.
36
39
 *
45
48
 *
46
49
 * If you don't like what you've done feel free to @ref unexecute .
47
50
 */
48
 
class KFormulaCommand : public KCommand
 
51
class PlainCommand : public KNamedCommand
49
52
{
50
53
public:
51
54
 
56
59
     * you can use the @ref KMacroCommand .
57
60
     *
58
61
     * @param name a description to be used as menu entry.
59
 
     * @param document the container we are working for.
60
 
     */
61
 
    KFormulaCommand(const QString& name, KFormulaContainer* document);
62
 
    virtual ~KFormulaCommand();
63
 
 
64
 
    /**
65
 
     * Executes the command using the KFormulaContainer's active
66
 
     * cursor.
67
 
     */
68
 
    virtual void execute() = 0;
69
 
 
70
 
    /**
71
 
     * Undoes the command using the KFormulaContainer's active
72
 
     * cursor.
73
 
     */
74
 
    virtual void unexecute() = 0;
75
 
 
76
 
    /**
77
 
     * A command might have no effect.
78
 
     * @returns true if nothing happened.
79
 
     */
80
 
    virtual bool isSenseless() { return false; }
 
62
     */
 
63
    PlainCommand(const QString& name);
 
64
    virtual ~PlainCommand();
81
65
 
82
66
    /**
83
67
     * debug only.
84
68
     */
85
69
    static int getEvilDestructionCount() { return evilDestructionCount; }
86
70
 
 
71
private:
 
72
 
 
73
    // debug
 
74
    static int evilDestructionCount;
 
75
};
 
76
 
 
77
 
 
78
class Command : public PlainCommand
 
79
{
 
80
public:
 
81
 
 
82
    /**
 
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 .
 
87
     *
 
88
     * @param name a description to be used as menu entry.
 
89
     * @param document the container we are working for.
 
90
     */
 
91
    Command(const QString& name, Container* document);
 
92
    virtual ~Command();
 
93
 
87
94
protected:
88
95
 
89
96
    /**
110
117
     * @returns the cursor that is active. It will be used to @ref execute
111
118
     * the command.
112
119
     */
113
 
    FormulaCursor* getActiveCursor() { return doc->getActiveCursor(); }
 
120
    FormulaCursor* getActiveCursor() { return doc->activeCursor(); }
114
121
 
115
122
    /**
116
123
     * Tells the document to check if the formula changed.
121
128
    /**
122
129
     * @returns our document.
123
130
     */
124
 
    KFormulaContainer* getDocument() const { return doc; }
 
131
    Container* getDocument() const { return doc; }
125
132
 
126
133
private:
127
134
 
145
152
    /**
146
153
     * The container we belong to.
147
154
     */
148
 
    KFormulaContainer* doc;
149
 
 
150
 
    // debug
151
 
    static int evilDestructionCount;
 
155
    Container* doc;
152
156
};
153
157
 
154
158
 
155
159
/**
156
160
 * Base for all commands that want to add a simple element.
157
161
 */
158
 
class KFCAdd : public KFormulaCommand
 
162
class KFCAdd : public Command
159
163
{
160
164
public:
161
165
 
162
 
    KFCAdd(const QString &name, KFormulaContainer* document);
 
166
    KFCAdd(const QString &name, Container* document);
163
167
 
164
168
    virtual void execute();
165
169
    virtual void unexecute();
175
179
     * the list where all elements are stored that are removed
176
180
     * from the tree.
177
181
     */
178
 
    QList<BasicElement> addList;
 
182
    QPtrList<BasicElement> addList;
179
183
};
180
184
 
181
185
 
183
187
 * Command that is used to remove the current selection
184
188
 * if we want to replace it with another element.
185
189
 */
186
 
class KFCRemoveSelection : public KFormulaCommand
 
190
class KFCRemoveSelection : public Command
187
191
{
188
192
public:
189
193
 
190
194
    /**
191
195
     * generic add command, default implementation do nothing
192
196
     */
193
 
    KFCRemoveSelection(KFormulaContainer* document,
194
 
                       BasicElement::Direction dir = BasicElement::beforeCursor);
 
197
    KFCRemoveSelection(Container* document,
 
198
                       Direction dir = beforeCursor);
195
199
 
196
200
    virtual void execute();
197
201
    virtual void unexecute();
202
206
     * the list where all elements are stored that are removed
203
207
     * from the tree.
204
208
     */
205
 
    QList<BasicElement> removedList;
 
209
    QPtrList<BasicElement> removedList;
206
210
 
207
 
    BasicElement::Direction dir;
 
211
    Direction dir;
208
212
};
209
213
 
210
214
 
211
215
/**
212
 
 * Removes the current selection and adds the any new elements
 
216
 * Removes the current selection and adds any new elements
213
217
 * afterwards.
214
218
 */
215
219
class KFCReplace : public KFCAdd
216
220
{
217
221
public:
218
222
 
219
 
    KFCReplace(const QString &name, KFormulaContainer* document);
 
223
    KFCReplace(const QString &name, Container* document);
220
224
    ~KFCReplace();
221
225
 
222
226
    virtual void execute();
235
239
 * Command that is used to remove the currently
236
240
 * selected element.
237
241
 */
238
 
class KFCRemove : public KFormulaCommand
 
242
class KFCRemove : public Command
239
243
{
240
244
public:
241
245
 
242
246
    /**
243
247
     * generic add command, default implementation do nothing
244
248
     */
245
 
    KFCRemove(KFormulaContainer* document, BasicElement::Direction dir);
 
249
    KFCRemove(Container* document, Direction dir);
246
250
    ~KFCRemove();
247
251
 
248
252
    virtual void execute();
252
256
     * A command might have no effect.
253
257
     * @returns true if nothing happened.
254
258
     */
255
 
    virtual bool isSenseless() { return removedList.isEmpty(); }
 
259
    //virtual bool isSenseless() { return removedList.isEmpty(); }
256
260
 
257
261
private:
258
262
 
260
264
     * the list where all elements are stored that are removed
261
265
     * from the tree.
262
266
     */
263
 
    QList<BasicElement> removedList;
 
267
    QPtrList<BasicElement> removedList;
264
268
 
265
269
    /**
266
270
     * The element we might have extracted.
274
278
     */
275
279
    FormulaCursor::CursorData* simpleRemoveCursor;
276
280
 
277
 
    BasicElement::Direction dir;
 
281
    Direction dir;
278
282
};
279
283
 
280
284
 
281
285
/**
282
286
 * Command to remove the parent element.
283
287
 */
284
 
class KFCRemoveEnclosing : public KFormulaCommand
 
288
class KFCRemoveEnclosing : public Command
285
289
{
286
290
public:
287
 
    KFCRemoveEnclosing(KFormulaContainer* document, BasicElement::Direction dir);
 
291
    KFCRemoveEnclosing(Container* document, Direction dir);
288
292
    ~KFCRemoveEnclosing();
289
293
 
290
294
    virtual void execute();
291
295
    virtual void unexecute();
292
296
 
293
 
    virtual bool isSenseless() { return element == 0; }
294
 
 
295
297
private:
296
298
    BasicElement* element;
297
299
 
298
 
    BasicElement::Direction direction;
 
300
    Direction direction;
299
301
};
300
302
 
301
303
 
303
305
 * The command that takes the main child out of the selected
304
306
 * element and replaces the element with it.
305
307
 */
306
 
class KFCAddReplacing : public KFormulaCommand
 
308
class KFCAddReplacing : public Command
307
309
{
308
310
public:
309
 
    KFCAddReplacing(const QString &name, KFormulaContainer* document);
 
311
    KFCAddReplacing(const QString &name, Container* document);
310
312
    ~KFCAddReplacing();
311
313
 
312
314
    virtual void execute();
331
333
{
332
334
public:
333
335
 
334
 
    KFCAddGenericIndex(KFormulaContainer* document, ElementIndexPtr index);
 
336
    KFCAddGenericIndex(Container* document, ElementIndexPtr index);
335
337
 
336
338
    virtual void execute();
337
339
 
349
351
{
350
352
public:
351
353
 
352
 
    KFCAddIndex(KFormulaContainer* document, IndexElement* element, ElementIndexPtr index);
 
354
    KFCAddIndex(Container* document, IndexElement* element, ElementIndexPtr index);
353
355
    ~KFCAddIndex();
354
356
 
355
357
    virtual void execute();
359
361
    KFCAddGenericIndex addIndex;
360
362
};
361
363
 
 
364
 
 
365
class FormulaElement;
 
366
 
 
367
class KFCChangeBaseSize : public PlainCommand {
 
368
public:
 
369
    KFCChangeBaseSize( const QString& name, Container* document, FormulaElement* formula, int size );
 
370
 
 
371
    void execute();
 
372
    void unexecute();
 
373
 
 
374
private:
 
375
    Container* m_document;
 
376
    FormulaElement* m_formula;
 
377
    int m_size;
 
378
    int m_oldSize;
 
379
};
 
380
 
 
381
 
 
382
/**
 
383
 * Base for all font commands that act on the current selection.
 
384
 * Implements the visitor pattern. (Really?)
 
385
 */
 
386
class FontCommand : public Command {
 
387
public:
 
388
    FontCommand( const QString& name, Container* document );
 
389
 
 
390
    /**
 
391
     * Collects all elements that are to be modified.
 
392
     */
 
393
    void addTextElement( TextElement* element ) { list.append(element); }
 
394
 
 
395
    /**
 
396
     * Collects all parent elements those children are to be changend.
 
397
     */
 
398
    void addElement( BasicElement* element ) { elementList.append( element ); }
 
399
 
 
400
protected:
 
401
 
 
402
    QPtrList<TextElement>& childrenList() { return list; }
 
403
 
 
404
    void collectChildren();
 
405
 
 
406
    void parseSequences( const QMap<SequenceElement*, int>& parents );
 
407
 
 
408
private:
 
409
 
 
410
    /**
 
411
     * the list where all elements are stored that are removed
 
412
     * from the tree.
 
413
     */
 
414
    QPtrList<TextElement> list;
 
415
 
 
416
    QPtrList<BasicElement> elementList;
 
417
};
 
418
 
 
419
 
 
420
/**
 
421
 * Changes the char style of a number of elements an their children.
 
422
 */
 
423
class CharStyleCommand : public FontCommand {
 
424
public:
 
425
    CharStyleCommand( CharStyle cs, const QString& name, Container* document );
 
426
 
 
427
    virtual void execute();
 
428
    virtual void unexecute();
 
429
 
 
430
private:
 
431
 
 
432
    typedef QValueVector<CharStyle> StyleList;
 
433
 
 
434
    StyleList styleList;
 
435
    CharStyle charStyle;
 
436
};
 
437
 
 
438
 
 
439
/**
 
440
 * Changes the char family of a number of elements an their children.
 
441
 */
 
442
class CharFamilyCommand : public FontCommand {
 
443
public:
 
444
    CharFamilyCommand( CharFamily cf, const QString& name, Container* document );
 
445
 
 
446
    virtual void execute();
 
447
    virtual void unexecute();
 
448
 
 
449
private:
 
450
 
 
451
    typedef QValueVector<CharFamily> FamilyList;
 
452
 
 
453
    FamilyList familyList;
 
454
    CharFamily charFamily;
 
455
};
 
456
 
 
457
 
362
458
KFORMULA_NAMESPACE_END
363
459
 
364
460
#endif // KFORMULACOMMAND_H