F:/KPlato/koffice/libs/kformula/FormulaElement.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    Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net>
00005    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <QKeyEvent>
00024 //#include <QPainter>
00025 
00026 #include <kdebug.h>
00027 
00028 #include <KoXmlWriter.h>
00029 
00030 #include "contextstyle.h"
00031 #include "FormulaContainer.h"
00032 #include "FormulaCursor.h"
00033 #include "FormulaElement.h"
00034 
00035 namespace KFormula {
00036 
00037 FormulaElement::FormulaElement() : BasicElement( 0 ),
00038                                    baseSize( 20 ),
00039                                    ownBaseSize( false )
00040 {
00041 }
00042 
00043 FormulaElement::~FormulaElement()
00044 {
00045     foreach( BasicElement* tmpElement, m_childElements )    // delete all child elements
00046         delete tmpElement;
00047 }
00048 
00049 const QList<BasicElement*> FormulaElement::childElements()
00050 {
00051     return m_childElements;
00052 }
00053 
00054 void FormulaElement::readMathML( const QDomElement& element )
00055 {
00056     readMathMLAttributes( element );
00057 }
00058 
00059 void FormulaElement::writeMathML( KoXmlWriter* writer, bool oasisFormat )
00060 {
00061     if( oasisFormat )
00062         writer->startElement( "math:semantics" );
00063     else
00064         writer->startDocument( "math", "http://www.w3.org/1998/Math/MathML" );
00065 
00066     foreach( BasicElement* tmpElement, m_childElements )
00067         tmpElement->writeMathML( writer, oasisFormat );
00068     
00069     if( oasisFormat )
00070         writer->endElement();
00071     else
00072         writer->endDocument();
00073 }
00074 
00075 
00076 
00077 
00078 
00079 void FormulaElement::setBaseSize( int size )
00080 {
00081     if ( size > 0 ) {
00082         baseSize = size;
00083         ownBaseSize = true;
00084     }
00085     else {
00086         ownBaseSize = false;
00087     }
00088 //    m_document->baseSizeChanged( size, ownBaseSize );
00089 }
00090 
00091 
00092 
00093 
00094 void FormulaElement::elementRemoval(BasicElement* child)
00095 {
00096  //   m_document->elementRemoval(child);
00097 }
00098 
00099 void FormulaElement::changed()
00100 {
00101 //    m_document->changed();
00102 }
00103 
00104 void FormulaElement::cursorHasMoved( FormulaCursor* cursor )
00105 {
00106 //    m_document->cursorHasMoved( cursor );
00107 }
00108 
00109 void FormulaElement::moveOutLeft( FormulaCursor* cursor )
00110 {
00111 //    m_document->moveOutLeft( cursor );
00112 }
00113 
00114 void FormulaElement::moveOutRight( FormulaCursor* cursor )
00115 {
00116 //    m_document->moveOutRight( cursor );
00117 }
00118 
00119 void FormulaElement::moveOutBelow( FormulaCursor* cursor )
00120 {
00121   //  m_document->moveOutBelow( cursor );
00122 }
00123 
00124 void FormulaElement::moveOutAbove( FormulaCursor* cursor )
00125 {
00126     //m_document->moveOutAbove( cursor );
00127 }
00128 
00129 void FormulaElement::removeFormula( FormulaCursor* cursor )
00130 {
00131   //  m_document->removeFormula( cursor );
00132 }
00133 
00134 void FormulaElement::insertFormula( FormulaCursor* cursor )
00135 {
00136 //    m_document->insertFormula( cursor );
00137 }
00138 
00139 void FormulaElement::calcSizes( const ContextStyle& style,
00140                                 ContextStyle::TextStyle tstyle,
00141                                 ContextStyle::IndexStyle istyle,
00142                                 StyleAttributes& style )
00143 {
00144     //BasicElement::calcSizes( style, tstyle, istyle );
00145 }
00146 
00147 
00148 void FormulaElement::draw( QPainter& painter, const LuPixelRect& r,
00149                            const ContextStyle& context,
00150                            ContextStyle::TextStyle tstyle,
00151                            ContextStyle::IndexStyle istyle,
00152                            StyleAttributes& style,
00153                            const LuPixelPoint& parentOrigin )
00154 {
00155 //    BasicElement::draw( painter, r, context, tstyle, istyle, parentOrigin );
00156 }
00157 
00158 
00162 void FormulaElement::calcSizes( ContextStyle& context )
00163 {
00164     //kDebug( DEBUGID ) << "FormulaElement::calcSizes" << endl;
00165     if ( ownBaseSize ) {
00166         context.setSizeFactor( static_cast<double>( getBaseSize() )/context.baseSize() );
00167     }
00168     else {
00169         context.setSizeFactor( 1 );
00170     }
00171     StyleAttributes style;
00172     calcSizes( context, context.getBaseTextStyle(),
00173                ContextStyle::normal, style );
00174 }
00175 
00179 void FormulaElement::draw( QPainter& painter, const LuPixelRect& r,
00180                            ContextStyle& context )
00181 {
00182     //kDebug( DEBUGID ) << "FormulaElement::draw" << endl;
00183     if ( ownBaseSize ) {
00184         context.setSizeFactor( static_cast<double>( getBaseSize() )/context.baseSize() );
00185     }
00186     else {
00187         context.setSizeFactor( 1 );
00188     }
00189     draw( painter, r, context, context.getBaseTextStyle(),
00190           ContextStyle::normal, style, LuPixelPoint() );
00191 }
00192 
00193 QDomElement FormulaElement::emptyFormulaElement( QDomDocument& doc )
00194 {
00195     QDomElement element = doc.createElement( getTagName() );
00196     /*
00197     element.setAttribute( "VERSION", "6" );
00198     if ( ownBaseSize ) {
00199         element.setAttribute( "BASESIZE", baseSize );
00200     }
00201     */
00202     return element;
00203 }
00207 void FormulaElement::writeDom(QDomElement element)
00208 {
00209     BasicElement::writeDom(element);
00210     element.setAttribute( "VERSION", "6" );
00211     if ( ownBaseSize ) {
00212         element.setAttribute( "BASESIZE", baseSize );
00213     }
00214 }
00215 
00220 bool FormulaElement::readAttributesFromDom(QDomElement element)
00221 {
00222     if (!BasicElement::readAttributesFromDom(element)) {
00223         return false;
00224     }
00225     int version = -1;
00226     QString versionStr = element.attribute( "VERSION" );
00227     if ( !versionStr.isNull() ) {
00228         version = versionStr.toInt();
00229     }
00230     if ( version > -1 ) {
00231         // Version 6 added the MultilineElement (TabMarker)
00232         // Version 5 added under- and overlines
00233         if ( version < 4 ) {
00234             convertNames( element );
00235         }
00236     }
00237     QString baseSizeStr = element.attribute( "BASESIZE" );
00238     if ( !baseSizeStr.isNull() ) {
00239         ownBaseSize = true;
00240         baseSize = baseSizeStr.toInt();
00241     }
00242     else {
00243         ownBaseSize = false;
00244     }
00245     return true;
00246 }
00247 
00253 bool FormulaElement::readContentFromDom(QDomNode& node)
00254 {
00255     return BasicElement::readContentFromDom(node);
00256 }
00257 
00258 void FormulaElement::convertNames( QDomNode node )
00259 {
00260     if ( node.isElement() && ( node.nodeName().toUpper() == "TEXT" ) ) {
00261         QDomNamedNodeMap attr = node.attributes();
00262         QDomAttr ch = attr.namedItem( "CHAR" ).toAttr();
00263         if ( ch.value() == "\\" ) {
00264             QDomNode sequence = node.parentNode();
00265             QDomDocument doc = sequence.ownerDocument();
00266             QDomElement nameseq = doc.createElement( "NAMESEQUENCE" );
00267             sequence.replaceChild( nameseq, node );
00268 
00269             bool inName = true;
00270             while ( inName ) {
00271                 inName = false;
00272                 QDomNode n = nameseq.nextSibling();
00273                 if ( n.isElement() && ( n.nodeName().toUpper() == "TEXT" ) ) {
00274                     attr = n.attributes();
00275                     ch = attr.namedItem( "CHAR" ).toAttr();
00276                     if ( ch.value().at( 0 ).isLetter() ) {
00277                         nameseq.appendChild( sequence.removeChild( n ) );
00278                         inName = true;
00279                     }
00280                 }
00281             }
00282         }
00283     }
00284     if ( node.hasChildNodes() ) {
00285         QDomNode n = node.firstChild();
00286         while ( !n.isNull() ) {
00287             convertNames( n );
00288             n = n.nextSibling();
00289         }
00290     }
00291 }
00292 
00293 
00294 
00295 } // namespace KFormula

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