lib

formulacursor.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                   Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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     // Yes, we do have a friend.
00053     friend class SequenceElement;
00054 
00055 public:
00056 
00063     FormulaCursor(FormulaElement* element);
00064 
00065     FormulaCursor& operator= (const FormulaCursor&);
00066 
00067     // where the cursor and the mark are
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, bool activeCursor );
00108 
00109 
00110     // simple cursor movement.
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     // how to travel
00127 
00128     bool getLinearMovement() const { return linearMovement; }
00129 
00134     void setLinearMovement(bool linear) { linearMovement = linear; }
00135 
00139     void goInsideElement(BasicElement* element);
00140 
00141     // mouse selection
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     // The range that is selected. Makes no sense if there is
00200     // no selection.
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     // undo/redo support
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
KDE Home | KDE Accessibility Home | Description of Access Keys