~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kpresenter/kptextobject.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
1
2
/* This file is part of the KDE project
2
3
   Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3
4
 
20
21
#ifndef kptextobject_h
21
22
#define kptextobject_h
22
23
 
23
 
#include <kpobject.h>
24
 
#include <ktextedit.h>
 
24
#include "kpobject.h"
 
25
#include "korichtext.h"
 
26
#include <kotextview.h>
 
27
#include <kostyle.h>
25
28
 
26
29
class KPresenterView;
27
30
class KPresenterDoc;
29
32
class TextCmd;
30
33
class KPGradient;
31
34
 
32
 
/******************************************************************/
33
 
/* Class: KPTextObject                                            */
34
 
/******************************************************************/
 
35
class KoTextView;
 
36
class KoTextObject;
 
37
class KPTextView;
 
38
class KCommand;
 
39
class KPrCanvas;
 
40
class KoPoint;
 
41
class KoVariable;
 
42
class KPrTextDrag;
 
43
class KPrTextDocument;
 
44
class DCOPObject;
 
45
class KPrPage;
 
46
class KoStyle;
35
47
 
36
 
class KPTextObject : public KP2DObject
 
48
class KPTextObject :  public QObject, public KP2DObject
37
49
{
38
 
    friend class TextCmd;
 
50
    Q_OBJECT
39
51
public:
40
52
    KPTextObject( KPresenterDoc *doc );
41
 
    virtual ~KPTextObject() {}
42
 
 
43
 
    virtual void setSize( int _width, int _height );
44
 
    virtual void resizeBy( int _dx, int _dy );
 
53
    virtual ~KPTextObject();
 
54
 
 
55
    virtual DCOPObject* dcopObject();
 
56
 
 
57
    virtual void setSize( double _width, double _height );
45
58
 
46
59
    virtual void setDrawEditRect( bool b )
47
 
    { drawEditRect = b; }
 
60
        { drawEditRect = b; }
48
61
    virtual void setDrawEmpty( bool b )
49
 
    { drawEmpty = b; }
 
62
        { drawEmpty = b; }
50
63
 
51
64
    virtual ObjType getType() const
52
 
    { return OT_TEXT; }
53
 
    virtual int getSubPresSteps() const
54
 
    { return ktextobject.paragraphs() - 1; }
 
65
        { return OT_TEXT; }
 
66
    virtual QString getTypeString() const
 
67
        { return i18n("Text"); }
 
68
 
55
69
    virtual bool getDrawEditRect() const
56
 
    { return drawEditRect; }
 
70
        { return drawEditRect; }
57
71
    virtual bool getDrawEmpty() const
58
 
    { return drawEmpty; }
59
 
 
60
 
    virtual KTextEdit* getKTextObject()
61
 
    { return &ktextobject; }
62
 
 
63
 
    virtual QDomDocumentFragment save( QDomDocument& doc );
64
 
    virtual void load(const QDomElement &element);
65
 
 
66
 
    virtual void draw( QPainter *_painter, int _diffx, int _diffy );
67
 
 
68
 
    virtual void activate( QWidget *_widget, int diffx, int diffy );
69
 
    virtual void deactivate( KPresenterDoc *doc );
70
 
 
71
 
    virtual void zoom( float _fakt );
72
 
    virtual void zoomOrig();
73
 
 
74
 
    virtual void extendObject2Contents( KPresenterView *view = 0 );
75
 
 
76
 
    void recalcPageNum( KPresenterDoc *doc );
77
 
 
 
72
        { return drawEmpty; }
 
73
    virtual int getSubPresSteps() const;
 
74
 
 
75
    virtual QBrush getBrush() const;
 
76
 
 
77
    virtual void setShadowParameter(int _distance,ShadowDirection _direction,const QColor &_color);
 
78
 
 
79
    virtual QDomDocumentFragment save( QDomDocument& doc, double offset );
 
80
    virtual double load(const QDomElement &element);
 
81
 
 
82
    virtual void paint( QPainter *_painter, KoZoomHandler*_zoomHandler,
 
83
                        bool drawingShadow, bool drawContour );
 
84
    void paint( QPainter *_painter, KoZoomHandler*_zoomHandler, bool onlyChanged, KoTextCursor* cursor,
 
85
                bool resetChanged, bool drawContour );
 
86
    void paintEdited( QPainter *_painter, KoZoomHandler*_zoomHandler,
 
87
                      bool onlyChanged, KoTextCursor* cursor, bool resetChanged );
 
88
 
 
89
    void drawCursor( QPainter *p, KoTextCursor *cursor, bool cursorVisible, KPrCanvas* /*canvas*/ );
 
90
 
 
91
    void recalcPageNum( KPrPage *page );
 
92
 
 
93
 
 
94
    /** Return the contained text object */
 
95
    KoTextObject * textObject() const { return m_textobj; }
 
96
    virtual void addTextObjects( QPtrList<KoTextObject> &lst ) const {
 
97
        if ( !isProtectContent() )
 
98
            lst.append( m_textobj );
 
99
    }
 
100
 
 
101
    KPrTextDocument *textDocument() const;
 
102
 
 
103
    KPresenterDoc* kPresenterDocument() const { return m_doc; }
 
104
 
 
105
    KPTextView * createKPTextView( KPrCanvas * );
 
106
    void applyStyleChange( StyleChangeDefMap changed );
 
107
 
 
108
    void removeHighlight();
 
109
    void highlightPortion( KoTextParag * parag, int index, int length, KPrCanvas *canvas, bool repaint, KDialogBase* dialog = 0 );
 
110
 
 
111
    KCommand * pasteKPresenter( KoTextCursor * cursor, const QCString & data, bool removeSelected );
 
112
 
 
113
    void saveParagraph( QDomDocument& doc,
 
114
                        KoTextParag * parag,
 
115
                        QDomElement &parentElem,
 
116
                        int from /* default 0 */,
 
117
                        int to /* default length()-2 */ );
 
118
    KoParagLayout loadParagLayout( QDomElement & parentElem, KPresenterDoc *doc, bool useRefStyle);
 
119
 
 
120
    static KoTextFormat loadFormat( QDomElement &n, KoTextFormat * refFormat, const QFont & defaultFont,
 
121
                                    const QString & defaultLanguage, bool hyphen );
 
122
 
 
123
    void setEditingTextObj( bool _edit ) { editingTextObj = _edit; }
 
124
 
 
125
    KCommand *textContentsToHeight();
 
126
    KCommand *textObjectToContents();
 
127
    void setProtectContent ( bool _protect ) { textObject()->setProtectContent(_protect);}
 
128
    bool isProtectContent() const { return textObject()->protectContent();}
 
129
    void loadVariable( QValueList<QDomElement> & listVariable,KoTextParag *lastParag, int offset=0 );
 
130
 
 
131
    void layout();
 
132
 
 
133
    int availableHeight() const;
 
134
 
 
135
    /** set left margin size */
 
136
    void setBLeft( double b ) { bleft = b; }
 
137
    /** set right margin size */
 
138
    void setBRight( double b ) { bright = b; }
 
139
    /** set top margin size */
 
140
    void setBTop( double b ) { btop = b; }
 
141
    /** set bottom margin size */
 
142
    void setBBottom( double b ) { bbottom = b; }
 
143
 
 
144
    /** get left margin size */
 
145
    double bLeft()const { return bleft; }
 
146
    /** get right margin size */
 
147
    double bRight()const { return bright; }
 
148
    /** get top margin size */
 
149
    double bTop()const { return btop; }
 
150
    /** get bottom margin size */
 
151
    double bBottom()const { return bbottom; }
 
152
 
 
153
    void setTextMargins( double _left, double _top, double right, double bottom);
 
154
 
 
155
    KoRect innerRect() const;
 
156
    double innerWidth() const;
 
157
    double innerHeight() const;
 
158
    void resizeTextDocument( bool widthChanged = true, bool heightChanged = true );
 
159
 
 
160
    VerticalAlignmentType verticalAlignment() const { return m_textVertAlign; }
 
161
    void setVerticalAligment( VerticalAlignmentType _type) ;
 
162
    double alignmentValue() const {  return alignVertical; }
 
163
    virtual KPTextObject *nextTextObject() { return this;}
 
164
    static void saveFormat( QDomElement & element, KoTextFormat*lastFormat );
 
165
signals:
 
166
    void repaintChanged( KPTextObject* );
 
167
 
 
168
protected slots:
 
169
    void slotFormatChanged(const KoTextFormat &);
 
170
    void slotAfterFormatting( int, KoTextParag*, bool* );
 
171
    void slotParagraphDeleted(KoTextParag*_parag);
78
172
protected:
79
173
    virtual QDomElement saveKTextObject( QDomDocument& doc );
80
 
    QDomElement saveHelper(const QString &tmpText, const QString &tmpFamily, const QString &tmpColor,
81
 
                           int tmpPointSize, unsigned int tmpBold, unsigned int tmpItalic,
82
 
                           unsigned int tmpUnderline, QDomDocument &doc);
83
 
 
84
 
    virtual void loadKTextObject( const QDomElement &e, int type );
85
 
    void drawParags( QPainter *p, int from, int to );
86
 
 
87
 
    KTextEdit ktextobject;
88
 
    bool drawEditRect, drawEmpty;
89
 
 
 
174
    QDomElement saveHelper(const QString &tmpText,KoTextFormat*lastFormat ,QDomDocument &doc);
 
175
 
 
176
    virtual void loadKTextObject( const QDomElement &e );
 
177
    void drawText( QPainter* _painter, KoZoomHandler* zoomHandler, bool onlyChanged, KoTextCursor* cursor, bool resetChanged );
 
178
    void drawParags( QPainter *p, KoZoomHandler* zoomHandler, const QColorGroup& cg, int from, int to );
 
179
    void saveParagLayout( const KoParagLayout& layout, QDomElement & parentElem );
 
180
    void invalidate();
 
181
    void recalcVerticalAlignment();
 
182
    virtual QPen defaultPen() const;
 
183
protected slots:
 
184
    void slotNewCommand( KCommand *cmd );
 
185
    void slotAvailableHeightNeeded();
 
186
    void slotRepaintChanged();
90
187
private:
91
188
    KPTextObject &operator=( const KPTextObject & );
92
 
 
 
189
    void shadowCompatibility();
93
190
    static const QString &tagTEXTOBJ, &attrLineSpacing, &attrParagSpacing,
94
 
                           &attrMargin, &attrBulletType1, &attrBulletType2,
95
 
                           &attrBulletType3, &attrBulletType4, &attrBulletColor1,
96
 
                           &attrBulletColor2, &attrBulletColor3, &attrBulletColor4,
97
 
                           &attrObjType, &tagP, &attrAlign, &attrType,
98
 
                           &attrDepth, &tagTEXT, &attrFamily, &attrPointSize,
99
 
                           &attrBold, &attrItalic, & attrUnderline, &attrColor, &attrWhitespace;
100
 
};
 
191
        &attrMargin, &attrBulletType1, &attrBulletType2,
 
192
        &attrBulletType3, &attrBulletType4, &attrBulletColor1,
 
193
        &attrBulletColor2, &attrBulletColor3, &attrBulletColor4,
 
194
        &attrObjType, &tagP, &attrAlign, &attrType,
 
195
        &attrDepth, &tagTEXT, &attrFamily, &attrPointSize,
 
196
        &attrBold, &attrItalic, & attrUnderline,& attrStrikeOut,
 
197
        &attrColor, &attrWhitespace, &attrTextBackColor,
 
198
        &attrVertAlign, &attrLinkName, &attrHrefName;
 
199
 
 
200
    /** The contained text object */
 
201
    KoTextObject *m_textobj;
 
202
    KPresenterDoc *m_doc;
 
203
    KoParagLayout m_paragLayout;
 
204
    VerticalAlignmentType m_textVertAlign;
 
205
    double bleft, bright, btop, bbottom; // margins
 
206
    double alignVertical;
 
207
    bool drawEditRect, drawEmpty;
 
208
    bool editingTextObj;
 
209
};
 
210
 
 
211
 
 
212
class KPTextView : public KoTextView
 
213
{
 
214
    Q_OBJECT
 
215
public:
 
216
    KPTextView( KPTextObject * txtObj, KPrCanvas *_canvas );
 
217
    virtual ~KPTextView();
 
218
 
 
219
    virtual KoTextViewIface* dcopObject();
 
220
 
 
221
    KoTextView * textView() { return this; }
 
222
    KPTextObject * kpTextObject() const { return m_kptextobj; }
 
223
 
 
224
    void keyPressEvent( QKeyEvent * );
 
225
    void keyReleaseEvent( QKeyEvent * );
 
226
    void mousePressEvent( QMouseEvent *, const QPoint &);
 
227
 
 
228
    void mouseMoveEvent( QMouseEvent *, const QPoint & );
 
229
    void mouseReleaseEvent( QMouseEvent *, const QPoint & );
 
230
    void mouseDoubleClickEvent( QMouseEvent *, const QPoint &);
 
231
    void dragEnterEvent( QDragEnterEvent * );
 
232
    void dragMoveEvent( QDragMoveEvent *, const QPoint & );
 
233
    void dropEvent( QDropEvent * );
 
234
 
 
235
    void clearSelection();
 
236
    void selectAll(bool select = true);
 
237
    virtual void drawCursor( bool b );
 
238
 
 
239
    const KoParagLayout & currentParagLayout() const { return m_paragLayout; }
 
240
    void showPopup( KPresenterView *view, const QPoint &point, QPtrList<KAction> &actionList );
 
241
    void insertVariable( int type, int subtype = 0 );
 
242
    void insertCustomVariable( const QString &name);
 
243
    void insertLink(const QString &_linkName, const QString & hrefName);
 
244
    void insertVariable( KoVariable *var, KoTextFormat *format =0, bool removeSelectedText=true,
 
245
                         bool refreshCustomMenu =false /*don't refresh variable custom menu all the time */);
 
246
 
 
247
    void terminate(bool removeSelection=true);
 
248
    void insertComment(const QString &_note);
 
249
 
 
250
public slots:
 
251
    void cut();
 
252
    void copy();
 
253
    void paste();
 
254
    // Reimplemented from KoTextView
 
255
    virtual void updateUI( bool updateFormat, bool force = false );
 
256
    virtual void ensureCursorVisible();
 
257
 
 
258
 
 
259
protected slots:
 
260
    virtual void startDrag();
 
261
 
 
262
    KPrTextDrag * newDrag( QWidget * parent );
 
263
 
 
264
protected:
 
265
    // Reimplemented from KoTextView
 
266
    virtual void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, QChar ch );
 
267
    virtual bool doIgnoreDoubleSpace(KoTextParag * parag, int index,QChar ch );
 
268
 
 
269
    virtual void doCompletion( KoTextCursor* cursor, KoTextParag *parag, int index );
 
270
 
 
271
    virtual void showFormat( KoTextFormat *format ) ;
 
272
 
 
273
    virtual bool pgUpKeyPressed();
 
274
    virtual bool pgDownKeyPressed();
 
275
 
 
276
    QPoint cursorPosition( const QPoint & pos );
 
277
 
 
278
    KPTextObject *m_kptextobj;
 
279
    KPrCanvas *m_canvas;
 
280
    KoParagLayout m_paragLayout;
 
281
    QPtrList<KAction> m_actionList; // for the kodatatools
 
282
};
 
283
 
101
284
 
102
285
#endif