lib

matrixelement.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                   Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef MATRIXELEMENT_H
00023 #define MATRIXELEMENT_H
00024 
00025 #include <qptrlist.h>
00026 
00027 #include "basicelement.h"
00028 
00029 KFORMULA_NAMESPACE_BEGIN
00030 
00031 
00032 class MatrixSequenceElement;
00033 
00034 
00038 class MatrixElement : public BasicElement {
00039     friend class KFCRemoveColumn;
00040     friend class KFCRemoveRow;
00041     friend class MatrixSequenceElement;
00042 
00043     enum VerticalAlign { NoAlign, TopAlign, BottomAlign, CenterAlign, BaselineAlign, AxisAlign };
00044     enum LineType { NoLine, NoneLine, SolidLine, DashedLine };
00045     enum SideType { NoSide, LeftSide, RightSide, LeftOverlapSide, RightOverlapSide };
00046     MatrixElement& operator=( const MatrixElement& ) { return *this; }
00047 public:
00048     MatrixElement(uint rows = 1, uint columns = 1, BasicElement* parent = 0);
00049     ~MatrixElement();
00050 
00051     MatrixElement( const MatrixElement& );
00052 
00053     virtual MatrixElement* clone() {
00054         return new MatrixElement( *this );
00055     }
00056 
00057     virtual bool accept( ElementVisitor* visitor );
00058 
00063     virtual void entered( SequenceElement* child );
00064 
00071     virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
00072                                    const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
00073 
00074     // drawing
00075     //
00076     // Drawing depends on a context which knows the required properties like
00077     // fonts, spaces and such.
00078     // It is essential to calculate elements size with the same context
00079     // before you draw.
00080 
00085     virtual void calcSizes( const ContextStyle& cstyle,
00086                             ContextStyle::TextStyle tstyle,
00087                             ContextStyle::IndexStyle istyle,
00088                             StyleAttributes& style );
00089 
00095     virtual void draw( QPainter& painter, const LuPixelRect& r,
00096                        const ContextStyle& context,
00097                        ContextStyle::TextStyle tstyle,
00098                        ContextStyle::IndexStyle istyle,
00099                        StyleAttributes& style,
00100                        const LuPixelPoint& parentOrigin );
00101 
00105     virtual void dispatchFontCommand( FontCommand* cmd );
00106 
00107     // navigation
00108     //
00109     // The elements are responsible to handle cursor movement themselves.
00110     // To do this they need to know the direction the cursor moves and
00111     // the element it comes from.
00112     //
00113     // The cursor might be in normal or in selection mode.
00114 
00120     virtual void moveLeft(FormulaCursor* cursor, BasicElement* from);
00121 
00127     virtual void moveRight(FormulaCursor* cursor, BasicElement* from);
00128 
00134     virtual void moveUp(FormulaCursor*, BasicElement*);
00135 
00141     virtual void moveDown(FormulaCursor*, BasicElement*);
00142 
00147     virtual void goInside(FormulaCursor* cursor);
00148 
00152     // If there is a main child we must provide the insert/remove semantics.
00153     virtual SequenceElement* getMainChild();
00154 
00159     //virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00160 
00165     //virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00166 
00171     //virtual void normalize(FormulaCursor*, Direction);
00172 
00177     virtual void selectChild(FormulaCursor*, BasicElement*);
00178 
00183     //virtual void childWillVanish(FormulaCursor* cursor, BasicElement* child) = 0;
00184 
00190     //virtual bool isSenseless();
00191 
00196     virtual QString toLatex();
00197 
00198     virtual QString formulaString();
00199 
00200     uint getRows() const { return content.count(); }
00201     uint getColumns() const { return content.getFirst()->count(); }
00202 
00203     SequenceElement* elementAt(uint row, uint column);
00204 
00205 protected:
00206 
00207     //Save/load support
00208 
00212     virtual QString getTagName() const { return "MATRIX"; }
00213 
00217     virtual void writeDom(QDomElement element);
00218 
00219     virtual QString getElementName() const { return "mtable"; }
00220     virtual void writeMathMLAttributes( QDomElement& element ) const;
00221     virtual void writeMathMLContent( QDomDocument& doc, 
00222                                      QDomElement& element,
00223                                      bool oasisFormat ) const;
00228     virtual bool readAttributesFromDom(QDomElement element);
00229 
00235     virtual bool readContentFromDom(QDomNode& node);
00236 
00237     virtual bool readAttributesFromMathMLDom( const QDomElement& element );
00238 
00245     virtual int readContentFromMathMLDom(QDomNode& node);
00246 
00247 private:
00248     void writeMathMLAttributes( QDomElement& element );
00249 
00250     MatrixSequenceElement* getElement(uint row, uint column)
00251         { return content.at(row)->at(column); }
00252 
00253     const MatrixSequenceElement* getElement( uint row, uint column ) const;
00254 
00260     bool searchElement(BasicElement* element, uint& row, uint& column);
00261 
00265     QPtrList< QPtrList< MatrixSequenceElement > > content;
00266 
00270     int m_rowNumber;
00271     VerticalAlign m_align;
00272     QValueList< VerticalAlign > m_rowAlign;
00273     QValueList< HorizontalAlign > m_columnAlign;
00274     QValueList< bool > m_alignmentScope;
00275     QValueList< SizeType > m_columnWidthType;
00276     QValueList< double > m_columnWidth;
00277     SizeType m_widthType;
00278     double m_width;
00279     QValueList< SizeType > m_rowSpacingType;
00280     QValueList< double > m_rowSpacing;
00281     QValueList< SizeType > m_columnSpacingType;
00282     QValueList< double > m_columnSpacing;
00283     QValueList< LineType > m_rowLines;
00284     QValueList< LineType > m_columnLines;
00285     LineType m_frame;
00286     SizeType m_frameHSpacingType;
00287     double m_frameHSpacing;
00288     SizeType m_frameVSpacingType;
00289     double m_frameVSpacing;
00290     SideType m_side;
00291     SizeType m_minLabelSpacingType;
00292     double m_minLabelSpacing;
00293     bool m_equalRows;
00294     bool m_customEqualRows;
00295     bool m_equalColumns;
00296     bool m_customEqualColumns;
00297     bool m_displayStyle;
00298     bool m_customDisplayStyle;
00299 };
00300 
00301 
00302 
00303 class MultilineSequenceElement;
00304 
00305 
00309 class MultilineElement : public BasicElement {
00310     friend class KFCNewLine;
00311 
00312     typedef BasicElement inherited;
00313 public:
00314 
00319     MultilineElement( BasicElement* parent = 0 );
00320     ~MultilineElement();
00321 
00322     MultilineElement( const MultilineElement& );
00323 
00324     virtual MultilineElement* clone() {
00325         return new MultilineElement( *this );
00326     }
00327 
00328     virtual bool accept( ElementVisitor* visitor );
00329 
00334     virtual void entered( SequenceElement* child );
00335 
00339     BasicElement* goToPos( FormulaCursor* cursor, bool& handled,
00340                            const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
00341 
00346     virtual void goInside(FormulaCursor* cursor);
00347 
00353     virtual void moveLeft( FormulaCursor* cursor, BasicElement* from );
00354 
00360     virtual void moveRight( FormulaCursor* cursor, BasicElement* from );
00361 
00367     virtual void moveUp( FormulaCursor* cursor, BasicElement* from );
00368 
00374     virtual void moveDown( FormulaCursor* cursor, BasicElement* from );
00375 
00380     virtual void calcSizes( const ContextStyle& cstyle,
00381                             ContextStyle::TextStyle tstyle,
00382                             ContextStyle::IndexStyle istyle,
00383                             StyleAttributes& style );
00384 
00390     virtual void draw( QPainter& painter, const LuPixelRect& r,
00391                        const ContextStyle& context,
00392                        ContextStyle::TextStyle tstyle,
00393                        ContextStyle::IndexStyle istyle,
00394                        StyleAttributes& style,
00395                        const LuPixelPoint& parentOrigin );
00396 
00400     virtual void dispatchFontCommand( FontCommand* cmd );
00401 
00402     virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00403     virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
00404 
00405     virtual void normalize(FormulaCursor*, Direction);
00406 
00407     virtual SequenceElement* getMainChild();
00408 
00413     virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
00414 
00419     virtual QString toLatex();
00420 
00421     virtual QString formulaString();
00422 
00423     virtual void writeMathML( QDomDocument& doc, QDomNode& parent, bool oasisFormat = false ) const ;
00424 
00425 protected:
00426 
00427     //Save/load support
00428 
00432     virtual QString getTagName() const { return "MULTILINE"; }
00433 
00437     virtual void writeDom(QDomElement element);
00438 
00443     virtual bool readAttributesFromDom(QDomElement element);
00444 
00450     virtual bool readContentFromDom(QDomNode& node);
00451 
00452 
00453 private:
00454 
00458     QPtrList< MultilineSequenceElement > content;
00459 };
00460 
00461 
00462 KFORMULA_NAMESPACE_END
00463 
00464 #endif // MATRIXELEMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys