lib Library API Documentation

symbolelement.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., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef SYMBOLELEMENT_H
00022 #define SYMBOLELEMENT_H
00023 
00024 #include "fontstyle.h"
00025 #include "basicelement.h"
00026 #include "kformuladefs.h"
00027 
00028 KFORMULA_NAMESPACE_BEGIN
00029 
00033 class SymbolElement : public BasicElement {
00034     SymbolElement operator=( const SymbolElement& ) { return *this; }
00035 public:
00036 
00037     //enum { contentPos, upperPos, lowerPos };
00038 
00039     SymbolElement(SymbolType type = EmptyBracket, BasicElement* parent = 0);
00040     ~SymbolElement();
00041 
00042     SymbolElement( const SymbolElement& );
00043 
00044     virtual SymbolElement* clone() {
00045         return new SymbolElement( *this );
00046     }
00047 
00048     virtual bool accept( ElementVisitor* visitor );
00049 
00056     virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
00057                                    const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
00058 
00059     // drawing
00060     //
00061     // Drawing depends on a context which knows the required properties like
00062     // fonts, spaces and such.
00063     // It is essential to calculate elements size with the same context
00064     // before you draw.
00065 
00070     virtual void calcSizes(const ContextStyle& context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle);
00071 
00077     virtual void draw( QPainter& painter, const LuPixelRect& r,
00078                        const ContextStyle& context,
00079                        ContextStyle::TextStyle tstyle,
00080                        ContextStyle::IndexStyle istyle,
00081                        const LuPixelPoint& parentOrigin );
00082 
00086     virtual void dispatchFontCommand( FontCommand* cmd );
00087 
00088     // navigation
00089     //
00090     // The elements are responsible to handle cursor movement themselves.
00091     // To do this they need to know the direction the cursor moves and
00092     // the element it comes from.
00093     //
00094     // The cursor might be in normal or in selection mode.
00095 
00101     virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00102 
00108     virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00109 
00115     virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
00116 
00122     virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
00123 
00124     // children
00125 
00133     //virtual void removeChild(FormulaCursor* cursor, BasicElement* child);
00134 
00135 
00136     // main child
00137     //
00138     // If an element has children one has to become the main one.
00139 
00140     virtual SequenceElement* getMainChild() { return content; }
00141     //virtual void setMainChild(SequenceElement*);
00142 
00143 
00154     virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00155 
00167     virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00168 
00173     virtual void normalize(FormulaCursor*, Direction);
00174 
00178     virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor);
00179 
00184     virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00185 
00190     //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
00191 
00192     bool hasUpper() const { return upper != 0; }
00193     bool hasLower() const { return lower != 0; }
00194 
00195     // If we want to create an index we need a cursor that points there.
00196 
00197     void setToUpper(FormulaCursor* cursor);
00198     void setToLower(FormulaCursor* cursor);
00199 
00200     // Moves the cursor inside the index. The index has to exist.
00201     void moveToUpper(FormulaCursor*, Direction);
00202     void moveToLower(FormulaCursor*, Direction);
00203 
00204     // Generic access to each index.
00205 
00206     ElementIndexPtr getUpperIndex() { return ElementIndexPtr( new UpperIndex( this ) ); }
00207     ElementIndexPtr getLowerIndex() { return ElementIndexPtr( new LowerIndex( this ) ); }
00208 
00212     ElementIndexPtr getIndex( int position );
00213 
00214     // Save&load
00215     //virtual QDomElement getElementDom(QDomDocument *doc);
00216     //virtual bool buildFromDom(QDomElement *elem);
00217 
00222     virtual QString toLatex();
00223 
00224     virtual QString formulaString();
00225 
00226     virtual void writeMathML( QDomDocument doc, QDomNode parent );
00227 
00228 protected:
00229 
00230     //Save/load support
00231 
00235     virtual QString getTagName() const { return "SYMBOL"; }
00236 
00240     virtual void writeDom(QDomElement element);
00241 
00246     virtual bool readAttributesFromDom(QDomElement element);
00247 
00253     virtual bool readContentFromDom(QDomNode& node);
00254 
00255 private:
00256 
00260     class SymbolElementIndex : public ElementIndex {
00261     public:
00262         SymbolElementIndex(SymbolElement* p) : parent(p) {}
00263         virtual SymbolElement* getElement() { return parent; }
00264     protected:
00265         SymbolElement* parent;
00266     };
00267 
00268     // We have a (very simple) type for every index.
00269 
00270     class UpperIndex : public SymbolElementIndex {
00271     public:
00272         UpperIndex(SymbolElement* parent) : SymbolElementIndex(parent) {}
00273         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00274             { parent->moveToUpper(cursor, direction); }
00275         virtual void setToIndex(FormulaCursor* cursor)
00276             { parent->setToUpper(cursor); }
00277         virtual bool hasIndex() const
00278             { return parent->hasUpper(); }
00279     };
00280 
00281     class LowerIndex : public SymbolElementIndex {
00282     public:
00283         LowerIndex(SymbolElement* parent) : SymbolElementIndex(parent) {}
00284         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00285             { parent->moveToLower(cursor, direction); }
00286         virtual void setToIndex(FormulaCursor* cursor)
00287             { parent->setToLower(cursor); }
00288         virtual bool hasIndex() const
00289             { return parent->hasLower(); }
00290     };
00291 
00292 
00293     void setToContent(FormulaCursor* cursor);
00294 
00295     SequenceElement* content;
00296     SequenceElement* upper;
00297     SequenceElement* lower;
00298 
00302     Artwork* symbol;
00303 
00304     SymbolType symbolType;
00305 };
00306 
00307 KFORMULA_NAMESPACE_END
00308 
00309 #endif // SYMBOLELEMENT_H
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:29 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003