00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef INDEXELEMENT_H
00022 #define INDEXELEMENT_H
00023
00024
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
00072
00073
00074
00075
00076
00077
00082 virtual void calcSizes( const ContextStyle& style,
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
00105
00106
00107
00108
00109
00110
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
00141
00149
00150
00151
00152
00153
00154
00155
00156 virtual SequenceElement* getMainChild() { return content; }
00157
00158
00159 SequenceElement* getExponent() { return upperRight; }
00160
00161
00162
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
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
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
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
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
00267 virtual QString formulaString();
00268
00269 protected:
00270
00271
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
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