kpresenter

KPrTextObject.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
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 kptextobject_h
22#define kptextobject_h
23
24#include "KPrObject.h"
25#include "KoRichText.h"
26#include <KoTextView.h>
27#include <KoStyleCollection.h> // for KoStyleChangeDefMap
28#include <KoStyleStack.h>
29
30class TQDragObject;
31
32class KoSavingContext;
33class KPrView;
34class KPrDocument;
35class TQDomElement;
36class TextCmd;
37class KPrGradient;
38
39class KoTextView;
40class KoTextObject;
41class KPrTextView;
42class KCommand;
43class KPrCanvas;
44class KoPoint;
45class KoVariable;
46class KPrTextDocument;
47class DCOPObject;
48class KPrPage;
49class KoParagStyle;
50
51class KPrTextObject : public TQObject, public KPr2DObject, public KoTextFlow
52{
53 TQ_OBJECT
54
55public:
56 KPrTextObject( KPrDocument *doc );
57 virtual ~KPrTextObject();
58
59 virtual DCOPObject* dcopObject();
60
61 virtual void setSize( double _width, double _height );
62
63 virtual void setDrawEditRect( bool b )
64 { drawEditRect = b; }
65 virtual void setDrawEmpty( bool b )
66 { drawEmpty = b; }
67
68 virtual ObjType getType() const
69 { return OT_TEXT; }
70 virtual TQString getTypeString() const
71 { return i18n("Text"); }
72
73 virtual bool getDrawEditRect() const
74 { return drawEditRect; }
75 virtual bool getDrawEmpty() const
76 { return drawEmpty; }
77 virtual int getSubPresSteps() const;
78
79 virtual TQBrush getBrush() const;
80
81 virtual void setShadowParameter(int _distance,ShadowDirection _direction,const TQColor &_color);
82
83 virtual TQDomDocumentFragment save( TQDomDocument& doc, double offset );
84 virtual double load(const TQDomElement &element);
85 virtual void loadOasis(const TQDomElement &element, KoOasisContext& context, KPrLoadingInfo *info);
86 virtual void saveOasisMarginElement( KoGenStyle &styleobjectauto ) const;
87
88 virtual void paint( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
89 int pageNum, bool drawingShadow, bool drawContour );
90 void paint( TQPainter *_painter, KoTextZoomHandler*_zoomHandler, bool onlyChanged, KoTextCursor* cursor,
91 bool resetChanged, bool drawContour );
92 void paintEdited( TQPainter *_painter, KoTextZoomHandler*_zoomHandler,
93 bool onlyChanged, KoTextCursor* cursor, bool resetChanged );
94
95 void drawCursor( TQPainter *p, KoTextCursor *cursor, bool cursorVisible, KPrCanvas* /*canvas*/ );
96
97 void recalcPageNum( KPrPage *page );
99 TQPoint cursorPos(KPrCanvas*, KoTextCursor *) const;
100
101
103 KoTextObject * textObject() const { return m_textobj; }
104 virtual void addTextObjects( TQPtrList<KoTextObject> &lst ) const {
105 if ( !isProtectContent() )
106 lst.append( m_textobj );
107 }
108
109 KPrTextDocument *textDocument() const;
110
111 KPrDocument* kPresenterDocument() const { return m_doc; }
112
113 KPrTextView * createKPTextView( KPrCanvas *,bool temp=false );
114 void applyStyleChange( KoStyleChangeDefMap changed );
115
116 void removeHighlight();
117 void highlightPortion( KoTextParag * parag, int index, int length, KPrCanvas *canvas, bool repaint, KDialogBase* dialog = 0 );
118
119 KCommand * pasteOasis( KoTextCursor * cursor, const TQByteArray & data, bool removeSelected );
120
121 void saveParagraph( TQDomDocument& doc,
122 KoTextParag * parag,
123 TQDomElement &parentElem,
124 int from /* default 0 */,
125 int to /* default length()-2 */ );
126 KoParagLayout loadParagLayout( TQDomElement & parentElem, KPrDocument *doc, bool useRefStyle);
127
128 static KoTextFormat loadFormat( TQDomElement &n, KoTextFormat * refFormat, const TQFont & defaultFont,
129 const TQString & defaultLanguage, bool hyphen );
130
131 void setEditingTextObj( bool _edit ) { editingTextObj = _edit; }
132
133 KCommand *textContentsToHeight();
134 KCommand *textObjectToContents();
135 void setProtectContent ( bool _protect ) { textObject()->setProtectContent(_protect);}
136 bool isProtectContent() const { return textObject()->protectContent();}
137 void loadVariable( TQValueList<TQDomElement> & listVariable,KoTextParag *lastParag, int offset=0 );
138
139 void layout();
140
142 int availableHeight() const;
143
145 void setBLeft( double b ) { bleft = b; }
147 void setBRight( double b ) { bright = b; }
149 void setBTop( double b ) { btop = b; }
151 void setBBottom( double b ) { bbottom = b; }
152
154 double bLeft()const { return bleft; }
156 double bRight()const { return bright; }
158 double bTop()const { return btop; }
160 double bBottom()const { return bbottom; }
161
162 void setTextMargins( double _left, double _top, double right, double bottom);
163
164 KoRect innerRect() const;
165 double innerWidth() const;
166 double innerHeight() const;
167 void resizeTextDocument( bool widthChanged = true, bool heightChanged = true );
168
169 VerticalAlignmentType verticalAlignment() const { return m_textVertAlign; }
170 void setVerticalAligment( VerticalAlignmentType _type) ;
171 double alignmentValue() const { return alignVertical; }
172 virtual KPrTextObject *nextTextObject() { return this;}
173 static void saveFormat( TQDomElement & element, KoTextFormat*lastFormat );
174
175 TQPoint viewToInternal( const TQPoint & pos, KPrCanvas* canvas ) const;
176
177signals:
178 void repaintChanged( KPrTextObject* );
179
180protected slots:
181 void slotFormatChanged(const KoTextFormat &);
182 void slotAfterFormatting( int, KoTextParag*, bool* );
183 void slotParagraphDeleted(KoTextParag*_parag);
184protected:
185 virtual const char * getOasisElementName() const;
186 virtual bool saveOasisObjectAttributes( KPOasisSaveContext &sc ) const;
187
188 virtual TQDomElement saveKTextObject( TQDomDocument& doc );
189 TQDomElement saveHelper(const TQString &tmpText,KoTextFormat*lastFormat ,TQDomDocument &doc);
190
191 virtual void fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles ) const;
192
193 virtual void loadKTextObject( const TQDomElement &e );
194 void drawText( TQPainter* _painter, KoTextZoomHandler* zoomHandler, bool onlyChanged, KoTextCursor* cursor, bool resetChanged );
195 void drawParags( TQPainter *p, KoTextZoomHandler* zoomHandler, const TQColorGroup& cg, int from, int to );
196 void saveParagLayout( const KoParagLayout& layout, TQDomElement & parentElem );
197 void invalidate();
198 void recalcVerticalAlignment();
199 virtual KoPen defaultPen() const;
200protected slots:
201 void slotNewCommand( KCommand *cmd );
202 void slotAvailableHeightNeeded();
203 void slotRepaintChanged();
204private:
205 KPrTextObject &operator=( const KPrTextObject & );
206 void shadowCompatibility();
207 static const TQString &tagTEXTOBJ, &attrLineSpacing, &attrParagSpacing,
208 &attrMargin, &attrBulletType1, &attrBulletType2,
209 &attrBulletType3, &attrBulletType4, &attrBulletColor1,
210 &attrBulletColor2, &attrBulletColor3, &attrBulletColor4,
211 &attrObjType, &tagP, &attrAlign, &attrType,
212 &attrDepth, &tagTEXT, &attrFamily, &attrPointSize,
213 &attrBold, &attrItalic, & attrUnderline,& attrStrikeOut,
214 &attrColor, &attrWhitespace, &attrTextBackColor,
215 &attrVertAlign, &attrLinkName, &attrHrefName;
216
218 KoTextObject *m_textobj;
219 KPrDocument *m_doc;
220 KoParagLayout m_paragLayout;
221 VerticalAlignmentType m_textVertAlign;
222 double bleft, bright, btop, bbottom; // margins
223 double alignVertical;
224 bool drawEditRect, drawEmpty;
225 bool editingTextObj;
226};
227
228
229class KPrTextView : public KoTextView
230{
231 TQ_OBJECT
232
233public:
234 KPrTextView( KPrTextObject * txtObj, KPrCanvas *_canvas, bool temp=false );
235 virtual ~KPrTextView();
236
237 virtual KoTextViewIface* dcopObject();
238
239 KoTextView * textView() { return this; }
240 KPrTextObject * kpTextObject() const { return m_kptextobj; }
241
242 void keyPressEvent( TQKeyEvent * );
243 void keyReleaseEvent( TQKeyEvent * );
244 void imStartEvent( TQIMEvent * );
245 void imComposeEvent( TQIMEvent * );
246 void imEndEvent( TQIMEvent * );
247 void mousePressEvent( TQMouseEvent *, const TQPoint &);
248 void mouseMoveEvent( TQMouseEvent *, const TQPoint & );
249 void mouseReleaseEvent( TQMouseEvent *, const TQPoint & );
250 void mouseDoubleClickEvent( TQMouseEvent *, const TQPoint &);
251 void dragEnterEvent( TQDragEnterEvent * );
252 void dragMoveEvent( TQDragMoveEvent *, const TQPoint & );
253 void dropEvent( TQDropEvent * );
254
255 void clearSelection();
256 void selectAll(bool select = true);
257 virtual void drawCursor( bool b );
258
259 const KoParagLayout & currentParagLayout() const { return m_paragLayout; }
260 void showPopup( KPrView *view, const TQPoint &point, TQPtrList<TDEAction> &actionList );
261 void insertVariable( int type, int subtype = 0 );
262 void insertCustomVariable( const TQString &name);
263 void insertLink(const TQString &_linkName, const TQString & hrefName);
264 void insertVariable( KoVariable *var, KoTextFormat *format =0,
265 bool refreshCustomMenu =false /*don't refresh variable custom menu all the time */);
266
267 void terminate(bool removeSelection=true);
268 void insertComment(const TQString &_note);
269
271 bool hasSelection() const;
272
273 virtual void removeToolTipCompletion();
274 bool isLinkVariable(const TQPoint &);
275 void openLink();
276 TQPoint viewToInternal( const TQPoint & pos ) const;
277
278public slots:
279 void cut();
280 void copy();
281 void paste();
282 // Reimplemented from KoTextView
283 virtual void updateUI( bool updateFormat, bool force = false );
284 virtual void ensureCursorVisible();
285
286
287protected slots:
288 virtual void startDrag();
289
290protected:
291 bool canDecode( TQMimeSource *e );
292 TQDragObject * newDrag( TQWidget * parent );
293 // Reimplemented from KoTextView
294 virtual void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, TQChar ch );
295 virtual bool doIgnoreDoubleSpace(KoTextParag * parag, int index,TQChar ch );
296 virtual bool doCompletion( KoTextCursor* cursor, KoTextParag *parag, int index );
297 virtual bool doToolTipCompletion( KoTextCursor* , KoTextParag *, int, int );
298 virtual void showToolTipBox(KoTextParag *parag, int index, TQWidget *widget, const TQPoint &pos);
299 virtual void textIncreaseIndent();
300 virtual bool textDecreaseIndent();
301 virtual void showFormat( KoTextFormat *format ) ;
302
303 virtual bool pgUpKeyPressed();
304 virtual bool pgDownKeyPressed();
305
306 KPrTextObject *m_kptextobj;
307 KPrCanvas *m_canvas;
308 KoParagLayout m_paragLayout;
309 TQPtrList<TDEAction> m_actionList; // for the kodatatools
310};
311
312
313#endif
Class KPCanvas - There is a single instance of this class for a given view.
Definition KPrCanvas.h:82
Class: KPrGradient.
Definition KPrGradient.h:40
Temporary information used only during loading.
This is our KoTextDocument reimplementation, to relate it to the textobject it's in.