formulacursor.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FORMULACURSOR_H
00022 #define FORMULACURSOR_H
00023
00024 #include <qstring.h>
00025
00026 #include "basicelement.h"
00027 #include "kformuladefs.h"
00028
00029 KFORMULA_NAMESPACE_BEGIN
00030
00031 class FormulaElement;
00032 class IndexElement;
00033 class MatrixElement;
00034 class NameSequence;
00035 class RootElement;
00036 class SymbolElement;
00037 class TextElement;
00038
00039
00050 class FormulaCursor {
00051
00052
00053 friend class SequenceElement;
00054
00055 public:
00056
00063 FormulaCursor(FormulaElement* element);
00064
00065 FormulaCursor& operator= (const FormulaCursor&);
00066
00067
00068 int getPos() const { return cursorPos; }
00069 int getMark() const { return markPos; }
00070
00074 bool hasChanged() const { return hasChangedFlag; }
00075
00080 void clearChangedFlag() { hasChangedFlag = false; }
00081
00085 bool isSelectionMode() const { return selectionFlag; }
00086
00090 bool isSelection() const { return selectionFlag && (getPos() != getMark()); }
00091
00095 void setSelection(bool selection) { selectionFlag = selection; hasChangedFlag = true; }
00096
00101 void calcCursorSize( const ContextStyle& context, bool smallCursor );
00102
00107 void draw( QPainter&, const ContextStyle& context, bool smallCursor );
00108
00109
00110
00111
00112 void moveLeft(int flag = NormalMovement);
00113 void moveRight(int flag = NormalMovement);
00114 void moveUp(int flag = NormalMovement);
00115 void moveDown(int flag = NormalMovement);
00116
00117 void moveHome(int flag = NormalMovement);
00118 void moveEnd(int flag = NormalMovement);
00119
00121 bool isHome() const;
00122
00124 bool isEnd() const;
00125
00126
00127
00128 bool getLinearMovement() const { return linearMovement; }
00129
00134 void setLinearMovement(bool linear) { linearMovement = linear; }
00135
00139 void goInsideElement(BasicElement* element);
00140
00141
00142
00143 void mousePress( const LuPixelPoint&, int flags );
00144 void mouseMove( const LuPixelPoint&, int flags );
00145 void mouseRelease( const LuPixelPoint&, int flags );
00146
00151 void insert(BasicElement*, Direction = beforeCursor);
00152
00158 void insert(QPtrList<BasicElement>&,
00159 Direction = beforeCursor);
00160
00166 void remove(QPtrList<BasicElement>&,
00167 Direction = beforeCursor);
00168
00169
00174 void replaceSelectionWith(BasicElement*,
00175 Direction = beforeCursor);
00176
00181 BasicElement* replaceByMainChildContent(Direction = beforeCursor);
00182
00190 BasicElement* removeEnclosingElement(Direction = beforeCursor);
00191
00196 bool elementIsSenseless();
00197
00198
00199
00200
00201
00202 int getSelectionStart() const { return QMIN(getPos(), getMark()); }
00203 int getSelectionEnd() const { return QMAX(getPos(), getMark()); }
00204
00205
00216 void setTo(BasicElement* element, int cursor, int mark=-1);
00217
00218 void setPos(int pos);
00219 void setMark(int mark);
00220
00221
00231 BasicElement* getElement() { return current; }
00232 const BasicElement* getElement() const { return current; }
00233
00234
00241 void normalize(Direction direction = beforeCursor);
00242
00243
00247 SequenceElement* normal();
00248 const SequenceElement* normal() const;
00249
00254 IndexElement* getActiveIndexElement();
00255
00260 RootElement* getActiveRootElement();
00261
00266 SymbolElement* getActiveSymbolElement();
00267
00272 NameSequence* getActiveNameSequence();
00273
00277 TextElement* getActiveTextElement();
00278
00282 MatrixElement* getActiveMatrixElement();
00283
00288 void selectActiveElement();
00289
00293 void copy( QDomDocument& doc );
00294
00299 bool buildElementsFromDom( QDomElement root, QPtrList<BasicElement>& list );
00300
00301
00302
00308 class CursorData {
00309 friend class FormulaCursor;
00310 BasicElement* current;
00311 int cursorPos;
00312 int markPos;
00313 bool selectionFlag;
00314 bool linearMovement;
00315 bool readOnly;
00316
00317 CursorData(BasicElement* c,
00318 int pos, int mark, bool selection, bool linear, bool ro)
00319 : current(c), cursorPos(pos), markPos(mark),
00320 selectionFlag(selection), linearMovement(linear),
00321 readOnly(ro) {}
00322 };
00323
00328 CursorData* getCursorData();
00329
00334 void setCursorData(CursorData* data);
00335
00339 void elementWillVanish(BasicElement* element);
00340
00344 void formulaLoaded(FormulaElement* rootElement);
00345
00349 const LuPixelPoint& getCursorPoint() const { return cursorPoint; }
00350
00354 const LuPixelRect& getCursorSize() const { return cursorSize; }
00355 void addCursorSize( const LuPixelRect& rect ) { cursorSize |= rect; }
00356
00360 bool isReadOnly() const;
00361
00365 void setReadOnly(bool ro) { readOnly = ro; }
00366
00367 private:
00368
00376 BasicElement* getActiveChild(Direction direction);
00377
00384 BasicElement* getSelectedChild();
00385
00390 bool pointsAfterMainChild(BasicElement*);
00391
00395 void handleSelectState(int flag);
00396
00397
00401 BasicElement* current;
00402
00409 int cursorPos;
00410
00417 int markPos;
00418
00423 bool selectionFlag;
00424
00429 bool linearMovement;
00430
00435 LuPixelPoint cursorPoint;
00436
00441 LuPixelRect cursorSize;
00442
00448 bool hasChangedFlag;
00449
00453 bool readOnly;
00454 };
00455
00456 KFORMULA_NAMESPACE_END
00457
00458 #endif // FORMULACURSOR_H
This file is part of the documentation for lib Library Version 1.4.2.