~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to lib/kotext/kotextview.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2001 David Faure <faure@kde.org>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License as published by the Free Software Foundation; either
7
 
   version 2 of the License, or (at your option) any later version.
8
 
 
9
 
   This library is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
   Library General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU Library General Public License
15
 
   along with this library; see the file COPYING.LIB.  If not, write to
16
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
   Boston, MA 02111-1307, USA.
18
 
*/
19
 
 
20
 
#ifndef kotextview_h
21
 
#define kotextview_h
22
 
 
23
 
#include <qobject.h>
24
 
#include <qpoint.h>
25
 
#include <qcolor.h>
26
 
#include <qfont.h>
27
 
#include <koRuler.h> // for KoTabulatorList
28
 
#include <kotextobject.h> // for KoTextView
29
 
#include <koffice_export.h>
30
 
class KoTextObject;
31
 
class KoTextDocument;
32
 
class KoTextParag;
33
 
class KoTextFormat;
34
 
class KoParagCounter;
35
 
class KCommand;
36
 
class QTimer;
37
 
class KAction;
38
 
class KInstance;
39
 
class KDataToolInfo;
40
 
class KoLinkVariable;
41
 
class KoVariable;
42
 
class KoTextViewIface;
43
 
#include "korichtext.h"
44
 
class KoBorder;
45
 
class KoParagStyle;
46
 
 
47
 
/**
48
 
 * Object that is created to edit a KoTextObject.
49
 
 * It handles all the events for it (mouse, keyboard).
50
 
 * There can be several KoTextView instances for the same KoTextObject.
51
 
 */
52
 
class KOTEXT_EXPORT KoTextView : public QObject, public KoTextFormatInterface
53
 
{
54
 
    Q_OBJECT
55
 
public:
56
 
    /**
57
 
     * Constructor. A KoTextView is associated to a KoTextObject.
58
 
     * Don't forget to call updateUI(true,true) in your derived constructor
59
 
     */
60
 
    KoTextView( KoTextObject *textobj );
61
 
    virtual ~KoTextView();
62
 
 
63
 
     virtual KoTextViewIface* dcopObject();
64
 
 
65
 
    /** Call this before deleting */
66
 
    /** don't remove selection when we made dnd between different frame*/
67
 
    void terminate( bool removeselection=true );
68
 
 
69
 
    KoTextObject * textObject() const { return m_textobj; }
70
 
    KoTextCursor * cursor() const { return m_cursor; }
71
 
    void setCursor( const KoTextCursor& cursor ) { *m_cursor = cursor; };
72
 
    KoTextDocument * textDocument() const;
73
 
 
74
 
    /** Return true if the view is allowed to modify the text object.
75
 
        This is the case by default */
76
 
    bool isReadWrite() const { return m_bReadWrite; }
77
 
    /** Call setReadWrite(false) to make the text view readonly */
78
 
    void setReadWrite( bool b ) { m_bReadWrite = b; }
79
 
 
80
 
    virtual KoTextFormat * currentFormat() const { return m_currentFormat; }
81
 
    void setCurrentFormat( KoTextFormat *fmt ) { m_currentFormat = fmt; }
82
 
 
83
 
    /**
84
 
     * Use this format for displaying the properties (Align/counter/...) of the object
85
 
     */
86
 
    virtual const KoParagLayout * currentParagLayoutFormat() const;
87
 
 
88
 
    virtual bool rtl() const;
89
 
 
90
 
    virtual KCommand *setChangeCaseOfTextCommand( KoChangeCaseDia::TypeOfCase _type );
91
 
 
92
 
    virtual KCommand* setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex = -1 );
93
 
 
94
 
    /** Implement the KoTextFormatInterface */
95
 
    virtual KCommand* setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false );
96
 
 
97
 
    // -- Paragraph settings --
98
 
    KCommand * setCounterCommand( const KoParagCounter & counter );
99
 
    KCommand * setAlignCommand( int align );
100
 
    KCommand * setPageBreakingCommand( int pageBreaking );
101
 
    KCommand * setLineSpacingCommand( double spacing, KoParagLayout::SpacingType _type );
102
 
    KCommand * setBordersCommand( const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& bottomBorder, const KoBorder& topBorder );
103
 
    KCommand * setMarginCommand( QStyleSheetItem::Margin m, double margin );
104
 
    KCommand * setTabListCommand( const KoTabulatorList & tabList );
105
 
    void applyStyle( const KoParagStyle * style );
106
 
 
107
 
    void dragStarted();
108
 
    void focusInEvent();
109
 
    void focusOutEvent();
110
 
    void handleKeyPressEvent( QKeyEvent * e, QWidget *, const QPoint& );
111
 
    void handleKeyReleaseEvent( QKeyEvent * e );
112
 
    void handleImStartEvent( QIMEvent * e );
113
 
    void handleImComposeEvent( QIMEvent * e );
114
 
    void handleImEndEvent( QIMEvent * e );
115
 
    // iPoint is in Layout Unit pixels
116
 
    // return true if we add new parag with "insert direct cursor"
117
 
    bool handleMousePressEvent( QMouseEvent* e, const QPoint& iPoint, bool canStartDrag = true, bool insertDirectCursor = false );
118
 
    void handleMouseMoveEvent( QMouseEvent* e, const QPoint& iPoint );
119
 
    void handleMouseReleaseEvent();
120
 
    void handleMouseDoubleClickEvent( QMouseEvent* e, const QPoint& iPoint );
121
 
    void handleMouseTripleClickEvent( QMouseEvent* e, const QPoint& /* Currently unused */ );
122
 
    bool maybeStartDrag( QMouseEvent* e );
123
 
 
124
 
    KoTextCursor selectWordUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard );
125
 
    KoTextCursor selectParagUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard, bool copyAndNotify = true );
126
 
    void extendParagraphSelection( const QPoint& iPoint );
127
 
 
128
 
    QString wordUnderCursor( const KoTextCursor& cursor );
129
 
 
130
 
    /** Return the list of actions from data-tools. Used to populate a RMB popupmenu usually. */
131
 
    QPtrList<KAction> dataToolActionList( KInstance * instance, const QString& word, bool & _singleWord );
132
 
 
133
 
    void insertSoftHyphen();
134
 
    void insertLineBreak();
135
 
    void insertNonbreakingSpace();
136
 
    void insertNonbreakingHyphen();
137
 
    void increaseNumberingLevel( const KoStyleCollection* styleCollection );
138
 
    void decreaseNumberingLevel( const KoStyleCollection* styleCollection );
139
 
    void insertSpecialChar( QChar _c, const QString& font );
140
 
    void changeCaseOfText( KoChangeCaseDia::TypeOfCase _type );
141
 
 
142
 
    void addBookmarks( const QString& );
143
 
 
144
 
    //return a pointer to the variable under the cursor, if any
145
 
    KoVariable *variable();
146
 
    //return a pointer to the link variable under the cursor, if any
147
 
    // (special case of variable())
148
 
    KoLinkVariable *linkVariable();
149
 
 
150
 
    /// A "drop move" will move the selected text to the given cursor position.
151
 
    /// This method only takes care of "removing the selected text"
152
 
    /// if the drop cursor isn't in the selected text (and !protectContent).
153
 
    KCommand *prepareDropMove( KoTextCursor dropCursor );
154
 
 
155
 
    void removeComment();
156
 
    void copyTextOfComment();
157
 
 
158
 
    // This is in fact "from selection or cursor"
159
 
    KoParagStyle * createStyleFromSelection( const QString & name );
160
 
    void updateStyleFromSelection( KoParagStyle* style );
161
 
 
162
 
    QString currentWordOrSelection() const;
163
 
 
164
 
    virtual void removeToolTipCompletion() {}
165
 
 
166
 
    // return true if we "insert direct cursor" and we insert new parag
167
 
    bool placeCursor( const QPoint &pos /* in internal coordinates */, bool insertDirectCursor=false );
168
 
 
169
 
public slots:
170
 
    /** Show the current settings (those for the paragraph and character under the cursor), in the GUI.
171
 
     * The default implementation handles m_currentFormat and calls showCurrentFormat().
172
 
     * If you reimplement, make sure to call KoTextView::updateUI(updateFormat,force); */
173
 
    virtual void updateUI( bool updateFormat, bool force = false );
174
 
    virtual void ensureCursorVisible() = 0;
175
 
    void showCurrentFormat();
176
 
 
177
 
    // This allows KoTextObject to hide/show all the cursors before modifying anything
178
 
    void hideCursor() { drawCursor( false ); }
179
 
    void showCursor() { drawCursor( true ); }
180
 
 
181
 
    /** This is a slot so that it's accessible from DCOP */
182
 
    void insertText( const QString &text );
183
 
    void newParagraph();
184
 
 
185
 
    void copyLink();
186
 
    void removeLink();
187
 
    void completion();
188
 
 
189
 
    void setCursor( KoTextCursor * _cursor ) { *m_cursor = *_cursor; }
190
 
 
191
 
protected slots:
192
 
    /** Start a drag */
193
 
    virtual void startDrag() = 0;
194
 
    void slotToolActivated( const KDataToolInfo & info, const QString & command );
195
 
signals:
196
 
    void copy();
197
 
    void cut();
198
 
    void paste();
199
 
 
200
 
protected:
201
 
    /**
202
 
     * Called when a character (@p ch) has been inserted into @p parag, at the given @p index.
203
 
     * This is a virtual method rather than a signal for performance reasons.
204
 
     */
205
 
    virtual void doAutoFormat( KoTextCursor* /*cursor*/, KoTextParag * /*parag*/,
206
 
                               int /*index*/, QChar /*ch*/ ) { }
207
 
 
208
 
    virtual bool doCompletion( KoTextCursor* , KoTextParag *, int  ) { return false; }
209
 
    virtual bool doToolTipCompletion( KoTextCursor* , KoTextParag *, int, int  ) { return false; }
210
 
    virtual void showToolTipBox( KoTextParag *, int , QWidget *, const QPoint& ) {}
211
 
 
212
 
    virtual void textIncreaseIndent() {}
213
 
    virtual bool textDecreaseIndent() { return true; }
214
 
 
215
 
    //return true if we are a doubleSpace
216
 
    virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
217
 
        int /*index*/,QChar /*ch*/ ) { return false;}
218
 
 
219
 
    /** Show the settings of this format in the GUI. Needs to be implemented in the application. */
220
 
    virtual void showFormat( KoTextFormat *format ) = 0;
221
 
 
222
 
    /** Draws the cursor (or hides it if b is false).
223
 
     * The default implementation only changes an internal flag, make sure to reimplement
224
 
     * and to call the parent implementation (in all cases)
225
 
     */
226
 
    virtual void drawCursor( bool b );
227
 
 
228
 
    /// Called when clicking on a link
229
 
    virtual bool openLink( KoLinkVariable* linkVariable );
230
 
 
231
 
    /** Reimplement this to handle PageUp. Example implementation:
232
 
        textView->cursor()->gotoPageUp( scrollview->visibleHeight() ); */
233
 
    virtual bool pgUpKeyPressed() = 0;
234
 
    /** Reimplement this to handle PageDown. Example implementation:
235
 
        textView->cursor()->gotoPageDown( scrollview->visibleHeight() ); */
236
 
    virtual bool pgDownKeyPressed() = 0;
237
 
    /** Reimplement this to handle CTRL+PageUp. Default implementation calls pgUpKeyPressed */
238
 
    virtual void ctrlPgUpKeyPressed() { pgUpKeyPressed(); }
239
 
    /** Reimplement this to handle CTRL+PageDown. Default implementation calls pgDownKeyPressed */
240
 
    virtual void ctrlPgDownKeyPressed() { pgDownKeyPressed(); }
241
 
 
242
 
    void deleteWordLeft();
243
 
    void deleteWordRight();
244
 
    bool insertParagraph( const QPoint &pos );
245
 
 
246
 
private slots:
247
 
    void blinkCursor();
248
 
    void tripleClickTimeout();
249
 
    void afterTripleClickTimeout();
250
 
protected:
251
 
    KoTextViewIface *dcop;
252
 
 public: // necessary to be public to allow script action in KoTextViewIface
253
 
    enum CursorAction { // keep in sync with QTextEdit
254
 
        MoveBackward,
255
 
        MoveForward,
256
 
        MoveWordBackward,
257
 
        MoveWordForward,
258
 
        MoveUp,
259
 
        MoveDown,
260
 
        MoveLineStart,
261
 
        MoveLineEnd,
262
 
        MoveHome,
263
 
        MoveEnd,
264
 
        MovePgUp,
265
 
        MovePgDown,
266
 
        MoveParagUp, // libkotext-specific
267
 
        MoveParagDown, // libkotext-specific
268
 
        MoveViewportUp, // KWord-specific
269
 
        MoveViewportDown // KWord-specific
270
 
    };
271
 
 
272
 
    void moveCursor( CursorAction action, bool select );
273
 
    bool moveCursor( CursorAction action );
274
 
 
275
 
private:
276
 
    KoTextObject *m_textobj;
277
 
    KoTextCursor *m_cursor;
278
 
    // Store the index of the variable on which we last clicked, to position m_cursor
279
 
    int m_variablePosition;
280
 
 
281
 
    KoTextFormat *m_currentFormat;
282
 
    QTimer *blinkTimer, *dragStartTimer;
283
 
    class KoTextViewPrivate;
284
 
    KoTextViewPrivate *d;
285
 
    QPoint dragStartPos;
286
 
    bool m_cursorVisible;
287
 
    bool blinkCursorVisible;
288
 
    bool inDoubleClick;
289
 
    bool mightStartDrag;
290
 
    bool m_bReadWrite;
291
 
    bool possibleTripleClick;
292
 
    bool afterTripleClick;
293
 
 
294
 
    bool m_singleWord;
295
 
    QString m_wordUnderCursor;
296
 
};
297
 
 
298
 
#endif