lib

KoTextView.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2006 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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> // for KoTabulatorList
00028 #include <KoTextObject.h> // for KoTextView
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     // -- Paragraph settings --
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     // iPoint is in Layout Unit pixels
00121     // return true if we add new parag with "insert direct cursor"
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& /* Currently unused */ );
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     //return a pointer to the variable under the cursor, if any
00150     KoVariable *variable();
00151     //return a pointer to the link variable under the cursor, if any
00152     // (special case of variable())
00153     KoLinkVariable *linkVariable();
00154 
00158     KCommand *prepareDropMove( KoTextCursor dropCursor );
00159 
00160     void removeComment();
00161     void copyTextOfComment();
00162 
00163     // This is in fact "from selection or cursor"
00164     KoParagStyle * createStyleFromSelection( const QString & name );
00165     void updateStyleFromSelection( KoParagStyle* style );
00166 
00167     QString currentWordOrSelection() const;
00168 
00169     virtual void removeToolTipCompletion() {}
00170 
00171     // return true if we "insert direct cursor" and we insert new parag
00172     bool placeCursor( const QPoint &pos /* in internal coordinates */, 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     // This allows KoTextObject to hide/show all the cursors before modifying anything
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* /*cursor*/, KoTextParag * /*parag*/,
00212                                int /*index*/, QChar /*ch*/ ) { }
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     //return true if we are a doubleSpace
00222     virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
00223         int /*index*/,QChar /*ch*/ ) { 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: // necessary to be public to allow script action in KoTextViewIface
00259     enum CursorAction { // keep in sync with QTextEdit
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, // libkotext-specific
00273         MoveParagDown, // libkotext-specific
00274         MoveViewportUp, // KWord-specific
00275         MoveViewportDown // KWord-specific
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     // Store the index of the variable on which we last clicked, to position m_cursor
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
KDE Home | KDE Accessibility Home | Description of Access Keys