lib

indexelement.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 INDEXELEMENT_H
00022 #define INDEXELEMENT_H
00023 
00024 // Formula include
00025 #include "basicelement.h"
00026 
00027 KFORMULA_NAMESPACE_BEGIN
00028 class SequenceElement;
00029 
00030 
00034 class IndexElement : public BasicElement {
00035     IndexElement& operator=( const IndexElement& ) { return *this; }
00036 public:
00037 
00038     IndexElement(BasicElement* parent = 0);
00039     ~IndexElement();
00040 
00041     IndexElement( const IndexElement& );
00042 
00043     virtual IndexElement* clone() {
00044         return new IndexElement( *this );
00045     }
00046 
00047     virtual bool accept( ElementVisitor* visitor );
00048 
00054     virtual QChar getCharacter() const;
00055 
00060     virtual void entered( SequenceElement* child );
00061 
00068     virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
00069                                    const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
00070 
00071     // drawing
00072     //
00073     // Drawing depends on a context which knows the required properties like
00074     // fonts, spaces and such.
00075     // It is essential to calculate elements size with the same context
00076     // before you draw.
00077 
00082     virtual void calcSizes( const ContextStyle& cstyle,
00083                             ContextStyle::TextStyle tstyle,
00084                             ContextStyle::IndexStyle istyle,
00085                             StyleAttributes& style );
00086 
00092     virtual void draw( QPainter& painter, const LuPixelRect& r,
00093                        const ContextStyle& context,
00094                        ContextStyle::TextStyle tstyle,
00095                        ContextStyle::IndexStyle istyle,
00096                        StyleAttributes& style,
00097                        const LuPixelPoint& parentOrigin );
00098 
00102     virtual void dispatchFontCommand( FontCommand* cmd );
00103 
00104     // navigation
00105     //
00106     // The elements are responsible to handle cursor movement themselves.
00107     // To do this they need to know the direction the cursor moves and
00108     // the element it comes from.
00109     //
00110     // The cursor might be in normal or in selection mode.
00111 
00117     virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00118 
00124     virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00125 
00131     virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
00132 
00138     virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
00139 
00140     // children
00141 
00149     //virtual void removeChild(FormulaCursor* cursor, BasicElement* child);
00150 
00151 
00152     // main child
00153     //
00154     // If an element has children one has to become the main one.
00155 
00156     virtual SequenceElement* getMainChild() { return content; }
00157     //SequenceElement* upperLeft;
00158     //SequenceElement* upperMiddle;
00159     SequenceElement* getExponent() { return upperRight; }
00160     //SequenceElement* lowerLeft;
00161     //SequenceElement* lowerMiddle;
00162     //SequenceElement* lowerRight;
00163 
00164 
00175     virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00176 
00188     virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00189 
00194     virtual void normalize(FormulaCursor*, Direction);
00195 
00199     virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor);
00200 
00205     virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00206 
00211     //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
00212 
00218     virtual bool isSenseless();
00219 
00220 
00221     bool hasUpperLeft()   const { return upperLeft   != 0; }
00222     bool hasUpperMiddle() const { return upperMiddle != 0; }
00223     bool hasUpperRight()  const { return upperRight  != 0; }
00224     bool hasLowerLeft()   const { return lowerLeft   != 0; }
00225     bool hasLowerMiddle() const { return lowerMiddle != 0; }
00226     bool hasLowerRight()  const { return lowerRight  != 0; }
00227 
00228     // If we want to create an index we need a cursor that points there.
00229 
00230     void setToUpperLeft(FormulaCursor* cursor);
00231     void setToUpperMiddle(FormulaCursor* cursor);
00232     void setToUpperRight(FormulaCursor* cursor);
00233     void setToLowerLeft(FormulaCursor* cursor);
00234     void setToLowerMiddle(FormulaCursor* cursor);
00235     void setToLowerRight(FormulaCursor* cursor);
00236 
00237     // If the index is there we need a way to move into it.
00238 
00239     void moveToUpperLeft(FormulaCursor* cursor, Direction direction);
00240     void moveToUpperMiddle(FormulaCursor* cursor, Direction direction);
00241     void moveToUpperRight(FormulaCursor* cursor, Direction direction);
00242     void moveToLowerLeft(FormulaCursor* cursor, Direction direction);
00243     void moveToLowerMiddle(FormulaCursor* cursor, Direction direction);
00244     void moveToLowerRight(FormulaCursor* cursor, Direction direction);
00245 
00246     // Generic access to each index.
00247 
00248     ElementIndexPtr getUpperLeft() { return ElementIndexPtr( new UpperLeftIndex( this ) ); }
00249     ElementIndexPtr getLowerLeft() { return ElementIndexPtr( new LowerLeftIndex( this ) ); }
00250     ElementIndexPtr getUpperMiddle() { return ElementIndexPtr( new UpperMiddleIndex( this ) ); }
00251     ElementIndexPtr getLowerMiddle() { return ElementIndexPtr( new LowerMiddleIndex( this ) ); }
00252     ElementIndexPtr getUpperRight() { return ElementIndexPtr( new UpperRightIndex( this ) ); }
00253     ElementIndexPtr getLowerRight() { return ElementIndexPtr( new LowerRightIndex( this ) ); }
00254 
00258     ElementIndexPtr getIndex( int position );
00259 
00264     virtual QString toLatex();
00265 
00266     // the upper right index is the only one we show
00267     virtual QString formulaString();
00268 
00269 protected:
00270 
00271     //Save/load support
00272 
00276     virtual QString getTagName() const { return "INDEX"; }
00277 
00281     virtual void writeDom(QDomElement element);
00282 
00283     virtual QString getElementName() const ;
00284     virtual void writeMathMLAttributes( QDomElement& element ) const ;
00285     virtual void writeMathMLContent( QDomDocument& doc, 
00286                                      QDomElement& element,
00287                                      bool oasisFormat ) const ;
00292     virtual bool readAttributesFromDom(QDomElement element);
00293 
00299     virtual bool readContentFromDom(QDomNode& node);
00300 
00301     virtual bool readAttributesFromMathMLDom( const QDomElement& element );
00308     virtual int readContentFromMathMLDom( QDomNode& node );
00309 
00310 private:
00311 
00315     class IndexElementIndex : public ElementIndex {
00316     public:
00317         IndexElementIndex(IndexElement* p) : parent(p) {}
00318         virtual IndexElement* getElement() { return parent; }
00319     protected:
00320         IndexElement* parent;
00321     };
00322 
00323     // We have a (very simple) type for every index.
00324 
00325     class UpperLeftIndex : public IndexElementIndex {
00326     public:
00327         UpperLeftIndex(IndexElement* parent) : IndexElementIndex(parent) {}
00328         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00329             { parent->moveToUpperLeft(cursor, direction); }
00330         virtual void setToIndex(FormulaCursor* cursor)
00331             { parent->setToUpperLeft(cursor); }
00332         virtual bool hasIndex() const
00333             { return parent->hasUpperLeft(); }
00334     };
00335 
00336     class LowerLeftIndex : public IndexElementIndex {
00337     public:
00338         LowerLeftIndex(IndexElement* parent) : IndexElementIndex(parent) {}
00339         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00340             { parent->moveToLowerLeft(cursor, direction); }
00341         virtual void setToIndex(FormulaCursor* cursor)
00342             { parent->setToLowerLeft(cursor); }
00343         virtual bool hasIndex() const
00344             { return parent->hasLowerLeft(); }
00345     };
00346 
00347     class UpperMiddleIndex : public IndexElementIndex {
00348     public:
00349         UpperMiddleIndex(IndexElement* parent) : IndexElementIndex(parent) {}
00350         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00351             { parent->moveToUpperMiddle(cursor, direction); }
00352         virtual void setToIndex(FormulaCursor* cursor)
00353             { parent->setToUpperMiddle(cursor); }
00354         virtual bool hasIndex() const
00355             { return parent->hasUpperMiddle(); }
00356     };
00357 
00358     class LowerMiddleIndex : public IndexElementIndex {
00359     public:
00360         LowerMiddleIndex(IndexElement* parent) : IndexElementIndex(parent) {}
00361         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00362             { parent->moveToLowerMiddle(cursor, direction); }
00363         virtual void setToIndex(FormulaCursor* cursor)
00364             { parent->setToLowerMiddle(cursor); }
00365         virtual bool hasIndex() const
00366             { return parent->hasLowerMiddle(); }
00367     };
00368 
00369     class UpperRightIndex : public IndexElementIndex {
00370     public:
00371         UpperRightIndex(IndexElement* parent) : IndexElementIndex(parent) {}
00372         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00373             { parent->moveToUpperRight(cursor, direction); }
00374         virtual void setToIndex(FormulaCursor* cursor)
00375             { parent->setToUpperRight(cursor); }
00376         virtual bool hasIndex() const
00377             { return parent->hasUpperRight(); }
00378     };
00379 
00380     class LowerRightIndex : public IndexElementIndex {
00381     public:
00382         LowerRightIndex(IndexElement* parent) : IndexElementIndex(parent) {}
00383         virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
00384             { parent->moveToLowerRight(cursor, direction); }
00385         virtual void setToIndex(FormulaCursor* cursor)
00386             { parent->setToLowerRight(cursor); }
00387         virtual bool hasIndex() const
00388             { return parent->hasLowerRight(); }
00389     };
00390 
00391 
00395     void setMiddleX(int xOffset, int middleWidth);
00396 
00400     int getFromPos(BasicElement* from);
00401 
00408     void setToContent(FormulaCursor* cursor);
00409 
00413     SequenceElement* content;
00414 
00420     SequenceElement* upperLeft;
00421     SequenceElement* upperMiddle;
00422     SequenceElement* upperRight;
00423     SequenceElement* lowerLeft;
00424     SequenceElement* lowerMiddle;
00425     SequenceElement* lowerRight;
00426 
00430     SizeType m_subScriptShiftType;
00431     double m_subScriptShift;
00432     SizeType m_superScriptShiftType;
00433     double m_superScriptShift;
00434     bool m_accentUnder;
00435     bool m_customAccentUnder;
00436     bool m_accent;
00437     bool m_customAccent;
00438 };
00439 
00440 KFORMULA_NAMESPACE_END
00441 
00442 #endif // INDEXELEMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys