rootelement.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 ROOTELEMENT_H
22#define ROOTELEMENT_H
23
24#include <tqpoint.h>
25
26#include "basicelement.h"
27
28KFORMULA_NAMESPACE_BEGIN
29class SequenceElement;
30
31
35class RootElement : public BasicElement {
36 RootElement& operator=( const RootElement& ) { return *this; }
37public:
38
39 //enum { contentPos, indexPos };
40
41 RootElement(BasicElement* parent = 0);
43
44 RootElement( const RootElement& );
45
46 virtual RootElement* clone() {
47 return new RootElement( *this );
48 }
49
50 virtual bool accept( ElementVisitor* visitor );
51
56 virtual void entered( SequenceElement* child );
57
64 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
65 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
66
71 virtual void calcSizes( const ContextStyle& cstyle,
73 ContextStyle::IndexStyle istyle,
74 StyleAttributes& style );
75
81 virtual void draw( TQPainter& painter, const LuPixelRect& r,
82 const ContextStyle& cstyle,
84 ContextStyle::IndexStyle istyle,
85 StyleAttributes& style,
86 const LuPixelPoint& parentOrigin );
87
91 virtual void dispatchFontCommand( FontCommand* cmd );
92
98 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
99
105 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
106
112 virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
113
119 virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
120
124 virtual void insert(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
125
132 virtual void remove(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
133
138 virtual void normalize(FormulaCursor*, Direction);
139
140 // main child
141 //
142 // If an element has children one has to become the main one.
143
144 virtual SequenceElement* getMainChild();
145 SequenceElement* getRadiant() { return index; }
146 //virtual void setMainChild(SequenceElement*);
147
152 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
153
158 //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
159
160 // Moves the cursor inside the index. The index has to exist.
161 void moveToIndex(FormulaCursor*, Direction);
162
163 // Sets the cursor to point to the place where the index normaly
164 // is. These functions are only used if there is no such index and
165 // we want to insert them.
166 void setToIndex(FormulaCursor*);
167
168 bool hasIndex() const { return index != 0; }
169
170 ElementIndexPtr getIndex() { return ElementIndexPtr( new RootElementIndex( this ) ); }
171
172 // Save&load
173 //virtual TQDomElement getElementDom(TQDomDocument *doc);
174 //virtual bool buildFromDom(TQDomElement *elem);
175
180 virtual TQString toLatex();
181
182 virtual TQString formulaString();
183
184protected:
185
186 //Save/load support
187
191 virtual TQString getTagName() const { return "ROOT"; }
192
196 virtual void writeDom(TQDomElement element);
197
202 virtual bool readAttributesFromDom(TQDomElement element);
203
209 virtual bool readContentFromDom(TQDomNode& node);
210
216 virtual bool readAttributesFromMathMLDom(const TQDomElement& element);
217
223 virtual int readContentFromMathMLDom(TQDomNode& node);
224
225private:
226
227 virtual TQString getElementName() const { return hasIndex() ? "mroot" : "msqrt"; }
228 virtual void writeMathMLContent( TQDomDocument& doc,
229 TQDomElement& element,
230 bool oasisFormat ) const ;
231
232 class RootElementIndex : public ElementIndex {
233 public:
234 RootElementIndex(RootElement* p) : parent(p) {}
235 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
236 { parent->moveToIndex(cursor, direction); }
237 virtual void setToIndex(FormulaCursor* cursor)
238 { parent->setToIndex(cursor); }
239 virtual bool hasIndex() const
240 { return parent->hasIndex(); }
241 virtual RootElement* getElement() { return parent; }
242 protected:
243 RootElement* parent;
244 };
245
246
250 SequenceElement* content;
251
255 SequenceElement* index;
256
260 LuPixelPoint rootOffset;
261
267 bool square;
268};
269
270
271KFORMULA_NAMESPACE_END
272
273#endif // ROOTELEMENT_H
Basis of every formula element.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
A type that describes an index.
Base for all font commands that act on the current selection.
The selection.
A nice graphical root.
Definition rootelement.h:35
virtual BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Reinserts the index if it has been removed.
void moveToIndex(FormulaCursor *, Direction)
Moves the cursor away from the given child.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
virtual void moveDown(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving down starting inside the element ‘from’.
virtual SequenceElement * getMainChild()
Removes the child.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual TQString toLatex()
virtual void moveUp(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving up starting inside the element ‘from’.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
virtual TQString getTagName() const
Returns the tag name of this element type.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
virtual void normalize(FormulaCursor *, Direction)
Moves the cursor to a normal place where new elements might be inserted.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
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 void draw(TQPainter &painter, const LuPixelRect &r, const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style, const LuPixelPoint &parentOrigin)
Draws the whole element including its children.
virtual void selectChild(FormulaCursor *cursor, BasicElement *child)
Sets the cursor to select the child.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
The element that contains a number of children.