indexelement.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 INDEXELEMENT_H
22#define INDEXELEMENT_H
23
24// Formula include
25#include "basicelement.h"
26
27KFORMULA_NAMESPACE_BEGIN
28class SequenceElement;
29
30
34class IndexElement : public BasicElement {
35 IndexElement& operator=( const IndexElement& ) { return *this; }
36public:
37
38 IndexElement(BasicElement* parent = 0);
40
41 IndexElement( const IndexElement& );
42
43 virtual IndexElement* clone() {
44 return new IndexElement( *this );
45 }
46
47 virtual bool accept( ElementVisitor* visitor );
48
54 virtual TQChar getCharacter() const;
55
60 virtual void entered( SequenceElement* child );
61
68 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
69 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
70
71 // drawing
72 //
73 // Drawing depends on a context which knows the required properties like
74 // fonts, spaces and such.
75 // It is essential to calculate elements size with the same context
76 // before you draw.
77
82 virtual void calcSizes( const ContextStyle& cstyle,
84 ContextStyle::IndexStyle istyle,
85 StyleAttributes& style );
86
92 virtual void draw( TQPainter& painter, const LuPixelRect& r,
93 const ContextStyle& context,
95 ContextStyle::IndexStyle istyle,
96 StyleAttributes& style,
97 const LuPixelPoint& parentOrigin );
98
102 virtual void dispatchFontCommand( FontCommand* cmd );
103
104 // navigation
105 //
106 // The elements are responsible to handle cursor movement themselves.
107 // To do this they need to know the direction the cursor moves and
108 // the element it comes from.
109 //
110 // The cursor might be in normal or in selection mode.
111
117 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
118
124 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
125
131 virtual void moveUp(FormulaCursor* cursor, BasicElement* from);
132
138 virtual void moveDown(FormulaCursor* cursor, BasicElement* from);
139
140 // children
141
149 //virtual void removeChild(FormulaCursor* cursor, BasicElement* child);
150
151
152 // main child
153 //
154 // If an element has children one has to become the main one.
155
156 virtual SequenceElement* getMainChild() { return content; }
157 //SequenceElement* upperLeft;
158 //SequenceElement* upperMiddle;
159 SequenceElement* getExponent() { return upperRight; }
160 //SequenceElement* lowerLeft;
161 //SequenceElement* lowerMiddle;
162 //SequenceElement* lowerRight;
163
164
175 virtual void insert(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
176
188 virtual void remove(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
189
194 virtual void normalize(FormulaCursor*, Direction);
195
199 virtual BasicElement* getChild(FormulaCursor*, Direction = beforeCursor);
200
205 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
206
211 //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
212
218 virtual bool isSenseless();
219
220
221 bool hasUpperLeft() const { return upperLeft != 0; }
222 bool hasUpperMiddle() const { return upperMiddle != 0; }
223 bool hasUpperRight() const { return upperRight != 0; }
224 bool hasLowerLeft() const { return lowerLeft != 0; }
225 bool hasLowerMiddle() const { return lowerMiddle != 0; }
226 bool hasLowerRight() const { return lowerRight != 0; }
227
228 // If we want to create an index we need a cursor that points there.
229
230 void setToUpperLeft(FormulaCursor* cursor);
231 void setToUpperMiddle(FormulaCursor* cursor);
232 void setToUpperRight(FormulaCursor* cursor);
233 void setToLowerLeft(FormulaCursor* cursor);
234 void setToLowerMiddle(FormulaCursor* cursor);
235 void setToLowerRight(FormulaCursor* cursor);
236
237 // If the index is there we need a way to move into it.
238
239 void moveToUpperLeft(FormulaCursor* cursor, Direction direction);
240 void moveToUpperMiddle(FormulaCursor* cursor, Direction direction);
241 void moveToUpperRight(FormulaCursor* cursor, Direction direction);
242 void moveToLowerLeft(FormulaCursor* cursor, Direction direction);
243 void moveToLowerMiddle(FormulaCursor* cursor, Direction direction);
244 void moveToLowerRight(FormulaCursor* cursor, Direction direction);
245
246 // Generic access to each index.
247
248 ElementIndexPtr getUpperLeft() { return ElementIndexPtr( new UpperLeftIndex( this ) ); }
249 ElementIndexPtr getLowerLeft() { return ElementIndexPtr( new LowerLeftIndex( this ) ); }
250 ElementIndexPtr getUpperMiddle() { return ElementIndexPtr( new UpperMiddleIndex( this ) ); }
251 ElementIndexPtr getLowerMiddle() { return ElementIndexPtr( new LowerMiddleIndex( this ) ); }
252 ElementIndexPtr getUpperRight() { return ElementIndexPtr( new UpperRightIndex( this ) ); }
253 ElementIndexPtr getLowerRight() { return ElementIndexPtr( new LowerRightIndex( this ) ); }
254
258 ElementIndexPtr getIndex( int position );
259
264 virtual TQString toLatex();
265
266 // the upper right index is the only one we show
267 virtual TQString formulaString();
268
269protected:
270
271 //Save/load support
272
276 virtual TQString getTagName() const { return "INDEX"; }
277
281 virtual void writeDom(TQDomElement element);
282
283 virtual TQString getElementName() const ;
284 virtual void writeMathMLAttributes( TQDomElement& element ) const ;
285 virtual void writeMathMLContent( TQDomDocument& doc,
286 TQDomElement& element,
287 bool oasisFormat ) const ;
292 virtual bool readAttributesFromDom(TQDomElement element);
293
299 virtual bool readContentFromDom(TQDomNode& node);
300
301 virtual bool readAttributesFromMathMLDom( const TQDomElement& element );
308 virtual int readContentFromMathMLDom( TQDomNode& node );
309
310private:
311
315 class IndexElementIndex : public ElementIndex {
316 public:
317 IndexElementIndex(IndexElement* p) : parent(p) {}
318 virtual IndexElement* getElement() { return parent; }
319 protected:
320 IndexElement* parent;
321 };
322
323 // We have a (very simple) type for every index.
324
325 class UpperLeftIndex : public IndexElementIndex {
326 public:
327 UpperLeftIndex(IndexElement* parent) : IndexElementIndex(parent) {}
328 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
329 { parent->moveToUpperLeft(cursor, direction); }
330 virtual void setToIndex(FormulaCursor* cursor)
331 { parent->setToUpperLeft(cursor); }
332 virtual bool hasIndex() const
333 { return parent->hasUpperLeft(); }
334 };
335
336 class LowerLeftIndex : public IndexElementIndex {
337 public:
338 LowerLeftIndex(IndexElement* parent) : IndexElementIndex(parent) {}
339 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
340 { parent->moveToLowerLeft(cursor, direction); }
341 virtual void setToIndex(FormulaCursor* cursor)
342 { parent->setToLowerLeft(cursor); }
343 virtual bool hasIndex() const
344 { return parent->hasLowerLeft(); }
345 };
346
347 class UpperMiddleIndex : public IndexElementIndex {
348 public:
349 UpperMiddleIndex(IndexElement* parent) : IndexElementIndex(parent) {}
350 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
351 { parent->moveToUpperMiddle(cursor, direction); }
352 virtual void setToIndex(FormulaCursor* cursor)
353 { parent->setToUpperMiddle(cursor); }
354 virtual bool hasIndex() const
355 { return parent->hasUpperMiddle(); }
356 };
357
358 class LowerMiddleIndex : public IndexElementIndex {
359 public:
360 LowerMiddleIndex(IndexElement* parent) : IndexElementIndex(parent) {}
361 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
362 { parent->moveToLowerMiddle(cursor, direction); }
363 virtual void setToIndex(FormulaCursor* cursor)
364 { parent->setToLowerMiddle(cursor); }
365 virtual bool hasIndex() const
366 { return parent->hasLowerMiddle(); }
367 };
368
369 class UpperRightIndex : public IndexElementIndex {
370 public:
371 UpperRightIndex(IndexElement* parent) : IndexElementIndex(parent) {}
372 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
373 { parent->moveToUpperRight(cursor, direction); }
374 virtual void setToIndex(FormulaCursor* cursor)
375 { parent->setToUpperRight(cursor); }
376 virtual bool hasIndex() const
377 { return parent->hasUpperRight(); }
378 };
379
380 class LowerRightIndex : public IndexElementIndex {
381 public:
382 LowerRightIndex(IndexElement* parent) : IndexElementIndex(parent) {}
383 virtual void moveToIndex(FormulaCursor* cursor, Direction direction)
384 { parent->moveToLowerRight(cursor, direction); }
385 virtual void setToIndex(FormulaCursor* cursor)
386 { parent->setToLowerRight(cursor); }
387 virtual bool hasIndex() const
388 { return parent->hasLowerRight(); }
389 };
390
391
395 void setMiddleX(int xOffset, int middleWidth);
396
400 int getFromPos(BasicElement* from);
401
408 void setToContent(FormulaCursor* cursor);
409
413 SequenceElement* content;
414
420 SequenceElement* upperLeft;
421 SequenceElement* upperMiddle;
422 SequenceElement* upperRight;
423 SequenceElement* lowerLeft;
424 SequenceElement* lowerMiddle;
425 SequenceElement* lowerRight;
426
430 SizeType m_subScriptShiftType;
431 double m_subScriptShift;
432 SizeType m_superScriptShiftType;
433 double m_superScriptShift;
434 bool m_accentUnder;
435 bool m_customAccentUnder;
436 bool m_accent;
437 bool m_customAccent;
438};
439
440KFORMULA_NAMESPACE_END
441
442#endif // INDEXELEMENT_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 with up to four indexes in the four corners.
virtual void moveDown(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving down starting inside the element ‘from’.
virtual bool isSenseless()
Moves the cursor away from the given child.
virtual int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
virtual void normalize(FormulaCursor *, Direction)
Moves the cursor to a normal place where new elements might be inserted.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual TQString toLatex()
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Inserts all new children at the cursor position.
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 void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
virtual void selectChild(FormulaCursor *cursor, BasicElement *child)
Sets the cursor to select the child.
ElementIndexPtr getIndex(int position)
Returns the index at the position.
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 TQString getTagName() const
Returns the tag name of this element type.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
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 moveUp(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving up starting inside the element ‘from’.
virtual BasicElement * getChild(FormulaCursor *, Direction=beforeCursor)
Returns the child at the cursor.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual TQChar getCharacter() const
virtual SequenceElement * getMainChild()
Removes the child.
The element that contains a number of children.