Eneboo - Documentación para desarrolladores
|
00001 /********************************************************************** 00002 ** $Id: qt/qtmultilineedit.h 3.3.8 edited Jan 11 14:37 $ 00003 ** 00004 ** Definition of QtMultiLineEdit widget class 00005 ** 00006 ** Created : 961005 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file contains a class moved out of the Qt GUI Toolkit API. It 00011 ** may be used, distributed and modified without limitation. 00012 ** 00013 **********************************************************************/ 00014 00015 #ifndef QTMULTILINEEDIT_H 00016 #define QTMULTILINEEDIT_H 00017 00018 #ifndef QT_H 00019 #include "qttableview.h" 00020 #include "qstring.h" 00021 #include "qptrlist.h" 00022 #endif // QT_H 00023 00024 #ifndef QT_NO_QTMULTILINEEDIT 00025 00026 struct QtMultiLineData; 00027 class QtMultiLineEditCommand; 00028 class QValidator; 00029 00030 class QtMultiLineEdit : public QtTableView 00031 { 00032 Q_OBJECT 00033 Q_ENUMS( EchoMode WordWrap WrapPolicy ) 00034 Q_PROPERTY( int numLines READ numLines ) 00035 Q_PROPERTY( bool atBeginning READ atBeginning ) 00036 Q_PROPERTY( bool atEnd READ atEnd ) 00037 Q_PROPERTY( int maxLineWidth READ maxLineWidth ) 00038 Q_PROPERTY( Alignment alignment READ alignment WRITE setAlignment ) 00039 Q_PROPERTY( bool edited READ edited WRITE setEdited DESIGNABLE false ) 00040 Q_PROPERTY( EchoMode echoMode READ echoMode WRITE setEchoMode ) 00041 Q_PROPERTY( int maxLength READ maxLength WRITE setMaxLength ) 00042 Q_PROPERTY( int maxLines READ maxLines WRITE setMaxLines ) 00043 Q_PROPERTY( int hMargin READ hMargin WRITE setHMargin ) 00044 Q_PROPERTY( WordWrap wordWrap READ wordWrap WRITE setWordWrap ) 00045 Q_PROPERTY( int wrapColumnOrWidth READ wrapColumnOrWidth WRITE setWrapColumnOrWidth ) 00046 Q_PROPERTY( WrapPolicy wrapPolicy READ wrapPolicy WRITE setWrapPolicy ) 00047 Q_PROPERTY( bool autoUpdate READ autoUpdate WRITE setAutoUpdate DESIGNABLE false ) 00048 Q_PROPERTY( bool undoEnabled READ isUndoEnabled WRITE setUndoEnabled ) 00049 Q_PROPERTY( int undoDepth READ undoDepth WRITE setUndoDepth ) 00050 Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly ) 00051 Q_PROPERTY( bool overWriteMode READ isOverwriteMode WRITE setOverwriteMode ) 00052 Q_PROPERTY( QString text READ text WRITE setText ) 00053 Q_PROPERTY( int length READ length ) 00054 00055 public: 00056 QtMultiLineEdit( QWidget *parent=0, const char *name=0 ); 00057 ~QtMultiLineEdit(); 00058 00059 QString textLine( int line ) const; 00060 int numLines() const; 00061 00062 QSize sizeHint() const; 00063 QSize minimumSizeHint() const; 00064 QSizePolicy sizePolicy() const; 00065 00066 virtual void setFont( const QFont &font ); 00067 00068 virtual void insertLine( const QString &s, int line = -1 ); 00069 virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE ); 00070 virtual void removeLine( int line ); 00071 00072 void cursorPosition( int *line, int *col ) const; 00073 virtual void setCursorPosition( int line, int col, bool mark = FALSE ); 00074 void getCursorPosition( int *line, int *col ) const; 00075 bool atBeginning() const; 00076 bool atEnd() const; 00077 00078 virtual void setFixedVisibleLines( int lines ); 00079 00080 int maxLineWidth() const; 00081 00082 void setAlignment( int flags ); 00083 int alignment() const; 00084 00085 virtual void setValidator( const QValidator * ); 00086 const QValidator * validator() const; 00087 00088 void setEdited( bool ); 00089 bool edited() const; 00090 00091 void cursorWordForward( bool mark ); 00092 void cursorWordBackward( bool mark ); 00093 00094 enum EchoMode { Normal, NoEcho, Password }; 00095 virtual void setEchoMode( EchoMode ); 00096 EchoMode echoMode() const; 00097 00098 void setMaxLength(int); 00099 int maxLength() const; 00100 virtual void setMaxLineLength(int); 00101 int maxLineLength() const; 00102 virtual void setMaxLines(int); 00103 int maxLines() const; 00104 virtual void setHMargin(int); 00105 int hMargin() const; 00106 00107 virtual void setSelection( int row_from, int col_from, int row_to, int col_t ); 00108 00109 enum WordWrap { 00110 NoWrap, 00111 WidgetWidth, 00112 FixedPixelWidth, 00113 FixedColumnWidth 00114 }; 00115 void setWordWrap( WordWrap mode ); 00116 WordWrap wordWrap() const; 00117 void setWrapColumnOrWidth( int ); 00118 int wrapColumnOrWidth() const; 00119 00120 enum WrapPolicy { 00121 AtWhiteSpace, 00122 Anywhere 00123 }; 00124 void setWrapPolicy( WrapPolicy policy ); 00125 WrapPolicy wrapPolicy() const; 00126 00127 bool autoUpdate() const; 00128 virtual void setAutoUpdate( bool ); 00129 00130 void setUndoEnabled( bool ); 00131 bool isUndoEnabled() const; 00132 void setUndoDepth( int ); 00133 int undoDepth() const; 00134 00135 bool isReadOnly() const; 00136 bool isOverwriteMode() const; 00137 00138 QString text() const; 00139 00140 int length() const; 00141 00142 static void setDefaultTabStop( int ex ); 00143 static int defaultTabStop(); 00144 public slots: 00145 virtual void setText( const QString &); 00146 virtual void setReadOnly( bool ); 00147 virtual void setOverwriteMode( bool ); 00148 00149 void clear(); 00150 void append( const QString &); 00151 void deselect(); 00152 void selectAll(); 00153 #ifndef QT_NO_CLIPBOARD 00154 void paste(); 00155 void pasteSubType(const QCString& subtype); 00156 void copyText() const; 00157 void copy() const; 00158 void cut(); 00159 #endif 00160 void insert( const QString& ); 00161 void undo(); 00162 void redo(); 00163 00164 signals: 00165 void textChanged(); 00166 void returnPressed(); 00167 void undoAvailable( bool ); 00168 void redoAvailable( bool ); 00169 void copyAvailable( bool ); 00170 00171 protected: 00172 void paintCell( QPainter *, int row, int col ); 00173 bool event( QEvent * ); 00174 00175 void mousePressEvent( QMouseEvent * ); 00176 void mouseMoveEvent( QMouseEvent * ); 00177 void mouseReleaseEvent( QMouseEvent * ); 00178 void mouseDoubleClickEvent( QMouseEvent * ); 00179 void wheelEvent( QWheelEvent * ); 00180 void keyPressEvent( QKeyEvent * ); 00181 void focusInEvent( QFocusEvent * ); 00182 void focusOutEvent( QFocusEvent * ); 00183 void timerEvent( QTimerEvent * ); 00184 void leaveEvent( QEvent * ); 00185 void resizeEvent( QResizeEvent * ); 00186 00187 bool focusNextPrevChild( bool ); 00188 00189 #ifndef QT_NO_DRAGANDDROP 00190 void dragMoveEvent( QDragMoveEvent* ); 00191 void dragEnterEvent( QDragEnterEvent * ); 00192 void dropEvent( QDropEvent* ); 00193 void dragLeaveEvent( QDragLeaveEvent* ); 00194 #endif 00195 00196 bool hasMarkedText() const; 00197 QString markedText() const; 00198 int textWidth( int ); 00199 int textWidth( const QString &); 00200 00201 QPoint cursorPoint() const; 00202 00203 protected: 00204 virtual void insert( const QString&, bool mark ); 00205 virtual void newLine(); 00206 virtual void killLine(); 00207 virtual void pageUp( bool mark=FALSE ); 00208 virtual void pageDown( bool mark=FALSE ); 00209 virtual void cursorLeft( bool mark=FALSE, bool wrap = TRUE ); 00210 virtual void cursorRight( bool mark=FALSE, bool wrap = TRUE ); 00211 virtual void cursorUp( bool mark=FALSE ); 00212 virtual void cursorDown( bool mark=FALSE ); 00213 virtual void backspace(); 00214 virtual void del(); 00215 virtual void home( bool mark=FALSE ); 00216 virtual void end( bool mark=FALSE ); 00217 00218 bool getMarkedRegion( int *line1, int *col1, 00219 int *line2, int *col2 ) const; 00220 int lineLength( int row ) const; 00221 QString *getString( int row ) const; 00222 bool isEndOfParagraph( int row ) const; 00223 QString stringShown( int row ) const; 00224 00225 protected: 00226 bool cursorOn; 00227 void insertChar( QChar ); 00228 00229 private slots: 00230 void clipboardChanged(); 00231 void blinkTimerTimeout(); 00232 void scrollTimerTimeout(); 00233 void dndTimeout(); 00234 00235 private: 00236 #ifndef QT_NO_MIME 00237 QCString pickSpecial(QMimeSource* ms, bool always_ask, const QPoint&); 00238 #endif 00239 #ifndef QT_NO_MIMECLIPBOARD 00240 void pasteSpecial(const QPoint&); 00241 #endif 00242 struct QtMultiLineEditRow { 00243 QtMultiLineEditRow( QString string, int width, bool nl = TRUE ) 00244 :s(string), w(width), newline( nl ) 00245 { 00246 }; 00247 QString s; 00248 int w; 00249 bool newline; 00250 }; 00251 QPtrList<QtMultiLineEditRow> *contents; 00252 QtMultiLineData *d; 00253 00254 bool readOnly; 00255 bool dummy; 00256 bool markIsOn; 00257 bool dragScrolling ; 00258 bool dragMarking; 00259 bool textDirty; 00260 bool wordMark; 00261 bool overWrite; 00262 00263 int cursorX; 00264 int cursorY; 00265 int markAnchorX; 00266 int markAnchorY; 00267 int markDragX; 00268 int markDragY; 00269 int curXPos; // cell coord of cursor 00270 int blinkTimer; // #### not used anymore - remove in 3.0 00271 int scrollTimer; // #### not used anymore - remove in 3.0 00272 00273 int mapFromView( int xPos, int row ); 00274 int mapToView( int xIndex, int row ); 00275 00276 void pixelPosToCursorPos(QPoint p, int* x, int* y) const; 00277 void setCursorPixelPosition(QPoint p, bool clear_mark=TRUE); 00278 00279 void setWidth( int ); 00280 void updateCellWidth(); 00281 bool partiallyInvisible( int row ); 00282 void makeVisible(); 00283 void setBottomCell( int row ); 00284 00285 void newMark( int posx, int posy, bool copy=TRUE ); 00286 void markWord( int posx, int posy ); 00287 void extendSelectionWord( int &newX, int&newY); 00288 int charClass( QChar ); 00289 void turnMark( bool on ); 00290 bool inMark( int posx, int posy ) const; 00291 bool beforeMark( int posx, int posy ) const; 00292 bool afterMark( int posx, int posy ) const; 00293 int setNumRowsAndTruncate(); 00294 00295 #ifndef QT_NO_DRAGANDDROP 00296 void doDrag(); 00297 #endif 00298 void startAutoScroll(); 00299 void stopAutoScroll(); 00300 00301 void cursorLeft( bool mark, bool clear_mark, bool wrap ); 00302 void cursorRight( bool mark, bool clear_mark, bool wrap ); 00303 void cursorUp( bool mark, bool clear_mark ); 00304 void cursorDown( bool mark, bool clear_mark ); 00305 00306 void wrapLine( int line, int removed = 0); 00307 void rebreakParagraph( int line, int removed = 0 ); 00308 void rebreakAll(); 00309 void insertAtAux( const QString &s, int line, int col, bool mark = FALSE ); 00310 void killLineAux(); 00311 void delAux(); 00312 int positionToOffsetInternal( int row, int col ) const; 00313 void offsetToPositionInternal( int position, int *row, int *col ) const; 00314 void deleteNextChar( int offset, int row, int col ); 00315 00316 void addUndoCmd( QtMultiLineEditCommand* ); 00317 void addRedoCmd( QtMultiLineEditCommand* ); 00318 void processCmd( QtMultiLineEditCommand*, bool ); 00319 00320 private: // Disabled copy constructor and operator= 00321 #if defined(Q_DISABLE_COPY) 00322 QtMultiLineEdit( const QtMultiLineEdit & ); 00323 QtMultiLineEdit &operator=( const QtMultiLineEdit & ); 00324 #endif 00325 }; 00326 00327 inline bool QtMultiLineEdit::isReadOnly() const { return readOnly; } 00328 00329 inline bool QtMultiLineEdit::isOverwriteMode() const { return overWrite; } 00330 00331 inline void QtMultiLineEdit::setOverwriteMode( bool on ) 00332 { 00333 overWrite = on; 00334 } 00335 00336 inline int QtMultiLineEdit::lineLength( int row ) const 00337 { 00338 return contents->at( row )->s.length(); 00339 } 00340 00341 inline bool QtMultiLineEdit::atEnd() const 00342 { 00343 return cursorY == (int)contents->count() - 1 00344 && cursorX == lineLength( cursorY ) ; 00345 } 00346 00347 inline bool QtMultiLineEdit::atBeginning() const 00348 { 00349 return cursorY == 0 && cursorX == 0; 00350 } 00351 00352 inline QString *QtMultiLineEdit::getString( int row ) const 00353 { 00354 return &(contents->at( row )->s); 00355 } 00356 00357 inline int QtMultiLineEdit::numLines() const 00358 { 00359 return contents->count(); 00360 } 00361 00362 #endif // QT_NO_QTMULTILINEEDIT 00363 00364 #endif // QTMULTILINEDIT_H