lib

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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, 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& style,
00071                             ContextStyle::TextStyle tstyle,
00072                             ContextStyle::IndexStyle istyle,
00073                             StyleAttributes& style );
00074 
00080     virtual void draw( QPainter& painter, const LuPixelRect& r,
00081                        const ContextStyle& context,
00082                        ContextStyle::TextStyle tstyle,
00083                        ContextStyle::IndexStyle istyle,
00084                        StyleAttributes& style,
00085                        const LuPixelPoint& parentOrigin );
00086 
00090     virtual void dispatchFontCommand( FontCommand* cmd );
00091 
00092     // navigation
00093     //
00094     // The elements are responsible to handle cursor movement themselves.
00095     // To do this they need to know the direction the cursor moves and
00096     // the element it comes from.
00097     //
00098     // The cursor might be in normal or in selection mode.
00099 
00105     virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00106 
00112     virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00113 
00119     virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
00120 
00126     virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
00127 
00128     // children
00129 
00137     //virtual void removeChild(FormulaCursor* cursor, BasicElement* child);
00138 
00139 
00140     // main child
00141     //
00142     // If an element has children one has to become the main one.
00143 
00144     virtual SequenceElement* getMainChild() { return content; }
00145     //virtual void setMainChild(SequenceElement*);
00146 
00147 
00158     virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00159 
00171     virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00172 
00177     virtual void normalize(FormulaCursor*, Direction);
00178 
00182     virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor);
00183 
00188     virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00189 
00194     //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
00195 
00196     bool hasUpper() const { return upper != 0; }
00197     bool hasLower() const { return lower != 0; }
00198 
00199     // If we want to create an index we need a cursor that points there.
00200 
00201     void setToUpper(FormulaCursor* cursor);
00202     void setToLower(FormulaCursor* cursor);
00203 
00204     // Moves the cursor inside the index. The index has to exist.
00205     void moveToUpper(FormulaCursor*, Direction);
00206     void moveToLower(FormulaCursor*, Direction);
00207 
00208     // Generic access to each index.
00209 
00210     ElementIndexPtr getUpperIndex() { return ElementIndexPtr( new UpperIndex( this ) ); }
00211     ElementIndexPtr getLowerIndex() { return ElementIndexPtr( new LowerIndex( this ) ); }
00212 
00216     ElementIndexPtr getIndex( int position );
00217 
00218     // Save&load
00219     //virtual QDomElement getElementDom(QDomDocument *doc);
00220     //virtual bool buildFromDom(QDomElement *elem);
00221 
00226     virtual QString toLatex();
00227 
00228     virtual QString formulaString();
00229 
00230     virtual void writeMathML( QDomDocument& doc, QDomNode& parent, bool oasisFormat = false ) const ;
00231 
00232 protected:
00233 
00234     //Save/load support
00235 
00239     virtual QString getTagName() const { return "SYMBOL"; }
00240 
00244     virtual void writeDom(QDomElement element);
00245 
00250     virtual bool readAttributesFromDom(QDomElement element);
00251 
00257     virtual bool readContentFromDom(QDomNode& node);
00258 
00259 private:
00260 
00264     class SymbolElementIndex : public ElementIndex {
00265     public:
00266         SymbolElementIndex(SymbolElement* p) : parent(p) {}
00267         virtual SymbolElement* getElement() { return parent; }
00268     protected:
00269         SymbolElement* parent;
00270     };
00271 
00272     // We have a (very simple) type for every index.
00273 
00274     class UpperIndex : public SymbolElementIndex {
00275     public:
00276         UpperIndex(SymbolElement* parent) : SymbolElementIndex(parent) {}
00277         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00278             { parent->moveToUpper(cursor, direction); }
00279         virtual void setToIndex(FormulaCursor* cursor)
00280             { parent->setToUpper(cursor); }
00281         virtual bool hasIndex() const
00282             { return parent->hasUpper(); }
00283     };
00284 
00285     class LowerIndex : public SymbolElementIndex {
00286     public:
00287         LowerIndex(SymbolElement* parent) : SymbolElementIndex(parent) {}
00288         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00289             { parent->moveToLower(cursor, direction); }
00290         virtual void setToIndex(FormulaCursor* cursor)
00291             { parent->setToLower(cursor); }
00292         virtual bool hasIndex() const
00293             { return parent->hasLower(); }
00294     };
00295 
00296 
00297     void setToContent(FormulaCursor* cursor);
00298 
00299     SequenceElement* content;
00300     SequenceElement* upper;
00301     SequenceElement* lower;
00302 
00306     Artwork* symbol;
00307 
00308     SymbolType symbolType;
00309 };
00310 
00311 KFORMULA_NAMESPACE_END
00312 
00313 #endif // SYMBOLELEMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys