1
/* This file is part of the KDE project
2
Copyright (C) 2001 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., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
27
#include <koRuler.h> // for KoTabulatorList
28
#include <kotextobject.h> // for KoTextView
29
#include <koffice_export.h>
42
class KoTextViewIface;
43
#include "korichtext.h"
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.
52
class KOTEXT_EXPORT KoTextView : public QObject, public KoTextFormatInterface
57
* Constructor. A KoTextView is associated to a KoTextObject.
58
* Don't forget to call updateUI(true,true) in your derived constructor
60
KoTextView( KoTextObject *textobj );
61
virtual ~KoTextView();
63
virtual KoTextViewIface* dcopObject();
65
/** Call this before deleting */
66
/** don't remove selection when we made dnd between different frame*/
67
void terminate( bool removeselection=true );
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;
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; }
80
virtual KoTextFormat * currentFormat() const { return m_currentFormat; }
81
void setCurrentFormat( KoTextFormat *fmt ) { m_currentFormat = fmt; }
84
* Use this format for displaying the properties (Align/counter/...) of the object
86
virtual const KoParagLayout * currentParagLayoutFormat() const;
88
virtual bool rtl() const;
90
virtual KCommand *setChangeCaseOfTextCommand( KoChangeCaseDia::TypeOfCase _type );
92
virtual KCommand* setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex = -1 );
94
/** Implement the KoTextFormatInterface */
95
virtual KCommand* setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false );
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 );
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 );
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 );
128
QString wordUnderCursor( const KoTextCursor& cursor );
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 );
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 );
142
void addBookmarks( const QString& );
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();
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 );
155
void removeComment();
156
void copyTextOfComment();
158
// This is in fact "from selection or cursor"
159
KoParagStyle * createStyleFromSelection( const QString & name );
160
void updateStyleFromSelection( KoParagStyle* style );
162
QString currentWordOrSelection() const;
164
virtual void removeToolTipCompletion() {}
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 );
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();
177
// This allows KoTextObject to hide/show all the cursors before modifying anything
178
void hideCursor() { drawCursor( false ); }
179
void showCursor() { drawCursor( true ); }
181
/** This is a slot so that it's accessible from DCOP */
182
void insertText( const QString &text );
189
void setCursor( KoTextCursor * _cursor ) { *m_cursor = *_cursor; }
193
virtual void startDrag() = 0;
194
void slotToolActivated( const KDataToolInfo & info, const QString & command );
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.
205
virtual void doAutoFormat( KoTextCursor* /*cursor*/, KoTextParag * /*parag*/,
206
int /*index*/, QChar /*ch*/ ) { }
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& ) {}
212
virtual void textIncreaseIndent() {}
213
virtual bool textDecreaseIndent() { return true; }
215
//return true if we are a doubleSpace
216
virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
217
int /*index*/,QChar /*ch*/ ) { return false;}
219
/** Show the settings of this format in the GUI. Needs to be implemented in the application. */
220
virtual void showFormat( KoTextFormat *format ) = 0;
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)
226
virtual void drawCursor( bool b );
228
/// Called when clicking on a link
229
virtual bool openLink( KoLinkVariable* linkVariable );
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(); }
242
void deleteWordLeft();
243
void deleteWordRight();
244
bool insertParagraph( const QPoint &pos );
248
void tripleClickTimeout();
249
void afterTripleClickTimeout();
251
KoTextViewIface *dcop;
252
public: // necessary to be public to allow script action in KoTextViewIface
253
enum CursorAction { // keep in sync with QTextEdit
266
MoveParagUp, // libkotext-specific
267
MoveParagDown, // libkotext-specific
268
MoveViewportUp, // KWord-specific
269
MoveViewportDown // KWord-specific
272
void moveCursor( CursorAction action, bool select );
273
bool moveCursor( CursorAction action );
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;
281
KoTextFormat *m_currentFormat;
282
QTimer *blinkTimer, *dragStartTimer;
283
class KoTextViewPrivate;
284
KoTextViewPrivate *d;
286
bool m_cursorVisible;
287
bool blinkCursorVisible;
291
bool possibleTripleClick;
292
bool afterTripleClick;
295
QString m_wordUnderCursor;