00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SEQUENCEELEMENT_H
00022 #define SEQUENCEELEMENT_H
00023
00024 #include <qptrlist.h>
00025 #include <qstring.h>
00026
00027 #include "basicelement.h"
00028
00029 class QKeyEvent;
00030
00031 KFORMULA_NAMESPACE_BEGIN
00032
00033 class SymbolTable;
00034 class ElementCreationStrategy;
00035
00040 class SequenceElement : public BasicElement {
00041 SequenceElement& operator=( const SequenceElement& ) { return *this; }
00042 public:
00043
00044 SequenceElement(BasicElement* parent = 0);
00045 ~SequenceElement();
00046
00047 SequenceElement( const SequenceElement& );
00048
00049 virtual SequenceElement* clone() {
00050 return new SequenceElement( *this );
00051 }
00052
00053 virtual bool accept( ElementVisitor* visitor );
00054
00058 virtual bool readOnly( const FormulaCursor* ) const;
00059
00063 virtual bool isTextOnly() const { return textSequence; }
00064
00071 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
00072 const LuPixelPoint& point,
00073 const LuPixelPoint& parentOrigin );
00074
00075
00076
00077
00078
00079
00080
00081
00085 void setSizeReduction(const ContextStyle& context);
00086
00091 bool isEmpty();
00092
00097 virtual void calcSizes(const ContextStyle& context,
00098 ContextStyle::TextStyle tstyle,
00099 ContextStyle::IndexStyle istyle);
00100
00106 virtual void draw( QPainter& painter, const LuPixelRect& r,
00107 const ContextStyle& context,
00108 ContextStyle::TextStyle tstyle,
00109 ContextStyle::IndexStyle istyle,
00110 const LuPixelPoint& parentOrigin );
00111
00115 virtual void dispatchFontCommand( FontCommand* cmd );
00116
00117 virtual void drawEmptyRect( QPainter& painter, const ContextStyle& context,
00118 const LuPixelPoint& upperLeft );
00119
00120 virtual void calcCursorSize( const ContextStyle& context,
00121 FormulaCursor* cursor, bool smallCursor );
00122
00126 virtual void drawCursor( QPainter& painter, const ContextStyle& context,
00127 FormulaCursor* cursor, bool smallCursor,
00128 bool activeCursor );
00129
00130
00131
00132
00133
00134
00135
00136
00137
00143 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00144
00150 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00151
00156 virtual void moveWordLeft(FormulaCursor* cursor);
00157
00162 virtual void moveWordRight(FormulaCursor* cursor);
00163
00169 virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
00170
00176 virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
00177
00182 virtual void moveHome(FormulaCursor* cursor);
00183
00188 virtual void moveEnd(FormulaCursor* cursor);
00189
00194 virtual void goInside(FormulaCursor* cursor);
00195
00196
00197
00198
00206 virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00207
00212 virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00213
00218 virtual void normalize(FormulaCursor*, Direction);
00219
00224 virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor);
00225
00230 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00231
00236 virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child);
00237
00241 int countChildren() const { return children.count(); }
00242
00246 bool isChildNumber( uint pos, BasicElement* child )
00247 { return children.at( pos ) == child; }
00248
00252 void selectAllChildren(FormulaCursor* cursor);
00253
00254 bool onlyTextSelected( FormulaCursor* cursor );
00255
00256
00265 virtual KCommand* buildCommand( Container*, Request* );
00266
00267
00273 virtual KCommand* input( Container* container, QChar ch );
00274 virtual KCommand* input( Container* container, QKeyEvent* event );
00275
00280 virtual void parse();
00281
00285 void getChildrenDom( QDomDocument& doc, QDomElement elem, uint from, uint to);
00286
00292 bool buildChildrenFromDom(QPtrList<BasicElement>& list, QDomNode n);
00293
00298 virtual QString toLatex();
00299
00300 virtual QString formulaString();
00301
00302 virtual void writeMathML( QDomDocument& doc, QDomNode parent, bool oasisFormat = false );
00303
00307 BasicElement* getChild(uint i) { return children.at(i); }
00308
00309
00310 int childPos( BasicElement* child ) { return children.find( child ); }
00311 int childPos( const BasicElement* child ) const;
00312
00313 class ChildIterator {
00314 public:
00315 ChildIterator( SequenceElement* sequence, int pos=0 )
00316 : m_sequence( sequence ), m_pos( pos ) {}
00317
00318 typedef BasicElement value_type;
00319 typedef BasicElement* pointer;
00320 typedef BasicElement& reference;
00321
00322
00323
00324 bool operator== ( const ChildIterator& it ) const
00325 { return m_pos==it.m_pos; }
00326 bool operator!= ( const ChildIterator& it ) const
00327 { return m_pos!=it.m_pos; }
00328
00329 const BasicElement& operator* () const
00330 { return *m_sequence->getChild( m_pos ); }
00331 BasicElement& operator* ()
00332 { return *m_sequence->getChild( m_pos ); }
00333
00334 ChildIterator& operator++ ()
00335 { ++m_pos; return *this; }
00336 ChildIterator operator++ ( int )
00337 { ChildIterator it( *this ); ++m_pos; return it; }
00338 ChildIterator& operator-- ()
00339 { --m_pos; return *this; }
00340 ChildIterator operator-- ( int )
00341 { ChildIterator it( *this ); --m_pos; return it; }
00342 ChildIterator& operator+= ( int j )
00343 { m_pos+=j; return *this; }
00344 ChildIterator & operator-= ( int j )
00345 { m_pos-=j; return *this; }
00346
00347 private:
00348 SequenceElement* m_sequence;
00349 int m_pos;
00350 };
00351
00352 typedef ChildIterator iterator;
00353
00354 iterator begin() { return ChildIterator( this, 0 ); }
00355 iterator end() { return ChildIterator( this, countChildren() ); }
00356
00357 static void setCreationStrategy( ElementCreationStrategy* strategy );
00358
00359 protected:
00360
00361
00362
00366 virtual QString getTagName() const { return "SEQUENCE"; }
00367
00371 virtual void writeDom(QDomElement element);
00372
00377 virtual bool readAttributesFromDom(QDomElement element);
00378
00384 virtual bool readContentFromDom(QDomNode& node);
00385
00392 virtual void setChildrenPositions();
00393
00399 virtual BasicElement* createElement(QString type);
00400
00407 luPixel getChildPosition( const ContextStyle& context, uint child );
00408
00412 virtual bool isFirstOfToken( BasicElement* child );
00413
00414 private:
00415
00419 void removeChild(QPtrList<BasicElement>& removedChildren, int pos);
00420
00421
00426 QPtrList<BasicElement> children;
00427
00431 ElementType* parseTree;
00432
00436 bool textSequence;
00437
00438 static ElementCreationStrategy* creationStrategy;
00439
00440 bool singlePipe;
00441 };
00442
00443
00448 class NameSequence : public SequenceElement {
00449 typedef SequenceElement inherited;
00450 public:
00451
00452 NameSequence( BasicElement* parent = 0 );
00453
00454 virtual NameSequence* clone() {
00455 return new NameSequence( *this );
00456 }
00457
00458 virtual bool accept( ElementVisitor* visitor );
00459
00463
00464
00470 virtual QChar getCharacter() const { return '\\'; }
00471
00476 virtual TokenType getTokenType() const { return NAME; }
00477
00481 virtual SequenceElement* getMainChild() { return this; }
00482
00483 virtual void calcCursorSize( const ContextStyle& context,
00484 FormulaCursor* cursor, bool smallCursor );
00485
00489 virtual void drawCursor( QPainter& painter, const ContextStyle& context,
00490 FormulaCursor* cursor, bool smallCursor,
00491 bool activeCursor );
00492
00497 virtual void moveWordLeft(FormulaCursor* cursor);
00498
00503 virtual void moveWordRight(FormulaCursor* cursor);
00504
00513 virtual KCommand* buildCommand( Container*, Request* );
00514
00515
00521 virtual KCommand* input( Container* container, QChar ch );
00522
00526 virtual void setElementType( ElementType* t );
00527
00531 BasicElement* replaceElement( const SymbolTable& table );
00532
00537 static bool isValidSelection( FormulaCursor* cursor );
00538
00539 virtual void writeMathML( QDomDocument& doc, QDomNode parent, bool oasisFormat = false );
00540
00541 protected:
00542
00546 virtual QString getTagName() const { return "NAMESEQUENCE"; }
00547
00553 virtual BasicElement* createElement( QString type );
00554
00559
00560
00566 virtual bool isFirstOfToken( BasicElement* ) { return false; }
00567
00568 private:
00569
00570 KCommand* compactExpressionCmd( Container* container );
00571
00572 QString buildName();
00573 };
00574
00575 KFORMULA_NAMESPACE_END
00576
00577 #endif // SEQUENCEELEMENT_H