lib

fractionelement.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef FRACTIONELEMENT_H
22#define FRACTIONELEMENT_H
23
24#include "basicelement.h"
25
26KFORMULA_NAMESPACE_BEGIN
27class SequenceElement;
28
29
33class FractionElement : public BasicElement {
34 FractionElement& operator=( const FractionElement& ) { return *this; }
35public:
36
37 enum { numeratorPos, denominatorPos };
38
39 FractionElement(BasicElement* parent = 0);
40 ~FractionElement();
41
42 FractionElement( const FractionElement& );
43
44 virtual FractionElement* clone() {
45 return new FractionElement( *this );
46 }
47
48 virtual bool accept( ElementVisitor* visitor );
49
54 virtual TokenType getTokenType() const { return INNER; }
55
60 virtual void entered( SequenceElement* child );
61
68 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
69 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
70
75 virtual void calcSizes( const ContextStyle& cstyle,
77 ContextStyle::IndexStyle istyle,
78 StyleAttributes& style );
79
85 virtual void draw( TQPainter& painter, const LuPixelRect& r,
86 const ContextStyle& cstyle,
88 ContextStyle::IndexStyle istyle,
89 StyleAttributes& style,
90 const LuPixelPoint& parentOrigin );
91
95 virtual void dispatchFontCommand( FontCommand* cmd );
96
102 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
103
109 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
110
116 virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
117
123 virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
124
128 virtual void insert(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
129
139 virtual void remove(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
140
141
142 // main child
143 //
144 // If an element has children one has to become the main one.
145
146 virtual SequenceElement* getMainChild();
147
148 SequenceElement* getNumerator() { return numerator; }
149 SequenceElement* getDenominator() { return denominator; }
150
156 virtual bool isSenseless();
157
162 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
163
168 //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
169
173 void showLine(bool line) {
174 m_lineThicknessType = RelativeSize;
175 if ( line ) {
176 m_lineThickness = 1.0;
177 }
178 else {
179 m_lineThickness = 0.0;
180 }
181 }
182
187 virtual TQString toLatex();
188
189 virtual TQString formulaString();
190
191protected:
192
193 //Save/load support
194
198 virtual TQString getTagName() const { return "FRACTION"; }
199
203 virtual void writeDom(TQDomElement element);
204
209 virtual bool readAttributesFromDom(TQDomElement element);
210
216 virtual bool readContentFromDom(TQDomNode& node);
217
222 virtual bool readAttributesFromMathMLDom(const TQDomElement& element);
223
229 virtual int readContentFromMathMLDom(TQDomNode& node);
230
231private:
232 virtual TQString getElementName() const { return "mfrac"; }
233 virtual void writeMathMLAttributes( TQDomElement& element ) const ;
234 virtual void writeMathMLContent( TQDomDocument& doc,
235 TQDomElement& element,
236 bool oasisFormat ) const ;
237
238 double lineThickness( const ContextStyle& context, double factor );
239
240 bool withLine() { return m_lineThicknessType == NoSize || m_lineThickness != 0.0; }
241
242 SequenceElement* numerator;
243 SequenceElement* denominator;
244
245 SizeType m_lineThicknessType;
246 double m_lineThickness;
247 HorizontalAlign m_numAlign;
248 HorizontalAlign m_denomAlign;
249 bool m_customBevelled;
250 bool m_bevelled;
251};
252
253KFORMULA_NAMESPACE_END
254
255#endif // FRACTIONELEMENT_H
Basis of every formula element.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
Base for all font commands that act on the current selection.
The selection.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
virtual void calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual TokenType getTokenType() const
void showLine(bool line)
Moves the cursor away from the given child.
virtual TQString toLatex()
virtual void dispatchFontCommand(FontCommand *cmd)
Draws the whole element including its children.
virtual int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Enters this element while moving to the left starting inside the element `from'.
virtual bool isSenseless()
Returns wether the element has no more useful children (except its main child) and should therefore b...
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual TQString getTagName() const
Returns the tag name of this element type.
virtual void selectChild(FormulaCursor *cursor, BasicElement *child)
Sets the cursor to select the child.
virtual SequenceElement * getMainChild()
Removes the child.
The element that contains a number of children.