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& 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
00101
00102
00103
00104
00105
00106
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
00137
00145
00146
00147
00148
00149
00150
00151
00152 virtual SequenceElement* getMainChild() { return content; }
00153
00154
00155 SequenceElement* getExponent() { return upperRight; }
00156
00157
00158
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
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
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
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
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
00263 virtual QString formulaString();
00264
00265 virtual void writeMathML( QDomDocument& doc, QDomNode parent, bool oasisFormat = false );
00266
00267 protected:
00268
00269
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
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