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.h>
00024 #include <qpoint.h>
00025 #include <qcolor.h>
00026 #include <qfont.h>
00027 #include <KoRuler.h>
00028 #include <KoTextObject.h>
00029 #include <koffice_export.h>
00030 class KoBgSpellCheck;
00031 class KoTextObject;
00032 class KoTextDocument;
00033 class KoTextParag;
00034 class KoTextFormat;
00035 class KoParagCounter;
00036 class KCommand;
00037 class QTimer;
00038 class KAction;
00039 class KInstance;
00040 class KDataToolInfo;
00041 class KoLinkVariable;
00042 class KoVariable;
00043 class KoTextViewIface;
00044 #include "KoRichText.h"
00045 class KoBorder;
00046 class KoParagStyle;
00047
00053 class KOTEXT_EXPORT KoTextView : public QObject, public KoTextFormatInterface
00054 {
00055 Q_OBJECT
00056 public:
00061 KoTextView( KoTextObject *textobj );
00062 virtual ~KoTextView();
00063
00064 void setBackSpeller( KoBgSpellCheck* backSpeller );
00065
00066 virtual KoTextViewIface* dcopObject();
00067
00070 void terminate( bool removeselection=true );
00071
00072 KoTextObject * textObject() const { return m_textobj; }
00073 KoTextCursor * cursor() const { return m_cursor; }
00074 void setCursor( const KoTextCursor& cursor ) { *m_cursor = cursor; };
00075 KoTextDocument * textDocument() const;
00076
00079 bool isReadWrite() const { return m_bReadWrite; }
00081 void setReadWrite( bool b ) { m_bReadWrite = b; }
00082
00083 virtual KoTextFormat * currentFormat() const { return m_currentFormat; }
00084 void setCurrentFormat( KoTextFormat *fmt ) { m_currentFormat = fmt; }
00085
00089 virtual const KoParagLayout * currentParagLayoutFormat() const;
00090
00091 virtual bool rtl() const;
00092
00093 virtual KCommand *setChangeCaseOfTextCommand( KoChangeCaseDia::TypeOfCase _type );
00094
00095 virtual KCommand* setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex = -1 );
00096
00098 virtual KCommand* setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false );
00099
00100
00101 KCommand * setCounterCommand( const KoParagCounter & counter );
00102 KCommand * setAlignCommand( int align );
00103 KCommand * setPageBreakingCommand( int pageBreaking );
00104 KCommand * setLineSpacingCommand( double spacing, KoParagLayout::SpacingType _type );
00105 KCommand * setBordersCommand( const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& bottomBorder, const KoBorder& topBorder );
00106 KCommand * setJoinBordersCommand( bool join );
00107 KCommand * setMarginCommand( QStyleSheetItem::Margin m, double margin );
00108 KCommand * setTabListCommand( const KoTabulatorList & tabList );
00109 KCommand * setBackgroundColorCommand( const QColor & color );
00110 void applyStyle( const KoParagStyle * style );
00111
00112 void dragStarted();
00113 void focusInEvent();
00114 void focusOutEvent();
00115 void handleKeyPressEvent( QKeyEvent * e, QWidget *, const QPoint& );
00116 void handleKeyReleaseEvent( QKeyEvent * e );
00117 void handleImStartEvent( QIMEvent * e );
00118 void handleImComposeEvent( QIMEvent * e );
00119 void handleImEndEvent( QIMEvent * e );
00120
00121
00122 bool handleMousePressEvent( QMouseEvent* e, const QPoint& iPoint, bool canStartDrag = true, bool insertDirectCursor = false );
00123 void handleMouseMoveEvent( QMouseEvent* e, const QPoint& iPoint );
00124 void handleMouseReleaseEvent();
00125 void handleMouseDoubleClickEvent( QMouseEvent* e, const QPoint& iPoint );
00126 void handleMouseTripleClickEvent( QMouseEvent* e, const QPoint& );
00127 bool maybeStartDrag( QMouseEvent* e );
00128
00129 KoTextCursor selectWordUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard );
00130 KoTextCursor selectParagUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard, bool copyAndNotify = true );
00131 void extendParagraphSelection( const QPoint& iPoint );
00132
00133 QString wordUnderCursor( const KoTextCursor& cursor );
00134
00136 QPtrList<KAction> dataToolActionList( KInstance * instance, const QString& word, bool & _singleWord );
00137
00138 void insertSoftHyphen();
00139 void insertLineBreak();
00140 void insertNonbreakingSpace();
00141 void insertNonbreakingHyphen();
00142 void increaseNumberingLevel( const KoStyleCollection* styleCollection );
00143 void decreaseNumberingLevel( const KoStyleCollection* styleCollection );
00144 void insertSpecialChar( QChar _c, const QString& font );
00145 void changeCaseOfText( KoChangeCaseDia::TypeOfCase _type );
00146
00147 void addBookmarks( const QString& );
00148
00149
00150 KoVariable *variable();
00151
00152
00153 KoLinkVariable *linkVariable();
00154
00158 KCommand *prepareDropMove( KoTextCursor dropCursor );
00159
00160 void removeComment();
00161 void copyTextOfComment();
00162
00163
00164 KoParagStyle * createStyleFromSelection( const QString & name );
00165 void updateStyleFromSelection( KoParagStyle* style );
00166
00167 QString currentWordOrSelection() const;
00168
00169 virtual void removeToolTipCompletion() {}
00170
00171
00172 bool placeCursor( const QPoint &pos , bool insertDirectCursor=false );
00173 void setOverwriteMode( bool overwriteMode );
00174
00175 public slots:
00179 virtual void updateUI( bool updateFormat, bool force = false );
00180 virtual void ensureCursorVisible() = 0;
00181 void showCurrentFormat();
00182
00183
00184 void hideCursor() { drawCursor( false ); }
00185 void showCursor() { drawCursor( true ); }
00186
00188 void insertText( const QString &text );
00189 void newParagraph();
00190
00191 void copyLink();
00192 void removeLink();
00193 void completion();
00194
00195 void setCursor( KoTextCursor * _cursor ) { *m_cursor = *_cursor; }
00196
00197 protected slots:
00199 virtual void startDrag() = 0;
00200 void slotToolActivated( const KDataToolInfo & info, const QString & command );
00201 signals:
00202 void copy();
00203 void cut();
00204 void paste();
00205
00206 protected:
00211 virtual void doAutoFormat( KoTextCursor* , KoTextParag * ,
00212 int , QChar ) { }
00213
00214 virtual bool doCompletion( KoTextCursor* , KoTextParag *, int ) { return false; }
00215 virtual bool doToolTipCompletion( KoTextCursor* , KoTextParag *, int, int ) { return false; }
00216 virtual void showToolTipBox( KoTextParag *, int , QWidget *, const QPoint& ) {}
00217
00218 virtual void textIncreaseIndent() {}
00219 virtual bool textDecreaseIndent() { return true; }
00220
00221
00222 virtual bool doIgnoreDoubleSpace(KoTextParag * ,
00223 int ,QChar ) { return false;}
00224
00226 virtual void showFormat( KoTextFormat *format ) = 0;
00227
00232 virtual void drawCursor( bool b );
00233
00235 virtual bool openLink( KoLinkVariable* linkVariable );
00236
00239 virtual bool pgUpKeyPressed() = 0;
00242 virtual bool pgDownKeyPressed() = 0;
00244 virtual void ctrlPgUpKeyPressed() { pgUpKeyPressed(); }
00246 virtual void ctrlPgDownKeyPressed() { pgDownKeyPressed(); }
00247
00248 void deleteWordLeft();
00249 void deleteWordRight();
00250 bool insertParagraph( const QPoint &pos );
00251
00252 private slots:
00253 void blinkCursor();
00254 void tripleClickTimeout();
00255 void afterTripleClickTimeout();
00256 protected:
00257 KoTextViewIface *dcop;
00258 public:
00259 enum CursorAction {
00260 MoveBackward,
00261 MoveForward,
00262 MoveWordBackward,
00263 MoveWordForward,
00264 MoveUp,
00265 MoveDown,
00266 MoveLineStart,
00267 MoveLineEnd,
00268 MoveHome,
00269 MoveEnd,
00270 MovePgUp,
00271 MovePgDown,
00272 MoveParagUp,
00273 MoveParagDown,
00274 MoveViewportUp,
00275 MoveViewportDown
00276 };
00277
00278 void moveCursor( CursorAction action, bool select );
00279 bool moveCursor( CursorAction action );
00280
00281 private:
00282 KoTextObject *m_textobj;
00283 KoTextCursor *m_cursor;
00284
00285
00286 int m_variablePosition;
00287 bool m_overwriteMode;
00288
00289 KoTextFormat *m_currentFormat;
00290 QTimer *blinkTimer, *dragStartTimer;
00291 class KoTextViewPrivate;
00292 KoTextViewPrivate *d;
00293 QPoint dragStartPos;
00294 bool m_cursorVisible;
00295 bool blinkCursorVisible;
00296 bool inDoubleClick;
00297 bool mightStartDrag;
00298 bool m_bReadWrite;
00299 bool possibleTripleClick;
00300 bool afterTripleClick;
00301
00302 bool m_singleWord;
00303 QString m_wordUnderCursor;
00304 };
00305
00306 #endif