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

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qpainter.h>
00021 
00022 #include "elementtype.h"
00023 #include "sequenceelement.h"
00024 #include "textelement.h"
00025 #include "fontstyle.h"
00026 #include "operatorelement.h"
00027 
00028 KFORMULA_NAMESPACE_BEGIN
00029 
00030 OperatorElement::OperatorElement( BasicElement* parent ) : TokenElement( parent ),
00031                                                            m_form( InfixForm ),
00032                                                            m_customForm( false ),
00033                                                            m_customFence( false ),
00034                                                            m_customSeparator( false ),
00035                                                            m_customLSpace( false ),
00036                                                            m_customRSpace( false ),
00037                                                            m_customStretchy( false ),
00038                                                            m_customSymmetric( false ),
00039                                                            m_customMaxSize( false ),
00040                                                            m_customMinSize( false ),
00041                                                            m_customLargeOp( false ),
00042                                                            m_customMovableLimits( false ),
00043                                                            m_customAccent( false )
00044 {
00045 }
00046 
00047 void OperatorElement::setForm( FormType type )
00048 {
00049     m_form = type;
00050 }
00051 
00052 bool OperatorElement::readAttributesFromMathMLDom( const QDomElement &element )
00053 {
00054     if ( ! BasicElement::readAttributesFromMathMLDom( element ) ) {
00055         return false;
00056     }
00057 
00058     QString formStr = element.attribute( "form" ).stripWhiteSpace().lower();
00059     if ( ! formStr.isNull() ) {
00060         m_customForm = true;
00061         if ( formStr == "prefix" ) {
00062             m_form = PrefixForm;
00063         }
00064         else if ( formStr == "infix" ) {
00065             m_form = InfixForm;
00066         }
00067         else if ( formStr == "postfix" ) {
00068             m_form = PostfixForm;
00069         }
00070         else {
00071             kWarning( DEBUGID ) << "Invalid value for attribute `form': " << formStr << endl;
00072             m_customForm = false;
00073         }
00074     }
00075     QString fenceStr = element.attribute( "fence" ).stripWhiteSpace().lower();
00076     if ( ! fenceStr.isNull() ) {
00077         m_customFence = true;
00078         if ( fenceStr == "true" ) {
00079             m_fence = true;
00080         }
00081         else if ( fenceStr == "false" ) {
00082             m_fence = false;
00083         }
00084         else {
00085             kWarning( DEBUGID ) << "Invalid value for attribute `fence': " << fenceStr << endl;
00086             m_customFence = false;
00087         }
00088     }
00089     QString separatorStr = element.attribute( "separator" ).stripWhiteSpace().lower();
00090     if ( ! separatorStr.isNull() ) {
00091         m_customSeparator = true;
00092         if ( separatorStr == "true" ) {
00093             m_separator = true;
00094         }
00095         else if ( separatorStr == "false" ) {
00096             m_separator = false;
00097         }
00098         else {
00099             kWarning( DEBUGID ) << "Invalid value for attribute `separator': " << separatorStr << endl;
00100             m_customSeparator = false;
00101         }
00102     }
00103     QString lspaceStr = element.attribute( "lspace" ).stripWhiteSpace().lower();
00104     if ( ! lspaceStr.isNull() ) {
00105         m_customLSpace = true;
00106         m_lspace = getSize( lspaceStr, &m_lspaceType );
00107         if ( m_lspaceType == NoSize ) {
00108             m_lspaceType = getSpace( lspaceStr );
00109         }
00110     }
00111     QString rspaceStr = element.attribute( "rspace" ).stripWhiteSpace().lower();
00112     if ( ! rspaceStr.isNull() ) {
00113         m_customRSpace = true;
00114         m_rspace = getSize( rspaceStr, &m_rspaceType );
00115         if ( m_rspaceType == NoSize ) {
00116             m_rspaceType = getSpace( rspaceStr );
00117         }
00118     }
00119     QString stretchyStr = element.attribute( "stretchy" ).stripWhiteSpace().lower();
00120     if ( ! stretchyStr.isNull() ) {
00121         m_customStretchy = true;
00122         if ( stretchyStr == "true" ) {
00123             m_stretchy = true;
00124         }
00125         else if ( stretchyStr == "false" ) {
00126             m_stretchy = false;
00127         }
00128         else {
00129             kWarning( DEBUGID ) << "Invalid value for attribute `stretchy': " << stretchyStr << endl;
00130             m_customStretchy = false;
00131         }
00132     }
00133     QString symmetricStr = element.attribute( "symmetric" ).stripWhiteSpace().lower();
00134     if ( ! symmetricStr.isNull() ) {
00135         m_customSymmetric = true;
00136         if ( symmetricStr == "true" ) {
00137             m_symmetric = true;
00138         }
00139         else if ( symmetricStr == "false" ) {
00140             m_symmetric = false;
00141         }
00142         else {
00143             kWarning( DEBUGID ) << "Invalid value for attribute `symmetric': " << symmetricStr << endl;
00144             m_customSymmetric = false;
00145         }
00146     }
00147     QString maxsizeStr = element.attribute( "maxsize" ).stripWhiteSpace().lower();
00148     if ( ! maxsizeStr.isNull() ) {
00149         m_customMaxSize = true;
00150         if ( maxsizeStr == "infinity" ) {
00151             m_maxSizeType = InfinitySize;
00152         }
00153         else {
00154             m_maxSize = getSize( maxsizeStr, &m_maxSizeType );
00155             if ( m_maxSizeType == NoSize ) {
00156                 m_maxSizeType = getSpace( maxsizeStr );
00157             }
00158         }
00159     }
00160     QString minsizeStr = element.attribute( "minsize" ).stripWhiteSpace().lower();
00161     if ( ! minsizeStr.isNull() ) {
00162         m_customMinSize = true;
00163         m_minSize = getSize( minsizeStr, &m_minSizeType );
00164         if ( m_minSizeType == NoSize ) {
00165             m_minSizeType = getSpace( minsizeStr );
00166         }
00167     }
00168     QString largeopStr = element.attribute( "largeop" ).stripWhiteSpace().lower();
00169     if ( ! largeopStr.isNull() ) {
00170         m_customLargeOp = true;
00171         if ( largeopStr == "true" ) {
00172             m_largeOp = true;
00173         }
00174         else if ( largeopStr == "false" ) {
00175             m_largeOp = false;
00176         }
00177         else {
00178             kWarning( DEBUGID ) << "Invalid value for attribute `largeop': " << largeopStr << endl;
00179             m_customLargeOp = false;
00180         }
00181     }
00182     QString movablelimitsStr = element.attribute( "movablelimits" ).stripWhiteSpace().lower();
00183     if ( ! movablelimitsStr.isNull() ) {
00184         m_customMovableLimits = true;
00185         if ( movablelimitsStr == "true" ) {
00186             m_movableLimits = true;
00187         }
00188         else if ( movablelimitsStr == "false" ) {
00189             m_movableLimits = false;
00190         }
00191         else {
00192             kWarning( DEBUGID ) << "Invalid value for attribute `movablelimits': " << movablelimitsStr << endl;
00193             m_customMovableLimits = false;
00194         }
00195     }
00196     QString accentStr = element.attribute( "accent" ).stripWhiteSpace().lower();
00197     if ( ! accentStr.isNull() ) {
00198         m_customAccent = true;
00199         if ( accentStr == "true" ) {
00200             m_accent = true;
00201         }
00202         else if ( accentStr == "false" ) {
00203             m_accent = false;
00204         }
00205         else {
00206             kWarning( DEBUGID ) << "Invalid value for attribute `accent': " << accentStr << endl;
00207             m_customAccent = false;
00208         }
00209     }
00210     return true;
00211 }
00212 
00213 void OperatorElement::writeMathMLAttributes( QDomElement& element ) const
00214 {
00215     if ( m_customForm ) {
00216         switch ( m_form ) {
00217         case PrefixForm:
00218             element.setAttribute( "form", "prefix" );
00219             break;
00220         case InfixForm:
00221             element.setAttribute( "form", "infix" );
00222             break;
00223         case PostfixForm:
00224             element.setAttribute( "form", "postfix" );
00225         default:
00226             break;
00227         }
00228     }
00229     if ( m_customFence ) {
00230         element.setAttribute( "fence", m_fence ? "true" : "false" );
00231     }
00232     if ( m_customSeparator ) {
00233         element.setAttribute( "separator", m_separator ? "true" : "false" );
00234     }
00235     if ( m_customLSpace ) {
00236         writeSizeAttribute( element, "lspace", m_lspaceType, m_lspace );
00237     }
00238     if ( m_customRSpace ) {
00239         writeSizeAttribute( element, "rspace", m_rspaceType, m_rspace );
00240     }
00241     if ( m_customStretchy ) {
00242         element.setAttribute( "stretchy", m_stretchy ? "true" : "false" );
00243     }
00244     if ( m_customSymmetric ) {
00245         element.setAttribute( "symmetric", m_symmetric ? "true" : "false" );
00246     }
00247     if ( m_customMaxSize ) {
00248         writeSizeAttribute( element, "maxsize", m_maxSizeType, m_maxSize );
00249     }
00250     if ( m_customMinSize ) {
00251         writeSizeAttribute( element, "minsize", m_minSizeType, m_minSize );
00252     }
00253     if ( m_customLargeOp ) {
00254         element.setAttribute( "largeop", m_largeOp ? "true" : "false" );
00255     }
00256     if ( m_customMovableLimits ) {
00257         element.setAttribute( "movablelimits", m_movableLimits ? "true" : "false" );
00258     }
00259     if ( m_customAccent ) {
00260         element.setAttribute( "accent", m_accent ? "true" : "false" );
00261     }
00262 }
00263 
00264 void OperatorElement::writeSizeAttribute( QDomElement& element, const QString &attr, SizeType type, double length ) const
00265 {
00266     switch ( type ) {
00267     case InfinitySize:
00268         element.setAttribute( attr, "infinity" );
00269         break;
00270     case AbsoluteSize:
00271         element.setAttribute( attr, QString( "%1pt" ).arg( length ) );
00272         break;
00273     case RelativeSize:
00274         element.setAttribute( attr, QString( "%1% " ).arg( length * 100.0 ) );
00275         break;
00276     case PixelSize:
00277         element.setAttribute( attr, QString( "%1px " ).arg( length ) );
00278         break;
00279     case NegativeVeryVeryThinMathSpace:
00280         element.setAttribute( attr, "negativeveryverythinmathspace" );
00281         break;
00282     case NegativeVeryThinMathSpace:
00283         element.setAttribute( attr, "negativeverythinmathspace" );
00284         break;
00285     case NegativeThinMathSpace:
00286         element.setAttribute( attr, "negativethinmathspace" );
00287         break;
00288     case NegativeMediumMathSpace:
00289         element.setAttribute( attr, "negativemediummathspace" );
00290         break;
00291     case NegativeThickMathSpace:
00292         element.setAttribute( attr, "negativethickmathspace" );
00293         break;
00294     case NegativeVeryThickMathSpace:
00295         element.setAttribute( attr, "negativeverythickmathspace" );
00296         break;
00297     case NegativeVeryVeryThickMathSpace:
00298         element.setAttribute( attr, "negativeveryverythickmathspace" );
00299         break;
00300     case VeryVeryThinMathSpace:
00301         element.setAttribute( attr, "veryverythinmathspace" );
00302         break;
00303     case VeryThinMathSpace:
00304         element.setAttribute( attr, "verythinmathspace" );
00305         break;
00306     case ThinMathSpace:
00307         element.setAttribute( attr, "thinmathspace" );
00308         break;
00309     case MediumMathSpace:
00310         element.setAttribute( attr, "mediummathspace" );
00311         break;
00312     case ThickMathSpace:
00313         element.setAttribute( attr, "thickmathspace" );
00314         break;
00315     case VeryThickMathSpace:
00316         element.setAttribute( attr, "verythickmathspace" );
00317         break;
00318     case VeryVeryThickMathSpace:
00319         element.setAttribute( attr, "veryverythickmathspace" );
00320         break;
00321     default:
00322         break;
00323     }
00324 }
00325 
00326 
00327 KFORMULA_NAMESPACE_END

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