lib

fractionelement.h

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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef FRACTIONELEMENT_H
00022 #define FRACTIONELEMENT_H
00023 
00024 #include "basicelement.h"
00025 
00026 KFORMULA_NAMESPACE_BEGIN
00027 class SequenceElement;
00028 
00029 
00033 class FractionElement : public BasicElement {
00034     FractionElement& operator=( const FractionElement& ) { return *this; }
00035 public:
00036 
00037     enum { numeratorPos, denominatorPos };
00038 
00039     FractionElement(BasicElement* parent = 0);
00040     ~FractionElement();
00041 
00042     FractionElement( const FractionElement& );
00043 
00044     virtual FractionElement* clone() {
00045         return new FractionElement( *this );
00046     }
00047 
00048     virtual bool accept( ElementVisitor* visitor );
00049 
00054     virtual TokenType getTokenType() const { return INNER; }
00055 
00060     virtual void entered( SequenceElement* child );
00061 
00068     virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
00069                                    const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
00070 
00075     virtual void calcSizes( const ContextStyle& cstyle,
00076                             ContextStyle::TextStyle tstyle,
00077                             ContextStyle::IndexStyle istyle,
00078                             StyleAttributes& style );
00079 
00085     virtual void draw( QPainter& painter, const LuPixelRect& r,
00086                        const ContextStyle& cstyle,
00087                        ContextStyle::TextStyle tstyle,
00088                        ContextStyle::IndexStyle istyle,
00089                        StyleAttributes& style,
00090                        const LuPixelPoint& parentOrigin );
00091 
00095     virtual void dispatchFontCommand( FontCommand* cmd );
00096 
00102     virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00103 
00109     virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00110 
00116     virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
00117 
00123     virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
00124 
00128     virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00129 
00139     virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00140 
00141 
00142     // main child
00143     //
00144     // If an element has children one has to become the main one.
00145 
00146     virtual SequenceElement* getMainChild();
00147 
00148     SequenceElement* getNumerator() { return numerator; }
00149     SequenceElement* getDenominator() { return denominator; }
00150 
00156     virtual bool isSenseless();
00157 
00162     virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00163 
00168     //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
00169 
00173     void showLine(bool line) { 
00174         m_lineThicknessType = RelativeSize;
00175         if ( line ) {
00176             m_lineThickness = 1.0;
00177         }
00178         else {
00179             m_lineThickness = 0.0;
00180         }
00181     }
00182 
00187     virtual QString toLatex();
00188 
00189     virtual QString formulaString();
00190 
00191 protected:
00192 
00193     //Save/load support
00194 
00198     virtual QString getTagName() const { return "FRACTION"; }
00199 
00203     virtual void writeDom(QDomElement element);
00204 
00209     virtual bool readAttributesFromDom(QDomElement element);
00210 
00216     virtual bool readContentFromDom(QDomNode& node);
00217 
00222     virtual bool readAttributesFromMathMLDom(const QDomElement& element);
00223 
00229     virtual int readContentFromMathMLDom(QDomNode& node);
00230 
00231 private:
00232     virtual QString getElementName() const { return "mfrac"; }
00233     virtual void writeMathMLAttributes( QDomElement& element ) const ;
00234     virtual void writeMathMLContent( QDomDocument& doc, 
00235                                      QDomElement& element,
00236                                      bool oasisFormat ) const ;
00237 
00238     double lineThickness( const ContextStyle& context, double factor );
00239 
00240     bool withLine() { return m_lineThicknessType == NoSize || m_lineThickness != 0.0; }
00241 
00242     SequenceElement* numerator;
00243     SequenceElement* denominator;
00244 
00245     SizeType m_lineThicknessType;
00246     double m_lineThickness;
00247     HorizontalAlign m_numAlign;
00248     HorizontalAlign m_denomAlign;
00249     bool m_customBevelled;
00250     bool m_bevelled;
00251 };
00252 
00253 KFORMULA_NAMESPACE_END
00254 
00255 #endif // FRACTIONELEMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys