lib Library API Documentation

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., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, 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& context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle); 00083 00089 virtual void draw( QPainter& painter, const LuPixelRect& r, 00090 const ContextStyle& context, 00091 ContextStyle::TextStyle tstyle, 00092 ContextStyle::IndexStyle istyle, 00093 const LuPixelPoint& parentOrigin ); 00094 00098 virtual void dispatchFontCommand( FontCommand* cmd ); 00099 00100 // navigation 00101 // 00102 // The elements are responsible to handle cursor movement themselves. 00103 // To do this they need to know the direction the cursor moves and 00104 // the element it comes from. 00105 // 00106 // The cursor might be in normal or in selection mode. 00107 00113 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from); 00114 00120 virtual void moveRight(FormulaCursor* cursor, BasicElement* from); 00121 00127 virtual void moveUp(FormulaCursor* cursor, BasicElement* from); 00128 00134 virtual void moveDown(FormulaCursor* cursor, BasicElement* from); 00135 00136 // children 00137 00145 //virtual void removeChild(FormulaCursor* cursor, BasicElement* child); 00146 00147 00148 // main child 00149 // 00150 // If an element has children one has to become the main one. 00151 00152 virtual SequenceElement* getMainChild() { return content; } 00153 //SequenceElement* upperLeft; 00154 //SequenceElement* upperMiddle; 00155 SequenceElement* getExponent() { return upperRight; } 00156 //SequenceElement* lowerLeft; 00157 //SequenceElement* lowerMiddle; 00158 //SequenceElement* lowerRight; 00159 00160 00171 virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction); 00172 00184 virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction); 00185 00190 virtual void normalize(FormulaCursor*, Direction); 00191 00195 virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor); 00196 00201 virtual void selectChild(FormulaCursor* cursor, BasicElement* child); 00202 00207 //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0; 00208 00214 virtual bool isSenseless(); 00215 00216 00217 bool hasUpperLeft() const { return upperLeft != 0; } 00218 bool hasUpperMiddle() const { return upperMiddle != 0; } 00219 bool hasUpperRight() const { return upperRight != 0; } 00220 bool hasLowerLeft() const { return lowerLeft != 0; } 00221 bool hasLowerMiddle() const { return lowerMiddle != 0; } 00222 bool hasLowerRight() const { return lowerRight != 0; } 00223 00224 // If we want to create an index we need a cursor that points there. 00225 00226 void setToUpperLeft(FormulaCursor* cursor); 00227 void setToUpperMiddle(FormulaCursor* cursor); 00228 void setToUpperRight(FormulaCursor* cursor); 00229 void setToLowerLeft(FormulaCursor* cursor); 00230 void setToLowerMiddle(FormulaCursor* cursor); 00231 void setToLowerRight(FormulaCursor* cursor); 00232 00233 // If the index is there we need a way to move into it. 00234 00235 void moveToUpperLeft(FormulaCursor* cursor, Direction direction); 00236 void moveToUpperMiddle(FormulaCursor* cursor, Direction direction); 00237 void moveToUpperRight(FormulaCursor* cursor, Direction direction); 00238 void moveToLowerLeft(FormulaCursor* cursor, Direction direction); 00239 void moveToLowerMiddle(FormulaCursor* cursor, Direction direction); 00240 void moveToLowerRight(FormulaCursor* cursor, Direction direction); 00241 00242 // Generic access to each index. 00243 00244 ElementIndexPtr getUpperLeft() { return ElementIndexPtr( new UpperLeftIndex( this ) ); } 00245 ElementIndexPtr getLowerLeft() { return ElementIndexPtr( new LowerLeftIndex( this ) ); } 00246 ElementIndexPtr getUpperMiddle() { return ElementIndexPtr( new UpperMiddleIndex( this ) ); } 00247 ElementIndexPtr getLowerMiddle() { return ElementIndexPtr( new LowerMiddleIndex( this ) ); } 00248 ElementIndexPtr getUpperRight() { return ElementIndexPtr( new UpperRightIndex( this ) ); } 00249 ElementIndexPtr getLowerRight() { return ElementIndexPtr( new LowerRightIndex( this ) ); } 00250 00254 ElementIndexPtr getIndex( int position ); 00255 00260 virtual QString toLatex(); 00261 00262 // the upper right index is the only one we show 00263 virtual QString formulaString(); 00264 00265 virtual void writeMathML( QDomDocument doc, QDomNode parent ); 00266 00267 protected: 00268 00269 //Save/load support 00270 00274 virtual QString getTagName() const { return "INDEX"; } 00275 00279 virtual void writeDom(QDomElement element); 00280 00285 virtual bool readAttributesFromDom(QDomElement element); 00286 00292 virtual bool readContentFromDom(QDomNode& node); 00293 00294 private: 00295 00299 class IndexElementIndex : public ElementIndex { 00300 public: 00301 IndexElementIndex(IndexElement* p) : parent(p) {} 00302 virtual IndexElement* getElement() { return parent; } 00303 protected: 00304 IndexElement* parent; 00305 }; 00306 00307 // We have a (very simple) type for every index. 00308 00309 class UpperLeftIndex : public IndexElementIndex { 00310 public: 00311 UpperLeftIndex(IndexElement* parent) : IndexElementIndex(parent) {} 00312 virtual void moveToIndex(FormulaCursor* cursor, Direction direction) 00313 { parent->moveToUpperLeft(cursor, direction); } 00314 virtual void setToIndex(FormulaCursor* cursor) 00315 { parent->setToUpperLeft(cursor); } 00316 virtual bool hasIndex() const 00317 { return parent->hasUpperLeft(); } 00318 }; 00319 00320 class LowerLeftIndex : public IndexElementIndex { 00321 public: 00322 LowerLeftIndex(IndexElement* parent) : IndexElementIndex(parent) {} 00323 virtual void moveToIndex(FormulaCursor* cursor, Direction direction) 00324 { parent->moveToLowerLeft(cursor, direction); } 00325 virtual void setToIndex(FormulaCursor* cursor) 00326 { parent->setToLowerLeft(cursor); } 00327 virtual bool hasIndex() const 00328 { return parent->hasLowerLeft(); } 00329 }; 00330 00331 class UpperMiddleIndex : public IndexElementIndex { 00332 public: 00333 UpperMiddleIndex(IndexElement* parent) : IndexElementIndex(parent) {} 00334 virtual void moveToIndex(FormulaCursor* cursor, Direction direction) 00335 { parent->moveToUpperMiddle(cursor, direction); } 00336 virtual void setToIndex(FormulaCursor* cursor) 00337 { parent->setToUpperMiddle(cursor); } 00338 virtual bool hasIndex() const 00339 { return parent->hasUpperMiddle(); } 00340 }; 00341 00342 class LowerMiddleIndex : public IndexElementIndex { 00343 public: 00344 LowerMiddleIndex(IndexElement* parent) : IndexElementIndex(parent) {} 00345 virtual void moveToIndex(FormulaCursor* cursor, Direction direction) 00346 { parent->moveToLowerMiddle(cursor, direction); } 00347 virtual void setToIndex(FormulaCursor* cursor) 00348 { parent->setToLowerMiddle(cursor); } 00349 virtual bool hasIndex() const 00350 { return parent->hasLowerMiddle(); } 00351 }; 00352 00353 class UpperRightIndex : public IndexElementIndex { 00354 public: 00355 UpperRightIndex(IndexElement* parent) : IndexElementIndex(parent) {} 00356 virtual void moveToIndex(FormulaCursor* cursor, Direction direction) 00357 { parent->moveToUpperRight(cursor, direction); } 00358 virtual void setToIndex(FormulaCursor* cursor) 00359 { parent->setToUpperRight(cursor); } 00360 virtual bool hasIndex() const 00361 { return parent->hasUpperRight(); } 00362 }; 00363 00364 class LowerRightIndex : public IndexElementIndex { 00365 public: 00366 LowerRightIndex(IndexElement* parent) : IndexElementIndex(parent) {} 00367 virtual void moveToIndex(FormulaCursor* cursor, Direction direction) 00368 { parent->moveToLowerRight(cursor, direction); } 00369 virtual void setToIndex(FormulaCursor* cursor) 00370 { parent->setToLowerRight(cursor); } 00371 virtual bool hasIndex() const 00372 { return parent->hasLowerRight(); } 00373 }; 00374 00375 00379 void setMiddleX(int xOffset, int middleWidth); 00380 00384 int getFromPos(BasicElement* from); 00385 00392 void setToContent(FormulaCursor* cursor); 00393 00397 SequenceElement* content; 00398 00404 SequenceElement* upperLeft; 00405 SequenceElement* upperMiddle; 00406 SequenceElement* upperRight; 00407 SequenceElement* lowerLeft; 00408 SequenceElement* lowerMiddle; 00409 SequenceElement* lowerRight; 00410 }; 00411 00412 KFORMULA_NAMESPACE_END 00413 00414 #endif // INDEXELEMENT_H
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:03:58 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003