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 #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     // -- 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 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     // iPoint is in Layout Unit pixels
00116     // return true if we add new parag with "insert direct cursor"
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& /* Currently unused */ );
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     //return a pointer to the variable under the cursor, if any
00145     KoVariable *variable();
00146     //return a pointer to the link variable under the cursor, if any
00147     // (special case of variable())
00148     KoLinkVariable *linkVariable();
00149 
00153     KCommand *prepareDropMove( KoTextCursor dropCursor );
00154 
00155     void removeComment();
00156     void copyTextOfComment();
00157 
00158     // This is in fact "from selection or cursor"
00159     KoParagStyle * createStyleFromSelection( const QString & name );
00160     void updateStyleFromSelection( KoParagStyle* style );
00161 
00162     QString currentWordOrSelection() const;
00163 
00164     virtual void removeToolTipCompletion() {}
00165 
00166     // return true if we "insert direct cursor" and we insert new parag
00167     bool placeCursor( const QPoint &pos /* in internal coordinates */, 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     // This allows KoTextObject to hide/show all the cursors before modifying anything
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* /*cursor*/, KoTextParag * /*parag*/,
00206                                int /*index*/, QChar /*ch*/ ) { }
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     //return true if we are a doubleSpace
00216     virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
00217         int /*index*/,QChar /*ch*/ ) { 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: // necessary to be public to allow script action in KoTextViewIface
00253     enum CursorAction { // keep in sync with QTextEdit
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, // libkotext-specific
00267         MoveParagDown, // libkotext-specific
00268         MoveViewportUp, // KWord-specific
00269         MoveViewportDown // KWord-specific
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     // Store the index of the variable on which we last clicked, to position m_cursor
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
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:12 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003