lib

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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, 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, 
00083                                  ContextStyle::TextStyle tstyle,
00084                                  double factor );
00085     virtual luPt getSpaceAfter( MultiElementType* type,
00086                                 const ContextStyle& context, 
00087                                 ContextStyle::TextStyle tstyle,
00088                                 double factor );
00089     virtual luPt getSpaceAfter( OperatorType* type,
00090                                 const ContextStyle& context,
00091                                 ContextStyle::TextStyle tstyle,
00092                                 double factor );
00093     virtual luPt getSpaceAfter( RelationType* type,
00094                                 const ContextStyle& context, 
00095                                 ContextStyle::TextStyle tstyle,
00096                                 double factor );
00097     virtual luPt getSpaceAfter( PunctuationType* type, 
00098                                 const ContextStyle& context,
00099                                 ContextStyle::TextStyle tstyle,
00100                                 double factor );
00101     virtual luPt getSpaceAfter( BracketType* type,
00102                                 const ContextStyle& context, 
00103                                 ContextStyle::TextStyle tstyle,
00104                                 double factor );
00105     virtual luPt getSpaceAfter( ComplexElementType* type,
00106                                 const ContextStyle& context,
00107                                 ContextStyle::TextStyle tstyle,
00108                                 double factor );
00109     virtual luPt getSpaceAfter( InnerElementType* type,
00110                                 const ContextStyle& context,
00111                                 ContextStyle::TextStyle tstyle,
00112                                 double factor );
00113 
00117     virtual QFont getFont( const ContextStyle& context );
00118 
00122     virtual void setUpPainter( const ContextStyle& context, QPainter& painter );
00123 
00124     // debug
00125     static int getEvilDestructionCount() { return evilDestructionCount; }
00126 
00127     virtual void output();
00128 
00132     void append( ElementType* );
00133 
00134     ElementType* getPrev() const { return prev; }
00135 
00136     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00137 
00138     virtual bool multiElement() const { return false; }
00139 
00140 protected:
00141 
00142     void setStart( uint start ) { from = start; }
00143     void setEnd( uint end ) { to = end; }
00144 
00145     luPt thinSpaceIfNotScript( const ContextStyle& context,
00146                                ContextStyle::TextStyle tstyle,
00147                                double factor );
00148     luPt mediumSpaceIfNotScript( const ContextStyle& context, 
00149                                  ContextStyle::TextStyle tstyle,
00150                                  double factor );
00151     luPt thickSpaceIfNotScript( const ContextStyle& context,
00152                                 ContextStyle::TextStyle tstyle,
00153                                 double factor );
00154 
00155 private:
00156 
00161     uint from;
00162 
00167     uint to;
00168 
00173     ElementType* prev;
00174 
00175     // debug
00176     static int evilDestructionCount;
00177 };
00178 
00179 
00184 class SequenceType : public ElementType {
00185 public:
00186     SequenceType( SequenceParser* parser );
00187     ~SequenceType();
00188 
00189     virtual void output();
00190 private:
00191 
00195     ElementType* last;
00196 };
00197 
00198 
00202 class MultiElementType : public ElementType {
00203 public:
00204     MultiElementType( SequenceParser* parser );
00205 
00206     virtual luPt getSpaceBefore( const ContextStyle& context, 
00207                                  ContextStyle::TextStyle tstyle, 
00208                                  double factor );
00209     virtual luPt getSpaceAfter( OperatorType* type,
00210                                 const ContextStyle& context,
00211                                 ContextStyle::TextStyle tstyle,
00212                                 double factor );
00213     virtual luPt getSpaceAfter( RelationType* type,
00214                                 const ContextStyle& context, 
00215                                 ContextStyle::TextStyle tstyle,
00216                                 double factor );
00217     virtual luPt getSpaceAfter( InnerElementType* type,
00218                                 const ContextStyle& context,
00219                                 ContextStyle::TextStyle tstyle,
00220                                 double factor );
00221 
00222     virtual bool multiElement() const { return true; }
00223 
00228     virtual QString text( SequenceElement* /*seq*/ ) const { return m_text; }
00229 
00230 private:
00231 
00232     QString m_text;
00233 };
00234 
00235 
00240 class TextType : public MultiElementType {
00241 public:
00242     TextType( SequenceParser* parser );
00243     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00244 };
00245 
00246 
00250 class NumberType : public MultiElementType {
00251 public:
00252     NumberType(SequenceParser* parser);
00253 
00257     virtual QFont getFont(const ContextStyle& context);
00258 
00262     virtual void setUpPainter(const ContextStyle& context, QPainter& painter);
00263 
00264     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00265 };
00266 
00267 
00271 class SingleElementType : public ElementType {
00272 public:
00273     SingleElementType( SequenceParser* parser );
00274 };
00275 
00276 
00280 class NameType : public MultiElementType {
00281 public:
00282     NameType( SequenceParser* parser );
00283 
00287     virtual QFont getFont( const ContextStyle& context );
00288 
00289     virtual void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false );
00290 
00291 private:
00292 };
00293 
00294 
00295 class AbstractOperatorType : public SingleElementType {
00296 public:
00297     AbstractOperatorType( SequenceParser* parser );
00298 
00299     void saveMathML( SequenceElement* se, QDomDocument& doc, QDomElement de, bool oasisFormat = false  );
00300 };
00301 
00302 class OperatorType : public AbstractOperatorType {
00303 public:
00304     OperatorType( SequenceParser* parser );
00305 
00306     virtual luPt getSpaceBefore( const ContextStyle& context,
00307                                  ContextStyle::TextStyle tstyle,
00308                                  double factor );
00309     virtual luPt getSpaceAfter( MultiElementType* type,
00310                                 const ContextStyle& context,
00311                                 ContextStyle::TextStyle tstyle,
00312                                 double factor );
00313     virtual luPt getSpaceAfter( BracketType* type,
00314                                 const ContextStyle& context,
00315                                 ContextStyle::TextStyle tstyle,
00316                                 double factor );
00317     virtual luPt getSpaceAfter( ComplexElementType* type,
00318                                 const ContextStyle& context,
00319                                 ContextStyle::TextStyle tstyle,
00320                                 double factor );
00321     virtual luPt getSpaceAfter( InnerElementType* type,
00322                                 const ContextStyle& context,
00323                                 ContextStyle::TextStyle tstyle,
00324                                 double factor );
00325 
00329     virtual QFont getFont(const ContextStyle& context);
00330 
00334     virtual void setUpPainter(const ContextStyle& context, QPainter& painter);
00335 };
00336 
00337 
00338 class RelationType : public AbstractOperatorType {
00339 public:
00340     RelationType( SequenceParser* parser );
00341 
00342     virtual luPt getSpaceBefore( const ContextStyle& context,
00343                                  ContextStyle::TextStyle tstyle,
00344                                  double factor );
00345     virtual luPt getSpaceAfter( MultiElementType* type,
00346                                 const ContextStyle& context,
00347                                 ContextStyle::TextStyle tstyle,
00348                                 double factor );
00349     virtual luPt getSpaceAfter( BracketType* type,
00350                                 const ContextStyle& context, 
00351                                 ContextStyle::TextStyle tstyle,
00352                                 double factor );
00353     virtual luPt getSpaceAfter( ComplexElementType* type,
00354                                 const ContextStyle& context,
00355                                 ContextStyle::TextStyle tstyle,
00356                                 double factor );
00357     virtual luPt getSpaceAfter( InnerElementType* type,
00358                                 const ContextStyle& context,
00359                                 ContextStyle::TextStyle tstyle,
00360                                 double factor );
00361 
00365     virtual QFont getFont( const ContextStyle& context );
00366 
00370     virtual void setUpPainter( const ContextStyle& context, QPainter& painter );
00371 };
00372 
00373 
00374 class PunctuationType : public AbstractOperatorType {
00375 public:
00376     PunctuationType( SequenceParser* parser );
00377 
00378     virtual luPt getSpaceBefore( const ContextStyle& context, 
00379                                  ContextStyle::TextStyle tstyle, 
00380                                  double factor );
00381     virtual luPt getSpaceAfter( MultiElementType* type,
00382                                 const ContextStyle& context,
00383                                 ContextStyle::TextStyle tstyle,
00384                                 double factor );
00385     virtual luPt getSpaceAfter( RelationType* type,
00386                                 const ContextStyle& context,
00387                                 ContextStyle::TextStyle tstyle,
00388                                 double factor );
00389     virtual luPt getSpaceAfter( PunctuationType* type,
00390                                 const ContextStyle& context,
00391                                 ContextStyle::TextStyle tstyle,
00392                                 double factor );
00393     virtual luPt getSpaceAfter( BracketType* type,
00394                                 const ContextStyle& context,
00395                                 ContextStyle::TextStyle tstyle,
00396                                 double factor );
00397     virtual luPt getSpaceAfter( ComplexElementType* type,
00398                                 const ContextStyle& context,
00399                                 ContextStyle::TextStyle tstyle,
00400                                 double factor );
00401     virtual luPt getSpaceAfter( InnerElementType* type,
00402                                 const ContextStyle& context,
00403                                 ContextStyle::TextStyle tstyle,
00404                                 double factor );
00405 
00409     virtual QFont getFont( const ContextStyle& context );
00410 
00414     virtual void setUpPainter( const ContextStyle& context, QPainter& painter );
00415 };
00416 
00417 
00418 class BracketType : public SingleElementType {
00419 public:
00420     BracketType( SequenceParser* parser );
00421 
00422     virtual luPt getSpaceBefore( const ContextStyle& context, 
00423                                  ContextStyle::TextStyle tstyle,
00424                                  double factor );
00425     virtual luPt getSpaceAfter( OperatorType* type,
00426                                 const ContextStyle& context,
00427                                 ContextStyle::TextStyle tstyle,
00428                                 double factor );
00429     virtual luPt getSpaceAfter( RelationType* type,
00430                                 const ContextStyle& context,
00431                                 ContextStyle::TextStyle tstyle,
00432                                 double factor );
00433     virtual luPt getSpaceAfter( InnerElementType* type,
00434                                 const ContextStyle& context,
00435                                 ContextStyle::TextStyle tstyle,
00436                                 double factor );
00437 };
00438 
00439 
00440 class ComplexElementType : public SingleElementType {
00441 public:
00442     ComplexElementType( SequenceParser* parser );
00443 
00444     // these spacings are equal to the ones from MultiElementType
00445     virtual luPt getSpaceBefore( const ContextStyle& context,
00446                                  ContextStyle::TextStyle tstyle,
00447                                  double factor );
00448     virtual luPt getSpaceAfter( OperatorType* type,
00449                                 const ContextStyle& context, 
00450                                 ContextStyle::TextStyle tstyle,
00451                                 double factor );
00452     virtual luPt getSpaceAfter( RelationType* type,
00453                                 const ContextStyle& context,
00454                                 ContextStyle::TextStyle tstyle,
00455                                 double factor );
00456     virtual luPt getSpaceAfter( InnerElementType* type,
00457                                 const ContextStyle& context,
00458                                 ContextStyle::TextStyle tstyle,
00459                                 double factor );
00460 };
00461 
00462 
00463 class InnerElementType : public SingleElementType {
00464 public:
00465     InnerElementType( SequenceParser* parser );
00466 
00467     virtual luPt getSpaceBefore( const ContextStyle& context,
00468                                  ContextStyle::TextStyle tstyle,
00469                                  double factor );
00470     virtual luPt getSpaceAfter( MultiElementType* type,
00471                                 const ContextStyle& context,
00472                                 ContextStyle::TextStyle tstyle,
00473                                 double factor );
00474     virtual luPt getSpaceAfter( OperatorType* type,
00475                                 const ContextStyle& context,
00476                                 ContextStyle::TextStyle tstyle,
00477                                 double factor );
00478     virtual luPt getSpaceAfter( RelationType* type,
00479                                 const ContextStyle& context,
00480                                 ContextStyle::TextStyle tstyle,
00481                                 double factor );
00482     virtual luPt getSpaceAfter( PunctuationType* type,
00483                                 const ContextStyle& context,
00484                                 ContextStyle::TextStyle tstyle,
00485                                 double factor );
00486     virtual luPt getSpaceAfter( BracketType* type,
00487                                 const ContextStyle& context,
00488                                 ContextStyle::TextStyle tstyle,
00489                                 double factor );
00490     virtual luPt getSpaceAfter( ComplexElementType* type,
00491                                 const ContextStyle& context,
00492                                 ContextStyle::TextStyle tstyle,
00493                                 double factor );
00494     virtual luPt getSpaceAfter( InnerElementType* type,
00495                                 const ContextStyle& context,
00496                                 ContextStyle::TextStyle tstyle,
00497                                 double factor );
00498 };
00499 
00500 
00501 KFORMULA_NAMESPACE_END
00502 
00503 #endif // ELEMENTTYPE_H
KDE Home | KDE Accessibility Home | Description of Access Keys