lib

textelement.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 TEXTELEMENT_H
00022 #define TEXTELEMENT_H
00023 
00024 #include <qfont.h>
00025 #include <qstring.h>
00026 
00027 #include "basicelement.h"
00028 
00029 class SymbolTable;
00030 
00031 
00032 KFORMULA_NAMESPACE_BEGIN
00033 
00037 class TextElement : public BasicElement {
00038     TextElement operator=( const TextElement& ) { return *this; }
00039 public:
00040 
00041     TextElement(QChar ch = ' ', bool beSymbol = false, BasicElement* parent = 0);
00042     TextElement( const TextElement& );
00043 
00044     virtual TextElement* clone() {
00045         return new TextElement( *this );
00046     }
00047 
00048     virtual bool accept( ElementVisitor* visitor );
00049 
00054     virtual TokenType getTokenType() const;
00055 
00059     virtual bool isInvisible() const;
00060 
00065     virtual QChar getCharacter() const { return character; }
00066 
00067     // drawing
00068     //
00069     // Drawing depends on a context which knows the required properties like
00070     // fonts, spaces and such.
00071     // It is essential to calculate elements size with the same context
00072     // before you draw.
00073 
00078     virtual void calcSizes( const ContextStyle& style,
00079                             ContextStyle::TextStyle tstyle,
00080                             ContextStyle::IndexStyle istyle,
00081                             StyleAttributes& style );
00082 
00088     virtual void draw( QPainter& painter, const LuPixelRect& r,
00089                        const ContextStyle& context,
00090                        ContextStyle::TextStyle tstyle,
00091                        ContextStyle::IndexStyle istyle,
00092                        StyleAttributes& style,
00093                        const LuPixelPoint& parentOrigin );
00094 
00098     virtual void dispatchFontCommand( FontCommand* cmd );
00099 
00103     void setColor( QColor c ) { color = c; }
00104 
00105     CharStyle getCharStyle() const { return charStyle(); }
00106     void setCharStyle( CharStyle cs );
00107 
00108     CharFamily getCharFamily() const { return charFamily(); }
00109     void setCharFamily( CharFamily cf );
00110 
00111     char format() const { return m_format; }
00112 
00117     //virtual void childWillVanish(FormulaCursor*, BasicElement*) {}
00118 
00122     bool isSymbol() const { return symbol; }
00123 
00128     virtual QString toLatex();
00129 
00130     virtual QString formulaString();
00131 
00132     virtual void writeMathML( QDomDocument& doc, QDomNode& parent, bool oasisFormat = false ) const ;
00133 
00134 protected:
00135 
00136     //Save/load support
00137 
00141     virtual QString getTagName() const { return "TEXT"; }
00142 
00146     virtual void writeDom(QDomElement element);
00147 
00152     virtual bool readAttributesFromDom(QDomElement element);
00153 
00159     virtual bool readContentFromDom(QDomNode& node);
00160 
00164     QChar getRealCharacter(const ContextStyle& context);
00165 
00169     QFont getFont(const ContextStyle& context, const StyleAttributes& style);
00170 
00174     void setUpPainter(const ContextStyle& context, QPainter& painter);
00175 
00176     const SymbolTable& getSymbolTable() const;
00177 
00178 private:
00179 
00183     QChar character;
00184 
00188     bool symbol;
00189 
00193     QColor color;
00194 
00200     CharStyle charStyle() const { return static_cast<CharStyle>( m_format & 0x0f ); }
00201     void charStyle( CharStyle cs )
00202         { m_format = ( m_format & 0xf0 ) | static_cast<char>( cs ); }
00203 
00209     CharFamily charFamily() const
00210         { return static_cast<CharFamily>( m_format >> 4 ); }
00211     void charFamily( CharFamily cf )
00212         { m_format = ( m_format & 0x0f ) | ( static_cast<char>( cf ) << 4 ); }
00213 
00218     char m_format;
00219 };
00220 
00221 
00225 class EmptyElement : public BasicElement {
00226     EmptyElement& operator=( const EmptyElement& ) { return *this; }
00227 public:
00228 
00229     EmptyElement( BasicElement* parent = 0 );
00230     EmptyElement( const EmptyElement& );
00231 
00232     virtual EmptyElement* clone() {
00233         return new EmptyElement( *this );
00234     }
00235 
00236     virtual bool accept( ElementVisitor* visitor );
00237 
00243     virtual QChar getCharacter() const { return 'A'; }
00244 
00249     virtual void calcSizes( const ContextStyle& style,
00250                             ContextStyle::TextStyle tstyle,
00251                             ContextStyle::IndexStyle istyle,
00252                             StyleAttributes& style );
00253 
00259     virtual void draw( QPainter& painter, const LuPixelRect& r,
00260                        const ContextStyle& context,
00261                        ContextStyle::TextStyle tstyle,
00262                        ContextStyle::IndexStyle istyle,
00263                        StyleAttributes& style,
00264                        const LuPixelPoint& parentOrigin );
00265 
00266 
00271     virtual QString toLatex();
00272 
00273 protected:
00274 
00275     //Save/load support
00276 
00280     virtual QString getTagName() const { return "EMPTY"; }
00281 
00282 };
00283 
00284 
00285 KFORMULA_NAMESPACE_END
00286 
00287 #endif // TEXTELEMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys