lib

rootelement.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 ROOTELEMENT_H
00022 #define ROOTELEMENT_H
00023 
00024 #include <qpoint.h>
00025 
00026 #include "basicelement.h"
00027 
00028 KFORMULA_NAMESPACE_BEGIN
00029 class SequenceElement;
00030 
00031 
00035 class RootElement : public BasicElement {
00036     RootElement& operator=( const RootElement& ) { return *this; }
00037 public:
00038 
00039     //enum { contentPos, indexPos };
00040 
00041     RootElement(BasicElement* parent = 0);
00042     ~RootElement();
00043 
00044     RootElement( const RootElement& );
00045 
00046     virtual RootElement* clone() {
00047         return new RootElement( *this );
00048     }
00049 
00050     virtual bool accept( ElementVisitor* visitor );
00051 
00056     virtual void entered( SequenceElement* child );
00057 
00064     virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
00065                                    const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
00066 
00071     virtual void calcSizes( const ContextStyle& style,
00072                             ContextStyle::TextStyle tstyle,
00073                             ContextStyle::IndexStyle istyle,
00074                             StyleAttributes& style );
00075 
00081     virtual void draw( QPainter& painter, const LuPixelRect& r,
00082                        const ContextStyle& style,
00083                        ContextStyle::TextStyle tstyle,
00084                        ContextStyle::IndexStyle istyle,
00085                        StyleAttributes& style,
00086                        const LuPixelPoint& parentOrigin );
00087 
00091     virtual void dispatchFontCommand( FontCommand* cmd );
00092 
00098     virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00099 
00105     virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00106 
00112     virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
00113 
00119     virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
00120 
00124     virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00125 
00132     virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00133 
00138     virtual void normalize(FormulaCursor*, Direction);
00139 
00140     // main child
00141     //
00142     // If an element has children one has to become the main one.
00143 
00144     virtual SequenceElement* getMainChild();
00145     SequenceElement* getRadiant() { return index; }
00146     //virtual void setMainChild(SequenceElement*);
00147 
00152     virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00153 
00158     //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
00159 
00160     // Moves the cursor inside the index. The index has to exist.
00161     void moveToIndex(FormulaCursor*, Direction);
00162 
00163     // Sets the cursor to point to the place where the index normaly
00164     // is. These functions are only used if there is no such index and
00165     // we want to insert them.
00166     void setToIndex(FormulaCursor*);
00167 
00168     bool hasIndex() const { return index != 0; }
00169 
00170     ElementIndexPtr getIndex() { return ElementIndexPtr( new RootElementIndex( this ) ); }
00171 
00172     // Save&load
00173     //virtual QDomElement getElementDom(QDomDocument *doc);
00174     //virtual bool buildFromDom(QDomElement *elem);
00175 
00180     virtual QString toLatex();
00181 
00182     virtual QString formulaString();
00183 
00184 protected:
00185 
00186     //Save/load support
00187 
00191     virtual QString getTagName() const { return "ROOT"; }
00192 
00196     virtual void writeDom(QDomElement element);
00197 
00202     virtual bool readAttributesFromDom(QDomElement element);
00203 
00209     virtual bool readContentFromDom(QDomNode& node);
00210 
00216     virtual bool readAttributesFromMathMLDom(const QDomElement& element);
00217 
00223     virtual int readContentFromMathMLDom(QDomNode& node);
00224 
00225 private:
00226 
00227     virtual QString getElementName() const { return hasIndex() ? "mroot" : "msqrt"; }
00228     virtual void writeMathMLContent( QDomDocument& doc, 
00229                                      QDomElement& element,
00230                                      bool oasisFormat ) const ;
00231 
00232     class RootElementIndex : public ElementIndex {
00233     public:
00234         RootElementIndex(RootElement* p) : parent(p) {}
00235         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00236             { parent->moveToIndex(cursor, direction); }
00237         virtual void setToIndex(FormulaCursor* cursor)
00238             { parent->setToIndex(cursor); }
00239         virtual bool hasIndex() const
00240             { return parent->hasIndex(); }
00241         virtual RootElement* getElement() { return parent; }
00242     protected:
00243         RootElement* parent;
00244     };
00245 
00246 
00250     SequenceElement* content;
00251 
00255     SequenceElement* index;
00256 
00260     LuPixelPoint rootOffset;
00261 
00267     bool square;
00268 };
00269 
00270 
00271 KFORMULA_NAMESPACE_END
00272 
00273 #endif // ROOTELEMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys