00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KFORMULACOMMAND_H
00023 #define KFORMULACOMMAND_H
00024
00025 #include <QMap>
00026 #include <QList>
00027 #include <QVector>
00028
00029 #include <kcommand.h>
00030
00031 #include "fontstyle.h"
00032 #include "FormulaContainer.h"
00033 #include "FormulaCursor.h"
00034
00035 namespace KFormula {
00036
00037 class TextElement;
00038 class MatrixElement;
00039 class MatrixRowElement;
00040 class MatrixEntryElement;
00041
00056 class KOFORMULA_EXPORT PlainCommand : public KNamedCommand
00057 {
00058 public:
00059
00068 PlainCommand(const QString& name);
00069 virtual ~PlainCommand();
00070
00074 static int getEvilDestructionCount() { return evilDestructionCount; }
00075
00076 private:
00077
00078
00079 static int evilDestructionCount;
00080 };
00081
00082
00083 class Command : public PlainCommand
00084 {
00085 public:
00086
00096 Command(const QString& name, Container* document);
00097 virtual ~Command();
00098
00099 protected:
00100
00105 FormulaCursor* getExecuteCursor();
00106
00111 FormulaCursor* getUnexecuteCursor();
00112
00119 void setUnexecuteCursor(FormulaCursor* cursor);
00120
00125 FormulaCursor* getActiveCursor() { return doc->activeCursor(); }
00126
00131 void testDirty() { doc->testDirty(); }
00132
00136 Container* getDocument() const { return doc; }
00137
00138 private:
00139
00140
00141
00145 void setExecuteCursor(FormulaCursor* cursor);
00146
00150
00151
00155
00156
00160 Container* doc;
00161 };
00162
00163
00167 class KFCAdd : public Command
00168 {
00169 public:
00170
00171 KFCAdd(const QString &name, Container* document);
00172
00173 virtual void execute();
00174 virtual void unexecute();
00175
00179 void addElement(BasicElement* element) { addList.append(element); }
00180
00181 private:
00182
00187 QList<BasicElement*> addList;
00188 };
00189
00190
00195 class KFCRemoveSelection : public Command
00196 {
00197 public:
00198
00202 KFCRemoveSelection(Container* document,
00203 Direction dir = beforeCursor);
00204
00205 virtual void execute();
00206 virtual void unexecute();
00207
00208 private:
00209
00214 QList<BasicElement*> removedList;
00215
00216 Direction dir;
00217 };
00218
00219
00224 class KFCReplace : public KFCAdd
00225 {
00226 public:
00227
00228 KFCReplace(const QString &name, Container* document);
00229 ~KFCReplace();
00230
00231 virtual void execute();
00232 virtual void unexecute();
00233
00234 private:
00235
00239 KFCRemoveSelection* removeSelection;
00240 };
00241
00242
00247 class KFCRemove : public Command
00248 {
00249 public:
00250
00254 KFCRemove(Container* document, Direction dir);
00255 ~KFCRemove();
00256
00257 virtual void execute();
00258 virtual void unexecute();
00259
00264
00265
00266 private:
00267
00272 QList<BasicElement*> removedList;
00273
00277 BasicElement* element;
00278
00284
00285
00286 Direction dir;
00287 };
00288
00289
00293 class KFCRemoveEnclosing : public Command
00294 {
00295 public:
00296 KFCRemoveEnclosing(Container* document, Direction dir);
00297 ~KFCRemoveEnclosing();
00298
00299 virtual void execute();
00300 virtual void unexecute();
00301
00302 private:
00303 BasicElement* element;
00304
00305 Direction direction;
00306 };
00307
00308
00313 class KFCAddReplacing : public Command
00314 {
00315 public:
00316 KFCAddReplacing(const QString &name, Container* document);
00317 ~KFCAddReplacing();
00318
00319 virtual void execute();
00320 virtual void unexecute();
00321
00322 void setElement(BasicElement* e) { element = e; }
00323
00324 private:
00325
00329 BasicElement* element;
00330 };
00331
00332
00337 class KFCAddGenericIndex : public KFCAdd
00338 {
00339 public:
00340
00341 KFCAddGenericIndex(Container* document, ElementIndexPtr index);
00342
00343 virtual void execute();
00344
00345 private:
00346 ElementIndexPtr index;
00347 };
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 class FormulaElement;
00368
00369 class KFCChangeBaseSize : public PlainCommand {
00370 public:
00371 KFCChangeBaseSize( const QString& name, Container* document, FormulaElement* formula, int size );
00372
00373 void execute();
00374 void unexecute();
00375
00376 private:
00377 Container* m_document;
00378 FormulaElement* m_formula;
00379 int m_size;
00380 int m_oldSize;
00381 };
00382
00383
00388 class FontCommand : public Command {
00389 public:
00390 FontCommand( const QString& name, Container* document );
00391
00395 void addTextElement( TextElement* element ) { list.append(element); }
00396
00400 void addElement( BasicElement* element ) { elementList.append( element ); }
00401
00402 protected:
00403
00404 QList<TextElement*>& childrenList() { return list; }
00405
00406 void collectChildren();
00407
00408 void parseSequences( const QMap<SequenceElement*, int>& parents );
00409
00410 private:
00411
00416 QList<TextElement*> list;
00417
00418 QList<BasicElement*> elementList;
00419 };
00420
00421
00425 class CharStyleCommand : public FontCommand {
00426 public:
00427 CharStyleCommand( CharStyle cs, const QString& name, Container* document );
00428
00429 virtual void execute();
00430 virtual void unexecute();
00431
00432 private:
00433
00434 typedef QVector<CharStyle> StyleList;
00435
00436 StyleList styleList;
00437 CharStyle charStyle;
00438 };
00439
00440
00444 class CharFamilyCommand : public FontCommand {
00445 public:
00446 CharFamilyCommand( CharFamily cf, const QString& name, Container* document );
00447
00448 virtual void execute();
00449 virtual void unexecute();
00450
00451 private:
00452
00453 typedef QVector<CharFamily> FamilyList;
00454
00455 FamilyList familyList;
00456 CharFamily charFamily;
00457 };
00458
00459
00460 class KFCRemoveRow : public Command
00461 {
00462 public:
00463 KFCRemoveRow( const QString& name, Container* document, MatrixElement* m, int r, int c );
00464 ~KFCRemoveRow();
00465
00466 virtual void execute();
00467 virtual void unexecute();
00468
00469 protected:
00470 MatrixElement* matrix;
00471 int rowPos;
00472 int colPos;
00473
00474 QList<MatrixRowElement*>* row;
00475 };
00476
00477
00478 class KFCInsertRow : public KFCRemoveRow {
00479 public:
00480 KFCInsertRow( const QString& name, Container* document, MatrixElement* m, int r, int c );
00481
00482 virtual void execute() { KFCRemoveRow::unexecute(); }
00483 virtual void unexecute() { KFCRemoveRow::execute(); }
00484 };
00485
00486
00487 class KFCRemoveColumn : public Command {
00488 public:
00489 KFCRemoveColumn( const QString& name, Container* document, MatrixElement* m, int r, int c );
00490 ~KFCRemoveColumn();
00491
00492 virtual void execute();
00493 virtual void unexecute();
00494
00495 protected:
00496 MatrixElement* matrix;
00497 int rowPos;
00498 int colPos;
00499
00500 QList<MatrixRowElement*>* column;
00501 };
00502
00503
00504 class KFCInsertColumn : public KFCRemoveColumn {
00505 public:
00506 KFCInsertColumn( const QString& name, Container* document, MatrixElement* m, int r, int c );
00507
00508 virtual void execute() { KFCRemoveColumn::unexecute(); }
00509 virtual void unexecute() { KFCRemoveColumn::execute(); }
00510 };
00511
00512 class KFCNewLine : public Command {
00513 public:
00514 KFCNewLine( const QString& name, Container* document,
00515 MatrixEntryElement* line, uint pos );
00516
00517 virtual ~KFCNewLine();
00518
00519 virtual void execute();
00520 virtual void unexecute();
00521
00522 private:
00523 MatrixEntryElement* m_line;
00524 MatrixEntryElement* m_newline;
00525 uint m_pos;
00526 };
00527
00528
00529
00530 }
00531
00532 #endif // KFORMULACOMMAND_H