Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qtextedit.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: qtextedit.h,v 1.2 2002/07/15 23:22:50 leseb Exp $
00003 **
00004 ** Definition of the QTextEdit class
00005 **
00006 ** Created : 990101
00007 **
00008 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the widgets module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QTEXTEDIT_H
00039 #define QTEXTEDIT_H
00040 
00041 #ifndef QT_H
00042 #include "qscrollview.h"
00043 #include "qstylesheet.h"
00044 #include "qvector.h"
00045 #include "qvaluelist.h"
00046 #endif // QT_H
00047 
00048 class QPainter;
00049 class QKeyEvent;
00050 class QResizeEvent;
00051 class QMouseEvent;
00052 class QTimer;
00053 class QFont;
00054 class QColor;
00055 struct QUndoRedoInfoPrivate;
00056 class QPopupMenu;
00057 
00058 namespace Qt3 {
00059 
00060 class QTextString;
00061 class QTextDocument;
00062 class QTextCursor;
00063 class QTextCommand;
00064 class QTextParagraph;
00065 class QTextFormat;
00066 class QTextEdit;
00067 class QTextBrowser;
00068 class QTextString;
00069 class QTextEditPrivate;
00070 
00071 class Q_EXPORT QTextEdit : public QScrollView
00072 {
00073     friend class QTextBrowser;
00074 
00075     Q_OBJECT
00076     Q_ENUMS( WordWrap WrapPolicy )
00077     Q_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat )
00078     Q_PROPERTY( QString text READ text WRITE setText )
00079     Q_PROPERTY( QBrush paper READ paper WRITE setPaper )
00080     Q_PROPERTY( bool linkUnderline READ linkUnderline WRITE setLinkUnderline )
00081     Q_PROPERTY( QString documentTitle READ documentTitle )
00082     Q_PROPERTY( int length READ length )
00083     Q_PROPERTY( WordWrap wordWrap READ wordWrap WRITE setWordWrap )
00084     Q_PROPERTY( int wrapColumnOrWidth READ wrapColumnOrWidth WRITE setWrapColumnOrWidth )
00085     Q_PROPERTY( WrapPolicy wrapPolicy READ wrapPolicy WRITE setWrapPolicy )
00086     Q_PROPERTY( bool hasSelectedText READ hasSelectedText )
00087     Q_PROPERTY( QString selectedText READ selectedText )
00088     Q_PROPERTY( int undoDepth READ undoDepth WRITE setUndoDepth )
00089     Q_PROPERTY( bool overwriteMode READ isOverwriteMode WRITE setOverwriteMode )
00090     Q_PROPERTY( bool modified READ isModified WRITE setModified DESIGNABLE false )
00091     Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
00092     Q_PROPERTY( bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled )
00093     Q_PROPERTY( int tabStopWidth READ tabStopWidth WRITE setTabStopWidth )
00094 
00095 public:
00096     enum WordWrap {
00097         NoWrap,
00098         WidgetWidth,
00099         FixedPixelWidth,
00100         FixedColumnWidth
00101     };
00102 
00103     enum WrapPolicy {
00104         AtWordBoundary,
00105         Anywhere,
00106         AtWhiteSpace = AtWordBoundary // deprecated, don't use
00107     };
00108 
00109     enum KeyboardAction {
00110         ActionBackspace,
00111         ActionDelete,
00112         ActionReturn,
00113         ActionKill
00114     };
00115 
00116     enum CursorAction {
00117         MoveBackward,
00118         MoveForward,
00119         MoveWordBackward,
00120         MoveWordForward,
00121         MoveUp,
00122         MoveDown,
00123         MoveLineStart,
00124         MoveLineEnd,
00125         MoveHome,
00126         MoveEnd,
00127         MovePgUp,
00128         MovePgDown
00129     };
00130 
00131     enum VerticalAlignment {
00132         AlignNormal,
00133         AlignSuperScript,
00134         AlignSubScript
00135     };
00136 
00137     QTextEdit( const QString& text, const QString& context = QString::null,
00138                QWidget* parent=0, const char* name=0);
00139     QTextEdit( QWidget* parent=0, const char* name=0 );
00140     virtual ~QTextEdit();
00141     void setPalette( const QPalette & );
00142 
00143     QString text() const;
00144     QString text( int para ) const;
00145     TextFormat textFormat() const;
00146     QString context() const;
00147     QString documentTitle() const;
00148 
00149     void getSelection( int *paraFrom, int *indexFrom,
00150                     int *paraTo, int *indexTo, int selNum = 0 ) const;
00151     virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE,
00152                        int *para = 0, int *index = 0 );
00153 
00154     int paragraphs() const;
00155     int lines() const;
00156     int linesOfParagraph( int para ) const;
00157     int lineOfChar( int para, int chr );
00158     int length() const;
00159     QRect paragraphRect( int para ) const;
00160     int paragraphAt( const QPoint &pos ) const;
00161     int charAt( const QPoint &pos, int *para ) const;
00162     int paragraphLength( int para ) const;
00163 
00164     QStyleSheet* styleSheet() const;
00165     QMimeSourceFactory* mimeSourceFactory() const;
00166 
00167     QBrush paper() const;
00168     bool linkUnderline() const;
00169 
00170     int heightForWidth( int w ) const;
00171 
00172     bool hasSelectedText() const;
00173     QString selectedText() const;
00174     bool isUndoAvailable() const;
00175     bool isRedoAvailable() const;
00176 
00177     WordWrap wordWrap() const;
00178     int wrapColumnOrWidth() const;
00179     WrapPolicy wrapPolicy() const;
00180 
00181     int tabStopWidth() const;
00182 
00183     QString anchorAt( const QPoint& pos );
00184 
00185     QSize sizeHint() const;
00186 
00187     bool isReadOnly() const { return readonly; }
00188 
00189     void getCursorPosition( int *parag, int *index ) const;
00190 
00191     bool isModified() const;
00192     bool italic() const;
00193     bool bold() const;
00194     bool underline() const;
00195     QString family() const;
00196     int pointSize() const;
00197     QColor color() const;
00198     QFont font() const;
00199     int alignment() const;
00200     int undoDepth() const;
00201 
00202     // do not use, will go away
00203     virtual bool getFormat( int para, int index, QFont *font, QColor *color, VerticalAlignment *verticalAlignment );
00204     // do not use, will go away
00205     virtual bool getParagraphFormat( int para, QFont *font, QColor *color,
00206                                      VerticalAlignment *verticalAlignment, int *alignment,
00207                                      QStyleSheetItem::DisplayMode *displayMode,
00208                                      QStyleSheetItem::ListStyle *listStyle,
00209                                      int *listDepth );
00210 
00211 
00212     bool isOverwriteMode() const { return overWrite; }
00213     QColor paragraphBackgroundColor( int para ) const;
00214 
00215     bool isUndoRedoEnabled() const;
00216     bool eventFilter( QObject *o, QEvent *e );
00217 
00218 public slots:
00219     void setEnabled( bool );
00220     virtual void setMimeSourceFactory( QMimeSourceFactory* factory );
00221     virtual void setStyleSheet( QStyleSheet* styleSheet );
00222     virtual void scrollToAnchor( const QString& name );
00223     virtual void setPaper( const QBrush& pap );
00224     virtual void setLinkUnderline( bool );
00225 
00226     virtual void setWordWrap( WordWrap mode );
00227     virtual void setWrapColumnOrWidth( int );
00228     virtual void setWrapPolicy( WrapPolicy policy );
00229 
00230     virtual void copy();
00231     virtual void append( const QString& text );
00232 
00233     void setText( const QString &txt ) { setText( txt, QString::null ); }
00234     virtual void setText( const QString &txt, const QString &context );
00235     virtual void setTextFormat( TextFormat f );
00236 
00237     virtual void selectAll( bool select = TRUE );
00238     virtual void setTabStopWidth( int ts );
00239     virtual void zoomIn( int range );
00240     virtual void zoomIn() { zoomIn( 1 ); }
00241     virtual void zoomOut( int range );
00242     virtual void zoomOut() { zoomOut( 1 ); }
00243     virtual void zoomTo( int size );
00244 
00245     virtual void sync();
00246     virtual void setReadOnly( bool b );
00247 
00248     virtual void undo();
00249     virtual void redo();
00250     virtual void cut();
00251     virtual void paste();
00252 #ifndef QT_NO_CLIPBOARD
00253     virtual void pasteSubType( const QCString &subtype );
00254 #endif
00255     virtual void clear();
00256     virtual void del();
00257     virtual void indent();
00258     virtual void setItalic( bool b );
00259     virtual void setBold( bool b );
00260     virtual void setUnderline( bool b );
00261     virtual void setFamily( const QString &f );
00262     virtual void setPointSize( int s );
00263     virtual void setColor( const QColor &c );
00264     virtual void setFont( const QFont &f );
00265     virtual void setVerticalAlignment( VerticalAlignment a );
00266     virtual void setAlignment( int a );
00267 
00268     // do not use, will go away
00269     virtual void setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::ListStyle listStyle );
00270 
00271     virtual void setCursorPosition( int parag, int index );
00272     virtual void setSelection( int parag_from, int index_from, int parag_to, int index_to, int selNum = 0 );
00273     virtual void setSelectionAttributes( int selNum, const QColor &back, bool invertText );
00274     virtual void setModified( bool m );
00275     virtual void resetFormat();
00276     virtual void setUndoDepth( int d );
00277     virtual void setFormat( QTextFormat *f, int flags );
00278     virtual void ensureCursorVisible();
00279     virtual void placeCursor( const QPoint &pos, QTextCursor *c = 0 );
00280     virtual void moveCursor( CursorAction action, bool select );
00281     virtual void doKeyboardAction( KeyboardAction action );
00282     virtual void removeSelectedText( int selNum = 0 );
00283     virtual void removeSelection( int selNum = 0 );
00284     virtual void setCurrentFont( const QFont &f );
00285     virtual void setOverwriteMode( bool b ) { overWrite = b; }
00286 
00287     virtual void scrollToBottom();
00288 
00289     virtual void insert( const QString &text, bool indent, bool checkNewLine, bool removeSelected );
00290     virtual void insertAt( const QString &text, int para, int index );
00291     virtual void removeParagraph( int para );
00292     virtual void insertParagraph( const QString &text, int para );
00293 
00294     virtual void setParagraphBackgroundColor( int para, const QColor &bg );
00295     virtual void clearParagraphBackground( int para );
00296 
00297     virtual void setUndoRedoEnabled( bool b );
00298 
00299 signals:
00300     void textChanged();
00301     void selectionChanged();
00302     void copyAvailable( bool );
00303     void undoAvailable( bool yes );
00304     void redoAvailable( bool yes );
00305     void currentFontChanged( const QFont &f );
00306     void currentColorChanged( const QColor &c );
00307     void currentAlignmentChanged( int a );
00308     void currentVerticalAlignmentChanged( VerticalAlignment a );
00309     void cursorPositionChanged( QTextCursor *c );
00310     void cursorPositionChanged( int para, int pos );
00311     void returnPressed();
00312     void modificationChanged( bool m );
00313 
00314 protected:
00315     void repaintChanged();
00316     void updateStyles();
00317     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00318     bool event( QEvent *e );
00319     void keyPressEvent( QKeyEvent *e );
00320     void resizeEvent( QResizeEvent *e );
00321     void viewportResizeEvent( QResizeEvent* );
00322     void contentsMousePressEvent( QMouseEvent *e );
00323     void contentsMouseMoveEvent( QMouseEvent *e );
00324     void contentsMouseReleaseEvent( QMouseEvent *e );
00325     void contentsMouseDoubleClickEvent( QMouseEvent *e );
00326 #ifndef QT_NO_WHEELEVENT
00327     void contentsWheelEvent( QWheelEvent *e );
00328 #endif
00329 #ifndef QT_NO_DRAGANDDROP
00330     void contentsDragEnterEvent( QDragEnterEvent *e );
00331     void contentsDragMoveEvent( QDragMoveEvent *e );
00332     void contentsDragLeaveEvent( QDragLeaveEvent *e );
00333     void contentsDropEvent( QDropEvent *e );
00334 #endif
00335     bool focusNextPrevChild( bool next );
00336     QTextDocument *document() const;
00337     QTextCursor *textCursor() const;
00338     void setDocument( QTextDocument *doc );
00339     virtual QPopupMenu *createPopupMenu( const QPoint& pos );
00340     virtual QPopupMenu *createPopupMenu();
00341     void drawCursor( bool visible );
00342 
00343     void windowActivationChange( bool );
00344 
00345 protected slots:
00346     virtual void doChangeInterval();
00347 
00348 private slots:
00349     void formatMore();
00350     void doResize();
00351     void autoScrollTimerDone();
00352     void blinkCursor();
00353     void setModified();
00354     void startDrag();
00355     void documentWidthChanged( int w );
00356 
00357 private:
00358     struct Q_EXPORT UndoRedoInfo {
00359         enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected, Format, Style };
00360 
00361         UndoRedoInfo( QTextDocument *dc );
00362         ~UndoRedoInfo();
00363         void clear();
00364         bool valid() const;
00365 
00366         QUndoRedoInfoPrivate *d;
00367         int id;
00368         int index;
00369         int eid;
00370         int eindex;
00371         QTextFormat *format;
00372         int flags;
00373         Type type;
00374         QTextDocument *doc;
00375         QByteArray styleInformation;
00376     };
00377 
00378 private:
00379     void updateCursor( const QPoint & pos );
00380     void handleMouseMove( const QPoint& pos );
00381     void drawContents( QPainter * );
00382     virtual bool linksEnabled() const { return FALSE; }
00383     void init();
00384     void checkUndoRedoInfo( UndoRedoInfo::Type t );
00385     void updateCurrentFormat();
00386     bool handleReadOnlyKeyEvent( QKeyEvent *e );
00387     void makeParagVisible( QTextParagraph *p );
00388 #ifndef QT_NO_MIME
00389     QCString pickSpecial(QMimeSource* ms, bool always_ask, const QPoint&);
00390 #endif
00391 #ifndef QT_NO_MIMECLIPBOARD
00392     void pasteSpecial(const QPoint&);
00393 #endif
00394     void setFontInternal( const QFont &f );
00395 
00396     virtual void emitHighlighted( const QString & ) {}
00397     virtual void emitLinkClicked( const QString & ) {}
00398 
00399     void readFormats( QTextCursor &c1, QTextCursor &c2, QTextString &text, bool fillStyles = FALSE );
00400     void clearUndoRedo();
00401     void paintDocument( bool drawAll, QPainter *p, int cx = -1, int cy = -1, int cw = -1, int ch = -1 );
00402     void moveCursor( CursorAction action );
00403     void ensureFormatted( QTextParagraph *p );
00404     void placeCursor( const QPoint &pos, QTextCursor *c, bool link );
00405     void updateMicroFocusHint();
00406 
00407 private:
00408     QTextDocument *doc;
00409     QTextCursor *cursor;
00410     QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer;
00411     QTextParagraph *lastFormatted;
00412     int interval;
00413     UndoRedoInfo undoRedoInfo;
00414     QTextFormat *currentFormat;
00415     int currentAlignment;
00416     QPoint oldMousePos, mousePos;
00417     QPoint dragStartPos;
00418     QString onLink;
00419     WordWrap wrapMode;
00420     WrapPolicy wPolicy;
00421     int wrapWidth;
00422     QString pressedLink;
00423     QTextEditPrivate *d;
00424     bool inDoubleClick : 1;
00425     bool mousePressed : 1;
00426     bool cursorVisible : 1;
00427     bool blinkCursorVisible : 1;
00428     bool readOnly : 1;
00429     bool modified : 1;
00430     bool mightStartDrag : 1;
00431     bool inDnD : 1;
00432     bool readonly : 1;
00433     bool undoEnabled : 1;
00434     bool overWrite : 1;
00435 };
00436 
00437 inline QTextDocument *QTextEdit::document() const
00438 {
00439     return doc;
00440 }
00441 
00442 inline QTextCursor *QTextEdit::textCursor() const
00443 {
00444     return cursor;
00445 }
00446 
00447 inline void QTextEdit::setCurrentFont( const QFont &f )
00448 {
00449     QTextEdit::setFontInternal( f );
00450 }
00451 
00452 }
00453 
00454 #endif //QTEXTVIEW_H

Generated on Sat Nov 5 16:17:07 2005 for OPIE by  doxygen 1.4.2