F:/KPlato/koffice/libs/kformula/BasicElement.h

Aller à la documentation de ce fichier.
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 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef BASICELEMENT_H
00023 #define BASICELEMENT_H
00024 
00025 #include <QHash>
00026 #include <QString>
00027 #include <QVariant>
00028 
00029 
00030 #include <QList>
00031 #include <QDomElement>
00032 #include <QDomDocument>
00033 
00034 #include "contextstyle.h"
00035 #include "kformuladefs.h"
00036 
00037 class KoXmlWriter;
00038 
00039 namespace KFormula {
00040 
00041 class FontCommand;
00042 class FormulaCursor;
00043 class FormulaElement;
00044 class SequenceElement;
00045 
00046 enum ElementType {
00047     Basic,
00048     Sequence,
00049     Fraction,
00050     Matrix,
00051     MatrixRow,
00052     MatrixEntry,
00053     UnderOver,
00054     MultiScript
00055 };
00056 
00057 
00080 class BasicElement {
00081 public:
00082     /*
00083      * The standard constructor
00084      * @param parent pointer to the BasicElement's parent
00085      */
00086     BasicElement( BasicElement* parent = 0 );
00087 
00089     virtual ~BasicElement();
00090 
00096     BasicElement* childElementAt( const QPointF& p );
00097 
00102     virtual const QList<BasicElement*> childElements();
00103 
00109     virtual void insertChild( FormulaCursor* cursor, BasicElement* child );
00110    
00115     virtual void removeChild( BasicElement* element );
00116 
00121     virtual void paint( QPainter& painter ) const;
00122 
00124     virtual void calculateSize();
00125     
00131     virtual void moveLeft( FormulaCursor* cursor, BasicElement* from );
00132 
00138     virtual void moveRight( FormulaCursor* cursor, BasicElement* from );
00139 
00145     virtual void moveUp( FormulaCursor* cursor, BasicElement* from );
00146 
00152     virtual void moveDown( FormulaCursor* cursor, BasicElement* from );
00153 
00158     virtual void moveHome( FormulaCursor* cursor );
00159 
00164     virtual void moveEnd( FormulaCursor* cursor );
00165 
00167     ElementType elementType() const;
00168     
00170     double height() const;
00171 
00173     double width() const;
00174 
00176     double baseLine() const;
00177 
00179     QPointF origin() const;
00180 
00182     const QRectF& boundingRect() const;
00183 
00185     void setWidth( double width );
00186 
00188     void setHeight( double height );
00189     
00191     void setBaseLine( double baseLine );
00192 
00194     void setOrigin( QPointF origin );
00195 
00197     void setParentElement( BasicElement* parent );
00198 
00200     BasicElement* parentElement() const;
00201 
00203     QString inheritAttribute( const QString& attribute ) const;
00204     
00206     virtual void readMathML( const QDomElement& element );
00207 
00209     virtual void writeMathML( KoXmlWriter* writer, bool oasisFormat = false );
00210 
00211 
00212 
00213 
00214 
00219     virtual bool readOnly( const BasicElement* child ) const;
00220 
00226     virtual QChar getCharacter() const { return QChar::Null; }
00227 
00232     virtual TokenType getTokenType() const { return ELEMENT; }
00233 
00234 
00238     LuPixelPoint widgetPos();
00239 
00241     virtual void calcSizes(const ContextStyle& context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle);
00242 
00248     virtual void draw( QPainter& painter, const LuPixelRect& r,
00249                        const ContextStyle& context,
00250                        ContextStyle::TextStyle tstyle,
00251                        ContextStyle::IndexStyle istyle,
00252                        const LuPixelPoint& parentOrigin );
00253 
00254 
00258     virtual void dispatchFontCommand( FontCommand* /*cmd*/ ) {}
00259     
00264     virtual void goInside(FormulaCursor* cursor);
00265 
00266     virtual SequenceElement* getMainChild() { return 0; }
00267 
00274     virtual void insert(FormulaCursor*, QList<BasicElement*>&, Direction) {}
00275 
00280     virtual void remove(FormulaCursor*, QList<BasicElement*>&, Direction) {}
00281 
00286     virtual void normalize(FormulaCursor*, Direction);
00287 
00293     virtual bool isSenseless() { return false; }
00294 
00298     virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor) { return 0; }
00299 
00304     virtual void selectChild(FormulaCursor*, BasicElement*) {}
00305 
00310     virtual void childWillVanish(FormulaCursor*, BasicElement*) {}
00311 
00315     virtual void registerTab( BasicElement* /*tab*/ ) {}
00316 
00317     // basic support
00318 
00319     const BasicElement* getParent() const { return m_parentElement; }
00320     BasicElement* getParent() { return m_parentElement; }
00321     void setParent(BasicElement* p) { m_parentElement = p; }
00322     double getX() const;
00323     double getY() const;
00324     void setX( double x );
00325     void setY( double y );
00326     double getWidth() const;
00327     double getHeight() const;
00328     luPixel getBaseline() const { return m_baseLine; }
00329     void setBaseline( luPixel line ) { m_baseLine = line; }
00330 
00331     luPixel axis( const ContextStyle& style, ContextStyle::TextStyle tstyle ) const {
00332         return getBaseline() - style.axisHeight( tstyle ); }
00333 
00339     QDomElement getElementDom( QDomDocument& doc);
00340 
00345     bool buildFromDom(QDomElement element);
00346 
00347 
00348 
00349 protected:
00351     void readMathMLAttributes( const QDomElement& element );
00352 
00354     void writeMathMLAttributes( KoXmlWriter* writer );
00355 
00356 
00357 
00361     virtual QString getTagName() const { return "BASIC"; }
00362 
00366     virtual void writeDom(QDomElement element);
00367 
00372     virtual bool readAttributesFromDom(QDomElement element);
00373 
00379     virtual bool readContentFromDom(QDomNode& node);
00380 
00387     bool buildChild( SequenceElement* child, QDomNode node, const QString & name );
00388 
00389 private:
00391     BasicElement* m_parentElement;
00392 
00394     QHash<QString,QString> m_attributes;
00395 
00397     ElementType m_elementType;
00398     
00400     QRectF m_boundingRect;
00401    
00403     double m_baseLine;
00404 };
00405 
00406 } // namespace KFormula
00407 
00408 #endif // BASICELEMENT_H

Généré le Wed Nov 22 23:41:00 2006 pour KPlato par  doxygen 1.5.1-p1