F:/KPlato/koffice/libs/kotext/KoTextView.h

Aller à la documentation de ce fichier.
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>
00024 #include <QPoint>
00025 #include <QColor>
00026 #include <QFont>
00027 //Added by qt3to4:
00028 #include <QMouseEvent>
00029 #include <QKeyEvent>
00030 #include <KoRuler.h> // for KoTabulatorList
00031 #include <KoTextObject.h> // for KoTextView
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 // class KoTextViewIface;
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 //     virtual KoTextViewIface* dcopObject();
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     // -- Paragraph settings --
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     // iPoint is in Layout Unit pixels
00124     // return true if we add new parag with "insert direct cursor"
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& /* Currently unused */ );
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     //return a pointer to the variable under the cursor, if any
00153     KoVariable *variable();
00154     //return a pointer to the link variable under the cursor, if any
00155     // (special case of variable())
00156     KoLinkVariable *linkVariable();
00157 
00161     KCommand *prepareDropMove( KoTextCursor dropCursor );
00162 
00163     void removeComment();
00164     void copyTextOfComment();
00165 
00166     // This is in fact "from selection or cursor"
00167     KoParagStyle * createStyleFromSelection( const QString & name );
00168     void updateStyleFromSelection( KoParagStyle* style );
00169 
00170     QString currentWordOrSelection() const;
00171 
00172     virtual void removeToolTipCompletion() {}
00173 
00174     // return true if we "insert direct cursor" and we insert new parag
00175     bool placeCursor( const QPoint &pos /* in internal coordinates */, 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     // This allows KoTextObject to hide/show all the cursors before modifying anything
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* /*cursor*/, KoTextParag * /*parag*/,
00215                                int /*index*/, QChar /*ch*/ ) { }
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     //return true if we are a doubleSpace
00225     virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
00226         int /*index*/,QChar /*ch*/ ) { 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 //     KoTextViewIface *dcop;
00261  public: // necessary to be public to allow script action in KoTextViewIface
00262     enum CursorAction { // keep in sync with QTextEdit
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, // libkotext-specific
00276         MoveParagDown, // libkotext-specific
00277         MoveViewportUp, // KWord-specific
00278         MoveViewportDown // KWord-specific
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     // Store the index of the variable on which we last clicked, to position m_cursor
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

Généré le Wed Nov 22 23:41:10 2006 pour KPlato par  doxygen 1.5.1-p1