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
00129
00130
00131
00132
00133
00134
00135
00136
00142 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00143
00149 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00150
00155 virtual void moveWordLeft(FormulaCursor* cursor);
00156
00161 virtual void moveWordRight(FormulaCursor* cursor);
00162
00168 virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
00169
00175 virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
00176
00181 virtual void moveHome(FormulaCursor* cursor);
00182
00187 virtual void moveEnd(FormulaCursor* cursor);
00188
00193 virtual void goInside(FormulaCursor* cursor);
00194
00195
00196
00197
00205 virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00206
00211 virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00212
00217 virtual void normalize(FormulaCursor*, Direction);
00218
00223 virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor);
00224
00229 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00230
00235 virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child);
00236
00240 int countChildren() const { return children.count(); }
00241
00245 bool isChildNumber( uint pos, BasicElement* child )
00246 { return children.at( pos ) == child; }
00247
00251 void selectAllChildren(FormulaCursor* cursor);
00252
00253 bool onlyTextSelected( FormulaCursor* cursor );
00254
00255
00264 virtual KCommand* buildCommand( Container*, Request* );
00265
00266
00272 virtual KCommand* input( Container* container, QChar ch );
00273 virtual KCommand* input( Container* container, QKeyEvent* event );
00274
00279 virtual void parse();
00280
00284 void getChildrenDom(QDomDocument doc, QDomElement elem, uint from, uint to);
00285
00291 bool buildChildrenFromDom(QPtrList<BasicElement>& list, QDomNode n);
00292
00297 virtual QString toLatex();
00298
00299 virtual QString formulaString();
00300
00301 virtual void writeMathML( QDomDocument doc, QDomNode parent );
00302
00306 BasicElement* getChild(uint i) { return children.at(i); }
00307
00308
00309 int childPos( BasicElement* child ) { return children.find( child ); }
00310 int childPos( const BasicElement* child ) const;
00311
00312 class ChildIterator {
00313 public:
00314 ChildIterator( SequenceElement* sequence, int pos=0 )
00315 : m_sequence( sequence ), m_pos( pos ) {}
00316
00317 typedef BasicElement value_type;
00318 typedef BasicElement* pointer;
00319 typedef BasicElement& reference;
00320
00321
00322
00323 bool operator== ( const ChildIterator& it ) const
00324 { return m_pos==it.m_pos; }
00325 bool operator!= ( const ChildIterator& it ) const
00326 { return m_pos!=it.m_pos; }
00327
00328 const BasicElement& operator* () const
00329 { return *m_sequence->getChild( m_pos ); }
00330 BasicElement& operator* ()
00331 { return *m_sequence->getChild( m_pos ); }
00332
00333 ChildIterator& operator++ ()
00334 { ++m_pos; return *this; }
00335 ChildIterator operator++ ( int )
00336 { ChildIterator it( *this ); ++m_pos; return it; }
00337 ChildIterator& operator-- ()
00338 { --m_pos; return *this; }
00339 ChildIterator operator-- ( int )
00340 { ChildIterator it( *this ); --m_pos; return it; }
00341 ChildIterator& operator+= ( int j )
00342 { m_pos+=j; return *this; }
00343 ChildIterator & operator-= ( int j )
00344 { m_pos-=j; return *this; }
00345
00346 private:
00347 SequenceElement* m_sequence;
00348 int m_pos;
00349 };
00350
00351 typedef ChildIterator iterator;
00352
00353 iterator begin() { return ChildIterator( this, 0 ); }
00354 iterator end() { return ChildIterator( this, countChildren() ); }
00355
00356 static void setCreationStrategy( ElementCreationStrategy* strategy );
00357
00358 protected:
00359
00360
00361
00365 virtual QString getTagName() const { return "SEQUENCE"; }
00366
00370 virtual void writeDom(QDomElement element);
00371
00376 virtual bool readAttributesFromDom(QDomElement element);
00377
00383 virtual bool readContentFromDom(QDomNode& node);
00384
00391 virtual void setChildrenPositions();
00392
00398 virtual BasicElement* createElement(QString type);
00399
00405 luPixel getChildPosition( const ContextStyle& context, uint child );
00406
00410 virtual bool isFirstOfToken( BasicElement* child );
00411
00412 private:
00413
00417 void removeChild(QPtrList<BasicElement>& removedChildren, int pos);
00418
00419
00424 QPtrList<BasicElement> children;
00425
00429 ElementType* parseTree;
00430
00434 bool textSequence;
00435
00436 static ElementCreationStrategy* creationStrategy;
00437 };
00438
00439
00444 class NameSequence : public SequenceElement {
00445 typedef SequenceElement inherited;
00446 public:
00447
00448 NameSequence( BasicElement* parent = 0 );
00449
00450 virtual NameSequence* clone() {
00451 return new NameSequence( *this );
00452 }
00453
00454 virtual bool accept( ElementVisitor* visitor );
00455
00459
00460
00466 virtual QChar getCharacter() const { return '\\'; }
00467
00472 virtual TokenType getTokenType() const { return NAME; }
00473
00477 virtual SequenceElement* getMainChild() { return this; }
00478
00479 virtual void calcCursorSize( const ContextStyle& context,
00480 FormulaCursor* cursor, bool smallCursor );
00481
00485 virtual void drawCursor( QPainter& painter, const ContextStyle& context,
00486 FormulaCursor* cursor, bool smallCursor );
00487
00492 virtual void moveWordLeft(FormulaCursor* cursor);
00493
00498 virtual void moveWordRight(FormulaCursor* cursor);
00499
00508 virtual KCommand* buildCommand( Container*, Request* );
00509
00510
00516 virtual KCommand* input( Container* container, QChar ch );
00517
00521 virtual void setElementType( ElementType* t );
00522
00526 BasicElement* replaceElement( const SymbolTable& table );
00527
00532 static bool isValidSelection( FormulaCursor* cursor );
00533
00534 virtual void writeMathML( QDomDocument doc, QDomNode parent );
00535
00536 protected:
00537
00541 virtual QString getTagName() const { return "NAMESEQUENCE"; }
00542
00548 virtual BasicElement* createElement( QString type );
00549
00554
00555
00561 virtual bool isFirstOfToken( BasicElement* ) { return false; }
00562
00563 private:
00564
00565 KCommand* compactExpressionCmd( Container* container );
00566
00567 QString buildName();
00568 };
00569
00570 KFORMULA_NAMESPACE_END
00571
00572 #endif // SEQUENCEELEMENT_H