00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef Z_MULTILINE_H
00016 #define Z_MULTILINE_H
00017
00018 #ifndef __cplusplus
00019 #error "This is a C++ header file;it requires C++ to compile."
00020 #endif
00021
00022 #ifndef QT_H
00023 #include "qtableview.h"
00024 #include "qstring.h"
00025 #include "qlist.h"
00026 #include "qregexp.h"
00027 #endif // QT_H
00028
00029 struct ZMultiLineData;
00030 class ZMultiLineEditCommand;
00031 class QValidator;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 class Q_EXPORT ZMultiLineEdit : public QTableView
00068 {
00069 Q_OBJECT
00070
00071 Q_ENUMS( EchoMode WordWrap WrapPolicy )
00072 Q_PROPERTY( int numLines READ numLines )
00073 Q_PROPERTY( bool atBeginning READ atBeginning )
00074 Q_PROPERTY( bool atEnd READ atEnd )
00075 Q_PROPERTY( int maxLineWidth READ maxLineWidth )
00076 Q_PROPERTY( Alignment alignment READ alignment WRITE setAlignment )
00077 Q_PROPERTY( bool edited READ edited WRITE setEdited DESIGNABLE false )
00078 Q_PROPERTY( EchoMode echoMode READ echoMode WRITE setEchoMode )
00079 Q_PROPERTY( int maxLength READ maxLength WRITE setMaxLength )
00080 Q_PROPERTY( int maxLines READ maxLines WRITE setMaxLines )
00081 Q_PROPERTY( int hMargin READ hMargin WRITE setHMargin )
00082 Q_PROPERTY( WordWrap wordWrap READ wordWrap WRITE setWordWrap )
00083 Q_PROPERTY( int wrapColumnOrWidth READ wrapColumnOrWidth WRITE setWrapColumnOrWidth )
00084 Q_PROPERTY( WrapPolicy wrapPolicy READ wrapPolicy WRITE setWrapPolicy )
00085 Q_PROPERTY( bool autoUpdate READ autoUpdate WRITE setAutoUpdate DESIGNABLE false )
00086 Q_PROPERTY( bool undoEnabled READ isUndoEnabled WRITE setUndoEnabled )
00087 Q_PROPERTY( int undoDepth READ undoDepth WRITE setUndoDepth )
00088 Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
00089 Q_PROPERTY( bool overWriteMode READ isOverwriteMode WRITE setOverwriteMode )
00090 Q_PROPERTY( QString text READ text WRITE setText )
00091 Q_PROPERTY( int length READ length )
00092
00093 public:
00094
00095 ZMultiLineEdit( QWidget *parent=0, const char *name=0);
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 ZMultiLineEdit( QWidget *parent,bool EZXStyle,int lines = 1,const char *name=0 );
00106
00107 virtual ~ZMultiLineEdit();
00108
00109
00110
00111
00112 void setIndent( int idt );
00113
00114
00115
00116
00117 int getIndent();
00118
00119
00120
00121
00122 int getLineHeight() const;
00123
00124
00125
00126
00127 void setUnderline( bool needUnderline = true );
00128
00129
00130
00131
00132
00133
00134 bool getUnderline();
00135
00136
00137
00138
00139
00140
00141
00142
00143 void setFilter( const QRegExp& filter, bool match = false );
00144
00145
00146
00147
00148 const QRegExp& getFilter() const;
00149
00150
00151
00152 QString textLine( int line ) const;
00153 int numLines() const;
00154
00155 QSize sizeHint() const;
00156 QSize minimumSizeHint() const;
00157 QSizePolicy sizePolicy() const;
00158
00159 virtual void setFont( const QFont &font );
00160
00161 virtual void insertLine( const QString &s, int line = -1 );
00162 virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE );
00163 virtual void removeLine( int line );
00164
00165 void cursorPosition( int *line, int *col ) const;
00166 virtual void setCursorPosition( int line, int col, bool mark = FALSE );
00167 void getCursorPosition( int *line, int *col ) const;
00168 bool atBeginning() const;
00169 bool atEnd() const;
00170
00171 virtual void setFixedVisibleLines( int lines );
00172
00173 int maxLineWidth() const;
00174
00175 void setAlignment( int flags );
00176 int alignment() const;
00177
00178 virtual void setValidator( const QValidator * );
00179 const QValidator * validator() const;
00180
00181 void setEdited( bool );
00182 bool edited() const;
00183
00184 void cursorWordForward( bool mark );
00185 void cursorWordBackward( bool mark );
00186
00187 enum EchoMode { Normal, NoEcho, Password };
00188 virtual void setEchoMode( EchoMode );
00189 EchoMode echoMode() const;
00190
00191 void setMaxLength(int);
00192 int maxLength() const;
00193 virtual void setMaxLineLength(int);
00194 int maxLineLength() const;
00195 virtual void setMaxLines(int);
00196 int maxLines() const;
00197 virtual void setHMargin(int);
00198 int hMargin() const;
00199
00200 virtual void setSelection( int row_from, int col_from, int row_to, int col_t );
00201
00202 enum WordWrap {
00203 NoWrap,
00204 WidgetWidth,
00205 FixedPixelWidth,
00206 FixedColumnWidth
00207 };
00208 void setWordWrap( WordWrap mode );
00209 WordWrap wordWrap() const;
00210 void setWrapColumnOrWidth( int );
00211 int wrapColumnOrWidth() const;
00212
00213 enum WrapPolicy {
00214 AtWhiteSpace,
00215 Anywhere
00216 };
00217 void setWrapPolicy( WrapPolicy policy );
00218 WrapPolicy wrapPolicy() const;
00219
00220 bool autoUpdate() const;
00221 virtual void setAutoUpdate( bool );
00222
00223 void setUndoEnabled( bool );
00224 bool isUndoEnabled() const;
00225 void setUndoDepth( int );
00226 int undoDepth() const;
00227
00228 bool isReadOnly() const;
00229 bool isOverwriteMode() const;
00230
00231 QString text() const;
00232
00233 int length() const;
00234
00235 static void setDefaultTabStop( int ex );
00236 static int defaultTabStop();
00237
00238 virtual void show();
00239
00240 public slots:
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 virtual void changeContentSize( int lines,QPoint cursorPos );
00252
00253 virtual void setText( const QString &);
00254 virtual void setReadOnly( bool );
00255 virtual void setOverwriteMode( bool );
00256
00257 void clear();
00258 void append( const QString &);
00259 void deselect();
00260 void selectAll();
00261 #ifndef QT_NO_CLIPBOARD
00262 void paste();
00263 void pasteSubType(const QCString& subtype);
00264 void copyText() const;
00265 void copy() const;
00266 void cut();
00267 void deleteText();
00268 #endif
00269 void insert( const QString& );
00270 void undo();
00271 void redo();
00272
00273 signals:
00274
00275 void clicked();
00276 void textTrancated();
00277 void textChanged();
00278 void returnPressed();
00279 void undoAvailable( bool );
00280 void redoAvailable( bool );
00281 void copyAvailable( bool );
00282
00283
00284
00285
00286
00287
00288 void changeSizeHint( QWidget* widget,QSize size,QPoint cusrorPos,int larger );
00289
00290
00291
00292
00293
00294
00295 void linesChanged( int lines,QPoint cursorPos );
00296
00297 protected:
00298
00299 void updateMask();
00300 void pixelPosToCursorPos(QPoint p, int* x, int* y) const;
00301 void setCursorPixelPosition(QPoint p, bool clear_mark = true);
00302
00303 void paintEvent(QPaintEvent * );
00304
00305 #define MOT_BLEND
00306 #ifdef MOT_BLEND
00307 void paintCell( QPainter *, int row, int col, int xPos, int yPos );
00308 #else
00309 void paintCell( QPainter *, int row, int col );
00310 #endif
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 virtual void drawLineText( QPainter* painter, int x, int y, int width,
00329 int height, int flags, const QString& lineStr);
00330 bool event( QEvent * );
00331
00332 void mousePressEvent( QMouseEvent * );
00333 void mouseMoveEvent( QMouseEvent * );
00334 void mouseReleaseEvent( QMouseEvent * );
00335 void mouseDoubleClickEvent( QMouseEvent * );
00336 void wheelEvent( QWheelEvent * );
00337 void keyPressEvent( QKeyEvent * );
00338 void focusInEvent( QFocusEvent * );
00339 void focusOutEvent( QFocusEvent * );
00340 void timerEvent( QTimerEvent * );
00341 void leaveEvent( QEvent * );
00342 void resizeEvent( QResizeEvent * );
00343
00344 bool focusNextPrevChild( bool );
00345
00346 #ifndef QT_NO_DRAGANDDROP
00347 void dragMoveEvent( QDragMoveEvent* );
00348 void dragEnterEvent( QDragEnterEvent * );
00349 void dropEvent( QDropEvent* );
00350 void dragLeaveEvent( QDragLeaveEvent* );
00351 #endif
00352
00353 bool hasMarkedText() const;
00354 QString markedText() const;
00355 int textWidth( int );
00356 int textWidth( const QString &);
00357
00358 QPoint cursorPoint() const;
00359
00360 protected:
00361
00362 virtual void insert( const QString&, bool mark );
00363 virtual void newLine();
00364 virtual void killLine();
00365 virtual void pageUp( bool mark=FALSE );
00366 virtual void pageDown( bool mark=FALSE );
00367 virtual void cursorLeft( bool mark=FALSE, bool wrap = TRUE );
00368 virtual void cursorRight( bool mark=FALSE, bool wrap = TRUE );
00369 virtual void cursorUp( bool mark=FALSE );
00370 virtual void cursorDown( bool mark=FALSE );
00371 virtual void backspace();
00372 virtual void del();
00373 virtual void home( bool mark=FALSE );
00374 virtual void end( bool mark=FALSE );
00375
00376 bool getMarkedRegion( int *line1, int *col1,
00377 int *line2, int *col2 ) const;
00378 int lineLength( int row ) const;
00379 QString *getString( int row ) const;
00380 bool isEndOfParagraph( int row ) const;
00381 QString stringShown( int row ) const;
00382
00383 protected:
00384
00385 bool cursorOn;
00386 void insertChar( QChar );
00387
00388 #ifndef QT_NO_QWS_MMI_TEST
00389 QRect globalRect( int mx, int my, int mwidth, int mheight );
00390 virtual int sendPackage();
00391 virtual int sendPackageItem( int mmix, int mmiy, int mmiwidth, int mmiheight, QString mmis );
00392 #endif
00393
00394 private slots:
00395
00396 void clipboardChanged();
00397 void blinkTimerTimeout();
00398 void scrollTimerTimeout();
00399 void dndTimeout();
00400
00401 private:
00402
00403 void init( QWidget *parent,bool style,int lines,const char *name );
00404 bool isValidChar( const QChar& ch );
00405 void filterString( QString& filtered,const QString& s );
00406 void autoSendScrollRequest( int lines,const QPoint& curPos );
00407
00408 #ifndef AMT_NO_THAI_ADDITIONS
00409 int clusterForward(int cp) const;
00410 int clusterBackward(int cp) const;
00411 int toClusterEnd(int cp) const;
00412 #endif
00413 #ifndef QT_NO_MIME
00414 QCString pickSpecial( QMimeSource* ms, bool always_ask, const QPoint& );
00415 #endif
00416
00417 void pasteSpecial(const QPoint&);
00418
00419 struct ZMultiLineEditRow {
00420 ZMultiLineEditRow( QString string, int width, bool nl = TRUE )
00421 :s(string), w(width), newline( nl ) {
00422 };
00423 QString s;
00424 int w;
00425 bool newline;
00426 };
00427 QList<ZMultiLineEditRow>* contents;
00428 ZMultiLineData* d;
00429
00430 int indent;
00431 QSize hint;
00432 bool ezx_style;
00433 int lines;
00434 int minLines;
00435 bool underline;
00436
00437 bool readOnly;
00438 bool dummy;
00439 bool markIsOn;
00440 bool dragScrolling ;
00441 bool dragMarking;
00442 bool textDirty;
00443 bool wordMark;
00444 bool overWrite;
00445
00446 int cursorX;
00447 int cursorY;
00448 int markAnchorX;
00449 int markAnchorY;
00450 int markDragX;
00451 int markDragY;
00452 int curXPos;
00453 int blinkTimer;
00454 int scrollTimer;
00455
00456 int mapFromView( int xPos, int row );
00457 int mapToView( int xIndex, int row );
00458
00459 void setWidth( int );
00460 void updateCellWidth();
00461 bool partiallyInvisible( int row );
00462 void makeVisible();
00463 void setBottomCell( int row );
00464
00465 void newMark( int posx, int posy, bool copy=TRUE );
00466 void markWord( int posx, int posy );
00467 void extendSelectionWord( int &newX, int&newY);
00468 int charClass( QChar );
00469 void turnMark( bool on );
00470 bool inMark( int posx, int posy ) const;
00471 bool beforeMark( int posx, int posy ) const;
00472 bool afterMark( int posx, int posy ) const;
00473 int setNumRowsAndTruncate();
00474
00475 #ifndef QT_NO_DRAGANDDROP
00476 void doDrag();
00477 #endif
00478 void startAutoScroll();
00479 void stopAutoScroll();
00480
00481 void cursorLeft( bool mark, bool clear_mark, bool wrap );
00482 void cursorRight( bool mark, bool clear_mark, bool wrap );
00483 void cursorUp( bool mark, bool clear_mark );
00484 void cursorDown( bool mark, bool clear_mark );
00485
00486 void wrapLine( int line, int removed = 0);
00487 void rebreakParagraph( int line, int removed = 0 );
00488 void rebreakAll();
00489 void insertAtAux( const QString &s, int line, int col, bool mark = FALSE );
00490 void killLineAux();
00491 void delAux();
00492 int positionToOffsetInternal( int row, int col ) const;
00493 void offsetToPositionInternal( int position, int *row, int *col ) const;
00494 void deleteNextChar( int offset, int row, int col );
00495
00496 void addUndoCmd( ZMultiLineEditCommand* );
00497 void addRedoCmd( ZMultiLineEditCommand* );
00498 void processCmd( ZMultiLineEditCommand*, bool );
00499
00500 private:
00501
00502 #if defined(Q_DISABLE_COPY)
00503 ZMultiLineEdit( const ZMultiLineEdit & );
00504 ZMultiLineEdit &operator=( const ZMultiLineEdit & );
00505 #endif
00506
00507 };
00508
00509 inline bool ZMultiLineEdit::isReadOnly() const { return readOnly; }
00510
00511 inline bool ZMultiLineEdit::isOverwriteMode() const { return overWrite; }
00512
00513 inline void ZMultiLineEdit::setOverwriteMode( bool on )
00514 {
00515 overWrite = on;
00516 }
00517
00518 inline int ZMultiLineEdit::lineLength( int row ) const
00519 {
00520 return contents->at( row )->s.length();
00521 }
00522
00523 inline bool ZMultiLineEdit::atEnd() const
00524 {
00525 return cursorY == (int)contents->count() - 1
00526 && cursorX == lineLength( cursorY ) ;
00527 }
00528
00529 inline bool ZMultiLineEdit::atBeginning() const
00530 {
00531 return cursorY == 0 && cursorX == 0;
00532 }
00533
00534 inline QString *ZMultiLineEdit::getString( int row ) const
00535 {
00536 return &(contents->at( row )->s);
00537 }
00538
00539 inline int ZMultiLineEdit::numLines() const
00540 {
00541 return contents->count();
00542 }
00543
00544 #endif
00545
00546
00547
00548
00549
00550
00551