F:/KPlato/koffice/libs/kformula/BasicElement.cpp

Aller à la documentation de ce fichier.
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                  2006 Martin Pfeiffer <hubipete@gmx.net>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "BasicElement.h"
00023 #include "FormulaCursor.h"
00024 #include <KoXmlWriter.h>
00025 
00026 #include <kdebug.h>
00027 #include "contextstyle.h"
00028 #include "SequenceElement.h"
00029 
00030 namespace KFormula {
00031 
00032 BasicElement::BasicElement( BasicElement* p ) : m_baseLine( 0.0 ),
00033                                                 m_parentElement( p )
00034 {
00035 }
00036 
00037 BasicElement::~BasicElement()
00038 {
00039     // TODO delete m_attributes 
00040 }
00041 
00042 void BasicElement::paint( QPainter& painter ) const
00043 {
00044     // TODO paint a blue rectangle with boundingRect
00045     // painter.setBrush( Qt::NoBrush );
00046     // painter.setPen( QPen(  ) );
00047     // painter.drawRect( m_boundingRect );
00048 }
00049 
00050 void BasicElement::calculateSize()
00051 {
00052     // set the bounding rect to a default value
00053     // m_boundingRect.setWidth( );
00054     // m_boundingRect.setHeight( ); 
00055 }
00056 
00057 void BasicElement::insertChild( FormulaCursor* cursor, BasicElement* element )
00058 {
00059     m_parentElement->insertChild( cursor, element );
00060 }
00061 
00062 void BasicElement::removeChild( BasicElement* )
00063 {   // do nothing a BasicElement has no children
00064 }
00065 
00066 const QList<BasicElement*> BasicElement::childElements() 
00067 {
00068     return QList<BasicElement*>();
00069 }
00070 
00071 const QRectF& BasicElement::boundingRect() const
00072 {
00073     return m_boundingRect;
00074 }
00075 
00076 double BasicElement::height() const
00077 {
00078     return m_boundingRect.height();
00079 }
00080 
00081 double BasicElement::width() const
00082 {
00083     return m_boundingRect.width();
00084 }
00085 
00086 double BasicElement::baseLine() const
00087 {
00088     return m_baseLine;
00089 }
00090 
00091 QPointF BasicElement::origin() const
00092 {
00093     return m_boundingRect.topLeft();
00094 }
00095 
00096 void BasicElement::setWidth( double width )
00097 {
00098     m_boundingRect.setWidth( width );
00099 }
00100 
00101 void BasicElement::setHeight( double height )
00102 {
00103     m_boundingRect.setHeight( height );
00104 }
00105 
00106 void BasicElement::setOrigin( QPointF origin )
00107 {
00108     m_boundingRect.setTopLeft( origin );
00109 }
00110 
00111 void BasicElement::setBaseLine( double baseLine )
00112 {
00113     m_baseLine = baseLine;
00114 }
00115 
00116 void BasicElement::setParentElement( BasicElement* parent )
00117 {
00118     m_parentElement = parent;
00119 }
00120 
00121 ElementType BasicElement::elementType() const
00122 {
00123     return m_elementType;
00124 }
00125 
00126 BasicElement* BasicElement::parentElement() const
00127 {
00128     return m_parentElement;
00129 }
00130 
00131 BasicElement* BasicElement::childElementAt( const QPointF& p )
00132 {
00133     if( !m_boundingRect.contains( p ) )
00134         return 0;
00135                 
00136     if( childElements().isEmpty() ) 
00137         return this;
00138               
00139     BasicElement* ownerElement = 0;
00140     foreach( BasicElement* tmpElement, childElements() )  
00141     {
00142         ownerElement = tmpElement->childElementAt( p );
00143         
00144         if( ownerElement )
00145             return ownerElement;
00146     }
00147     
00148     return this;    // if no child contains the point, it's the FormulaElement itsself
00149 }
00150 
00151 QString BasicElement::inheritAttribute( const QString& attribute ) const
00152 {
00153     if( !m_attributes.contains( attribute ) )
00154         return QString();
00155     else
00156         m_attributes.value( attribute );
00157 }
00158 
00159 void BasicElement::moveLeft( FormulaCursor* cursor, BasicElement* )
00160 {
00161     if( cursor->currentElement() == this )
00162         parentElement()->moveLeft( cursor, this );
00163     else
00164         cursor->setCursorTo( this, 0 );
00165 }
00166 
00167 void BasicElement::moveRight( FormulaCursor* cursor, BasicElement* )
00168 {
00169     if( cursor->currentElement() == this )
00170         parentElement()->moveRight( cursor, this );
00171     else
00172         cursor->setCursorTo( this, 0 );
00173 }
00174 
00175 void BasicElement::moveUp( FormulaCursor* cursor, BasicElement* )
00176 {
00177     if( cursor->currentElement() == this )
00178         parentElement()->moveUp( cursor, this );
00179     else
00180         cursor->setCursorTo( this, 0 );
00181 }
00182 
00183 void BasicElement::moveDown( FormulaCursor* cursor, BasicElement* )
00184 {
00185     if( cursor->currentElement() == this )
00186         parentElement()->moveDown( cursor, this );
00187     else
00188         cursor->setCursorTo( this, 0 );
00189 }
00190 
00191 void BasicElement::moveHome( FormulaCursor* cursor )
00192 {
00193     parentElement()->moveHome( cursor );
00194 }
00195 
00196 void BasicElement::moveEnd( FormulaCursor* cursor )
00197 {
00198     parentElement()->moveEnd( cursor );
00199 }
00200 
00201 void BasicElement::readMathML( const QDomElement& element )
00202 {
00203     readMathMLAttributes( element );
00204 }
00205 
00206 void BasicElement::readMathMLAttributes( const QDomElement& element )
00207 {
00208     QDomAttr attribute;
00209     int attributeCount = element.attributes().count();
00210     for( int i = 0; i < attributeCount; i++ )
00211     {
00212          attribute = element.attributes().item( i ).toAttr();
00213          m_attributes.insert( attribute.name(), attribute.value() );
00214     }
00215 }
00216 
00217 void BasicElement::writeMathML( KoXmlWriter* , bool )
00218 {
00219 }
00220 
00221 void BasicElement::writeMathMLAttributes( KoXmlWriter* writer )
00222 {
00223     foreach( QString value, m_attributes )
00224         writer->addAttribute( m_attributes.key( value ).toLatin1(), value );
00225 }
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 void BasicElement::calcSizes(const ContextStyle& context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle)
00240 {
00241 }
00242 
00243 void BasicElement::draw( QPainter& painter, const LuPixelRect& r,
00244                        const ContextStyle& context,
00245                              ContextStyle::TextStyle tstyle,
00246                              ContextStyle::IndexStyle istyle,
00247                             const LuPixelPoint& parentOrigin )
00248 
00249 {}
00250 
00251 bool BasicElement::readOnly( const BasicElement* /*child*/ ) const
00252 {
00253     return m_parentElement->readOnly( this );
00254 }
00255 
00259 LuPixelPoint BasicElement::widgetPos()
00260 {
00261     luPixel x = 0;
00262     luPixel y = 0;
00263     for (BasicElement* element = this; element != 0; element = element->getParent()) {
00264         x += element->getX();
00265         y += element->getY();
00266     }
00267     return LuPixelPoint(x, y);
00268 }
00269 
00274 void BasicElement::goInside(FormulaCursor* cursor)
00275 {
00276     BasicElement* mainChild = getMainChild();
00277     if (mainChild != 0) {
00278       mainChild->goInside(cursor);
00279     }
00280 }
00281 
00286 void BasicElement::normalize(FormulaCursor* cursor, Direction direction)
00287 {
00288     BasicElement* element = getMainChild();
00289     if (element != 0) {
00290         if (direction == beforeCursor) {
00291             element->moveLeft(cursor, this);
00292         }
00293         else {
00294             element->moveRight(cursor, this);
00295         }
00296     }
00297 }
00298 
00299 QDomElement BasicElement::getElementDom( QDomDocument& doc)
00300 {
00301     QDomElement de = doc.createElement(getTagName());
00302     writeDom(de);
00303     return de;
00304 }
00305 
00306 bool BasicElement::buildFromDom(QDomElement element)
00307 {
00308     if (element.tagName() != getTagName()) {
00309         kWarning( DEBUGID ) << "Wrong tag name " << element.tagName().toLatin1() << " for " << getTagName().toLatin1() << ".\n";
00310         return false;
00311     }
00312     if (!readAttributesFromDom(element)) {
00313         return false;
00314     }
00315     QDomNode node = element.firstChild();
00316     return readContentFromDom(node);
00317 }
00318 
00322 void BasicElement::writeDom(QDomElement)
00323 {
00324 }
00325 
00330 bool BasicElement::readAttributesFromDom(QDomElement)
00331 {
00332     return true;
00333 }
00334 
00340 bool BasicElement::readContentFromDom(QDomNode&)
00341 {
00342     return true;
00343 }
00344 
00345 
00350 bool BasicElement::buildChild( SequenceElement* child, QDomNode node, const QString & name )
00351 {
00352     if (node.isElement()) {
00353         QDomElement e = node.toElement();
00354         if (e.tagName().toUpper() == name) {
00355             QDomNode nodeInner = e.firstChild();
00356             if (nodeInner.isElement()) {
00357                 QDomElement element = nodeInner.toElement();
00358                 return child->buildFromDom( element );
00359             }
00360         }
00361     }
00362     return false;
00363 }
00364 
00365 
00366 
00367 void BasicElement::setX( double x )
00368 {
00369     m_boundingRect.setX( x );
00370 }
00371 
00372 void BasicElement::setY( double y )
00373 {
00374     m_boundingRect.setY( y );
00375 }
00376 
00377 double BasicElement::getHeight() const
00378 {
00379     return m_boundingRect.height();
00380 }
00381 
00382 double BasicElement::getWidth() const
00383 {
00384     return m_boundingRect.width();
00385 }
00386 
00387 double BasicElement::getY() const
00388 {
00389     return m_boundingRect.y();
00390 }
00391 
00392 double BasicElement::getX() const
00393 {
00394     return m_boundingRect.x();
00395 }
00396 
00397 
00398 
00399 } // namespace KFormula

Généré le Wed Nov 22 23:41:00 2006 pour KPlato par  doxygen 1.5.1-p1