lib Library API Documentation

kotextview.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 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., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, 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 class KoTextObject;
00030 class KoTextDocument;
00031 class KoTextParag;
00032 class KoTextFormat;
00033 class KoParagCounter;
00034 class KCommand;
00035 class QTimer;
00036 class KAction;
00037 class KInstance;
00038 class KDataToolInfo;
00039 class KoLinkVariable;
00040 class KoVariable;
00041 class KoTextViewIface;
00042 #include "korichtext.h"
00043 class KoBorder;
00044 class KoStyle;
00045 
00051 class KoTextView : public QObject, public KoTextFormatInterface
00052 {
00053     Q_OBJECT
00054 public:
00059     KoTextView( KoTextObject *textobj );
00060     virtual ~KoTextView();
00061 
00062      virtual KoTextViewIface* dcopObject();
00063 
00066     void terminate(bool removeselection=true);
00067 
00068     KoTextObject * textObject() const { return m_textobj; }
00069     KoTextCursor * cursor() const { return m_cursor; }
00070     KoTextDocument * textDocument() const;
00071 
00074     bool isReadWrite() const { return m_bReadWrite; }
00076     void setReadWrite( bool b ) { m_bReadWrite = b; }
00077 
00078     virtual KoTextFormat * currentFormat() const { return m_currentFormat; }
00079     void setCurrentFormat( KoTextFormat *fmt ) { m_currentFormat = fmt; }
00080 
00084     virtual const KoParagLayout * currentParagLayoutFormat() const;
00085 
00086     virtual bool rtl() const;
00087 
00088     virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type);
00089 
00090     //void setParagLayoutFormat( KoParagLayout *newLayout,int flags,int marginIndex=-1);
00091     virtual KCommand* setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1);
00092 
00094     //void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont);
00095     virtual KCommand* setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false);
00096 
00097     // -- Paragraph settings --
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 KoStyle * style );
00106 
00107     void dragStarted();
00108     void focusInEvent();
00109     void focusOutEvent();
00110     void handleKeyPressEvent( QKeyEvent * e );
00111     void handleKeyReleaseEvent( QKeyEvent * e );
00112     // iPoint is in Layout Unit pixels
00113     // return true if we add new parag with "insert direct cursor"
00114     bool handleMousePressEvent( QMouseEvent* e, const QPoint& iPoint, bool canStartDrag = true, bool insertDirectCursor = false );
00115     void handleMouseMoveEvent( QMouseEvent* e, const QPoint& iPoint );
00116     void handleMouseReleaseEvent();
00117     void handleMouseDoubleClickEvent( QMouseEvent* e, const QPoint& iPoint );
00118     void handleMouseTripleClickEvent( QMouseEvent* e, const QPoint& /* Currently unused */ );
00119     bool maybeStartDrag( QMouseEvent* e );
00120 
00121     KoTextCursor selectWordUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard );
00122     KoTextCursor selectParagUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard, bool copyAndNotify = true );
00123     void extendParagraphSelection( const QPoint& iPoint );
00124 
00125     QString wordUnderCursor( const KoTextCursor& cursor );
00126 
00128     QPtrList<KAction> dataToolActionList(KInstance * instance, const QString& word, bool & _singleWord );
00129 
00130     void insertSoftHyphen();
00131     void insertLineBreak();
00132     void insertNonbreakingSpace();
00133     void insertSpecialChar(QChar _c, const QString& font);
00134     void changeCaseOfText(KoChangeCaseDia::TypeOfCase _type);
00135 
00136     void addBookmarks(const QString &);
00137 
00138     //return a pointer to the variable under the cursor, if any
00139     KoVariable *variable();
00140     //return a pointer to the link variable under the cursor, if any
00141     // (special case of variable())
00142     KoLinkVariable *linkVariable();
00143 
00144     KCommand *dropEvent( KoTextObject *tmp,KoTextCursor dropCursor, bool dropInSameObj);
00145 
00146     void removeComment();
00147     void copyTextOfComment();
00148 
00149     // This is in fact "from selection or cursor"
00150     KoStyle * createStyleFromSelection(const QString & name);
00151     void updateStyleFromSelection(KoStyle* style);
00152 
00153     QString underCursorWord();
00154 
00155 public slots:
00159     virtual void updateUI( bool updateFormat, bool force = false );
00160     virtual void ensureCursorVisible() = 0;
00161     void showCurrentFormat();
00162 
00163     // This allows KoTextObject to hide/show all the cursors before modifying anything
00164     void hideCursor() { drawCursor( false ); }
00165     void showCursor() { drawCursor( true ); }
00166 
00168     void insertText( const QString &text );
00169     void newParagraph();
00170 
00171     QString refLink()const {return m_refLink;}
00172 
00173     void openLink();
00174     void copyLink();
00175     void removeLink();
00176     void completion();
00177 
00178 protected slots:
00180     virtual void startDrag() = 0;
00181     void slotToolActivated( const KDataToolInfo & info, const QString & command );
00182 signals:
00183     void copy();
00184     void cut();
00185     void paste();
00186 
00187 protected:
00192     virtual void doAutoFormat( KoTextCursor* /*cursor*/, KoTextParag * /*parag*/,
00193                                int /*index*/, QChar /*ch*/ ) { }
00194 
00195     virtual void doCompletion( KoTextCursor* /*textEditCursor*/, KoTextParag */*parag*/, int /*index*/ ) { }
00196 
00197     //return true if we are a doubleSpace
00198     virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
00199         int /*index*/,QChar /*ch*/ ) { return false;}
00200 
00202     virtual void showFormat( KoTextFormat *format ) = 0;
00203 
00208     virtual void drawCursor( bool b );
00209 
00210     // return true if we "insert direct cursor" and we insert new parag
00211     bool placeCursor( const QPoint &pos /* in internal coordinates */, bool insertDirectCursor=false );
00212 
00215     virtual bool pgUpKeyPressed() = 0;
00218     virtual bool pgDownKeyPressed() = 0;
00220     virtual void ctrlPgUpKeyPressed() { pgUpKeyPressed(); }
00222     virtual void ctrlPgDownKeyPressed() { pgDownKeyPressed(); }
00223 
00224     void deleteWordLeft();
00225     void deleteWordRight();
00226     bool insertParagraph(const QPoint &pos);
00227 
00228 private slots:
00229     void blinkCursor();
00230     void setCursor( KoTextCursor * _cursor ) { *m_cursor = *_cursor; }
00231     void tripleClickTimeout();
00232     void afterTripleClickTimeout();
00233 protected:
00234     KoTextViewIface *dcop;
00235  public: // necessary to be public to allow script action in KoTextViewIface
00236     enum CursorAction { // keep in sync with QTextEdit
00237         MoveBackward,
00238         MoveForward,
00239         MoveWordBackward,
00240         MoveWordForward,
00241         MoveUp,
00242         MoveDown,
00243         MoveLineStart,
00244         MoveLineEnd,
00245         MoveHome,
00246         MoveEnd,
00247         MovePgUp,
00248         MovePgDown,
00249         MoveParagUp, // libkotext-specific
00250         MoveParagDown, // libkotext-specific
00251         MoveViewportUp, // KWord-specific
00252         MoveViewportDown // KWord-specific
00253     };
00254 
00255     void moveCursor( CursorAction action, bool select );
00256     bool moveCursor( CursorAction action );
00257 
00258 private:
00259     KoTextObject *m_textobj;
00260     KoTextCursor *m_cursor;
00261     KoTextFormat *m_currentFormat;
00262     QTimer *blinkTimer, *dragStartTimer;
00263     class KoTextViewPrivate;
00264     KoTextViewPrivate *d;
00265     QPoint dragStartPos;
00266     bool m_cursorVisible;
00267     bool blinkCursorVisible;
00268     bool inDoubleClick;
00269     bool mightStartDrag;
00270     bool m_bReadWrite;
00271     bool possibleTripleClick;
00272     bool afterTripleClick;
00273 
00274     bool m_singleWord;
00275     QString m_wordUnderCursor;
00276     QString m_refLink;
00277     //store variable position.
00278     //all type of variable
00279     int variablePosition;
00280 };
00281 
00282 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:27 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003