lib Library API Documentation

elementtype.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 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef ELEMENTTYPE_H
00022 #define ELEMENTTYPE_H
00023 
00024 #include <qfont.h>
00025 #include <qstring.h>
00026 #include <qdom.h>
00027 
00028 #include "contextstyle.h"
00029 #include "kformuladefs.h"
00030 
00031 class QPainter;
00032 
00033 KFORMULA_NAMESPACE_BEGIN
00034 
00035 class BasicElement;
00036 class BracketType;
00037 class ComplexElementType;
00038 class InnerElementType;
00039 class MultiElementType;
00040 class OperatorType;
00041 class PunctuationType;
00042 class RelationType;
00043 class SequenceElement;
00044 class SequenceParser;
00045 class TextElement;
00046 
00047 
00052 class ElementType {
00053 public:
00054     ElementType(SequenceParser* parser);
00055     virtual ~ElementType();
00056 
00060     virtual bool isInvisible(const TextElement&) const { return false; }
00061 
00066     virtual QString text( SequenceElement* seq ) const;
00067 
00071     uint start() const { return from; }
00072 
00076     uint end() const { return to; }
00077 
00082     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00083     virtual luPt getSpaceAfter( MultiElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00084     virtual luPt getSpaceAfter( OperatorType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00085     virtual luPt getSpaceAfter( RelationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00086     virtual luPt getSpaceAfter( PunctuationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00087     virtual luPt getSpaceAfter( BracketType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00088     virtual luPt getSpaceAfter( ComplexElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00089     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00090 
00094     virtual QFont getFont( const ContextStyle& context );
00095 
00099     virtual void setUpPainter( const ContextStyle& context, QPainter& painter );
00100 
00101     // debug
00102     static int getEvilDestructionCount() { return evilDestructionCount; }
00103 
00104     virtual void output();
00105 
00109     void append( ElementType* );
00110 
00111     ElementType* getPrev() const { return prev; }
00112 
00113     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00114 
00115     virtual bool multiElement() const { return false; }
00116 
00117 protected:
00118 
00119     void setStart( uint start ) { from = start; }
00120     void setEnd( uint end ) { to = end; }
00121 
00122     luPt thinSpaceIfNotScript( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00123     luPt mediumSpaceIfNotScript( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00124     luPt thickSpaceIfNotScript( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00125 
00126 private:
00127 
00132     uint from;
00133 
00138     uint to;
00139 
00144     ElementType* prev;
00145 
00146     // debug
00147     static int evilDestructionCount;
00148 };
00149 
00150 
00155 class SequenceType : public ElementType {
00156 public:
00157     SequenceType( SequenceParser* parser );
00158     ~SequenceType();
00159 
00160     virtual void output();
00161 private:
00162 
00166     ElementType* last;
00167 };
00168 
00169 
00173 class MultiElementType : public ElementType {
00174 public:
00175     MultiElementType( SequenceParser* parser );
00176 
00177     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00178     virtual luPt getSpaceAfter( OperatorType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00179     virtual luPt getSpaceAfter( RelationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00180     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00181 
00182     virtual bool multiElement() const { return true; }
00183 
00188     virtual QString text( SequenceElement* /*seq*/ ) const { return m_text; }
00189 
00190 private:
00191 
00192     QString m_text;
00193 };
00194 
00195 
00200 class TextType : public MultiElementType {
00201 public:
00202     TextType( SequenceParser* parser );
00203     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00204 };
00205 
00206 
00210 class NumberType : public MultiElementType {
00211 public:
00212     NumberType(SequenceParser* parser);
00213 
00217     virtual QFont getFont(const ContextStyle& context);
00218 
00222     virtual void setUpPainter(const ContextStyle& context, QPainter& painter);
00223 
00224     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00225 };
00226 
00227 
00231 class SingleElementType : public ElementType {
00232 public:
00233     SingleElementType( SequenceParser* parser );
00234 };
00235 
00236 
00240 class NameType : public MultiElementType {
00241 public:
00242     NameType( SequenceParser* parser );
00243 
00247     virtual QFont getFont( const ContextStyle& context );
00248 
00249     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00250 
00251 private:
00252 };
00253 
00254 
00255 class AbstractOperatorType : public SingleElementType {
00256 public:
00257     AbstractOperatorType( SequenceParser* parser );
00258 
00259     void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false  );
00260 };
00261 
00262 class OperatorType : public AbstractOperatorType {
00263 public:
00264     OperatorType( SequenceParser* parser );
00265 
00266     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00267     virtual luPt getSpaceAfter( MultiElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00268     virtual luPt getSpaceAfter( BracketType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00269     virtual luPt getSpaceAfter( ComplexElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00270     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00271 
00275     virtual QFont getFont(const ContextStyle& context);
00276 
00280     virtual void setUpPainter(const ContextStyle& context, QPainter& painter);
00281 };
00282 
00283 
00284 class RelationType : public AbstractOperatorType {
00285 public:
00286     RelationType( SequenceParser* parser );
00287 
00288     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00289     virtual luPt getSpaceAfter( MultiElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00290     virtual luPt getSpaceAfter( BracketType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00291     virtual luPt getSpaceAfter( ComplexElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00292     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00293 
00297     virtual QFont getFont( const ContextStyle& context );
00298 
00302     virtual void setUpPainter( const ContextStyle& context, QPainter& painter );
00303 };
00304 
00305 
00306 class PunctuationType : public AbstractOperatorType {
00307 public:
00308     PunctuationType( SequenceParser* parser );
00309 
00310     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00311     virtual luPt getSpaceAfter( MultiElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00312     virtual luPt getSpaceAfter( RelationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00313     virtual luPt getSpaceAfter( PunctuationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00314     virtual luPt getSpaceAfter( BracketType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00315     virtual luPt getSpaceAfter( ComplexElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00316     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00317 
00321     virtual QFont getFont( const ContextStyle& context );
00322 
00326     virtual void setUpPainter( const ContextStyle& context, QPainter& painter );
00327 };
00328 
00329 
00330 class BracketType : public SingleElementType {
00331 public:
00332     BracketType( SequenceParser* parser );
00333 
00334     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00335     virtual luPt getSpaceAfter( OperatorType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00336     virtual luPt getSpaceAfter( RelationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00337     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00338 };
00339 
00340 
00341 class ComplexElementType : public SingleElementType {
00342 public:
00343     ComplexElementType( SequenceParser* parser );
00344 
00345     // these spacings are equal to the ones from MultiElementType
00346     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00347     virtual luPt getSpaceAfter( OperatorType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00348     virtual luPt getSpaceAfter( RelationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00349     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00350 };
00351 
00352 
00353 class InnerElementType : public SingleElementType {
00354 public:
00355     InnerElementType( SequenceParser* parser );
00356 
00357     virtual luPt getSpaceBefore( const ContextStyle& context, ContextStyle::TextStyle tstyle );
00358     virtual luPt getSpaceAfter( MultiElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00359     virtual luPt getSpaceAfter( OperatorType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00360     virtual luPt getSpaceAfter( RelationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00361     virtual luPt getSpaceAfter( PunctuationType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00362     virtual luPt getSpaceAfter( BracketType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00363     virtual luPt getSpaceAfter( ComplexElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00364     virtual luPt getSpaceAfter( InnerElementType* type, const ContextStyle& context, ContextStyle::TextStyle tstyle );
00365 };
00366 
00367 
00368 KFORMULA_NAMESPACE_END
00369 
00370 #endif // ELEMENTTYPE_H
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:39:55 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003