1
/* This file is part of the KDE project
2
Copyright (C) 2001-2006 David Faure <faure@kde.org>
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.
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.
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., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
27
#include <KoRuler.h> // for KoTabulatorList
28
#include <KoTextObject.h> // for KoTextView
29
#include <koffice_export.h>
43
class KoTextViewIface;
44
#include "KoRichText.h"
49
* Object that is created to edit a KoTextObject.
50
* It handles all the events for it (mouse, keyboard).
51
* There can be several KoTextView instances for the same KoTextObject.
53
class KOTEXT_EXPORT KoTextView : public QObject, public KoTextFormatInterface
58
* Constructor. A KoTextView is associated to a KoTextObject.
59
* Don't forget to call updateUI(true,true) in your derived constructor
61
KoTextView( KoTextObject *textobj );
62
virtual ~KoTextView();
64
void setBackSpeller( KoBgSpellCheck* backSpeller );
66
virtual KoTextViewIface* dcopObject();
68
/** Call this before deleting */
69
/** don't remove selection when we made dnd between different frame*/
70
void terminate( bool removeselection=true );
72
KoTextObject * textObject() const { return m_textobj; }
73
KoTextCursor * cursor() const { return m_cursor; }
74
void setCursor( const KoTextCursor& cursor ) { *m_cursor = cursor; };
75
KoTextDocument * textDocument() const;
77
/** Return true if the view is allowed to modify the text object.
78
This is the case by default */
79
bool isReadWrite() const { return m_bReadWrite; }
80
/** Call setReadWrite(false) to make the text view readonly */
81
void setReadWrite( bool b ) { m_bReadWrite = b; }
83
virtual KoTextFormat * currentFormat() const { return m_currentFormat; }
84
void setCurrentFormat( KoTextFormat *fmt ) { m_currentFormat = fmt; }
87
* Use this format for displaying the properties (Align/counter/...) of the object
89
virtual const KoParagLayout * currentParagLayoutFormat() const;
91
virtual bool rtl() const;
93
virtual KCommand *setChangeCaseOfTextCommand( KoChangeCaseDia::TypeOfCase _type );
95
virtual KCommand* setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex = -1 );
97
/** Implement the KoTextFormatInterface */
98
virtual KCommand* setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false );
100
// -- Paragraph settings --
101
KCommand * setCounterCommand( const KoParagCounter & counter );
102
KCommand * setAlignCommand( int align );
103
KCommand * setPageBreakingCommand( int pageBreaking );
104
KCommand * setLineSpacingCommand( double spacing, KoParagLayout::SpacingType _type );
105
KCommand * setBordersCommand( const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& bottomBorder, const KoBorder& topBorder );
106
KCommand * setJoinBordersCommand( bool join );
107
KCommand * setMarginCommand( QStyleSheetItem::Margin m, double margin );
108
KCommand * setTabListCommand( const KoTabulatorList & tabList );
109
KCommand * setBackgroundColorCommand( const QColor & color );
110
void applyStyle( const KoParagStyle * style );
114
void focusOutEvent();
115
void handleKeyPressEvent( QKeyEvent * e, QWidget *, const QPoint& );
116
void handleKeyReleaseEvent( QKeyEvent * e );
117
void handleImStartEvent( QIMEvent * e );
118
void handleImComposeEvent( QIMEvent * e );
119
void handleImEndEvent( QIMEvent * e );
120
// iPoint is in Layout Unit pixels
121
// return true if we add new parag with "insert direct cursor"
122
bool handleMousePressEvent( QMouseEvent* e, const QPoint& iPoint, bool canStartDrag = true, bool insertDirectCursor = false );
123
void handleMouseMoveEvent( QMouseEvent* e, const QPoint& iPoint );
124
void handleMouseReleaseEvent();
125
void handleMouseDoubleClickEvent( QMouseEvent* e, const QPoint& iPoint );
126
void handleMouseTripleClickEvent( QMouseEvent* e, const QPoint& /* Currently unused */ );
127
bool maybeStartDrag( QMouseEvent* e );
129
KoTextCursor selectWordUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard );
130
KoTextCursor selectParagUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard, bool copyAndNotify = true );
131
void extendParagraphSelection( const QPoint& iPoint );
133
QString wordUnderCursor( const KoTextCursor& cursor );
135
/** Return the list of actions from data-tools. Used to populate a RMB popupmenu usually. */
136
QPtrList<KAction> dataToolActionList( KInstance * instance, const QString& word, bool & _singleWord );
138
void insertSoftHyphen();
139
void insertLineBreak();
140
void insertNonbreakingSpace();
141
void insertNonbreakingHyphen();
142
void increaseNumberingLevel( const KoStyleCollection* styleCollection );
143
void decreaseNumberingLevel( const KoStyleCollection* styleCollection );
144
void insertSpecialChar( QChar _c, const QString& font );
145
void changeCaseOfText( KoChangeCaseDia::TypeOfCase _type );
147
void addBookmarks( const QString& );
149
//return a pointer to the variable under the cursor, if any
150
KoVariable *variable();
151
//return a pointer to the link variable under the cursor, if any
152
// (special case of variable())
153
KoLinkVariable *linkVariable();
155
/// A "drop move" will move the selected text to the given cursor position.
156
/// This method only takes care of "removing the selected text"
157
/// if the drop cursor isn't in the selected text (and !protectContent).
158
KCommand *prepareDropMove( KoTextCursor dropCursor );
160
void removeComment();
161
void copyTextOfComment();
163
// This is in fact "from selection or cursor"
164
KoParagStyle * createStyleFromSelection( const QString & name );
165
void updateStyleFromSelection( KoParagStyle* style );
167
QString currentWordOrSelection() const;
169
virtual void removeToolTipCompletion() {}
171
// return true if we "insert direct cursor" and we insert new parag
172
bool placeCursor( const QPoint &pos /* in internal coordinates */, bool insertDirectCursor=false );
173
void setOverwriteMode( bool overwriteMode );
176
/** Show the current settings (those for the paragraph and character under the cursor), in the GUI.
177
* The default implementation handles m_currentFormat and calls showCurrentFormat().
178
* If you reimplement, make sure to call KoTextView::updateUI(updateFormat,force); */
179
virtual void updateUI( bool updateFormat, bool force = false );
180
virtual void ensureCursorVisible() = 0;
181
void showCurrentFormat();
183
// This allows KoTextObject to hide/show all the cursors before modifying anything
184
void hideCursor() { drawCursor( false ); }
185
void showCursor() { drawCursor( true ); }
187
/** This is a slot so that it's accessible from DCOP */
188
void insertText( const QString &text );
195
void setCursor( KoTextCursor * _cursor ) { *m_cursor = *_cursor; }
199
virtual void startDrag() = 0;
200
void slotToolActivated( const KDataToolInfo & info, const QString & command );
208
* Called when a character (@p ch) has been inserted into @p parag, at the given @p index.
209
* This is a virtual method rather than a signal for performance reasons.
211
virtual void doAutoFormat( KoTextCursor* /*cursor*/, KoTextParag * /*parag*/,
212
int /*index*/, QChar /*ch*/ ) { }
214
virtual bool doCompletion( KoTextCursor* , KoTextParag *, int ) { return false; }
215
virtual bool doToolTipCompletion( KoTextCursor* , KoTextParag *, int, int ) { return false; }
216
virtual void showToolTipBox( KoTextParag *, int , QWidget *, const QPoint& ) {}
218
virtual void textIncreaseIndent() {}
219
virtual bool textDecreaseIndent() { return true; }
221
//return true if we are a doubleSpace
222
virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
223
int /*index*/,QChar /*ch*/ ) { return false;}
225
/** Show the settings of this format in the GUI. Needs to be implemented in the application. */
226
virtual void showFormat( KoTextFormat *format ) = 0;
228
/** Draws the cursor (or hides it if b is false).
229
* The default implementation only changes an internal flag, make sure to reimplement
230
* and to call the parent implementation (in all cases)
232
virtual void drawCursor( bool b );
234
/// Called when clicking on a link
235
virtual bool openLink( KoLinkVariable* linkVariable );
237
/** Reimplement this to handle PageUp. Example implementation:
238
textView->cursor()->gotoPageUp( scrollview->visibleHeight() ); */
239
virtual bool pgUpKeyPressed() = 0;
240
/** Reimplement this to handle PageDown. Example implementation:
241
textView->cursor()->gotoPageDown( scrollview->visibleHeight() ); */
242
virtual bool pgDownKeyPressed() = 0;
243
/** Reimplement this to handle CTRL+PageUp. Default implementation calls pgUpKeyPressed */
244
virtual void ctrlPgUpKeyPressed() { pgUpKeyPressed(); }
245
/** Reimplement this to handle CTRL+PageDown. Default implementation calls pgDownKeyPressed */
246
virtual void ctrlPgDownKeyPressed() { pgDownKeyPressed(); }
248
void deleteWordLeft();
249
void deleteWordRight();
250
bool insertParagraph( const QPoint &pos );
254
void tripleClickTimeout();
255
void afterTripleClickTimeout();
257
KoTextViewIface *dcop;
258
public: // necessary to be public to allow script action in KoTextViewIface
259
enum CursorAction { // keep in sync with QTextEdit
272
MoveParagUp, // libkotext-specific
273
MoveParagDown, // libkotext-specific
274
MoveViewportUp, // KWord-specific
275
MoveViewportDown // KWord-specific
278
void moveCursor( CursorAction action, bool select );
279
bool moveCursor( CursorAction action );
282
KoTextObject *m_textobj;
283
KoTextCursor *m_cursor;
285
// Store the index of the variable on which we last clicked, to position m_cursor
286
int m_variablePosition;
287
bool m_overwriteMode;
289
KoTextFormat *m_currentFormat;
290
QTimer *blinkTimer, *dragStartTimer;
291
class KoTextViewPrivate;
292
KoTextViewPrivate *d;
294
bool m_cursorVisible;
295
bool blinkCursorVisible;
299
bool possibleTripleClick;
300
bool afterTripleClick;
303
QString m_wordUnderCursor;