kformula/flake

BasicElement.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    Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net>
00005    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
00006                  2009 Jeremias Epperlein <jeeree@web.de>
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public License
00019    along with this library; see the file COPYING.LIB.  If not, write to
00020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021    Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #ifndef BASICELEMENT_H
00025 #define BASICELEMENT_H
00026 
00027 #include "kformula_export.h"
00028 #include "ElementFactory.h"
00029 
00030 #include <QHash>
00031 #include <QList>
00032 #include <QString>
00033 #include <QRectF>
00034 #include <QLineF>
00035 class QPainter;
00036 class QVariant;
00037 class KoXmlWriter;
00038 #include "KoXmlReaderForward.h"
00039 class AttributeManager;
00040 class FormulaCursor;
00041 class QPainterPath;
00042 class TableEntryElement;
00043 #define DEBUGID 40000
00044 
00068 class KOFORMULA_EXPORT BasicElement {
00069 public:
00070     /*
00071      * The standard constructor
00072      * @param parent pointer to the BasicElement's parent
00073      */
00074     BasicElement( BasicElement* parent = 0 );
00075 
00077     virtual ~BasicElement();
00078 
00084     BasicElement* childElementAt( const QPointF& p );
00085 
00090     virtual const QList<BasicElement*> childElements() const;
00091 
00097     virtual bool replaceChild( BasicElement* oldelement, BasicElement* newelement );
00098 
00104     virtual void paint( QPainter& painter, AttributeManager* am );
00105 
00111     virtual void paintEditingHints( QPainter& painter, AttributeManager* am );
00112 
00113     
00128     virtual void layout( const AttributeManager* am );
00129 
00133     virtual void stretch();
00134 
00140     virtual bool acceptCursor( const FormulaCursor& cursor );
00141     
00148     virtual QLineF cursorLine(int position) const;
00149     
00150     virtual QPainterPath selectionRegion(const int pos1, const int pos2) const;
00151     
00152     virtual QList<BasicElement*> elementsBetween(int pos1, int pos2) const;
00153     
00160     virtual bool moveCursor(FormulaCursor& newcursor, FormulaCursor& oldcursor);
00161     
00163     virtual ElementType elementType() const;
00164 
00166     void setWidth( double width );
00167 
00169     double width() const;
00170 
00172     void setHeight( double height );
00173 
00175     double height() const;
00176 
00178     const QRectF& boundingRect() const;
00179 
00181     const QRectF absoluteBoundingRect() const;
00182 
00193     virtual bool setCursorTo(FormulaCursor& cursor, QPointF point);
00194 
00196     const QRectF& childrenBoundingRect() const;
00197 
00199     void setChildrenBoundingRect(const QRectF &rect);
00200 
00202     void setBaseLine( double baseLine );
00203 
00205     double baseLine() const;
00206 
00208     void setOrigin( QPointF origin );
00209 
00211     QPointF origin() const;
00212 
00214     void setParentElement( BasicElement* parent );
00215 
00217     BasicElement* parentElement() const;
00218 
00220     virtual int endPosition() const;
00221     
00226     virtual int positionOfChild(BasicElement* child) const;
00227         
00229     virtual BasicElement* elementBefore(int position) const;
00230     
00232     virtual BasicElement* elementAfter(int position) const;
00233     
00235     void setScaleFactor( double scaleFactor );
00236 
00238     double scaleFactor() const;
00239 
00241     void setScaleLevel( int scaleLevel );
00242 
00244     int scaleLevel() const;
00245 
00251     void setAttribute( const QString& name, const QVariant& value );
00252 
00254     QString attribute( const QString& attribute ) const;
00255 
00257     virtual QString inheritsAttribute( const QString& attribute ) const;
00258 
00260     virtual QString attributesDefaultValue( const QString& attribute ) const;
00261 
00263     bool displayStyle() const;
00264     
00266     void setDisplayStyle(bool displayStyle);
00267 
00269     bool readMathML( const KoXmlElement& element );
00270 
00272     void writeMathML( KoXmlWriter* writer ) const;
00273 
00275     bool hasDescendant(BasicElement* other) const;
00276 
00278     BasicElement* emptyDescendant();
00279 
00281     virtual bool isEmpty() const;
00282 
00284     virtual bool isInferredRow() const;
00285 
00287     BasicElement* formulaElement();
00288 
00294     virtual void writeElementTree(int indent=0, bool wrong=false) const;
00295 
00297     virtual const QString writeElementContent() const;
00298     
00300     TableEntryElement* parentTableEntry();
00301 
00302 protected:
00304     virtual bool readMathMLAttributes( const KoXmlElement& element );
00305 
00307     virtual bool readMathMLContent( const KoXmlElement& element );
00308 
00310     virtual void writeMathMLAttributes( KoXmlWriter* writer ) const;
00311 
00313     virtual void writeMathMLContent( KoXmlWriter* writer ) const;
00314 
00315     static void cleanElementTree(BasicElement* element);
00316     
00317 private:
00319     BasicElement* m_parentElement;
00320 
00322     QHash<QString,QString> m_attributes;
00323 
00325     QRectF m_boundingRect;
00326     
00331     QRectF m_childrenBoundingRect;
00332 
00334     double m_baseLine;
00335 
00337     double m_scaleFactor;
00338 
00340     double m_scaleLevel;
00341 
00343     bool m_displayStyle;
00344 };
00345 
00346 #endif // BASICELEMENT_H