00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef kotextview_h
00021 #define kotextview_h
00022
00023 #include <QObject>
00024 #include <QPoint>
00025 #include <QColor>
00026 #include <QFont>
00027
00028 #include <QMouseEvent>
00029 #include <QKeyEvent>
00030 #include <KoRuler.h>
00031 #include <KoTextObject.h>
00032 #include <koffice_export.h>
00033 class KActionCollection;
00034 class KoBgSpellCheck;
00035 class KoTextObject;
00036 class KoTextDocument;
00037 class KoTextParag;
00038 class KoTextFormat;
00039 class KoParagCounter;
00040 class KCommand;
00041 class QTimer;
00042 class KAction;
00043 class KInstance;
00044 class KDataToolInfo;
00045 class KoLinkVariable;
00046 class KoVariable;
00047
00048 #include "KoRichText.h"
00049 #include <QClipboard>
00050 class KoBorder;
00051 class KoParagStyle;
00052
00058 class KOTEXT_EXPORT KoTextView : public QObject, public KoTextFormatInterface
00059 {
00060 Q_OBJECT
00061 public:
00066 KoTextView( KoTextObject *textobj );
00067 virtual ~KoTextView();
00068
00069 void setBackSpeller( KoBgSpellCheck* backSpeller );
00070
00071
00072
00075 void terminate( bool removeselection=true );
00076
00077 KoTextObject * textObject() const { return m_textobj; }
00078 KoTextCursor * cursor() const { return m_cursor; }
00079 void setCursor( const KoTextCursor& cursor ) { *m_cursor = cursor; };
00080 KoTextDocument * textDocument() const;
00081
00084 bool isReadWrite() const { return m_bReadWrite; }
00086 void setReadWrite( bool b ) { m_bReadWrite = b; }
00087
00088 virtual KoTextFormat * currentFormat() const { return m_currentFormat; }
00089 void setCurrentFormat( KoTextFormat *fmt ) { m_currentFormat = fmt; }
00090
00094 virtual const KoParagLayout * currentParagLayoutFormat() const;
00095
00096 virtual bool rtl() const;
00097
00098 virtual KCommand *setChangeCaseOfTextCommand( KoChangeCaseDia::TypeOfCase _type );
00099
00100 virtual KCommand* setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex = -1 );
00101
00103 virtual KCommand* setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false );
00104
00105
00106 KCommand * setCounterCommand( const KoParagCounter & counter );
00107 KCommand * setAlignCommand( int align );
00108 KCommand * setPageBreakingCommand( int pageBreaking );
00109 KCommand * setLineSpacingCommand( double spacing, KoParagLayout::SpacingType _type );
00110 KCommand * setBordersCommand( const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& bottomBorder, const KoBorder& topBorder );
00111 KCommand * setJoinBordersCommand( bool join );
00112 KCommand * setMarginCommand( Q3StyleSheetItem::Margin m, double margin );
00113 KCommand * setTabListCommand( const KoTabulatorList & tabList );
00114 KCommand * setBackgroundColorCommand( const QColor & color );
00115 void applyStyle( const KoParagStyle * style );
00116
00117 void dragStarted();
00118 void focusInEvent();
00119 void focusOutEvent();
00120 void handleKeyPressEvent( QKeyEvent * e, QWidget *, const QPoint& );
00121 void handleKeyReleaseEvent( QKeyEvent * e );
00122 void handleInputMethodEvent( QInputMethodEvent * e );
00123
00124
00125 bool handleMousePressEvent( QMouseEvent* e, const QPoint& iPoint, bool canStartDrag = true, bool insertDirectCursor = false );
00126 void handleMouseMoveEvent( QMouseEvent* e, const QPoint& iPoint );
00127 void handleMouseReleaseEvent();
00128 void handleMouseDoubleClickEvent( QMouseEvent* e, const QPoint& iPoint );
00129 void handleMouseTripleClickEvent( QMouseEvent* e, const QPoint& );
00130 bool maybeStartDrag( QMouseEvent* e );
00131
00132 KoTextCursor selectWordUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard );
00133 KoTextCursor selectParagUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard, bool copyAndNotify = true );
00134 void extendParagraphSelection( const QPoint& iPoint );
00135
00136 QString wordUnderCursor( const KoTextCursor& cursor );
00137
00139 QList<KAction *> dataToolActionList( KInstance * instance, KActionCollection* parent, const QString& word, bool & _singleWord );
00140
00141 void insertSoftHyphen();
00142 void insertLineBreak();
00143 void insertNonbreakingSpace();
00144 void insertNonbreakingHyphen();
00145 void increaseNumberingLevel( const KoStyleCollection* styleCollection );
00146 void decreaseNumberingLevel( const KoStyleCollection* styleCollection );
00147 void insertSpecialChar( QChar _c, const QString& font );
00148 void changeCaseOfText( KoChangeCaseDia::TypeOfCase _type );
00149
00150 void addBookmarks( const QString& );
00151
00152
00153 KoVariable *variable();
00154
00155
00156 KoLinkVariable *linkVariable();
00157
00161 KCommand *prepareDropMove( KoTextCursor dropCursor );
00162
00163 void removeComment();
00164 void copyTextOfComment();
00165
00166
00167 KoParagStyle * createStyleFromSelection( const QString & name );
00168 void updateStyleFromSelection( KoParagStyle* style );
00169
00170 QString currentWordOrSelection() const;
00171
00172 virtual void removeToolTipCompletion() {}
00173
00174
00175 bool placeCursor( const QPoint &pos , bool insertDirectCursor=false );
00176 void setOverwriteMode( bool overwriteMode );
00177
00178 public slots:
00182 virtual void updateUI( bool updateFormat, bool force = false );
00183 virtual void ensureCursorVisible() = 0;
00184 void showCurrentFormat();
00185
00186
00187 void hideCursor() { drawCursor( false ); }
00188 void showCursor() { drawCursor( true ); }
00189
00191 void insertText( const QString &text );
00192 void newParagraph();
00193
00194 void copyLink();
00195 void removeLink();
00196 void completion();
00197
00198 void setCursor( KoTextCursor * _cursor ) { *m_cursor = *_cursor; }
00199
00200 protected slots:
00202 virtual void startDrag() = 0;
00203 void slotToolActivated( const KDataToolInfo & info, const QString & command );
00204 signals:
00205 void copy(QClipboard::Mode mode);
00206 void cut();
00207 void paste();
00208
00209 protected:
00214 virtual void doAutoFormat( KoTextCursor* , KoTextParag * ,
00215 int , QChar ) { }
00216
00217 virtual bool doCompletion( KoTextCursor* , KoTextParag *, int ) { return false; }
00218 virtual bool doToolTipCompletion( KoTextCursor* , KoTextParag *, int, int ) { return false; }
00219 virtual void showToolTipBox( KoTextParag *, int , QWidget *, const QPoint& ) {}
00220
00221 virtual void textIncreaseIndent() {}
00222 virtual bool textDecreaseIndent() { return true; }
00223
00224
00225 virtual bool doIgnoreDoubleSpace(KoTextParag * ,
00226 int ,QChar ) { return false;}
00227
00229 virtual void showFormat( KoTextFormat *format ) = 0;
00230
00235 virtual void drawCursor( bool b );
00236
00238 virtual bool openLink( KoLinkVariable* linkVariable );
00239
00242 virtual bool pgUpKeyPressed() = 0;
00245 virtual bool pgDownKeyPressed() = 0;
00247 virtual void ctrlPgUpKeyPressed() { pgUpKeyPressed(); }
00249 virtual void ctrlPgDownKeyPressed() { pgDownKeyPressed(); }
00250
00251 void deleteWordLeft();
00252 void deleteWordRight();
00253 bool insertParagraph( const QPoint &pos );
00254
00255 private slots:
00256 void blinkCursor();
00257 void tripleClickTimeout();
00258 void afterTripleClickTimeout();
00259 protected:
00260
00261 public:
00262 enum CursorAction {
00263 MoveBackward,
00264 MoveForward,
00265 MoveWordBackward,
00266 MoveWordForward,
00267 MoveUp,
00268 MoveDown,
00269 MoveLineStart,
00270 MoveLineEnd,
00271 MoveHome,
00272 MoveEnd,
00273 MovePgUp,
00274 MovePgDown,
00275 MoveParagUp,
00276 MoveParagDown,
00277 MoveViewportUp,
00278 MoveViewportDown
00279 };
00280
00281 void moveCursor( CursorAction action, bool select );
00282 bool moveCursor( CursorAction action );
00283
00284 private:
00285 KoTextObject *m_textobj;
00286 KoTextCursor *m_cursor;
00287
00288
00289 int m_variablePosition;
00290 bool m_overwriteMode;
00291
00292 KoTextFormat *m_currentFormat;
00293 QTimer *blinkTimer, *dragStartTimer;
00294 class KoTextViewPrivate;
00295 KoTextViewPrivate *d;
00296 QPoint dragStartPos;
00297 bool m_cursorVisible;
00298 bool blinkCursorVisible;
00299 bool inDoubleClick;
00300 bool mightStartDrag;
00301 bool m_bReadWrite;
00302 bool possibleTripleClick;
00303 bool afterTripleClick;
00304
00305 bool m_singleWord;
00306 QString m_wordUnderCursor;
00307 };
00308
00309 #endif