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