lib Library API Documentation

basicelement.cc

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 #include <qstring.h> 00022 #include <kdebug.h> 00023 00024 #include "contextstyle.h" 00025 #include "basicelement.h" 00026 #include "formulacursor.h" 00027 #include "formulaelement.h" 00028 #include "sequenceelement.h" 00029 00030 KFORMULA_NAMESPACE_BEGIN 00031 using namespace std; 00032 00033 00034 int BasicElement::evilDestructionCount = 0; 00035 00036 BasicElement::BasicElement( BasicElement* p ) 00037 : parent( p ), m_baseline( 0 ), elementType( 0 ) 00038 { 00039 setX( 0 ); 00040 setY( 0 ); 00041 setWidth( 0 ); 00042 setHeight( 0 ); 00043 evilDestructionCount++; 00044 } 00045 00046 BasicElement::~BasicElement() 00047 { 00048 evilDestructionCount--; 00049 } 00050 00051 BasicElement::BasicElement( const BasicElement& other ) 00052 : parent( 0 ), 00053 m_baseline( other.m_baseline ), 00054 elementType( other.elementType ) 00055 { 00056 setX( other.getX() ); 00057 setY( other.getY() ); 00058 setWidth( other.getWidth() ); 00059 setHeight( other.getHeight() ); 00060 evilDestructionCount++; 00061 } 00062 00063 00064 bool BasicElement::readOnly( const BasicElement* /*child*/ ) const 00065 { 00066 return parent->readOnly( this ); 00067 } 00068 00069 00070 FormulaElement* BasicElement::formula() 00071 { 00072 //if ( parent != 0 ) { 00073 return parent->formula(); 00074 //} 00075 //return 0; 00076 } 00077 00078 00082 BasicElement* BasicElement::goToPos( FormulaCursor*, bool&, 00083 const LuPixelPoint& point, const LuPixelPoint& parentOrigin ) 00084 { 00085 luPixel x = point.x() - (parentOrigin.x() + getX()); 00086 if ((x >= 0) && (x < getWidth())) { 00087 luPixel y = point.y() - (parentOrigin.y() + getY()); 00088 if ((y >= 0) && (y < getHeight())) { 00089 return this; 00090 } 00091 } 00092 return 0; 00093 } 00094 00098 LuPixelPoint BasicElement::widgetPos() 00099 { 00100 luPixel x = 0; 00101 luPixel y = 0; 00102 for (BasicElement* element = this; element != 0; element = element->parent) { 00103 x += element->getX(); 00104 y += element->getY(); 00105 } 00106 return LuPixelPoint(x, y); 00107 } 00108 00109 00114 void BasicElement::goInside(FormulaCursor* cursor) 00115 { 00116 BasicElement* mainChild = getMainChild(); 00117 if (mainChild != 0) { 00118 mainChild->goInside(cursor); 00119 } 00120 } 00121 00122 00123 void BasicElement::entered( SequenceElement* /*child*/ ) 00124 { 00125 formula()->tell( "" ); 00126 } 00127 00128 00134 void BasicElement::moveLeft(FormulaCursor* cursor, BasicElement*) 00135 { 00136 getParent()->moveLeft(cursor, this); 00137 } 00138 00139 00145 void BasicElement::moveRight(FormulaCursor* cursor, BasicElement*) 00146 { 00147 getParent()->moveRight(cursor, this); 00148 } 00149 00150 00155 void BasicElement::normalize(FormulaCursor* cursor, Direction direction) 00156 { 00157 BasicElement* element = getMainChild(); 00158 if (element != 0) { 00159 if (direction == beforeCursor) { 00160 element->moveLeft(cursor, this); 00161 } 00162 else { 00163 element->moveRight(cursor, this); 00164 } 00165 } 00166 } 00167 00168 00169 QDomElement BasicElement::getElementDom(QDomDocument& doc) 00170 { 00171 QDomElement de = doc.createElement(getTagName()); 00172 writeDom(de); 00173 return de; 00174 } 00175 00176 00177 void BasicElement::writeMathML( QDomDocument doc, QDomNode parent ) 00178 { 00179 parent.appendChild( doc.createComment( QString( "MathML Error in %1" ) 00180 .arg( getTagName() ) ) ); 00181 } 00182 00183 bool BasicElement::buildFromDom(QDomElement element) 00184 { 00185 if (element.tagName() != getTagName()) { 00186 kdWarning( DEBUGID ) << "Wrong tag name " << element.tagName().latin1() << " for " << getTagName().latin1() << ".\n"; 00187 return false; 00188 } 00189 if (!readAttributesFromDom(element)) { 00190 return false; 00191 } 00192 QDomNode node = element.firstChild(); 00193 return readContentFromDom(node); 00194 } 00195 00199 void BasicElement::writeDom(QDomElement) 00200 { 00201 } 00202 00207 bool BasicElement::readAttributesFromDom(QDomElement) 00208 { 00209 return true; 00210 } 00211 00217 bool BasicElement::readContentFromDom(QDomNode&) 00218 { 00219 return true; 00220 } 00221 00222 00227 bool BasicElement::buildChild( SequenceElement* child, QDomNode node, QString name ) 00228 { 00229 if (node.isElement()) { 00230 QDomElement e = node.toElement(); 00231 if (e.tagName().upper() == name) { 00232 QDomNode nodeInner = e.firstChild(); 00233 if (nodeInner.isElement()) { 00234 QDomElement element = nodeInner.toElement(); 00235 return child->buildFromDom( element ); 00236 } 00237 } 00238 } 00239 return false; 00240 } 00241 00242 QString BasicElement::toLatex() 00243 { 00244 return "{}"; 00245 } 00246 00247 KFORMULA_NAMESPACE_END
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