symbolelement.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 SYMBOLELEMENT_H
22#define SYMBOLELEMENT_H
23
24#include "fontstyle.h"
25#include "basicelement.h"
26#include "kformuladefs.h"
27
28KFORMULA_NAMESPACE_BEGIN
29
34 SymbolElement operator=( const SymbolElement& ) { return *this; }
35public:
36
37 //enum { contentPos, upperPos, lowerPos };
38
39 SymbolElement(SymbolType type = EmptyBracket, BasicElement* parent = 0);
41
43
44 virtual SymbolElement* clone() {
45 return new SymbolElement( *this );
46 }
47
48 virtual bool accept( ElementVisitor* visitor );
49
56 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
57 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
58
59 // drawing
60 //
61 // Drawing depends on a context which knows the required properties like
62 // fonts, spaces and such.
63 // It is essential to calculate elements size with the same context
64 // before you draw.
65
70 virtual void calcSizes( const ContextStyle& cstyle,
72 ContextStyle::IndexStyle istyle,
73 StyleAttributes& style );
74
80 virtual void draw( TQPainter& painter, const LuPixelRect& r,
81 const ContextStyle& context,
83 ContextStyle::IndexStyle istyle,
84 StyleAttributes& style,
85 const LuPixelPoint& parentOrigin );
86
90 virtual void dispatchFontCommand( FontCommand* cmd );
91
92 // navigation
93 //
94 // The elements are responsible to handle cursor movement themselves.
95 // To do this they need to know the direction the cursor moves and
96 // the element it comes from.
97 //
98 // The cursor might be in normal or in selection mode.
99
105 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
106
112 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
113
119 virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
120
126 virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
127
128 // children
129
137 //virtual void removeChild(FormulaCursor* cursor, BasicElement* child);
138
139
140 // main child
141 //
142 // If an element has children one has to become the main one.
143
144 virtual SequenceElement* getMainChild() { return content; }
145 //virtual void setMainChild(SequenceElement*);
146
147
158 virtual void insert(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
159
171 virtual void remove(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
172
177 virtual void normalize(FormulaCursor*, Direction);
178
182 virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor);
183
188 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
189
194 //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
195
196 bool hasUpper() const { return upper != 0; }
197 bool hasLower() const { return lower != 0; }
198
199 // If we want to create an index we need a cursor that points there.
200
201 void setToUpper(FormulaCursor* cursor);
202 void setToLower(FormulaCursor* cursor);
203
204 // Moves the cursor inside the index. The index has to exist.
205 void moveToUpper(FormulaCursor*, Direction);
206 void moveToLower(FormulaCursor*, Direction);
207
208 // Generic access to each index.
209
210 ElementIndexPtr getUpperIndex() { return ElementIndexPtr( new UpperIndex( this ) ); }
211 ElementIndexPtr getLowerIndex() { return ElementIndexPtr( new LowerIndex( this ) ); }
212
216 ElementIndexPtr getIndex( int position );
217
218 // Save&load
219 //virtual TQDomElement getElementDom(TQDomDocument *doc);
220 //virtual bool buildFromDom(TQDomElement *elem);
221
226 virtual TQString toLatex();
227
228 virtual TQString formulaString();
229
230 virtual void writeMathML( TQDomDocument& doc, TQDomNode& parent, bool oasisFormat = false ) const ;
231
232protected:
233
234 //Save/load support
235
239 virtual TQString getTagName() const { return "SYMBOL"; }
240
244 virtual void writeDom(TQDomElement element);
245
250 virtual bool readAttributesFromDom(TQDomElement element);
251
257 virtual bool readContentFromDom(TQDomNode& node);
258
259private:
260
264 class SymbolElementIndex : public ElementIndex {
265 public:
266 SymbolElementIndex(SymbolElement* p) : parent(p) {}
267 virtual SymbolElement* getElement() { return parent; }
268 protected:
269 SymbolElement* parent;
270 };
271
272 // We have a (very simple) type for every index.
273
274 class UpperIndex : public SymbolElementIndex {
275 public:
276 UpperIndex(SymbolElement* parent) : SymbolElementIndex(parent) {}
277 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
278 { parent->moveToUpper(cursor, direction); }
279 virtual void setToIndex(FormulaCursor* cursor)
280 { parent->setToUpper(cursor); }
281 virtual bool hasIndex() const
282 { return parent->hasUpper(); }
283 };
284
285 class LowerIndex : public SymbolElementIndex {
286 public:
287 LowerIndex(SymbolElement* parent) : SymbolElementIndex(parent) {}
288 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
289 { parent->moveToLower(cursor, direction); }
290 virtual void setToIndex(FormulaCursor* cursor)
291 { parent->setToLower(cursor); }
292 virtual bool hasIndex() const
293 { return parent->hasLower(); }
294 };
295
296
297 void setToContent(FormulaCursor* cursor);
298
299 SequenceElement* content;
300 SequenceElement* upper;
301 SequenceElement* lower;
302
306 Artwork* symbol;
307
308 SymbolType symbolType;
309};
310
311KFORMULA_NAMESPACE_END
312
313#endif // SYMBOLELEMENT_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.
The element that contains a number of children.
A symbol is simply a piece of art.
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 calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
ElementIndexPtr getIndex(int position)
Returns the index at the position.
virtual void moveUp(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving up starting inside the element ‘from’.
virtual SequenceElement * getMainChild()
Removes the child.
virtual BasicElement * getChild(FormulaCursor *, Direction=beforeCursor)
Returns the child at the cursor.
virtual void moveDown(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving down starting inside the element ‘from’.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual void selectChild(FormulaCursor *cursor, BasicElement *child)
Sets the cursor to select the child.
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Inserts all new children at the cursor position.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
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 TQString toLatex()
virtual void draw(TQPainter &painter, const LuPixelRect &r, const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style, const LuPixelPoint &parentOrigin)
Draws the whole element including its children.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
bool hasUpper() const
Moves the cursor away from the given child.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
virtual TQString getTagName() const
Returns the tag name of this element type.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.