matrixelement.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 Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#ifndef MATRIXELEMENT_H
23#define MATRIXELEMENT_H
24
25#include <tqptrlist.h>
26
27#include "basicelement.h"
28
29KFORMULA_NAMESPACE_BEGIN
30
31
32class MatrixSequenceElement;
33
34
39 friend class KFCRemoveColumn;
40 friend class KFCRemoveRow;
41 friend class MatrixSequenceElement;
42
43 enum VerticalAlign { NoAlign, TopAlign, BottomAlign, CenterAlign, BaselineAlign, AxisAlign };
44 enum LineType { NoLine, NoneLine, SolidLine, DashedLine };
45 enum SideType { NoSide, LeftSide, RightSide, LeftOverlapSide, RightOverlapSide };
46 MatrixElement& operator=( const MatrixElement& ) { return *this; }
47public:
48 MatrixElement(uint rows = 1, uint columns = 1, BasicElement* parent = 0);
50
52
53 virtual MatrixElement* clone() {
54 return new MatrixElement( *this );
55 }
56
57 virtual bool accept( ElementVisitor* visitor );
58
63 virtual void entered( SequenceElement* child );
64
71 virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
72 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
73
74 // drawing
75 //
76 // Drawing depends on a context which knows the required properties like
77 // fonts, spaces and such.
78 // It is essential to calculate elements size with the same context
79 // before you draw.
80
85 virtual void calcSizes( const ContextStyle& cstyle,
87 ContextStyle::IndexStyle istyle,
88 StyleAttributes& style );
89
95 virtual void draw( TQPainter& painter, const LuPixelRect& r,
96 const ContextStyle& context,
98 ContextStyle::IndexStyle istyle,
99 StyleAttributes& style,
100 const LuPixelPoint& parentOrigin );
101
105 virtual void dispatchFontCommand( FontCommand* cmd );
106
107 // navigation
108 //
109 // The elements are responsible to handle cursor movement themselves.
110 // To do this they need to know the direction the cursor moves and
111 // the element it comes from.
112 //
113 // The cursor might be in normal or in selection mode.
114
120 virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
121
127 virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
128
134 virtual void moveUp(FormulaCursor*, BasicElement*);
135
141 virtual void moveDown(FormulaCursor*, BasicElement*);
142
147 virtual void goInside(FormulaCursor* cursor);
148
152 // If there is a main child we must provide the insert/remove semantics.
153 virtual SequenceElement* getMainChild();
154
159 //virtual void insert(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
160
165 //virtual void remove(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
166
171 //virtual void normalize(FormulaCursor*, Direction);
172
177 virtual void selectChild(FormulaCursor*, BasicElement*);
178
183 //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
184
190 //virtual bool isSenseless();
191
196 virtual TQString toLatex();
197
198 virtual TQString formulaString();
199
200 uint getRows() const { return content.count(); }
201 uint getColumns() const { return content.getFirst()->count(); }
202
203 SequenceElement* elementAt(uint row, uint column);
204
205protected:
206
207 //Save/load support
208
212 virtual TQString getTagName() const { return "MATRIX"; }
213
217 virtual void writeDom(TQDomElement element);
218
219 virtual TQString getElementName() const { return "mtable"; }
220 virtual void writeMathMLAttributes( TQDomElement& element ) const;
221 virtual void writeMathMLContent( TQDomDocument& doc,
222 TQDomElement& element,
223 bool oasisFormat ) const;
228 virtual bool readAttributesFromDom(TQDomElement element);
229
235 virtual bool readContentFromDom(TQDomNode& node);
236
237 virtual bool readAttributesFromMathMLDom( const TQDomElement& element );
238
245 virtual int readContentFromMathMLDom(TQDomNode& node);
246
247private:
248 void writeMathMLAttributes( TQDomElement& element );
249
250 MatrixSequenceElement* getElement(uint row, uint column)
251 { return content.at(row)->at(column); }
252
253 const MatrixSequenceElement* getElement( uint row, uint column ) const;
254
260 bool searchElement(BasicElement* element, uint& row, uint& column);
261
265 TQPtrList< TQPtrList< MatrixSequenceElement > > content;
266
270 int m_rowNumber;
271 VerticalAlign m_align;
272 TQValueList< VerticalAlign > m_rowAlign;
273 TQValueList< HorizontalAlign > m_columnAlign;
274 TQValueList< bool > m_alignmentScope;
275 TQValueList< SizeType > m_columnWidthType;
276 TQValueList< double > m_columnWidth;
277 SizeType m_widthType;
278 double m_width;
279 TQValueList< SizeType > m_rowSpacingType;
280 TQValueList< double > m_rowSpacing;
281 TQValueList< SizeType > m_columnSpacingType;
282 TQValueList< double > m_columnSpacing;
283 TQValueList< LineType > m_rowLines;
284 TQValueList< LineType > m_columnLines;
285 LineType m_frame;
286 SizeType m_frameHSpacingType;
287 double m_frameHSpacing;
288 SizeType m_frameVSpacingType;
289 double m_frameVSpacing;
290 SideType m_side;
291 SizeType m_minLabelSpacingType;
292 double m_minLabelSpacing;
293 bool m_equalRows;
294 bool m_customEqualRows;
295 bool m_equalColumns;
296 bool m_customEqualColumns;
297 bool m_displayStyle;
298 bool m_customDisplayStyle;
299};
300
301
302
303class MultilineSequenceElement;
304
305
310 friend class KFCNewLine;
311
312 typedef BasicElement inherited;
313public:
314
319 MultilineElement( BasicElement* parent = 0 );
321
323
324 virtual MultilineElement* clone() {
325 return new MultilineElement( *this );
326 }
327
328 virtual bool accept( ElementVisitor* visitor );
329
334 virtual void entered( SequenceElement* child );
335
339 BasicElement* goToPos( FormulaCursor* cursor, bool& handled,
340 const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
341
346 virtual void goInside(FormulaCursor* cursor);
347
353 virtual void moveLeft( FormulaCursor* cursor, BasicElement* from );
354
360 virtual void moveRight( FormulaCursor* cursor, BasicElement* from );
361
367 virtual void moveUp( FormulaCursor* cursor, BasicElement* from );
368
374 virtual void moveDown( FormulaCursor* cursor, BasicElement* from );
375
380 virtual void calcSizes( const ContextStyle& cstyle,
382 ContextStyle::IndexStyle istyle,
383 StyleAttributes& style );
384
390 virtual void draw( TQPainter& painter, const LuPixelRect& r,
391 const ContextStyle& context,
393 ContextStyle::IndexStyle istyle,
394 StyleAttributes& style,
395 const LuPixelPoint& parentOrigin );
396
400 virtual void dispatchFontCommand( FontCommand* cmd );
401
402 virtual void insert(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
403 virtual void remove(FormulaCursor*, TQPtrList<BasicElement>&, Direction);
404
405 virtual void normalize(FormulaCursor*, Direction);
406
407 virtual SequenceElement* getMainChild();
408
413 virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
414
419 virtual TQString toLatex();
420
421 virtual TQString formulaString();
422
423 virtual void writeMathML( TQDomDocument& doc, TQDomNode& parent, bool oasisFormat = false ) const ;
424
425protected:
426
427 //Save/load support
428
432 virtual TQString getTagName() const { return "MULTILINE"; }
433
437 virtual void writeDom(TQDomElement element);
438
443 virtual bool readAttributesFromDom(TQDomElement element);
444
450 virtual bool readContentFromDom(TQDomNode& node);
451
452
453private:
454
458 TQPtrList< MultilineSequenceElement > content;
459};
460
461
462KFORMULA_NAMESPACE_END
463
464#endif // MATRIXELEMENT_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 int readContentFromMathMLDom(TQDomNode &node)
Reads our content from the MathML node.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual void moveUp(FormulaCursor *, BasicElement *)
Enters this element while moving up starting inside the element ‘from’.
virtual void selectChild(FormulaCursor *, BasicElement *)
Inserts all new children at the cursor position.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual TQString getTagName() const
Returns the tag name of this element type.
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
virtual TQString toLatex()
Moves the cursor away from the given child.
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 moveDown(FormulaCursor *, BasicElement *)
Enters this element while moving down starting inside the element ‘from’.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
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 SequenceElement * getMainChild()
We define the Main Child of a matrix to be the first row/column.
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 BasicElement * goToPos(FormulaCursor *, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Sets the cursor and returns the element the point is in.
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual void goInside(FormulaCursor *cursor)
Sets the cursor inside this element to its start position.
Any number of lines.
virtual void entered(SequenceElement *child)
The cursor has entered one of our child sequences.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
virtual void insert(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Inserts all new children at the cursor position.
BasicElement * goToPos(FormulaCursor *cursor, bool &handled, const LuPixelPoint &point, const LuPixelPoint &parentOrigin)
Returns the element the point is in.
virtual void remove(FormulaCursor *, TQPtrList< BasicElement > &, Direction)
Removes all selected children and returns them.
virtual void moveDown(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving down starting inside the element ‘from’.
virtual void goInside(FormulaCursor *cursor)
Sets the cursor inside this element to its start 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 bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual void moveRight(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the right starting inside the element ‘from’.
virtual void normalize(FormulaCursor *, Direction)
Moves the cursor to a normal place where new elements might be inserted.
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 TQString getTagName() const
Returns the tag name of this element type.
virtual SequenceElement * getMainChild()
Removes the child.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual void moveUp(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving up starting inside the element ‘from’.
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 TQString toLatex()
virtual void moveLeft(FormulaCursor *cursor, BasicElement *from)
Enters this element while moving to the left starting inside the element ‘from’.
The element that contains a number of children.