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

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net>
00003    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
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., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "UnderOverElement.h"
00022 #include "ElementFactory.h"
00023 #include <KoXmlWriter.h>
00024 
00025 namespace KFormula {
00026 
00027 UnderOverElement::UnderOverElement( BasicElement* parent ) : BasicElement( parent )
00028 {
00029     m_baseElement = new BasicElement( this );
00030     m_underElement = new BasicElement( this );
00031     m_overElement = new BasicElement( this );
00032 }
00033 
00034 UnderOverElement::~UnderOverElement()
00035 {
00036     delete m_baseElement;
00037     delete m_underElement;
00038     delete m_overElement;
00039 }
00040 
00041 const QList<BasicElement*> UnderOverElement::childElements()
00042 {
00043     QList<BasicElement*> tmp;
00044     return tmp << m_baseElement << m_underElement << m_overElement;
00045 }
00046 
00047 /* 
00048  * TODO: Upgrade to new API
00049  */
00050 bool UnderOverElement::readAttributesFromMathMLDom( const QDomElement& element )
00051 {
00052     if ( !BasicElement::readAttributesFromMathMLDom( element ) ) {
00053         return false;
00054     }
00055 
00056     QString tag = element.tagName().stripWhiteSpace().lower();
00057 
00058     if ( tag == "munder" || tag == "munderover" ) {
00059         QString accentunderStr = element.attribute( "accentunder" ).stripWhiteSpace().lower();
00060         if ( ! accentunderStr.isNull() ) {
00061             if ( accentunderStr == "true" ) {
00062                 m_customAccentUnder = true;
00063                 m_accentUnder = true;
00064             }
00065             else if ( accentunderStr == "false" ) {
00066                 m_customAccentUnder = true;
00067                 m_accentUnder = false;
00068             }
00069             else {
00070                 kdWarning( DEBUGID ) << "Invalid value for attribute `accentunder': " 
00071                                      << accentunderStr << endl;
00072             }
00073         }
00074     }
00075     if ( tag == "mover" || tag == "munderover" ) {
00076         QString accentStr = element.attribute( "accent" ).stripWhiteSpace().lower();
00077         if ( ! accentStr.isNull() ) {
00078             if ( accentStr == "true" ) {
00079                 m_customAccent = true;
00080                 m_accent = true;
00081             }
00082             else if ( accentStr == "false" ) {
00083                 m_customAccent = true;
00084                 m_accent = false;
00085             }
00086             else {
00087                 kdWarning( DEBUGID ) << "Invalid value for attribute `accent': " 
00088                                      << accentStr << endl;
00089             }
00090         }
00091     }
00092     return true;
00093 }
00094 
00095 void UnderOverElement::readMathML( const QDomElement& element )
00096 {
00097     readMathMLAttributes( element );
00098 
00099     if( element.childNodes().count() != 3 && element.childNodes().count() != 2 )
00100         return;
00101 
00102     QDomElement tmp = element.firstChildElement();
00103     delete m_baseElement;
00104     m_baseElement = ElementFactory::createElement( tmp.tagName(), this );
00105     m_baseElement->readMathML( tmp );
00106 
00107     tmp = tmp.nextSiblingElement();
00108     if( element.tagName() == "mover" )
00109     {
00110         delete m_overElement;
00111         m_overElement = ElementFactory::createElement( tmp.tagName(), this );
00112         m_overElement->readMathML( tmp );
00113     }
00114     else
00115     {
00116         delete m_underElement;
00117         m_underElement = ElementFactory::createElement( tmp.tagName(), this );
00118         m_underElement->readMathML( tmp );
00119     }
00120 
00121     tmp = tmp.nextSiblingElement();
00122     if( !tmp.isNull() )
00123     {
00124         delete m_overElement;
00125         m_overElement = ElementFactory::createElement( tmp.tagName(), this );
00126         m_overElement->readMathML( tmp );
00127     }
00128 }
00129 
00130 /*
00131  * TODO: Upgrade to new API
00132  */
00133 void UnderOverElement::writeMathMLAttributes( QDomElement& element ) const
00134 {
00135     QString tag = getElementName();
00136     if ( tag == "munder" || tag == "munderover" ) {
00137         if ( m_customAccentUnder ) {
00138             element.setAttribute( "accentunder", m_accentUnder ? "true" : "false" );
00139         }
00140     }
00141     if ( tag == "mover" || tag == "munderover" ) {
00142         if ( m_customAccent ) {
00143             element.setAttribute( "accent", m_accent ? "true" : "false" );
00144         }
00145     }
00146 }
00147 
00148 
00149 void UnderOverElement::writeMathML( KoXmlWriter* writer, bool oasisFormat )
00150 {
00151     if( m_underElement->elementType() != Basic && m_overElement->elementType() == Basic )
00152     {
00153         writer->startElement( oasisFormat ? "math:munder" : "munder" );
00154         writeMathMLAttributes( writer );
00155         m_baseElement->writeMathML( writer, oasisFormat );
00156         m_underElement->writeMathML( writer, oasisFormat );
00157     }
00158     if( m_overElement->elementType() != Basic && m_underElement->elementType() == Basic )
00159     {
00160         writer->startElement( oasisFormat ? "math:mover" : "mover" );
00161         writeMathMLAttributes( writer );
00162         m_baseElement->writeMathML( writer, oasisFormat );
00163         m_overElement->writeMathML( writer, oasisFormat );
00164     }
00165     else
00166     {
00167         writer->startElement( oasisFormat ? "math:munderover" : "munderover" );
00168         writeMathMLAttributes( writer );
00169         m_baseElement->writeMathML( writer, oasisFormat );
00170         m_underElement->writeMathML( writer, oasisFormat );
00171         m_overElement->writeMathML( writer, oasisFormat );
00172     }
00173 
00174     writer->endElement();
00175 }
00176 
00177 void UnderOverElement::calcSizes( const ContextStyle& context, ContextStyle::TextStyle tstyle,
00178                                   ContextStyle::IndexStyle istyle, StyleAttributes& style)
00179 {
00180 }
00181 
00182 void UnderOverElement::draw( QPainter& painter, const LuPixelRect& r,
00183                              const ContextStyle& context,
00184                              ContextStyle::TextStyle tstyle,
00185                              ContextStyle::IndexStyle istyle,
00186                              StyleAttributes& style,
00187                              const LuPixelPoint& parentOrigin )
00188 {}
00189 
00190 
00191 } // namespace KFormula

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