kformula/flake

FormulaCursor.h

Go to the documentation of this file.
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                  2006 Martin Pfeiffer <hubipete@gmx.net>
00005                  2009 Jeremias Epperlein <jeeree@web.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #ifndef FORMULACURSOR_H
00024 #define FORMULACURSOR_H
00025 
00026 #include "kformula_export.h"
00027 #include <QString>
00028 #include <QPair>
00029 #include "FormulaData.h"
00030 
00031 class BasicElement;
00032 class QString;
00033 class QPainter;
00034 class QPointF;
00035 class QRectF;
00036 class QUndoCommand;
00037 
00038 enum CursorDirection {
00039     MoveRight,
00040     MoveLeft,
00041     MoveUp,
00042     MoveDown,
00043     NoDirection
00044 };
00045 
00046 
00056 class KOFORMULA_EXPORT FormulaCursor {
00057 public:
00058     FormulaCursor(BasicElement* element, bool selecting, int position, int mark);
00059     FormulaCursor(BasicElement* element, int position);
00060     FormulaCursor();
00061     FormulaCursor(const FormulaCursor& other);
00062 
00067     void paint( QPainter &painter ) const;
00068 
00070     bool isHome() const;
00071 
00073     bool isEnd() const;
00074 
00076     BasicElement* currentElement() const;
00077 
00079     int position() const;
00080 
00082     void setPosition(int position);
00083 
00085     void setCurrentElement(BasicElement* element);
00086 
00088     CursorDirection direction() const;
00089 
00094     void setSelecting( bool selecting );
00095 
00097     bool isSelecting() const;
00098 
00100     bool hasSelection() const;
00101 
00103     void setMark(int position);
00104 
00106     int mark() const;
00107 
00109     void selectElement(BasicElement* element);
00110 
00112     QPair<int,int> selection() const;
00113 
00115     bool isAccepted() const;
00116 
00118     void move( CursorDirection direction );
00119 
00120     void moveTo( const FormulaCursor& pos);
00121 
00122     void moveTo(BasicElement* element, int position);
00123 
00124     void moveTo(BasicElement* element);
00125     
00127     bool moveCloseTo( BasicElement* element, FormulaCursor& cursor);
00128 
00130     void moveHome();
00131 
00133     void moveEnd();
00134 
00136     QPointF getCursorPosition();
00137     
00139     void setCursorTo( const QPointF& point );
00140 
00142     bool insideToken() const;
00143 
00145     bool insideInferredRow() const;
00146 
00148     bool insideFixedElement() const;
00149 
00150     bool performMovement( FormulaCursor& oldcursor );
00151 
00152     FormulaCursor& operator+=(int step);
00153 
00154     int offset();
00155 
00156 private:
00158     BasicElement* m_currentElement;
00159 
00161     int m_position;
00162 
00164     int m_mark;
00165 
00167     bool m_selecting;
00168 
00169     CursorDirection m_direction;
00170 };
00171 
00172 #endif // FORMULACURSOR_H