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, bool oasisFormat = false );
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 bool singlePipe;
00439 };
00440
00441
00446 class NameSequence : public SequenceElement {
00447 typedef SequenceElement inherited;
00448 public:
00449
00450 NameSequence( BasicElement* parent = 0 );
00451
00452 virtual NameSequence* clone() {
00453 return new NameSequence( *this );
00454 }
00455
00456 virtual bool accept( ElementVisitor* visitor );
00457
00461
00462
00468 virtual QChar getCharacter() const { return '\\'; }
00469
00474 virtual TokenType getTokenType() const { return NAME; }
00475
00479 virtual SequenceElement* getMainChild() { return this; }
00480
00481 virtual void calcCursorSize( const ContextStyle& context,
00482 FormulaCursor* cursor, bool smallCursor );
00483
00487 virtual void drawCursor( QPainter& painter, const ContextStyle& context,
00488 FormulaCursor* cursor, bool smallCursor );
00489
00494 virtual void moveWordLeft(FormulaCursor* cursor);
00495
00500 virtual void moveWordRight(FormulaCursor* cursor);
00501
00510 virtual KCommand* buildCommand( Container*, Request* );
00511
00512
00518 virtual KCommand* input( Container* container, QChar ch );
00519
00523 virtual void setElementType( ElementType* t );
00524
00528 BasicElement* replaceElement( const SymbolTable& table );
00529
00534 static bool isValidSelection( FormulaCursor* cursor );
00535
00536 virtual void writeMathML( QDomDocument& doc, QDomNode parent, bool oasisFormat = false );
00537
00538 protected:
00539
00543 virtual QString getTagName() const { return "NAMESEQUENCE"; }
00544
00550 virtual BasicElement* createElement( QString type );
00551
00556
00557
00563 virtual bool isFirstOfToken( BasicElement* ) { return false; }
00564
00565 private:
00566
00567 KCommand* compactExpressionCmd( Container* container );
00568
00569 QString buildName();
00570 };
00571
00572 KFORMULA_NAMESPACE_END
00573
00574 #endif // SEQUENCEELEMENT_H