lib

KoTextCustomItem.h
1/* This file is part of the KDE project
2
3 Original TQTextCustomItem is
4 Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
5 KoText modifications
6 Copyright (C) 2001-2005 David Faure <faure@kde.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23
24// This file isn't standalone at this point; it's included by KoRichText.h
25
33class KOTEXT_EXPORT KoTextCustomItem
34{
35public:
36 KoTextCustomItem( KoTextDocument *p );
37 virtual ~KoTextCustomItem();
38 virtual void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected ) /* = 0*/;
39
40 // Called after the item's paragraph has been formatted
41 virtual void finalize() {}
42
43 void move( int x, int y ) { xpos = x; ypos = y; }
44 int x() const { return xpos; }
45 int y() const { return ypos; }
46
47 // Called when the format of the character is being changed, see KoTextStringChar::setFormat
48 virtual void setFormat( KoTextFormat * ) { }
49
50 //virtual void setPainter( TQPainter*, bool adjust );
51
52 enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
53 virtual Placement placement() const { return PlaceInline; }
54 bool placeInline() { return placement() == PlaceInline; }
55
56 virtual bool ownLine() const { return false; }
57 // Called for "ownline" items
58 virtual void resize( int nwidth ) { width = nwidth; }
59 virtual void invalidate() {};
60
61 virtual bool isNested() const { return false; }
62 virtual int minimumWidth() const { return 0; }
63 virtual int widthHint() const { return 0; }
64 virtual int ascent() const { return height; }
65
66 virtual TQString richText() const { return TQString(); }
67
68 int width;
69 int height;
70
71 TQRect geometry() const { return TQRect( xpos, ypos, width, height ); }
72
73 virtual bool enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, bool atEnd = false );
74 virtual bool enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, const TQPoint & );
75 virtual bool next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
76 virtual bool prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
77 virtual bool down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
78 virtual bool up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
79
80 void setParagraph( KoTextParag * p ) { parag = p; }
81 KoTextParag *paragraph() const { return parag; }
82
83 virtual void pageBreak( int /*y*/, KoTextFlow* /*flow*/ ) {}
84
85 KoTextDocument *parent;
86
87
88
90 KoTextDocument * textDocument() const { return parent; }
91
95 virtual void setDeleted( bool b ) { m_deleted = b; }
96
97 bool isDeleted() const { return m_deleted; }
98
104 virtual KCommand * createCommand() { return 0L; }
105 virtual KCommand * deleteCommand() { return 0L; }
106
108 virtual void save( TQDomElement& formatElem ) = 0;
110 virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const = 0;
112 virtual int typeId() const = 0;
113
116 virtual void resize() {}
117
122 virtual void recalc() { resize(); }
123
126 int index() const;
127
130 KoTextFormat * format() const;
131
135 virtual void drawCustomItem(TQPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected, int offset, bool drawingShadow) = 0;
136
137protected:
138 bool m_deleted;
139
140protected:
141 int xpos;
142 int ypos;
143private:
144 KoTextParag *parag;
145};
Used during saving to Oasis format (and discarded at the end of the saving).
KoTextCustomItem is the base class for custom items (i.e.
virtual void drawCustomItem(TQPainter *p, int x, int y, int wpix, int hpix, int ascentpix, int cx, int cy, int cw, int ch, const TQColorGroup &cg, bool selected, int offset, bool drawingShadow)=0
All coordinates are in pixels.
KoTextDocument * textDocument() const
The text document in which this customitem is.
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context) const =0
Save to Oasis XML.
virtual void resize()
Reimplement this to calculate the item width It is important to start with "if ( m_deleted ) return;"...
virtual void save(TQDomElement &formatElem)=0
Save to XML.
virtual void setDeleted(bool b)
When the user deletes a custom item, it isn't destroyed but moved into the undo/redo history - setDel...
virtual int typeId() const =0
Return type of custom item.
virtual KCommand * createCommand()
Called when the item is created or 'deleted' by the user Most custom items don't need to reimplement ...
virtual void recalc()
Reimplemented by KoVariable to recalculate the value.
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
A class for writing out XML (to any TQIODevice), with a special attention on performance.
Definition KoXmlWriter.h:37