lib

bracketelement.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 BRACKETELEMENT_H
22#define BRACKETELEMENT_H
23
24#include <tqpoint.h>
25#include <tqsize.h>
26
27#include "basicelement.h"
28
29KFORMULA_NAMESPACE_BEGIN
30
31class Artwork;
32class SequenceElement;
33
34
39class SingleContentElement : public BasicElement {
40 SingleContentElement& operator=( const SingleContentElement& ) { return *this; }
41public:
42
43 SingleContentElement(BasicElement* parent = 0);
44 ~SingleContentElement();
45
46 SingleContentElement( const SingleContentElement& );
47
53 virtual TQChar getCharacter() const;
54
61 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
62 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
63
67 virtual void dispatchFontCommand( FontCommand* cmd );
68
74 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
75
81 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
82
88 virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
89
95 virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
96
103 virtual void remove(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
104
109 virtual void normalize(FormulaCursor*, Direction);
110
111 // main child
112 //
113 // If an element has children one has to become the main one.
114
115 virtual SequenceElement* getMainChild();
116
121 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
122
123protected:
124
128 virtual void writeDom(TQDomElement element);
129
130 virtual void writeMathMLContent( TQDomDocument& doc,
131 TQDomElement& element,
132 bool oasisFormat ) const;
138 virtual bool readContentFromDom(TQDomNode& node);
139
145 virtual int readContentFromMathMLDom(TQDomNode& node);
146
147 SequenceElement* getContent() { return content; }
148
149private:
150
154 SequenceElement* content;
155};
156
157
161class BracketElement : public SingleContentElement {
162 typedef SingleContentElement inherited;
163 BracketElement& operator=( const BracketElement& ) { return *this; }
164public:
165
166 enum { contentPos };
167
168 BracketElement(SymbolType left = EmptyBracket, SymbolType right = EmptyBracket,
169 BasicElement* parent = 0);
170 ~BracketElement();
171
172 BracketElement( const BracketElement& );
173
174 virtual BracketElement* clone() {
175 return new BracketElement( *this );
176 }
177
178 virtual bool accept( ElementVisitor* visitor );
179
184 virtual TokenType getTokenType() const { return BRACKET; }
185
190 virtual void entered( SequenceElement* child );
191
198 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
199 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
200
205 virtual void calcSizes( const ContextStyle& context,
207 ContextStyle::IndexStyle istyle,
208 StyleAttributes& style );
209
215 virtual void draw( TQPainter& painter, const LuPixelRect& r,
216 const ContextStyle& context,
218 ContextStyle::IndexStyle istyle,
219 StyleAttributes& style,
220 const LuPixelPoint& parentOrigin );
221
222protected:
223
224 //Save/load support
225
229 virtual TQString getTagName() const { return "BRACKET"; }
230
235 virtual bool readAttributesFromDom(TQDomElement element);
236
237 virtual void writeDom(TQDomElement element);
238
239 virtual TQString getElementName() const { return "mfenced"; }
240 virtual void writeMathMLAttributes( TQDomElement& element ) const;
245 virtual bool readAttributesFromMathMLDom(const TQDomElement& element);
246
253 virtual int readContentFromMathMLDom(TQDomNode& node);
254
259 virtual TQString toLatex();
260
261 virtual TQString formulaString();
262
263private:
264
268 TQString latexString(char);
269
275 int operatorType( TQDomNode& node, bool open );
276
281 int searchOperator( const TQDomNode& node );
282
286 Artwork* left;
287 Artwork* right;
288
289 SymbolType leftType;
290 SymbolType rightType;
291
292 TQString m_separators;
293 bool m_operator;
294 bool m_customLeft;
295 bool m_customRight;
296};
297
298
302class OverlineElement : public SingleContentElement {
303 OverlineElement& operator=( const OverlineElement& ) { return *this; }
304public:
305
306 OverlineElement(BasicElement* parent = 0);
307 ~OverlineElement();
308
309 OverlineElement( const OverlineElement& );
310
311 virtual OverlineElement* clone() {
312 return new OverlineElement( *this );
313 }
314
315 virtual bool accept( ElementVisitor* visitor );
316
321 virtual void entered( SequenceElement* child );
322
327 virtual void calcSizes( const ContextStyle& context,
329 ContextStyle::IndexStyle istyle,
330 StyleAttributes& style );
331
337 virtual void draw( TQPainter& painter, const LuPixelRect& r,
338 const ContextStyle& context,
340 ContextStyle::IndexStyle istyle,
341 StyleAttributes& style,
342 const LuPixelPoint& parentOrigin );
343
348 virtual TQString toLatex();
349
350 virtual TQString formulaString();
351
352 virtual void writeMathML( TQDomDocument& doc, TQDomNode& parent, bool oasisFormat = false ) const;
353
354protected:
355
356 //Save/load support
357
361 virtual TQString getTagName() const { return "OVERLINE"; }
362
363private:
364};
365
366
370class UnderlineElement : public SingleContentElement {
371 UnderlineElement& operator=( const UnderlineElement& ) { return *this; }
372public:
373 UnderlineElement(BasicElement* parent = 0);
374 ~UnderlineElement();
375
376 UnderlineElement( const UnderlineElement& );
377
378 virtual UnderlineElement* clone() {
379 return new UnderlineElement( *this );
380 }
381
382 virtual bool accept( ElementVisitor* visitor );
383
388 virtual void entered( SequenceElement* child );
389
394 virtual void calcSizes( const ContextStyle& context,
396 ContextStyle::IndexStyle istyle,
397 StyleAttributes& style );
398
404 virtual void draw( TQPainter& painter, const LuPixelRect& r,
405 const ContextStyle& context,
407 ContextStyle::IndexStyle istyle,
408 StyleAttributes& style,
409 const LuPixelPoint& parentOrigin );
410
415 virtual TQString toLatex();
416
417 virtual TQString formulaString();
418
419 virtual void writeMathML( TQDomDocument& doc, TQDomNode& parent, bool oasisFormat = false ) const;
420
421protected:
422
423 //Save/load support
424
428 virtual TQString getTagName() const { return "UNDERLINE"; }
429
430private:
431};
432
433
434KFORMULA_NAMESPACE_END
435
436#endif // BRACKETELEMENT_H
Basis of every formula element.
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 writeDom(TQDomElement element)
Draws the whole element including its children.
virtual TQString toLatex()
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
virtual TokenType getTokenType() const
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual TQString getTagName() const
Draws the whole element including its children.
virtual void calcSizes(const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
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 TQString toLatex()
Draws the whole element including its children.
virtual TQString getTagName() const
Returns the tag name of this element type.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual void calcSizes(const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
The element that contains a number of children.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
virtual TQChar getCharacter() const
virtual void normalize(FormulaCursor *, Direction)
Moves the cursor to a normal place where new elements might be inserted.
virtual SequenceElement * getMainChild()
Removes the child.
virtual void selectChild(FormulaCursor *cursor, BasicElement *child)
Sets the cursor to select the child.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
virtual int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Enters this element while moving to the left starting inside the element `from'.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
virtual TQString toLatex()
Draws the whole element including its children.
virtual TQString getTagName() const
Returns the tag name of this element type.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual void calcSizes(const ContextStyle &context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.