lib Library API Documentation

basicelement.h

00001 /* This file is part of the KDE project 00002 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org> 00003 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #ifndef BASICELEMENT_H 00022 #define BASICELEMENT_H 00023 00024 // Qt Include 00025 #include <qdom.h> 00026 #include <qptrlist.h> 00027 #include <qstring.h> 00028 00029 // KDE Include 00030 00031 // Formula include 00032 #include "contextstyle.h" 00033 #include "kformuladefs.h" 00034 00035 class QKeyEvent; 00036 00037 class KCommand; 00038 00039 KFORMULA_NAMESPACE_BEGIN 00040 00041 class ComplexElement; 00042 class Container; 00043 class ElementType; 00044 class ElementVisitor; 00045 class FontCommand; 00046 class FormulaCursor; 00047 class FormulaElement; 00048 class SequenceElement; 00049 00050 00074 class BasicElement 00075 { 00076 friend class SequenceElement; 00077 friend class SequenceParser; 00078 00079 BasicElement& operator= ( const BasicElement& ) { return *this; } 00080 public: 00081 00082 /* 00083 * Each element might contain children. Each child needs 00084 * its own unique number. It is not guaranteed, however, 00085 * that the number stays the same all the time. 00086 * (The SequenceElement's children are simply counted.) 00087 */ 00088 00089 BasicElement(BasicElement* parent = 0); 00090 virtual ~BasicElement(); 00091 00092 // deep copy 00093 BasicElement( const BasicElement& ); 00094 00095 virtual BasicElement* clone() = 0; 00096 00100 virtual bool accept( ElementVisitor* ) = 0; 00101 00106 virtual bool readOnly( const BasicElement* child ) const; 00107 00111 virtual FormulaElement* formula(); 00112 00116 virtual const FormulaElement* formula() const { return parent->formula(); } 00117 00123 virtual QChar getCharacter() const { return QChar::null; } 00124 00129 virtual TokenType getTokenType() const { return ELEMENT; } 00130 00134 virtual bool isInvisible() const { return false; } 00135 00142 virtual BasicElement* goToPos( FormulaCursor*, bool& handled, 00143 const LuPixelPoint& point, const LuPixelPoint& parentOrigin ); 00144 00148 LuPixelPoint widgetPos(); 00149 00150 00151 // drawing 00152 // 00153 // Drawing depends on a context which knows the required properties like 00154 // fonts, spaces and such. 00155 // It is essential to calculate elements size with the same context 00156 // before you draw. 00157 00162 virtual void calcSizes(const ContextStyle& context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle) = 0; 00163 00169 virtual void draw( QPainter& painter, const LuPixelRect& r, 00170 const ContextStyle& context, 00171 ContextStyle::TextStyle tstyle, 00172 ContextStyle::IndexStyle istyle, 00173 const LuPixelPoint& parentOrigin ) = 0; 00174 00175 00179 virtual void dispatchFontCommand( FontCommand* /*cmd*/ ) {} 00180 00181 // navigation 00182 // 00183 // The elements are responsible to handle cursor movement themselves. 00184 // To do this they need to know the direction the cursor moves and 00185 // the element it comes from. 00186 // 00187 // The cursor might be in normal or in selection mode. 00188 00194 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from); 00195 00201 virtual void moveRight(FormulaCursor* cursor, BasicElement* from); 00202 00208 virtual void moveUp(FormulaCursor*, BasicElement*) {} 00209 00215 virtual void moveDown(FormulaCursor*, BasicElement* ) {} 00216 00221 virtual void moveHome(FormulaCursor*) {} 00222 00227 virtual void moveEnd(FormulaCursor*) {} 00228 00233 virtual void goInside(FormulaCursor* cursor); 00234 00239 virtual void entered( SequenceElement* /*child*/ ); 00240 00241 // children 00242 00250 //virtual void removeChild(FormulaCursor* cursor, BasicElement* child) {} 00251 00252 00253 // main child 00254 // 00255 // If an element has children one has to become the main one. 00256 00257 virtual SequenceElement* getMainChild() { return 0; } 00258 //virtual void setMainChild(SequenceElement*) {} 00259 00260 00261 // editing 00262 // 00263 // Insert and remove children. 00264 00271 virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction) {} 00272 00277 virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction) {} 00278 00283 virtual void normalize(FormulaCursor*, Direction); 00284 00285 00291 virtual bool isSenseless() { return false; } 00292 00296 virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor) { return 0; } 00297 00298 00303 virtual void selectChild(FormulaCursor*, BasicElement*) {} 00304 00305 00310 virtual void childWillVanish(FormulaCursor*, BasicElement*) {} 00311 00312 00316 virtual void registerTab( BasicElement* /*tab*/ ) {} 00317 00318 00327 virtual KCommand* buildCommand( Container*, Request* ) { return 0; } 00328 00334 virtual KCommand* input( Container*, QKeyEvent* ) { return 0; } 00335 00336 // basic support 00337 00338 const BasicElement* getParent() const { return parent; } 00339 BasicElement* getParent() { return parent; } 00340 void setParent(BasicElement* p) { parent = p; } 00341 00342 luPixel getX() const { return m_x; } 00343 luPixel getY() const { return m_y; } 00344 00345 void setX( luPixel x ) { m_x = x; } 00346 void setY( luPixel y ) { m_y = y; } 00347 00348 //QSize getSize() { return size; } 00349 00350 luPixel getWidth() const { return m_width; } 00351 luPixel getHeight() const { return m_height; } 00352 00353 void setWidth( luPixel width ) { m_width = width; } 00354 void setHeight( luPixel height ) { m_height = height; } 00355 00356 luPixel getBaseline() const { return m_baseline; } 00357 void setBaseline( luPixel line ) { m_baseline = line; } 00358 00359 luPixel axis( const ContextStyle& style, ContextStyle::TextStyle tstyle ) const { 00360 return getBaseline() - style.axisHeight( tstyle ); } 00361 00367 QDomElement getElementDom(QDomDocument& doc); 00368 00372 virtual void writeMathML( QDomDocument doc, QDomNode parent ); 00373 00378 bool buildFromDom(QDomElement element); 00379 00383 //bool buildFromMathMLDom( QDomElement& element ); 00384 00385 // debug 00386 static int getEvilDestructionCount() { return evilDestructionCount; } 00387 00392 ElementType* getElementType() const { return elementType; } 00393 00397 virtual void setElementType(ElementType* t) { elementType = t; } 00398 00399 protected: 00400 00401 //Save/load support 00402 00406 virtual QString getTagName() const { return "BASIC"; } 00407 00411 virtual void writeDom(QDomElement element); 00412 00417 virtual bool readAttributesFromDom(QDomElement element); 00418 00424 virtual bool readContentFromDom(QDomNode& node); 00425 00426 00433 bool buildChild( SequenceElement* child, QDomNode node, QString name ); 00434 00435 00440 virtual QString toLatex(); 00441 00442 virtual QString formulaString() { return ""; } 00443 00444 private: 00445 00451 BasicElement* parent; 00452 00456 //QSize size; 00457 luPixel m_width; 00458 luPixel m_height; 00459 00463 //KoPoint position; 00464 luPixel m_x; 00465 luPixel m_y; 00466 00475 luPixel m_baseline; 00476 00483 //luPixel m_axis; 00484 00489 ElementType* elementType; 00490 00491 // debug 00492 static int evilDestructionCount; 00493 }; 00494 00495 KFORMULA_NAMESPACE_END 00496 00497 #endif // BASICELEMENT_H
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Sep 24 18:22:21 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003