textelement.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
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef TEXTELEMENT_H
22#define TEXTELEMENT_H
23
24#include <tqfont.h>
25#include <tqstring.h>
26
27#include "basicelement.h"
28
29class SymbolTable;
30
31
32KFORMULA_NAMESPACE_BEGIN
33
37class TextElement : public BasicElement {
38 TextElement operator=( const TextElement& ) { return *this; }
39public:
40
41 TextElement(TQChar ch = ' ', bool beSymbol = false, BasicElement* parent = 0);
42 TextElement( const TextElement& );
43
44 virtual TextElement* clone() {
45 return new TextElement( *this );
46 }
47
48 virtual bool accept( ElementVisitor* visitor );
49
54 virtual TokenType getTokenType() const;
55
59 virtual bool isInvisible() const;
60
65 virtual TQChar getCharacter() const { return character; }
66
67 // drawing
68 //
69 // Drawing depends on a context which knows the required properties like
70 // fonts, spaces and such.
71 // It is essential to calculate elements size with the same context
72 // before you draw.
73
78 virtual void calcSizes( const ContextStyle& cstyle,
80 ContextStyle::IndexStyle istyle,
81 StyleAttributes& style );
82
88 virtual void draw( TQPainter& painter, const LuPixelRect& r,
89 const ContextStyle& context,
91 ContextStyle::IndexStyle istyle,
92 StyleAttributes& style,
93 const LuPixelPoint& parentOrigin );
94
98 virtual void dispatchFontCommand( FontCommand* cmd );
99
103 void setColor( TQColor c ) { color = c; }
104
105 CharStyle getCharStyle() const { return charStyle(); }
106 void setCharStyle( CharStyle cs );
107
108 CharFamily getCharFamily() const { return charFamily(); }
109 void setCharFamily( CharFamily cf );
110
111 char format() const { return m_format; }
112
117 //virtual void childWillVanish(FormulaCursor*, BasicElement*) {}
118
122 bool isSymbol() const { return symbol; }
123
128 virtual TQString toLatex();
129
130 virtual TQString formulaString();
131
132 virtual void writeMathML( TQDomDocument& doc, TQDomNode& parent, bool oasisFormat = false ) const ;
133
134protected:
135
136 //Save/load support
137
141 virtual TQString getTagName() const { return "TEXT"; }
142
146 virtual void writeDom(TQDomElement element);
147
152 virtual bool readAttributesFromDom(TQDomElement element);
153
159 virtual bool readContentFromDom(TQDomNode& node);
160
164 TQChar getRealCharacter(const ContextStyle& context);
165
169 TQFont getFont(const ContextStyle& context, const StyleAttributes& style);
170
174 void setUpPainter(const ContextStyle& context, TQPainter& painter);
175
176 const SymbolTable& getSymbolTable() const;
177
178private:
179
183 TQChar character;
184
188 bool symbol;
189
193 TQColor color;
194
200 CharStyle charStyle() const { return static_cast<CharStyle>( m_format & 0x0f ); }
201 void charStyle( CharStyle cs )
202 { m_format = ( m_format & 0xf0 ) | static_cast<char>( cs ); }
203
209 CharFamily charFamily() const
210 { return static_cast<CharFamily>( m_format >> 4 ); }
211 void charFamily( CharFamily cf )
212 { m_format = ( m_format & 0x0f ) | ( static_cast<char>( cf ) << 4 ); }
213
218 char m_format;
219};
220
221
226 EmptyElement& operator=( const EmptyElement& ) { return *this; }
227public:
228
229 EmptyElement( BasicElement* parent = 0 );
230 EmptyElement( const EmptyElement& );
231
232 virtual EmptyElement* clone() {
233 return new EmptyElement( *this );
234 }
235
236 virtual bool accept( ElementVisitor* visitor );
237
243 virtual TQChar getCharacter() const { return 'A'; }
244
249 virtual void calcSizes( const ContextStyle& cstyle,
251 ContextStyle::IndexStyle istyle,
252 StyleAttributes& style );
253
259 virtual void draw( TQPainter& painter, const LuPixelRect& r,
260 const ContextStyle& context,
262 ContextStyle::IndexStyle istyle,
263 StyleAttributes& style,
264 const LuPixelPoint& parentOrigin );
265
266
271 virtual TQString toLatex();
272
273protected:
274
275 //Save/load support
276
280 virtual TQString getTagName() const { return "EMPTY"; }
281
282};
283
284
285KFORMULA_NAMESPACE_END
286
287#endif // TEXTELEMENT_H
Basis of every formula element.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
An element that represents an empty box.
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 TQChar getCharacter() const
virtual TQString getTagName() const
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 bool accept(ElementVisitor *visitor)
Visit this element.
virtual TQString toLatex()
Base for all font commands that act on the current selection.
The symbol table.
Definition symboltable.h:77
An element that represents one char.
Definition textelement.h:37
virtual void dispatchFontCommand(FontCommand *cmd)
Dispatch this FontCommand to all our TextElement children.
void setUpPainter(const ContextStyle &context, TQPainter &painter)
Sets up the painter to be used for drawing.
virtual bool isInvisible() const
virtual void writeMathML(TQDomDocument &doc, TQDomNode &parent, bool oasisFormat=false) const
Same as above, just MathML.
virtual TQString toLatex()
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual TQChar getCharacter() const
Definition textelement.h:65
TQChar getRealCharacter(const ContextStyle &context)
bool isSymbol() const
Moves the cursor away from the given child.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual TokenType getTokenType() const
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.
void setColor(TQColor c)
Set the color to use to display.
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 readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual TQString getTagName() const
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
TQFont getFont(const ContextStyle &context, const StyleAttributes &style)