Source Code (Use browser search to find items of interest.)
Class Index
qt'QMultiLineEdit (./qt-2.1.0/src/widgets/qmultilineedit.h:39)
class Q_EXPORT QMultiLineEdit : public QTableView
{
Q_OBJECT
Q_ENUMS( EchoMode WordWrap WrapPolicy )
Q_PROPERTY( int numLines READ numLines )
Q_PROPERTY( bool atBeginning READ atBeginning )
Q_PROPERTY( bool atEnd READ atEnd )
Q_PROPERTY( int maxLineWidth READ maxLineWidth )
Q_PROPERTY( Alignment alignment READ alignment WRITE setAlignment )
Q_PROPERTY( bool edited READ edited WRITE setEdited )
Q_PROPERTY( EchoMode echoMode READ echoMode WRITE setEchoMode )
Q_PROPERTY( int maxLength READ maxLength WRITE setMaxLength )
Q_PROPERTY( int maxLineLength READ maxLineLength WRITE setMaxLineLength )
Q_PROPERTY( int maxLines READ maxLines WRITE setMaxLines )
Q_PROPERTY( int hMargin READ hMargin WRITE setHMargin )
Q_PROPERTY( WordWrap wordWrap READ wordWrap WRITE setWordWrap )
Q_PROPERTY( int wrapColumnOrWidth READ wrapColumnOrWidth WRITE setWrapColumnOrWidth )
Q_PROPERTY( WrapPolicy wrapPolicy READ wrapPolicy WRITE setWrapPolicy )
Q_PROPERTY( bool autoUpdate READ autoUpdate WRITE setAutoUpdate )
Q_PROPERTY( bool undoEnabled READ isUndoEnabled WRITE setUndoEnabled )
Q_PROPERTY( int undoDepth READ undoDepth WRITE setUndoDepth )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
Q_PROPERTY( bool overWriteMode READ isOverwriteMode WRITE setOverwriteMode )
Q_PROPERTY( QString text READ text WRITE setText )
Q_PROPERTY( int length READ length )
public:
QMultiLineEdit( QWidget *parent=0, const char *name=0 );
~QMultiLineEdit();
QString textLine( int line ) const;
int numLines() const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
QSizePolicy sizePolicy() const;
virtual void setFont( const QFont &font );
virtual void insertLine( const QString &s, int line = -1 );
virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE );
virtual void removeLine( int line );
void cursorPosition( int *line, int *col ) const;
virtual void setCursorPosition( int line, int col, bool mark = FALSE );
void getCursorPosition( int *line, int *col ) const;
bool atBeginning() const;
bool atEnd() const;
virtual void setFixedVisibleLines( int lines );
int maxLineWidth() const;
void setAlignment( int flags );
int alignment() const;
virtual void setValidator( const QValidator * );
const QValidator * validator() const;
void setEdited( bool );
bool edited() const;
void cursorWordForward( bool mark );
void cursorWordBackward( bool mark );
enum EchoMode { Normal, NoEcho, Password };
virtual void setEchoMode( EchoMode );
EchoMode echoMode() const;
void setMaxLength(int);
int maxLength() const;
virtual void setMaxLineLength(int);
int maxLineLength() const;
virtual void setMaxLines(int);
int maxLines() const;
virtual void setHMargin(int);
int hMargin() const;
virtual void setSelection( int row_from, int col_from, int row_to, int col_t );
enum WordWrap {
NoWrap,
WidgetWidth,
FixedPixelWidth,
FixedColumnWidth
};
void setWordWrap( WordWrap mode );
WordWrap wordWrap() const;
void setWrapColumnOrWidth( int );
int wrapColumnOrWidth() const;
enum WrapPolicy {
AtWhiteSpace,
Anywhere
};
void setWrapPolicy( WrapPolicy policy );
WrapPolicy wrapPolicy() const;
bool autoUpdate() const;
virtual void setAutoUpdate( bool );
void setUndoEnabled( bool );
bool isUndoEnabled() const;
void setUndoDepth( int );
int undoDepth() const;
bool isReadOnly() const;
bool isOverwriteMode() const;
QString text() const;
int length() const;
static void setDefaultTabStop( int ex );
static int defaultTabStop();
public slots:
virtual void setText( const QString &);
virtual void setReadOnly( bool );
virtual void setOverwriteMode( bool );
void clear();
void append( const QString &);
void deselect();
void selectAll();
void paste();
void copyText() const;
void copy() const;
void cut();
void insert( const QString& );
void undo();
void redo();
signals:
void textChanged();
void returnPressed();
void undoAvailable( bool );
void redoAvailable( bool );
protected:
void paintCell( QPainter *, int row, int col );
void mousePressEvent( QMouseEvent * );
void mouseMoveEvent( QMouseEvent * );
void mouseReleaseEvent( QMouseEvent * );
void mouseDoubleClickEvent( QMouseEvent * );
void wheelEvent( QWheelEvent * );
void keyPressEvent( QKeyEvent * );
void focusInEvent( QFocusEvent * );
void focusOutEvent( QFocusEvent * );
void timerEvent( QTimerEvent * );
void leaveEvent( QEvent * );
void resizeEvent( QResizeEvent * );
void dragMoveEvent( QDragMoveEvent* );
void dragEnterEvent( QDragEnterEvent * );
void dropEvent( QDropEvent* );
void dragLeaveEvent( QDragLeaveEvent* );
bool hasMarkedText() const;
QString markedText() const;
int textWidth( int );
int textWidth( const QString &);
QPoint cursorPoint() const;
protected:
virtual void insert( const QString&, bool mark );
virtual void newLine();
virtual void killLine();
virtual void pageUp( bool mark=FALSE );
virtual void pageDown( bool mark=FALSE );
virtual void cursorLeft( bool mark=FALSE, bool wrap = TRUE );
virtual void cursorRight( bool mark=FALSE, bool wrap = TRUE );
virtual void cursorUp( bool mark=FALSE );
virtual void cursorDown( bool mark=FALSE );
virtual void backspace();
virtual void del();
virtual void home( bool mark=FALSE );
virtual void end( bool mark=FALSE );
bool getMarkedRegion( int *line1, int *col1,
int *line2, int *col2 ) const;
int lineLength( int row ) const;
QString *getString( int row ) const;
bool isEndOfParagraph( int row ) const;
QString stringShown( int row ) const;
protected:
bool cursorOn;
void insertChar( QChar );
private slots:
void clipboardChanged();
void blinkTimerTimeout();
void scrollTimerTimeout();
void dndTimeout();
private:
struct QMultiLineEditRow {
QMultiLineEditRow( QString string, int width, bool nl = TRUE )
:s(string), w(width), newline( nl )
{
};
QString s;
int w;
bool newline;
};
QList<QMultiLineEditRow> *contents;
QMultiLineData *d;
bool readOnly;
bool dummy;
bool markIsOn;
bool dragScrolling ;
bool dragMarking;
bool textDirty;
bool wordMark;
bool overWrite;
int cursorX;
int cursorY;
int markAnchorX;
int markAnchorY;
int markDragX;
int markDragY;
int curXPos; // cell coord of cursor
int blinkTimer; // #### not used anymore - remove in 3.0
int scrollTimer; // #### not used anymore - remove in 3.0
int mapFromView( int xPos, int row );
int mapToView( int xIndex, int row );
void pixelPosToCursorPos(QPoint p, int* x, int* y) const;
void setCursorPixelPosition(QPoint p, bool clear_mark=TRUE);
void setWidth( int );
void updateCellWidth();
bool partiallyInvisible( int row );
void makeVisible();
void setBottomCell( int row );
void newMark( int posx, int posy, bool copy=TRUE );
void markWord( int posx, int posy );
void extendSelectionWord( int &newX, int&newY);
int charClass( QChar );
void turnMarkOff();
bool inMark( int posx, int posy ) const;
bool beforeMark( int posx, int posy ) const;
bool afterMark( int posx, int posy ) const;
void doDrag();
void startAutoScroll();
void stopAutoScroll();
void cursorLeft( bool mark, bool clear_mark, bool wrap );
void cursorRight( bool mark, bool clear_mark, bool wrap );
void cursorUp( bool mark, bool clear_mark );
void cursorDown( bool mark, bool clear_mark );
void wrapLine( int line, int removed = 0);
void rebreakParagraph( int line, int removed = 0 );
void rebreakAll();
void insertAtAux( const QString &s, int line, int col, bool mark = FALSE );
void killLineAux();
void delAux();
int positionToOffsetInternal( int row, int col ) const;
void offsetToPositionInternal( int position, int *row, int *col ) const;
void deleteNextChar( int offset, int row, int col );
void addUndoCmd( QMultiLineEditCommand* );
void addRedoCmd( QMultiLineEditCommand* );
void processCmd( QMultiLineEditCommand*, bool );
private: // Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
QMultiLineEdit( const QMultiLineEdit & );
QMultiLineEdit &operator=( const QMultiLineEdit & );
#endif
};
inline bool QMultiLineEdit::isReadOnly() const { return readOnly; }
inline bool QMultiLineEdit::isOverwriteMode() const { return overWrite; }
inline void QMultiLineEdit::setOverwriteMode( bool on )
{
overWrite = on;
}
inline int QMultiLineEdit::lineLength( int row ) const
{
return contents->at( row )->s.length();
}
inline bool QMultiLineEdit::atEnd() const
{
return cursorY == (int)contents->count() - 1
&& cursorX == lineLength( cursorY ) ;
}
inline bool QMultiLineEdit::atBeginning() const
{
return cursorY == 0 && cursorX == 0;
}
inline QString *QMultiLineEdit::getString( int row ) const
{
return &(contents->at( row )->s);
}
inline int QMultiLineEdit::numLines() const
{
return contents->count();
}
qt'QMultiLineEdit::numLines() (./qt-2.1.0/include/qmultilineedit.h:349)
inline int QMultiLineEdit::numLines() const
{
return contents->count();
}
qt'QMultiLineEdit::addUndoCmd() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:236)
void QMultiLineEdit::addUndoCmd(QMultiLineEditCommand* c)
{
if ( d->undoList.isEmpty() )
emit undoAvailable(TRUE);
else if ( c->merge( d->undoList.last() ) ) {
delete c;
return;
}
if ( int(d->undoList.count()) >= d->undodepth )
d->undoList.removeFirst();
d->undoList.append(c);
if ( !d->redoList.isEmpty() ) {
d->redoList.clear();
emit redoAvailable( FALSE );
}
}
qt'QMultiLineEdit::addRedoCmd() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:254)
void QMultiLineEdit::addRedoCmd(QMultiLineEditCommand* c)
{
if ( d->redoList.isEmpty() )
emit redoAvailable(TRUE);
d->redoList.append(c);
}
qt'QMultiLineEdit::setDefaultTabStop() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:290)
void QMultiLineEdit::setDefaultTabStop( int ex )
{
defTabStop = ex;
}
/*!
Returns the distance between tab stops.
\sa setDefaultTabStop();
*/
qt'QMultiLineEdit::defaultTabStop() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:303)
int QMultiLineEdit::defaultTabStop()
{
return defTabStop;
}
qt'QMultiLineEdit::QMultiLineEdit() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:387)
QMultiLineEdit::QMultiLineEdit( QWidget *parent , const char *name )
:QTableView( parent, name, WNorthWestGravity | WRepaintNoErase )
{
d = new QMultiLineData;
QFontMetrics fm( font() );
setCellHeight( fm.lineSpacing() );
setNumCols( 1 );
setNumRows( 0 );
contents = new QList<QMultiLineEditRow>;
contents->setAutoDelete( TRUE );
cursorX = 0; cursorY = 0;
curXPos = 0;
setTableFlags( Tbl_autoVScrollBar|Tbl_autoHScrollBar|
Tbl_smoothVScrolling |
Tbl_clipCellPainting
);
setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
setBackgroundMode( PaletteBase );
setWFlags( WResizeNoErase );
setKeyCompression( TRUE );
setFocusPolicy( WheelFocus );
setCursor( ibeamCursor );
verticalScrollBar()->setCursor( arrowCursor );
horizontalScrollBar()->setCursor( arrowCursor );
readOnly = FALSE;
cursorOn = FALSE;
markIsOn = FALSE;
dragScrolling = FALSE;
dragMarking = FALSE;
textDirty = FALSE;
wordMark = FALSE;
overWrite = FALSE;
markAnchorX = 0;
markAnchorY = 0;
markDragX = 0;
markDragY = 0;
d->blinkTimer = new QTimer( this );
connect( d->blinkTimer, SIGNAL( timeout() ),
this, SLOT( blinkTimerTimeout() ) );
d->scrollTimer = new QTimer( this );
connect( d->scrollTimer, SIGNAL( timeout() ),
this, SLOT( scrollTimerTimeout() ) );
d->dnd_timer = new QTimer( this );
connect( d->dnd_timer, SIGNAL( timeout() ),
this, SLOT( dndTimeout() ) );
d->scrollTime = 0;
dummy = TRUE;
int w = textWidth( QString::fromLatin1("") );
contents->append( new QMultiLineEditRow(QString::fromLatin1(""), w) );
setNumRows( 1 );
setWidth( w );
setAcceptDrops(TRUE);
d->popup = new QPopupMenu( this );
d->id[ 0 ] = d->popup->insertItem( tr( "Undo" ) );
d->id[ 1 ] = d->popup->insertItem( tr( "Redo" ) );
d->popup->insertSeparator();
d->id[ 2 ] = d->popup->insertItem( tr( "Cut" ) );
d->id[ 3 ] = d->popup->insertItem( tr( "Copy" ) );
d->id[ 4 ] = d->popup->insertItem( tr( "Paste" ) );
d->id[ 5 ] = d->popup->insertItem( tr( "Clear" ) );
d->popup->insertSeparator();
d->id[ 6 ] = d->popup->insertItem( tr( "Select All" ) );
}
/*! \fn int QMultiLineEdit::numLines() const
Returns the number of lines in the editor. The count includes any
empty lines at top and bottom, so for an empty editor this method
will return 1.
*/
/*! \fn bool QMultiLineEdit::atEnd() const
Returns TRUE if the cursor is placed at the end of the text.
*/
/*! \fn bool QMultiLineEdit::atBeginning() const
Returns TRUE if the cursor is placed at the beginning of the text.
*/
/*!
\fn int QMultiLineEdit::lineLength( int line ) const
Returns the number of characters at line number \a line.
*/
/*! \fn QString *QMultiLineEdit::getString( int line ) const
Returns a pointer to the text at line \a line.
*/
/*! \fn void QMultiLineEdit::textChanged()
This signal is emitted when the text is changed by an event or by a
slot. Note that the signal is not emitted when you call a non-slot
function such as insertLine().
\sa returnPressed()
*/
/*! \fn void QMultiLineEdit::returnPressed()
This signal is emitted when the user presses the return or enter
key. It is not emitted if isReadOnly() is TRUE.
\sa textChanged()
*/
/*!
\fn void QMultiLineEdit::undoAvailable (bool yes)
This signal is emitted when the availability of undo changes.
If \a yes is TRUE, then undo() will work until
undoAvailable(FALSE) is next emitted.
*/
/*!
\fn void QMultiLineEdit::redoAvailable (bool yes)
This signal is emitted when the availability of redo changes.
If \a yes is TRUE, then redo() will work until
redoAvailable(FALSE) is next emitted.
*/
/*! \fn bool QMultiLineEdit::isReadOnly() const
Returns FALSE if this multi line edit accepts text input.
Scrolling and cursor movements are accepted in any case.
\sa setReadOnly() QWidget::isEnabled()
*/
/*! \fn bool QMultiLineEdit::isOverwriteMode() const
Returns TRUE if this multi line edit is in overwrite mode, i.e.
if characters typed replace characters in the editor.
\sa setOverwriteMode()
*/
/*! \fn void QMultiLineEdit::setOverwriteMode( bool on )
Sets overwrite mode if \a on is TRUE. Overwrite mode means
that characters typed replace characters in the editor.
\sa isOverwriteMode()
*/
/*!
If \a on is FALSE, this multi line edit accepts text input.
Scrolling and cursor movements are accepted in any case.
\sa isReadOnly() QWidget::setEnabled()
*/
qt'QMultiLineEdit::setReadOnly() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:553)
void QMultiLineEdit::setReadOnly( bool on )
{
if ( readOnly != on ) {
readOnly = on;
setCursor( on ? arrowCursor : ibeamCursor );
}
}
/*!
Returns the width in pixels of the longest text line in this editor.
*/
qt'QMultiLineEdit::maxLineWidth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:564)
int QMultiLineEdit::maxLineWidth() const
{
return d->maxLineWidth;
}
/*!
Destroys the QMultiLineEdit
*/
qt'QMultiLineEdit::~QMultiLineEdit() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:573)
QMultiLineEdit::~QMultiLineEdit()
{
delete contents;
delete d;
}
qt'QMultiLineEdit::paintCell() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:602)
void QMultiLineEdit::paintCell( QPainter *painter, int row, int )
{
const QColorGroup & g = colorGroup();
QFontMetrics fm( painter->font() );
QString s = stringShown(row);
if ( s.isNull() ) {
qWarning( "QMultiLineEdit::paintCell: (%s) no text at line %d",
name( "unnamed" ), row );
return;
}
QRect updateR = cellUpdateRect();
QPixmap *buffer = getCacheBuffer( updateR.size() );
ASSERT(buffer);
buffer->fill ( g.base() );
QPainter p( buffer );
p.setFont( painter->font() );
p.translate( -updateR.left(), -updateR.top() );
p.setTabStops( tabStopDist(fm) );
int yPos = 0;
int markX1, markX2; // in x-coordinate pixels
markX1 = markX2 = 0; // avoid gcc warning
if ( markIsOn ) {
int markBeginX, markBeginY;
int markEndX, markEndY;
getMarkedRegion( &markBeginY, &markBeginX, &markEndY, &markEndX );
if ( row >= markBeginY && row <= markEndY ) {
if ( row == markBeginY ) {
markX1 = markBeginX;
if ( row == markEndY ) // both marks on same row
markX2 = markEndX;
else
markX2 = s.length(); // mark till end of line
} else {
if ( row == markEndY ) {
markX1 = 0;
markX2 = markEndX;
} else {
markX1 = 0; // whole line is marked
markX2 = s.length(); // whole line is marked
}
}
}
}
p.setPen( g.text() );
QMultiLineEditRow* r = contents->at( row );
int wcell = cellWidth() - 2*d->lr_marg;// - d->marg_extra;
int wrow = r->w;
int x = d->lr_marg - p.fontMetrics().leftBearing(s[0]);
if ( d->align == Qt::AlignCenter || d->align == Qt::AlignHCenter )
x += (wcell - wrow) / 2;
else if ( d->align == Qt::AlignRight )
x += wcell - wrow;
p.drawText( x, yPos, cellWidth()-d->lr_marg-x, cellHeight(),
d->align == AlignLeft?ExpandTabs:0, s );
if ( !r->newline && BREAK_WITHIN_WORDS )
p.drawPixmap( x + wrow - d->lr_marg - d->marg_extra, yPos, d->arrow );
#if 0
if ( r->newline )
p.drawLine( d->lr_marg, yPos+cellHeight()-2, cellWidth() - d->lr_marg, yPos+cellHeight()-2);
#endif
if ( markX1 != markX2 ) {
int sLength = s.length();
int xpos1 = mapToView( markX1, row );
int xpos2 = mapToView( markX2, row );
int fillxpos1 = xpos1;
int fillxpos2 = xpos2;
if ( markX1 == 0 )
fillxpos1 -= 2;
if ( markX2 == sLength )
fillxpos2 += 3;
p.setClipping( TRUE );
p.setClipRect( fillxpos1 - updateR.left(), 0,
fillxpos2 - fillxpos1, cellHeight(row) );
p.fillRect( fillxpos1, 0, fillxpos2 - fillxpos1, cellHeight(row),
g.brush( QColorGroup::Highlight ) );
p.setPen( g.highlightedText() );
p.drawText( x, yPos, cellWidth()-d->lr_marg-x, cellHeight(),
d->align == AlignLeft?ExpandTabs:0, s );
p.setClipping( FALSE );
}
if ( row == cursorY && cursorOn && !readOnly ) {
int cursorPos = QMIN( (int)s.length(), cursorX );
int cXPos = mapToView( cursorPos, row );
int cYPos = 0;
if ( hasFocus() || d->dnd_forcecursor ) {
p.setPen( g.text() );
/* styled?
p.drawLine( cXPos - 2, cYPos,
cXPos + 2, cYPos );
*/
p.drawLine( cXPos, cYPos,
cXPos, cYPos + fm.height() - 2);
/* styled?
p.drawLine( cXPos - 2, cYPos + fm.height() - 2,
cXPos + 2, cYPos + fm.height() - 2);
*/
// TODO: set it other times, eg. when scrollbar moves view
QWMatrix wm = painter->worldMatrix();
setMicroFocusHint( int(wm.dx()+cXPos),
int (wm.dy()+cYPos),
1, fm.ascent() );
}
}
p.end();
painter->drawPixmap( updateR.left(), updateR.top(), *buffer,
0, 0, updateR.width(), updateR.height() );
}
/*!
Returns the width in pixels of the string \a s.
NOTE: only appropriate for whole lines.
*/
qt'QMultiLineEdit::textWidth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:721)
int QMultiLineEdit::textWidth( const QString &s )
{
int w = 0;
if ( !s.isNull() ) {
w = textWidthWithTabs( QFontMetrics( font() ), s, 0, s.length(),
d->align );
}
return w + 2 * d->lr_marg + d->marg_extra;
}
/*!
Returns the width in pixels of the text at line \a line.
*/
qt'QMultiLineEdit::textWidth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:736)
int QMultiLineEdit::textWidth( int line )
{
if ( d->echomode == Password) {
QString s = stringShown(line);
return textWidth( s );
}
QMultiLineEditRow* r = contents->at(line);
return r?r->w:0;
}
/*!
Starts the cursor blinking.
*/
qt'QMultiLineEdit::focusInEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:750)
void QMultiLineEdit::focusInEvent( QFocusEvent * )
{
stopAutoScroll();
if ( !d->blinkTimer->isActive() )
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
cursorOn = TRUE;
updateCell( cursorY, 0, FALSE );
}
/*!\reimp
*/
qt'QMultiLineEdit::leaveEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:762)
void QMultiLineEdit::leaveEvent( QEvent * )
{
}
/*!\reimp
*/
qt'QMultiLineEdit::focusOutEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:769)
void QMultiLineEdit::focusOutEvent( QFocusEvent * )
{
stopAutoScroll();
d->blinkTimer->stop();
if ( cursorOn ) {
cursorOn = FALSE;
updateCell( cursorY, 0, FALSE );
}
}
/*!
\reimp
Present for bianry compatibility only!
*/
qt'QMultiLineEdit::timerEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:785)
void QMultiLineEdit::timerEvent( QTimerEvent * )
{
// ############ Remove in 3.0!!!!!!!!
}
qt'QMultiLineEdit::doDrag() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:790)
void QMultiLineEdit::doDrag()
{
if ( d->dnd_timer ) {
d->dnd_timer->stop();
}
QDragObject *drag_text = new QTextDrag(markedText(), this);
if ( readOnly ) {
drag_text->dragCopy();
} else {
if ( drag_text->drag() && QDragObject::target() != this ) {
del();
if ( textDirty && !d->isHandlingEvent )
emit textChanged();
}
}
d->dnd_primed = FALSE;
}
/*!
If there is marked text, sets \a line1, \a col1, \a line2 and \a col2
to the start and end of the marked region and returns TRUE. Returns
FALSE if there is no marked text.
*/
qt'QMultiLineEdit::getMarkedRegion() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:813)
bool QMultiLineEdit::getMarkedRegion( int *line1, int *col1,
int *line2, int *col2 ) const
{
if ( !markIsOn || !line1 || !line2 || !col1 || !col2 )
return FALSE;
if ( markAnchorY < markDragY ||
markAnchorY == markDragY && markAnchorX < markDragX) {
*line1 = markAnchorY;
*col1 = markAnchorX;
*line2 = markDragY;
*col2 = markDragX;
} else {
*line1 = markDragY;
*col1 = markDragX;
*line2 = markAnchorY;
*col2 = markAnchorX;
}
return markIsOn;
}
/*!
Returns TRUE if there is marked text.
*/
qt'QMultiLineEdit::hasMarkedText() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:838)
bool QMultiLineEdit::hasMarkedText() const
{
return markIsOn;
}
/*!
Returns a copy of the marked text.
*/
qt'QMultiLineEdit::markedText() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:848)
QString QMultiLineEdit::markedText() const
{
int markBeginX, markBeginY;
int markEndX, markEndY;
if ( !getMarkedRegion( &markBeginY, &markBeginX, &markEndY, &markEndX ) )
return QString();
if ( markBeginY == markEndY ) { //just one line
QString *s = getString( markBeginY );
return s->mid( markBeginX, markEndX - markBeginX );
} else { //multiline
QString *firstS, *lastS;
firstS = getString( markBeginY );
lastS = getString( markEndY );
int i;
QString tmp;
if ( firstS )
tmp += firstS->mid(markBeginX);
if ( contents->at( markBeginY )->newline )
tmp += '\n';
for( i = markBeginY + 1; i < markEndY ; i++ ) {
tmp += *getString(i);
if ( contents->at( i )->newline )
tmp += '\n';
}
if ( lastS ) {
tmp += lastS->left(markEndX);
} else {
tmp.truncate(tmp.length()-1);
}
return tmp;
}
}
/*!
Returns the text at line number \a line (possibly the empty string),
or a \link QString::operator!() null string\endlink if \a line is invalid.
*/
qt'QMultiLineEdit::textLine() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:891)
QString QMultiLineEdit::textLine( int line ) const
{
QString *s = getString(line);
if ( s ) {
if ( s->isNull() )
return QString::fromLatin1("");
else
return *s;
} else
return QString::null;
}
/*!
Returns a copy of the whole text. If the multi line edit contains no
text, a
\link QString::operator!() null string\endlink
is returned.
*/
qt'QMultiLineEdit::text() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:911)
QString QMultiLineEdit::text() const
{
QString tmp;
for( int i = 0 ; i < (int)contents->count() ; i++ ) {
tmp += *getString(i);
if ( i+1 < (int)contents->count() && contents->at(i)->newline )
tmp += '\n';
}
return tmp;
}
/*!
Selects all text without moving the cursor.
*/
qt'QMultiLineEdit::selectAll() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:927)
void QMultiLineEdit::selectAll()
{
markAnchorX = 0;
markAnchorY = 0;
markDragY = numLines() - 1;
markDragX = lineLength( markDragY );
markIsOn = ( markDragX != markAnchorX || markDragY != markAnchorY );
if ( autoUpdate() )
update();
}
/*!
Deselects all text (i.e. removes marking) and leaves the cursor at the
current position.
*/
qt'QMultiLineEdit::deselect() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:945)
void QMultiLineEdit::deselect()
{
turnMarkOff();
}
/*!
Sets the text to \a s, removing old text, if any.
*/
qt'QMultiLineEdit::setText() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:955)
void QMultiLineEdit::setText( const QString &s )
{
bool oldUndo = isUndoEnabled();
setUndoEnabled( FALSE );
bool oldAuto = autoUpdate();
setAutoUpdate( FALSE );
clear();
insertLine( s, -1 );
emit textChanged();
setAutoUpdate(oldAuto);
if ( autoUpdate() )
update();
setUndoEnabled( oldUndo );
}
/*!
Appends \a s to the text.
*/
qt'QMultiLineEdit::append() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:975)
void QMultiLineEdit::append( const QString &s )
{
bool oldUndo = isUndoEnabled();
setUndoEnabled( FALSE );
insertLine( s, -1 );
setUndoEnabled( oldUndo );
emit textChanged();
}
/*! \reimp
Passes wheel events to the vertical scrollbar.
*/
qt'QMultiLineEdit::wheelEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:987)
void QMultiLineEdit::wheelEvent( QWheelEvent *e ){
QApplication::sendEvent( verticalScrollBar(), e);
}
/*!
The key press event handler converts a key press to some line editor
action.
Here are the default key bindings when isReadOnly() is FALSE:
<ul>
<li><i> Left Arrow </i> Move the cursor one character leftwards
<li><i> Right Arrow </i> Move the cursor one character rightwards
<li><i> Up Arrow </i> Move the cursor one line upwards
<li><i> Down Arrow </i> Move the cursor one line downwards
<li><i> Page Up </i> Move the cursor one page upwards
<li><i> Page Down </i> Move the cursor one page downwards
<li><i> Backspace </i> Delete the character to the left of the cursor
<li><i> Home </i> Move the cursor to the beginning of the line
<li><i> End </i> Move the cursor to the end of the line
<li><i> Delete </i> Delete the character to the right of the cursor
<li><i> Shift - Left Arrow </i> Mark text one character leftwards
<li><i> Shift - Right Arrow </i> Mark text one character rightwards
<li><i> Control-A </i> Move the cursor to the beginning of the line
<li><i> Control-B </i> Move the cursor one character leftwards
<li><i> Control-C </i> Copy the marked text to the clipboard
<li><i> Control-D </i> Delete the character to the right of the cursor
<li><i> Control-E </i> Move the cursor to the end of the line
<li><i> Control-F </i> Move the cursor one character rightwards
<li><i> Control-H </i> Delete the character to the left of the cursor
<li><i> Control-K </i> Delete to end of line
<li><i> Control-N </i> Move the cursor one line downwards
<li><i> Control-P </i> Move the cursor one line upwards
<li><i> Control-V </i> Paste the clipboard text into line edit
<li><i> Control-X </i> Cut the marked text, copy to clipboard
<li><i> Control-Z </i> Undo the last operation
<li><i> Control-Y </i> Redo the last operation
<li><i> Control - Left Arrow </i> Move the cursor one word leftwards
<li><i> Control - Right Arrow </i> Move the cursor one word rightwards
<li><i> Control - Up Arrow </i> Move the cursor one word upwards
<li><i> Control - Down Arrow </i> Move the cursor one word downwards
<li><i> Control - Home Arrow </i> Move the cursor to the beginning of the text
<li><i> Control - End Arrow </i> Move the cursor to the end of the text
</ul>
In addition, the following key bindings are used on Windows:
<ul>
<li><i> Shift - Delete </i> Cut the marked text, copy to clipboard
<li><i> Shift - Insert </i> Paste the clipboard text into line edit
<li><i> Control - Insert </i> Copy the marked text to the clipboard
</ul>
All other keys with valid ASCII codes insert themselves into the line.
Here are the default key bindings when isReadOnly() is TRUE:
<ul>
<li><i> Left Arrow </i> Scrolls the table rightwards
<li><i> Right Arrow </i> Scrolls the table rightwards
<li><i> Up Arrow </i> Scrolls the table one line downwards
<li><i> Down Arrow </i> Scrolls the table one line upwards
<li><i> Page Up </i> Scrolls the table one page downwards
<li><i> Page Down </i> Scrolls the table one page upwards
<li><i> Control-C </i> Copy the marked text to the clipboard
</ul>
*/
qt'QMultiLineEdit::keyPressEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1052)
void QMultiLineEdit::keyPressEvent( QKeyEvent *e )
{
textDirty = FALSE;
d->isHandlingEvent = TRUE;
int unknown = 0;
if ( readOnly ) {
int pageSize = viewHeight() / cellHeight();
switch ( e->key() ) {
case Key_Left:
setXOffset( xOffset() - viewWidth()/10 );
break;
case Key_Right:
setXOffset( xOffset() + viewWidth()/10 );
break;
case Key_Up:
setTopCell( topCell() - 1 );
break;
case Key_Down:
setTopCell( topCell() + 1 );
break;
case Key_Next:
setTopCell( topCell() + pageSize );
break;
case Key_Prior:
setTopCell( QMAX( topCell() - pageSize, 0 ) );
break;
case Key_C:
if ( echoMode() == Normal && (e->state()&ControlButton) )
copy();
else
unknown++;
break;
default:
unknown++;
}
if ( unknown )
e->ignore();
d->isHandlingEvent = FALSE;
return;
}
if ( e->text().length() &&
e->key() != Key_Return &&
e->key() != Key_Enter &&
e->key() != Key_Delete &&
e->key() != Key_Backspace &&
(!e->ascii() || e->ascii()>=32)
) {
insert( e->text() );
//QApplication::sendPostedEvents( this, QEvent::Paint );
if ( textDirty )
emit textChanged();
d->isHandlingEvent = FALSE;
return;
}
if ( e->state() & ControlButton ) {
switch ( e->key() ) {
case Key_A:
home( e->state() & ShiftButton );
break;
case Key_B:
cursorLeft( e->state() & ShiftButton );
break;
case Key_C:
if ( echoMode() == Normal )
copy();
break;
case Key_D:
del();
break;
case Key_E:
end( e->state() & ShiftButton );
break;
case Key_Left:
cursorWordBackward( e->state() & ShiftButton );
break;
case Key_Right:
cursorWordForward( e->state() & ShiftButton );
break;
case Key_Up:
cursorUp( e->state() & ShiftButton );
break;
case Key_Down:
cursorDown( e->state() & ShiftButton );
break;
case Key_Home:
setCursorPosition(0,0, e->state() & ShiftButton );
break;
case Key_End:
setCursorPosition( numLines()-1, lineLength( numLines()-1 ),
e->state() & ShiftButton );
break;
case Key_F:
cursorRight( e->state() & ShiftButton );
break;
case Key_H:
backspace();
break;
case Key_K:
killLine();
break;
case Key_N:
cursorDown( e->state() & ShiftButton );
break;
case Key_P:
cursorUp( e->state() & ShiftButton );
break;
case Key_V:
paste();
break;
case Key_X:
cut();
break;
case Key_Z:
undo();
break;
case Key_Y:
redo();
break;
#if defined (_WS_WIN_)
case Key_Insert:
copy();
#endif
default:
unknown++;
}
} else {
switch ( e->key() ) {
case Key_Left:
cursorLeft( e->state() & ShiftButton );
break;
case Key_Right:
cursorRight( e->state() & ShiftButton );
break;
case Key_Up:
cursorUp( e->state() & ShiftButton );
break;
case Key_Down:
cursorDown( e->state() & ShiftButton );
break;
case Key_Backspace:
backspace();
break;
case Key_Home:
home( e->state() & ShiftButton );
break;
case Key_End:
end( e->state() & ShiftButton );
break;
case Key_Delete:
#if defined (_WS_WIN_)
if ( e->state() & ShiftButton ) {
cut();
break;
}
#endif
del();
break;
case Key_Next:
pageDown( e->state() & ShiftButton );
break;
case Key_Prior:
pageUp( e->state() & ShiftButton );
break;
case Key_Enter:
case Key_Return:
newLine();
emit returnPressed();
break;
case Key_Tab:
insert( e->text() );
break;
#if defined (_WS_WIN_)
case Key_Insert:
if ( e->state() & ShiftButton )
paste();
else
unknown++;
break;
#endif
default:
unknown++;
}
}
if ( textDirty )
emit textChanged();
if ( unknown ) // unknown key
e->ignore();
d->isHandlingEvent = FALSE;
}
/*!
Moves the cursor one page down. If \a mark is TRUE, the text
is marked.
*/
qt'QMultiLineEdit::pageDown() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1251)
void QMultiLineEdit::pageDown( bool mark )
{
bool oldAuto = autoUpdate();
if ( mark )
setAutoUpdate( FALSE );
if ( partiallyInvisible( cursorY ) )
cursorY = topCell();
int delta = cursorY - topCell();
int pageSize = viewHeight() / cellHeight();
int newTopCell = QMIN( topCell() + pageSize, numLines() - 1 - pageSize );
if ( pageSize >= numLines() ) { // quick fix to handle small texts
newTopCell = topCell();
}
if ( !curXPos )
curXPos = mapToView( cursorX, cursorY );
int oldY = cursorY;
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
if ( newTopCell != topCell() ) {
cursorY = newTopCell + delta;
cursorX = mapFromView( curXPos, cursorY );
if ( mark )
newMark( cursorX, cursorY, FALSE );
setTopCell( newTopCell );
} else if ( cursorY != (int)contents->count() - 1) { // just move the cursor
cursorY = QMIN( cursorY + pageSize, numLines() - 1);
cursorX = mapFromView( curXPos, cursorY );
if ( mark )
newMark( cursorX, cursorY, FALSE );
makeVisible();
}
if ( oldAuto )
if ( mark ) {
setAutoUpdate( TRUE );
update();
} else {
updateCell( oldY, 0, FALSE );
}
if ( !mark )
turnMarkOff();
}
/*!
Moves the cursor one page up. If \a mark is TRUE, the text
is marked.
*/
qt'QMultiLineEdit::pageUp() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1304)
void QMultiLineEdit::pageUp( bool mark )
{
bool oldAuto = autoUpdate();
if ( mark )
setAutoUpdate( FALSE );
if ( partiallyInvisible( cursorY ) )
cursorY = topCell();
int delta = cursorY - topCell();
int pageSize = viewHeight() / cellHeight();
bool partial = delta == pageSize && viewHeight() != pageSize * cellHeight();
int newTopCell = QMAX( topCell() - pageSize, 0 );
if ( pageSize > numLines() ) { // quick fix to handle small texts
newTopCell = 0;
delta = 0;
}
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
if ( !curXPos )
curXPos = mapToView( cursorX, cursorY );
int oldY = cursorY;
if ( newTopCell != topCell() ) {
cursorY = QMIN( newTopCell + delta, numLines() - 1 );
if ( partial )
cursorY--;
cursorX = mapFromView( curXPos, cursorY );
if ( mark )
newMark( cursorX, cursorY, FALSE );
setTopCell( newTopCell );
} else { // just move the cursor
cursorY = QMAX( cursorY - pageSize, 0 );
cursorX = mapFromView( curXPos, cursorY );
if ( mark )
newMark( cursorX, cursorY, FALSE );
}
if ( oldAuto )
if ( mark ) {
setAutoUpdate( TRUE );
update();
} else {
updateCell( oldY, 0, FALSE );
}
if ( !mark )
turnMarkOff();
}
qt'QMultiLineEdit::insertAtAux() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1352)
void QMultiLineEdit::insertAtAux( const QString &txt, int line, int col, bool mark )
{
dummy = FALSE;
d->blinkTimer->stop();
cursorOn = TRUE;
int oldw = contentsRect().width();
line = QMAX( QMIN( line, numLines() - 1), 0 );
col = QMAX( QMIN( col, lineLength( line )), 0 );
QString itxt = txt;
QMultiLineEditRow *row = contents->at( line );
if ( d->maxlen >= 0 && length() + int(txt.length()) > d->maxlen )
itxt.truncate( d->maxlen - length() );
row->s.insert( uint(col), itxt );
if ( mark ) {
markAnchorX = col;
markAnchorY = line;
}
if ( cursorX == col && cursorY == line ) {
cursorX += itxt.length();
}
QFontMetrics fm( font() );
if ( !WORD_WRAP || ( col == 0 && itxt.contains('\n') == int(itxt.length())) )
wrapLine( line, 0 );
else if ( WORD_WRAP && itxt.find('\n')<0 && itxt.find('\t')<0
&& (
( DYNAMIC_WRAP && fm.width( itxt ) + row->w < contentsRect().width() - 2*d->lr_marg - d->marg_extra )
||
( FIXED_WIDTH_WRAP && ( d->wrapcol < 0 || fm.width( itxt ) + row->w < d->wrapcol ) )
||
( FIXED_COLUMN_WRAP && ( d->wrapcol < 0 || int(row->s.length()) < d->wrapcol ) )
)
&& ( itxt.find(' ') < 0 || row->s.find(' ') >= 0 && row->s.find(' ') < col ) ){
row->w = textWidth( row->s );
setWidth( QMAX( maxLineWidth(), row->w) );
updateCell( line, 0, FALSE );
}
else {
if ( line > 0 && !contents->at( line-1)->newline )
rebreakParagraph( line-1 );
else
rebreakParagraph( line );
}
if ( mark )
newMark( cursorX, cursorY, FALSE );
textDirty = TRUE;
d->edited = TRUE;
if ( autoUpdate() ) {
makeVisible();
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
if ( DYNAMIC_WRAP && oldw != contentsRect().width() ) {
setAutoUpdate( FALSE );
rebreakAll();
setAutoUpdate( TRUE );
update();
}
}
}
/*!
Inserts \a txt at line number \a line. If \a line is less than zero,
or larger than the number of rows, the new text is put at the end.
If \a txt contains newline characters, several lines are inserted.
The cursor position is not changed.
*/
qt'QMultiLineEdit::insertLine() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1424)
void QMultiLineEdit::insertLine( const QString &txt, int line )
{
QString s = txt;
int oldXPos = cursorX;
int oldYPos = cursorY;
if ( line < 0 || line >= int( contents->count() ) ) {
if ( !dummy )
contents->append( new QMultiLineEditRow(QString::fromLatin1(""), 0) );
if ( WORD_WRAP && s.length() > 0 && s.find( " " ) < 0 )
s.append( "\n" );
insertAt( s, numLines()-1, 0 );
}
else {
s.append('\n');
insertAt( s, line, 0 );
}
cursorX = oldXPos;
cursorY = oldYPos;
}
/*!
Deletes the line at line number \a line. If \a
line is less than zero, or larger than the number of lines,
no line is deleted.
*/
qt'QMultiLineEdit::removeLine() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1450)
void QMultiLineEdit::removeLine( int line )
{
CLEAR_UNDO;
if ( line >= numLines() )
return;
if ( cursorY >= line && cursorY > 0 )
cursorY--;
bool updt = autoUpdate() && rowIsVisible( line );
QMultiLineEditRow* r = contents->at( line );
ASSERT( r );
bool recalc = r->w == maxLineWidth();
contents->remove( line );
if ( contents->count() == 0 ) {
int w = textWidth( QString::fromLatin1("") );
contents->append( new QMultiLineEditRow(QString::fromLatin1(""), w) );
setWidth( w );
dummy = TRUE;
}
setNumRows( contents->count() );
if ( recalc )
updateCellWidth();
makeVisible();
if (updt)
update();
textDirty = TRUE;
d->edited = TRUE;
}
/*!
Inserts \a s at the current cursor position.
*/
qt'QMultiLineEdit::insert() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1481)
void QMultiLineEdit::insert( const QString& s )
{
insert( s, FALSE );
}
/*!
Inserts \a c at the current cursor position.
(this function is provided for backward compatibility -
it simply calls insert()).
*/
qt'QMultiLineEdit::insertChar() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1491)
void QMultiLineEdit::insertChar( QChar c )
{
insert(c);
}
/*!
Inserts \a c at the current cursor position.
*/
qt'QMultiLineEdit::insert() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1500)
void QMultiLineEdit::insert( const QString& str, bool mark )
{
dummy = FALSE;
bool wasMarkedText = hasMarkedText();
if ( wasMarkedText )
addUndoCmd( new QBeginCommand );
if ( wasMarkedText )
del(); // ## Will flicker
QString *s = getString( cursorY );
if ( cursorX > (int)s->length() )
cursorX = s->length();
else if ( overWrite && !wasMarkedText && cursorX < (int)s->length() )
del(); // ## Will flicker
insertAt(str, cursorY, cursorX, mark );
makeVisible();
if ( wasMarkedText )
addUndoCmd( new QEndCommand() );
}
/*!
Makes a line break at the current cursor position.
*/
qt'QMultiLineEdit::newLine() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1525)
void QMultiLineEdit::newLine()
{
insert("\n");
}
/*!
Deletes text from the current cursor position to the end of the line.
*/
qt'QMultiLineEdit::killLineAux() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1534)
void QMultiLineEdit::killLineAux()
{
deselect(); // -sanders Don't let del() delete marked region
QMultiLineEditRow* r = contents->at( cursorY );
if ( cursorX == (int)r->s.length() ) {
// if (r->newline) // -sanders Only del newlines!
del();
return;
} else {
bool recalc = r->w == maxLineWidth();
r->s.remove( cursorX, r->s.length() );
r->w = textWidth( r->s );
updateCell( cursorY, 0, FALSE );
if ( recalc )
updateCellWidth();
rebreakParagraph( cursorY ); // -sanders
textDirty = TRUE;
d->edited = TRUE;
}
curXPos = 0;
makeVisible();
turnMarkOff();
}
/*!
Moves the cursor one character to the left. If \a mark is TRUE, the text
is marked. If \a wrap is TRUE, the cursor moves to the end of the
previous line if it is placed at the beginning of the current line.
\sa cursorRight() cursorUp() cursorDown()
*/
qt'QMultiLineEdit::cursorLeft() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1567)
void QMultiLineEdit::cursorLeft( bool mark, bool wrap )
{
cursorLeft(mark,!mark,wrap);
}
qt'QMultiLineEdit::cursorLeft() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1571)
void QMultiLineEdit::cursorLeft( bool mark, bool clear_mark, bool wrap )
{
if ( cursorX != 0 || cursorY != 0 && wrap ) {
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
d->blinkTimer->stop();
int ll = lineLength( cursorY );
if ( cursorX > ll )
cursorX = ll;
cursorOn = TRUE;
cursorX--;
if ( cursorX < 0 ) {
int oldY = cursorY;
if ( cursorY > 0 ) {
cursorY--;
cursorX = lineLength( cursorY );
if ( cursorX > 1 && !isEndOfParagraph( cursorY ) )
cursorX--;
} else {
cursorY = 0; //### ?
cursorX = 0;
}
updateCell( oldY, 0, FALSE );
}
if ( mark )
newMark( cursorX, cursorY, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
updateCell( cursorY, 0, FALSE );
}
curXPos = 0;
makeVisible();
if ( clear_mark )
turnMarkOff();
}
/*!
Moves the cursor one character to the right. If \a mark is TRUE, the text
is marked. If \a wrap is TRUE, the cursor moves to the beginning of the next
line if it is placed at the end of the current line.
\sa cursorLeft() cursorUp() cursorDown()
*/
qt'QMultiLineEdit::cursorRight() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1615)
void QMultiLineEdit::cursorRight( bool mark, bool wrap )
{
cursorRight(mark,!mark,wrap);
}
qt'QMultiLineEdit::cursorRight() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1619)
void QMultiLineEdit::cursorRight( bool mark, bool clear_mark, bool wrap )
{
int strl = lineLength( cursorY );
if ( strl > 1 && !isEndOfParagraph( cursorY ) )
strl--;
if ( cursorX < strl || cursorY < (int)contents->count() - 1 && wrap ) {
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
d->blinkTimer->stop();
cursorOn = TRUE;
cursorX++;
if ( cursorX > strl ) {
int oldY = cursorY;
if ( cursorY < (int) contents->count() - 1 ) {
cursorY++;
cursorX = 0;
} else {
cursorX = lineLength( cursorY );
}
updateCell( oldY, 0, FALSE );
}
if ( mark )
newMark( cursorX, cursorY, FALSE );
updateCell( cursorY, 0, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
}
curXPos = 0;
makeVisible();
if ( clear_mark )
turnMarkOff();
}
/*!
Moves the cursor up one line. If \a mark is TRUE, the text
is marked.
\sa cursorDown() cursorLeft() cursorRight()
*/
qt'QMultiLineEdit::cursorUp() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1659)
void QMultiLineEdit::cursorUp( bool mark )
{
cursorUp(mark,!mark);
}
qt'QMultiLineEdit::cursorUp() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1663)
void QMultiLineEdit::cursorUp( bool mark, bool clear_mark )
{
if ( cursorY != 0 ) {
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
if ( !curXPos )
curXPos = mapToView( cursorX, cursorY );
int oldY = cursorY;
d->blinkTimer->stop();
cursorOn = TRUE;
cursorY--;
if ( cursorY < 0 ) {
cursorY = 0;
}
cursorX = mapFromView( curXPos, cursorY );
if ( mark )
newMark( cursorX, cursorY, FALSE );
updateCell( oldY, 0, FALSE );
updateCell( cursorY, 0, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
}
makeVisible();
if ( clear_mark )
turnMarkOff();
}
/*!
Moves the cursor one line down. If \a mark is TRUE, the text
is marked.
\sa cursorUp() cursorLeft() cursorRight()
*/
qt'QMultiLineEdit::cursorDown() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1697)
void QMultiLineEdit::cursorDown( bool mark )
{
cursorDown(mark,!mark);
}
qt'QMultiLineEdit::cursorDown() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1701)
void QMultiLineEdit::cursorDown( bool mark, bool clear_mark )
{
int lastLin = contents->count() - 1;
if ( cursorY != lastLin ) {
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
if ( !curXPos )
curXPos = mapToView( cursorX, cursorY );
int oldY = cursorY;
d->blinkTimer->stop();
cursorOn = TRUE;
cursorY++;
if ( cursorY > lastLin ) {
cursorY = lastLin;
}
cursorX = mapFromView( curXPos, cursorY );
if ( mark )
newMark( cursorX, cursorY, FALSE );
updateCell( oldY, 0, FALSE );
updateCell( cursorY, 0, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
}
makeVisible();
if ( clear_mark )
turnMarkOff();
}
/*!
Turns off marked text
*/
qt'QMultiLineEdit::turnMarkOff() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1733)
void QMultiLineEdit::turnMarkOff()
{
if ( markIsOn ) {
markIsOn = FALSE;
update();
}
}
/*!
Deletes the character on the left side of the text cursor and moves
the cursor one position to the left. If a text has been marked by
the user (e.g. by clicking and dragging) the cursor is put at the
beginning of the marked text and the marked text is removed.
\sa del()
*/
qt'QMultiLineEdit::backspace() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1752)
void QMultiLineEdit::backspace()
{
if ( hasMarkedText() ) {
del();
} else {
if ( !atBeginning() ) {
cursorLeft( FALSE );
del();
}
}
makeVisible();
}
qt'QMultiLineEdit::delAux() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1765)
void QMultiLineEdit::delAux()
{
int markBeginX, markBeginY;
int markEndX, markEndY;
QRect oldContents = contentsRect();
if ( getMarkedRegion( &markBeginY, &markBeginX, &markEndY, &markEndX ) ) {
markIsOn = FALSE;
textDirty = TRUE;
d->edited = TRUE;
if ( markBeginY == markEndY ) { //just one line
QMultiLineEditRow *r = contents->at( markBeginY );
ASSERT(r);
bool recalc = r->w == maxLineWidth();
r->s.remove( markBeginX, markEndX - markBeginX );
r->w = textWidth( r->s );
cursorX = markBeginX;
cursorY = markBeginY;
if (autoUpdate() )
updateCell( cursorY, 0, FALSE );
if ( recalc )
updateCellWidth();
} else { //multiline
bool oldAuto = autoUpdate();
setAutoUpdate( FALSE );
ASSERT( markBeginY >= 0);
ASSERT( markEndY < (int)contents->count() );
QMultiLineEditRow *firstR, *lastR;
firstR = contents->at( markBeginY );
lastR = contents->at( markEndY );
ASSERT( firstR != lastR );
firstR->s.remove( markBeginX, firstR->s.length() - markBeginX );
lastR->s.remove( 0, markEndX );
firstR->s.append( lastR->s ); // lastS will be removed in loop below
firstR->newline = lastR->newline; // Don't forget this -sanders
firstR->w = textWidth( firstR->s );
for( int i = markBeginY + 1 ; i <= markEndY ; i++ )
contents->remove( markBeginY + 1 );
if ( contents->isEmpty() )
insertLine( QString::fromLatin1(""), -1 );
cursorX = markBeginX;
cursorY = markBeginY;
curXPos = 0;
setNumRows( contents->count() );
updateCellWidth();
setAutoUpdate( oldAuto );
if ( autoUpdate() )
update();
}
markAnchorY = markDragY = cursorY;
markAnchorX = markDragX = cursorX;
} else {
if ( !atEnd() ) {
textDirty = TRUE;
d->edited = TRUE;
QMultiLineEditRow *r = contents->at( cursorY );
if ( cursorX == (int) r->s.length() ) { // remove newline
QMultiLineEditRow* other = contents->at( cursorY + 1 );
if ( ! r->newline && cursorX )
r->s.truncate( r->s.length()-1 );
bool needBreak = !r->s.isEmpty();
r->s += other->s;
r->newline = other->newline;
contents->remove( cursorY + 1 );
if ( needBreak )
rebreakParagraph( cursorY, 1 );
else
wrapLine( cursorY, 1 );
} else {
bool recalc = r->w == maxLineWidth();
r->s.remove( cursorX, 1 );
rebreakParagraph( cursorY );
if ( recalc )
updateCellWidth();
}
}
}
if ( DYNAMIC_WRAP && oldContents != contentsRect() ) {
if ( oldContents.width() != contentsRect().width() ) {
bool oldAuto = autoUpdate();
setAutoUpdate( FALSE );
rebreakAll();
setAutoUpdate( oldAuto );
}
if ( autoUpdate() )
update();
}
curXPos = 0;
makeVisible();
}
/*!
Moves the text cursor to the left end of the line. If \a mark is
TRUE, text is marked towards the first position. If it is FALSE and
the cursor is moved, all marked text is unmarked.
\sa end()
*/
qt'QMultiLineEdit::home() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1869)
void QMultiLineEdit::home( bool mark )
{
if ( cursorX != 0 ) {
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
d->blinkTimer->stop();
cursorX = 0;
cursorOn = TRUE;
if ( mark )
newMark( cursorX, cursorY, FALSE );
updateCell( cursorY, 0, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
}
curXPos = 0;
if ( !mark )
turnMarkOff();
makeVisible();
}
/*!
Moves the text cursor to the right end of the line. If mark is TRUE
text is marked towards the last position. If it is FALSE and the
cursor is moved, all marked text is unmarked.
\sa home()
*/
qt'QMultiLineEdit::end() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1898)
void QMultiLineEdit::end( bool mark )
{
int tlen = lineLength( cursorY );
if ( cursorX != tlen ) {
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
d->blinkTimer->stop();
cursorX = tlen;
cursorOn = TRUE;
if ( mark )
newMark( cursorX, cursorY, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
updateCell( cursorY, 0, FALSE );
}
curXPos = 0;
makeVisible();
if ( !mark )
turnMarkOff();
}
/*!\reimp
*/
qt'QMultiLineEdit::mousePressEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1922)
void QMultiLineEdit::mousePressEvent( QMouseEvent *e )
{
stopAutoScroll();
d->dnd_startpos = e->pos();
if ( e->button() == RightButton ) {
d->popup->setItemEnabled( this->d->id[ 0 ],
!this->d->undoList.isEmpty() );
d->popup->setItemEnabled( this->d->id[ 1 ],
!this->d->redoList.isEmpty() );
d->popup->setItemEnabled( this->d->id[ 2 ],
!isReadOnly() && hasMarkedText() );
d->popup->setItemEnabled( this->d->id[ 3 ], hasMarkedText() );
d->popup->setItemEnabled( this->d->id[ 4 ],
!isReadOnly() && (bool)QApplication::clipboard()->text().length() );
d->popup->setItemEnabled( this->d->id[ 5 ],
!isReadOnly() && (bool)text().length() );
int allSelected = markIsOn && markAnchorX == 0 && markAnchorY == 0 &&
markDragY == numLines() - 1 && markDragX == lineLength( markDragY );
d->popup->setItemEnabled( this->d->id[ 6 ],
(bool)text().length() && !allSelected );
int id = d->popup->exec( e->globalPos() );
if ( id == d->id[ 0 ] )
undo();
else if ( id == d->id[ 1 ] )
redo();
else if ( id == d->id[ 2 ] )
cut();
else if ( id == d->id[ 3 ] )
copy();
else if ( id == d->id[ 4 ] )
paste();
else if ( id == d->id[ 5 ] )
clear();
else if ( id == d->id[ 6 ] )
selectAll();
return;
}
if ( e->button() != MidButton && e->button() != LeftButton)
return;
int newX, newY;
pixelPosToCursorPos( e->pos(), &newX, &newY );
if ( e->state() & ShiftButton ) {
wordMark = FALSE;
dragMarking = TRUE;
setCursorPosition( newY, newX, TRUE);
return;
}
if (
inMark(newX, newY) // Click on highlighted text
&& echoMode() == Normal // No DnD of passwords, etc.
&& e->pos().y() < totalHeight() // Click past the end is not dragging
)
{
// The user might be trying to drag
d->dnd_primed = TRUE;
d->dnd_timer->start( QApplication::startDragTime(), FALSE );
} else {
wordMark = FALSE;
dragMarking = TRUE;
setCursorPixelPosition(e->pos());
}
}
qt'QMultiLineEdit::pixelPosToCursorPos() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:1992)
void QMultiLineEdit::pixelPosToCursorPos(QPoint p, int* x, int* y) const
{
*y = findRow( p.y() );
if ( *y < 0 ) {
if ( p.y() < lineWidth() ) {
*y = topCell();
} else {
*y = lastRowVisible();
p.setX(cellWidth());
}
}
*y = QMIN( (int)contents->count() - 1, *y );
QFontMetrics fm( font() );
*x = xPosToCursorPos( stringShown( *y ), fm,
p.x() - d->lr_marg + xOffset(),
cellWidth() - 2 * d->lr_marg - d->marg_extra,
d->align );
}
qt'QMultiLineEdit::setCursorPixelPosition() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2011)
void QMultiLineEdit::setCursorPixelPosition(QPoint p, bool clear_mark)
{
int newY;
pixelPosToCursorPos( p, &cursorX, &newY );
curXPos = 0;
if ( clear_mark ) {
markAnchorX = cursorX;
markAnchorY = newY;
bool markWasOn = markIsOn;
markIsOn = FALSE;
if ( markWasOn ) {
cursorY = newY;
update();
d->isHandlingEvent = FALSE;
return;
}
}
if ( cursorY != newY ) {
int oldY = cursorY;
cursorY = newY;
updateCell( oldY, 0, FALSE );
}
updateCell( cursorY, 0, FALSE ); // ###
}
qt'QMultiLineEdit::startAutoScroll() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2036)
void QMultiLineEdit::startAutoScroll()
{
if ( !dragScrolling ) {
d->scrollTime = initialScrollTime;
d->scrollAccel = initialScrollAccel;
d->scrollTimer->start( d->scrollTime, FALSE );
dragScrolling = TRUE;
}
}
qt'QMultiLineEdit::stopAutoScroll() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2046)
void QMultiLineEdit::stopAutoScroll()
{
if ( dragScrolling ) {
d->scrollTimer->stop();
dragScrolling = FALSE;
}
}
/*!\reimp
*/
qt'QMultiLineEdit::mouseMoveEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2056)
void QMultiLineEdit::mouseMoveEvent( QMouseEvent *e )
{
d->dnd_timer->stop();
if ( d->dnd_primed &&
( d->dnd_startpos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
doDrag();
return;
}
if ( !dragMarking )
return;
if ( rect().contains( e->pos() ) ) {
stopAutoScroll();
} else if ( !dragScrolling ) {
startAutoScroll();
}
int newX, newY;
pixelPosToCursorPos(e->pos(), &newX, &newY);
if ( wordMark ) {
extendSelectionWord( newX, newY);
}
if ( markDragX == newX && markDragY == newY )
return;
int oldY = markDragY;
newMark( newX, newY, FALSE );
for ( int i = QMIN(oldY,newY); i <= QMAX(oldY,newY); i++ )
updateCell( i, 0, FALSE );
}
qt'QMultiLineEdit::extendSelectionWord() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2087)
void QMultiLineEdit::extendSelectionWord( int &newX, int&newY)
{
QString s = stringShown( newY );
int lim = s.length();
if ( newX >= 0 && newX < lim ) {
int i = newX;
int startclass = charClass(s.at(i));
if ( markAnchorY < markDragY ||
( markAnchorY == markDragY && markAnchorX < markDragX ) ) {
// going right
while ( i < lim && charClass(s.at(i)) == startclass )
i++;
} else {
// going left
while ( i >= 0 && charClass(s.at(i)) == startclass )
i--;
i++;
}
newX = i;
}
}
/*!\reimp
*/
qt'QMultiLineEdit::mouseReleaseEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2114)
void QMultiLineEdit::mouseReleaseEvent( QMouseEvent *e )
{
stopAutoScroll();
if ( d->dnd_timer->isActive() ) {
d->dnd_timer->stop();
d->dnd_primed = FALSE;
setCursorPixelPosition(e->pos());
}
wordMark = FALSE;
dragMarking = FALSE;
textDirty = FALSE;
d->isHandlingEvent = TRUE;
if ( markAnchorY == markDragY && markAnchorX == markDragX )
markIsOn = FALSE;
#if defined(_WS_X11_)
else if ( echoMode() == Normal )
copy();
#else
else if ( style() == MotifStyle && echoMode() == Normal )
copy();
#endif
if ( e->button() == MidButton && !readOnly ) {
#if defined(_WS_X11_)
paste(); // Will repaint the cursor line.
#else
if ( style() == MotifStyle )
paste();
#endif
}
d->isHandlingEvent = FALSE;
if ( !readOnly && textDirty )
emit textChanged();
}
/*!\reimp
*/
qt'QMultiLineEdit::mouseDoubleClickEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2153)
void QMultiLineEdit::mouseDoubleClickEvent( QMouseEvent *m )
{
if ( m->button() == LeftButton ) {
if ( m->state() & ShiftButton ) {
int newX = cursorX;
int newY = cursorY;
extendSelectionWord( newX, newY);
newMark( newX, newY, FALSE );
} else {
markWord( cursorX, cursorY );
}
dragMarking = TRUE;
wordMark = TRUE;
updateCell( cursorY, 0, FALSE );
}
}
/*!
\reimp
*/
qt'QMultiLineEdit::dragEnterEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2175)
void QMultiLineEdit::dragEnterEvent( QDragEnterEvent * )
{
cursorOn = TRUE;
updateCell( cursorY, 0, FALSE );
}
/*!\reimp
*/
qt'QMultiLineEdit::dragMoveEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2183)
void QMultiLineEdit::dragMoveEvent( QDragMoveEvent* event )
{
if ( readOnly ) return;
event->accept( QTextDrag::canDecode(event) );
d->dnd_forcecursor = TRUE;
setCursorPixelPosition(event->pos(), FALSE);
d->dnd_forcecursor = FALSE;
QRect inside_margin(scroll_margin, scroll_margin,
width()-scroll_margin*2, height()-scroll_margin*2);
if ( !inside_margin.contains(event->pos()) ) {
startAutoScroll();
}
if ( event->source() == this && event->action() == QDropEvent::Move )
event->acceptAction();
}
/*!\reimp
*/
qt'QMultiLineEdit::dragLeaveEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2201)
void QMultiLineEdit::dragLeaveEvent( QDragLeaveEvent* )
{
if ( cursorOn ) {
cursorOn = FALSE;
updateCell( cursorY, 0, FALSE );
}
stopAutoScroll();
}
/*!\reimp
*/
qt'QMultiLineEdit::dropEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2212)
void QMultiLineEdit::dropEvent( QDropEvent* event )
{
if ( readOnly ) return;
QString text;
if ( QTextDrag::decode(event, text) ) {
int i = -1;
while ( ( i = text.find( '\r' ) ) != -1 )
text.replace( i,1,"" );
if ( event->source() == this && event->action() == QDropEvent::Move ) {
event->acceptAction();
// Careful not to tread on my own feet
int newX, newY;
pixelPosToCursorPos( event->pos(), &newX, &newY );
if ( afterMark( newX, newY ) ) {
// The tricky case
int x1, y1, x2, y2;
getMarkedRegion( &y1, &x1, &y2, &x2 );
if ( newY == y2 ) {
newY = y1;
newX = x1 + newX - x2;
} else {
newY -= y2 - y1;
}
addUndoCmd( new QBeginCommand );
del();
setCursorPosition(newY, newX);
insert(text, TRUE);
addUndoCmd( new QEndCommand );
} else if ( beforeMark( newX, newY ) ) {
// Easy
addUndoCmd( new QBeginCommand );
del();
setCursorPosition(newY, newX);
insert(text, TRUE);
addUndoCmd( new QEndCommand );
} else {
// Do nothing.
}
} else {
setCursorPixelPosition(event->pos());
insert(text, TRUE);
}
update();
}
}
/*!
Returns TRUE if line \a line is invisible or partially invisible.
*/
qt'QMultiLineEdit::partiallyInvisible() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2263)
bool QMultiLineEdit::partiallyInvisible( int line )
{
int y;
if ( !rowYPos( line, &y ) )
return TRUE;
if ( y < 0 ) {
//debug( "line %d occluded at top", line );
return TRUE;
} else if ( y + cellHeight() - 2 > viewHeight() ) {
//debug( "line %d occluded at bottom", line );
return TRUE;
}
return FALSE;
}
/*!
Scrolls such that the cursor is visible
*/
qt'QMultiLineEdit::makeVisible() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2282)
void QMultiLineEdit::makeVisible()
{
if ( !autoUpdate() )
return;
if ( partiallyInvisible( cursorY ) ) {
if ( cursorY >= lastRowVisible() )
setBottomCell( cursorY );
else
setTopCell( cursorY );
}
int xPos = mapToView( cursorX, cursorY );
if ( xPos < xOffset() ) {
int of = xPos - 10; //###
setXOffset( of );
} else if ( xPos > xOffset() + viewWidth() ) {
int of = xPos - viewWidth() + 10; //###
setXOffset( of );
}
}
/*!
Computes the character position in line \a line which corresponds
to pixel \a xPos
*/
qt'QMultiLineEdit::mapFromView() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2308)
int QMultiLineEdit::mapFromView( int xPos, int line )
{
QString s = stringShown( line );
if ( !s )
return 0;
QFontMetrics fm( font() );
int index = xPosToCursorPos( s, fm,
xPos - d->lr_marg,
cellWidth() - 2 * d->lr_marg - d->marg_extra,
d->align );
return index;
}
/*!
Computes the pixel position in line \a line which corresponds to
character position \a xIndex
*/
qt'QMultiLineEdit::mapToView() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2326)
int QMultiLineEdit::mapToView( int xIndex, int line )
{
QString s = stringShown( line );
xIndex = QMIN( (int)s.length(), xIndex );
QFontMetrics fm( font() );
int wcell = cellWidth() - 2 * d->lr_marg;// - d->marg_extra;
int wrow = contents->at( line )->w;
int w = textWidthWithTabs( fm, s, 0, xIndex, d->align ) - 1;
if ( d->align == Qt::AlignCenter || d->align == Qt::AlignHCenter )
w += (wcell - wrow) / 2;
else if ( d->align == Qt::AlignRight )
w += wcell - wrow;
return d->lr_marg + w;
}
/*!
Traverses the list and finds an item with the maximum width, and
updates the internal list box structures accordingly.
*/
qt'QMultiLineEdit::updateCellWidth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2346)
void QMultiLineEdit::updateCellWidth()
{
QMultiLineEditRow* r = contents->first();
int maxW = 0;
int w;
switch ( d->echomode ) {
case Normal:
while ( r ) {
w = r->w;
if ( w > maxW )
maxW = w;
r = contents->next();
}
break;
case Password: {
uint l = 0;
while ( r ) {
l = QMAX(l, r->s.length() );
r = contents->next();
}
QString t;
t.fill(QChar('*'), l);
maxW = textWidth(t);
}
break;
case NoEcho:
maxW = textWidth(QString::fromLatin1(""));
}
setWidth( maxW );
}
/*!
Sets the bottommost visible line to \a line.
*/
qt'QMultiLineEdit::setBottomCell() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2382)
void QMultiLineEdit::setBottomCell( int line )
{
//debug( "setBottomCell %d", line );
int rowY = cellHeight() * line;
int newYPos = rowY + cellHeight() - viewHeight();
setYOffset( QMAX( newYPos, 0 ) );
}
/*!
Copies text from the clipboard onto the current cursor position.
Any marked text is first deleted.
*/
qt'QMultiLineEdit::paste() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2394)
void QMultiLineEdit::paste()
{
addUndoCmd( new QBeginCommand );
//debug( "paste" );
if ( hasMarkedText() )
del();
QString t = QApplication::clipboard()->text();
if ( !t.isEmpty() ) {
if ( hasMarkedText() )
turnMarkOff();
#if defined(_OS_WIN32_)
// Need to convert CRLF to NL
QRegExp crlf("\\r\\n");
t.replace( crlf, "\n" );
#endif
for (int i=0; (uint)i<t.length(); i++) {
if ( t[i] < ' ' && t[i] != '\n' && t[i] != '\t' )
t[i] = ' ';
}
insertAt( t, cursorY, cursorX );
markIsOn = FALSE;
curXPos = 0;
makeVisible();
}
if ( textDirty && !d->isHandlingEvent )
emit textChanged();
addUndoCmd( new QEndCommand );
}
/*!
Removes all text.
*/
qt'QMultiLineEdit::clear() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2432)
void QMultiLineEdit::clear()
{
addUndoCmd( new QDelTextCmd( 0, text() ) );
setEdited( TRUE );
contents->clear();
cursorX = cursorY = 0;
int w = textWidth( QString::fromLatin1("") );
contents->append( new QMultiLineEditRow(QString::fromLatin1(""), w) );
setNumRows( 1 );
setWidth( w );
dummy = TRUE;
markIsOn = FALSE;
if ( autoUpdate() )
update();
if ( !d->isHandlingEvent ) //# && not already empty
emit textChanged();
update();
}
/*!\reimp
*/
qt'QMultiLineEdit::setFont() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2455)
void QMultiLineEdit::setFont( const QFont &font )
{
QWidget::setFont( font );
d->clearChartable();
QFontMetrics fm( font );
setCellHeight( fm.lineSpacing() );
for ( QMultiLineEditRow* r = contents->first(); r; r = contents->next() )
r->w = textWidth( r->s );
rebreakAll();
updateCellWidth();
}
/*!
Sets a new marked text limit, does not repaint the widget.
*/
qt'QMultiLineEdit::newMark() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2471)
void QMultiLineEdit::newMark( int posx, int posy, bool /*copy*/ )
{
if ( markIsOn && markDragX == posx && markDragY == posy &&
cursorX == posx && cursorY == posy )
return;
markDragX = posx;
markDragY = posy;
cursorX = posx;
cursorY = posy;
markIsOn = ( markDragX != markAnchorX || markDragY != markAnchorY );
}
qt'QMultiLineEdit::beforeMark() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2483)
bool QMultiLineEdit::beforeMark( int posx, int posy ) const
{
int x1, y1, x2, y2;
if ( !getMarkedRegion( &y1, &x1, &y2, &x2 ) )
return FALSE;
return
(y1 > posy || y1 == posy && x1 > posx)
&& (y2 > posy || y2 == posy && x2 > posx);
}
qt'QMultiLineEdit::afterMark() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2493)
bool QMultiLineEdit::afterMark( int posx, int posy ) const
{
int x1, y1, x2, y2;
if ( !getMarkedRegion( &y1, &x1, &y2, &x2 ) )
return FALSE;
return
(y1 < posy || y1 == posy && x1 < posx)
&& (y2 < posy || y2 == posy && x2 < posx);
}
qt'QMultiLineEdit::inMark() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2503)
bool QMultiLineEdit::inMark( int posx, int posy ) const
{
int x1, y1, x2, y2;
if ( !getMarkedRegion( &y1, &x1, &y2, &x2 ) )
return FALSE;
return
(y1 < posy || y1 == posy && x1 <= posx)
&& (y2 > posy || y2 == posy && x2 >= posx);
}
/*!
Marks the word at character position \a posx, \a posy.
*/
qt'QMultiLineEdit::markWord() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2516)
void QMultiLineEdit::markWord( int posx, int posy )
{
QString& s = contents->at( posy )->s;
int i = posx - 1;
while ( i >= 0 && s[i].isPrint() && !s[i].isSpace() )
i--;
i++;
markAnchorY = posy;
markAnchorX = i;
while ( s[i].isPrint() && !s[i].isSpace() )
i++;
markDragX = i;
markDragY = posy;
markIsOn = ( markDragX != markAnchorX || markDragY != markAnchorY );
#if defined(_WS_X11_)
if ( echoMode() == Normal )
copy();
#else
if ( style() == MotifStyle && echoMode() == Normal )
copy();
#endif
}
/*!
This may become a protected virtual member in a future Qt.
This implementation is an example of a useful classification
that aids selection of common units like filenames and URLs.
*/
qt'QMultiLineEdit::charClass() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2547)
int QMultiLineEdit::charClass( QChar ch )
{
if ( !ch.isPrint() || ch.isSpace() ) return 1;
else if ( ch.isLetter() || ch=='-' || ch=='+' || ch==':'
|| ch=='.' || ch=='/' || ch=='\\'
|| ch=='@' || ch=='$' || ch=='~' ) return 2;
else return 3;
}
/*!
Copies the marked text to the clipboard. Will only copy
if echoMode() is Normal.
*/
qt'QMultiLineEdit::copy() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2561)
void QMultiLineEdit::copy() const
{
QString t = markedText();
if ( !t.isEmpty() && echoMode() == Normal ) {
#if defined(_WS_X11_)
disconnect( QApplication::clipboard(), SIGNAL(dataChanged()), this, 0);
#endif
#if defined(_OS_WIN32_)
// Need to convert NL to CRLF
QRegExp nl("\\n");
t.replace( nl, "\r\n" );
#endif
QApplication::clipboard()->setText( t );
#if defined(_WS_X11_)
connect( QApplication::clipboard(), SIGNAL(dataChanged()),
this, SLOT(clipboardChanged()) );
#endif
}
}
/*! \obsolete
Backward compatibility.
*/
qt'QMultiLineEdit::copyText() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2585)
void QMultiLineEdit::copyText() const
{
copy();
}
/*!
Copies the selected text to the clipboard and deletes the selected text.
*/
qt'QMultiLineEdit::cut() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2595)
void QMultiLineEdit::cut()
{
if ( hasMarkedText() ) {
if ( echoMode() == Normal )
copy();
del();
if ( textDirty && !d->isHandlingEvent )
emit textChanged();
}
}
/*!
This private slot is activated when this line edit owns the clipboard and
some other widget/application takes over the clipboard. (X11 only)
*/
qt'QMultiLineEdit::clipboardChanged() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2612)
void QMultiLineEdit::clipboardChanged()
{
#if defined(_WS_X11_)
disconnect( QApplication::clipboard(), SIGNAL(dataChanged()),
this, SLOT(clipboardChanged()) );
markIsOn = FALSE;
update();
#endif
}
/*!
Sets maxLineWidth() and maybe cellWidth() to \a w without updating the entire widget.
*/
qt'QMultiLineEdit::setWidth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2627)
void QMultiLineEdit::setWidth( int w )
{
if ( w ==d->maxLineWidth )
return;
bool u = autoUpdate();
setAutoUpdate( FALSE );
d->maxLineWidth = w;
if ( d->align == AlignLeft )
setCellWidth( w );
else
setCellWidth( QMAX( w, contentsRect().width() ) );
setAutoUpdate( u );
if ( autoUpdate() && d->align != AlignLeft )
update();
}
/*!
Sets the cursor position to character number \a col in line number \a line.
The parameters are adjusted to lie within the legal range.
If \a mark is FALSE, the selection is cleared. otherwise it is extended
\sa cursorPosition()
*/
qt'QMultiLineEdit::setCursorPosition() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2653)
void QMultiLineEdit::setCursorPosition( int line, int col, bool mark )
{
if ( mark && !hasMarkedText() ) {
markAnchorX = cursorX;
markAnchorY = cursorY;
}
int oldY = cursorY;
cursorY = QMAX( QMIN( line, numLines() - 1), 0 );
cursorX = QMAX( QMIN( col, lineLength( cursorY )), 0 );
curXPos = 0;
makeVisible();
if ( mark ) {
newMark( cursorX, cursorY, FALSE );
for ( int i = QMIN(oldY,cursorY); i <= QMAX(oldY,cursorY); i++ )
updateCell( i, 0, FALSE );
} else {
updateCell( oldY, 0, FALSE );
turnMarkOff();
}
}
/*! \obsolete
Use getCursorPosition() instead.
*/
qt'QMultiLineEdit::cursorPosition() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2681)
void QMultiLineEdit::cursorPosition( int *line, int *col ) const
{
getCursorPosition(line,col);
}
/*!
Returns the current line and character
position within that line, in the variables pointed to
by \a line and \a col respectively.
\sa setCursorPosition()
*/
qt'QMultiLineEdit::getCursorPosition() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2695)
void QMultiLineEdit::getCursorPosition( int *line, int *col ) const
{
if ( line )
*line = cursorY;
if ( col )
*col = cursorX;
}
/*!
Returns TRUE if the view updates itself automatically whenever it
is changed in some way.
\sa setAutoUpdate()
*/
qt'QMultiLineEdit::autoUpdate() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2711)
bool QMultiLineEdit::autoUpdate() const
{
return QTableView::autoUpdate();
}
/*!
Sets the auto-update option of multi-line editor to \e enable.
If \e enable is TRUE (this is the default) then the editor updates
itself automatically whenever it has changed in some way (generally,
when text has been inserted or deleted).
If \e enable is FALSE, the view does NOT repaint itself, or update
its internal state variables itself when it is changed. This can be
useful to avoid flicker during large changes, and is singularly
useless otherwise: Disable auto-update, do the changes, re-enable
auto-update, and call repaint().
\warning Do not leave the view in this state for a long time
(i.e. between events ). If, for example, the user interacts with the
view when auto-update is off, strange things can happen.
Setting auto-update to TRUE does not repaint the view, you must call
repaint() to do this (preferable repaint(FALSE) to avoid flicker).
\sa autoUpdate() repaint()
*/
qt'QMultiLineEdit::setAutoUpdate() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2740)
void QMultiLineEdit::setAutoUpdate( bool enable )
{
QTableView::setAutoUpdate( enable );
}
/*!
Sets the fixed height of the QMultiLineEdit so that \e lines text lines
are visible given the current font.
\sa setMaxLines(), setFixedHeight()
*/
qt'QMultiLineEdit::setFixedVisibleLines() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2751)
void QMultiLineEdit::setFixedVisibleLines( int lines )
{
int ls = fontMetrics().lineSpacing();
setFixedHeight( frameWidth()*2 + ls*lines );
return;
}
/*!
Returns the top center point where the cursor is drawn
*/
qt'QMultiLineEdit::cursorPoint() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2764)
QPoint QMultiLineEdit::cursorPoint() const
{
QPoint cp( 0, 0 );
QFontMetrics fm( font() );
int col, row;
col = row = 0;
cursorPosition( &row, &col );
QString line = textLine( row );
ASSERT( line );
cp.setX( d->lr_marg + textWidthWithTabs( fm, line, 0, col, d->align ) - 1 );
cp.setY( (row * cellHeight()) + viewRect().y() );
return cp;
}
/*! \reimp
*/
qt'QMultiLineEdit::sizePolicy() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2782)
QSizePolicy QMultiLineEdit::sizePolicy() const
{
if ( d->maxlines >= 0 && d->maxlines <= 6 ) {
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
} else {
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}
}
/*!\reimp
*/
qt'QMultiLineEdit::sizeHint() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2794)
QSize QMultiLineEdit::sizeHint() const
{
constPolish();
int expected_lines;
if ( d->maxlines >= 0 && d->maxlines <= 6 ) {
expected_lines = d->maxlines;
} else {
expected_lines = 6;
}
QFontMetrics fm( font() );
int h = fm.lineSpacing()*(expected_lines-1)+fm.height() + frameWidth()*2;
int w = fm.width('x')*35;
int maxh = maximumSize().height();
if ( maxh < QWIDGETSIZE_MAX )
h = maxh;
return QSize( w, h );
}
/*!
Returns a size sufficient for one character, and scroll bars.
*/
qt'QMultiLineEdit::minimumSizeHint() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2819)
QSize QMultiLineEdit::minimumSizeHint() const
{
constPolish();
QFontMetrics fm( font() );
int h = fm.lineSpacing() + frameWidth()*2;
int w = fm.maxWidth();
h += frameWidth();
w += frameWidth();
if ( testTableFlags(Tbl_hScrollBar|Tbl_autoHScrollBar) )
w += verticalScrollBar()->sizeHint().width();
if ( testTableFlags(Tbl_vScrollBar|Tbl_autoVScrollBar) )
h += horizontalScrollBar()->sizeHint().height();
return QSize(w,h);
}
/*!\reimp
*/
qt'QMultiLineEdit::resizeEvent() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2839)
void QMultiLineEdit::resizeEvent( QResizeEvent *e )
{
int oldw = contentsRect().width();
QTableView::resizeEvent( e );
if ( DYNAMIC_WRAP
&& (e->oldSize().width() != width()
|| oldw != contentsRect().width() ) ) {
bool oldAuto = autoUpdate();
setAutoUpdate( FALSE );
rebreakAll();
if ( oldw != contentsRect().width() )
rebreakAll();
setAutoUpdate( oldAuto );
if ( autoUpdate() )
repaint( FALSE );
} else if ( d->align != AlignLeft ) {
d->maxLineWidth = 0; // trigger update
updateCellWidth();
}
}
/*!
Sets the alignment. Possible values are \c AlignLeft, \c Align(H)Center
and \c AlignRight.
\sa alignment(), Qt::AlignmentFlags
*/
qt'QMultiLineEdit::setAlignment() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2866)
void QMultiLineEdit::setAlignment( int flags )
{
if ( d->align != flags ) {
d->align = flags;
update();
}
}
/*!
Returns the alignment.
\sa setAlignment(), Qt::AlignmentFlags.
*/
qt'QMultiLineEdit::alignment() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2879)
int QMultiLineEdit::alignment() const
{
return d->align;
}
/*!
Not supported at this time.
*/
qt'QMultiLineEdit::setValidator() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2888)
void QMultiLineEdit::setValidator( const QValidator *v )
{
d->val = v;
// #### validate text now
}
/*!
Not supported at this time.
*/
qt'QMultiLineEdit::validator() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2897)
const QValidator * QMultiLineEdit::validator() const
{
return d->val;
}
/*! Sets the edited flag of this line edit to \a on. The edited flag
is never read by QMultiLineEdit, but is changed to TRUE whenever the user
changes its contents.
This is useful e.g. for things that need to provide a default value,
but cannot find the default at once. Just open the widget without the
best default and when the default is known, check the edited() return
value and set the line edit's contents if the user has not started
editing the line edit. Another example is to detect whether the
contents need saving.
\sa edited()
*/
qt'QMultiLineEdit::setEdited() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2915)
void QMultiLineEdit::setEdited( bool e )
{
d->edited = e;
}
/*! Returns the edited flag of the line edit. If this returns FALSE,
the contents has not been changed since the construction of the
QMultiLineEdit (or the last call to setEdited( FALSE ), if any). If
it returns TRUE, the contents have been edited, or setEdited( TRUE )
has been called.
\sa setEdited()
*/
qt'QMultiLineEdit::edited() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2928)
bool QMultiLineEdit::edited() const
{
return d->edited;
}
/*! \enum QMultiLineEdit::EchoMode
This enum type describes the ways in which QLineEdit can display its
contents. The currently defined values are: <ul>
<li> \c Normal - display characters as they are entered. This is
the default.
<li> \c NoEcho - do not display anything.
<li> \c Password - display asterisks instead of the characters
actually entered.
</ul>
\sa setEchoMode() echoMode() QLineEdit::EchoMode
*/
/*!
Sets the echo mode to \a em. The default is \c Normal.
The display is updated according.
\sa setEchoMode()
*/
qt'QMultiLineEdit::setEchoMode() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2959)
void QMultiLineEdit::setEchoMode( EchoMode em )
{
if ( d->echomode != em ) {
d->echomode = em;
updateCellWidth();
update();
}
}
/*!
Returns the currently set echo mode.
\sa setEchoMode()
*/
QMultiLineEdit::EchoMode QMultiLineEdit::echoMode() const
{
return d->echomode;
}
/*!
Returns the string shown at line \a row, including
processing of the echoMode().
*/
qt'QMultiLineEdit::stringShown() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:2984)
QString QMultiLineEdit::stringShown(int row) const
{
QString* s = getString(row);
if ( !s ) return QString::null;
switch ( d->echomode ) {
case Normal:
if (!*s) return QString::fromLatin1("");
return *s;
case Password:
{
QString r;
r.fill(QChar('*'), (int)s->length());
if ( !r ) r = QString::fromLatin1("");
return r;
}
case NoEcho:
return QString::fromLatin1("");
}
return QString::fromLatin1("");
}
/*!
Sets the maximum text length to \a m. Use -1 for unlimited
(the default). Existing overlong text will be truncated.
\sa maxLength()
*/
qt'QMultiLineEdit::setMaxLength() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3011)
void QMultiLineEdit::setMaxLength(int m)
{
d->maxlen = m;
}
/*!
Returns the currently set text length limit, or -1 if there is
no limit (this is the default).
\sa setMaxLength()
*/
qt'QMultiLineEdit::maxLength() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3022)
int QMultiLineEdit::maxLength() const
{
return d->maxlen;
}
/*!
Returns the length of the current text.
\sa setMaxLength()
*/
qt'QMultiLineEdit::length() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3033)
int QMultiLineEdit::length() const
{
int l = 0;
for ( QMultiLineEditRow* r = contents->first(); r; r = contents->next() ) {
l += r->s.length();
if ( r->newline )
++l;
}
return l;
}
/*!
Sets the maximum length of lines to \a m. Use -1 for unlimited
(the default). Existing long lines will be truncated.
\sa maxLineLength()
*/
qt'QMultiLineEdit::setMaxLineLength() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3051)
void QMultiLineEdit::setMaxLineLength(int m)
{
bool trunc = d->maxlinelen >= 0 && d->maxlinelen < m;
d->maxlinelen = m;
if ( trunc ) {
QMultiLineEditRow* r = contents->first();
while ( r ) {
r->s.truncate( m );
r = contents->next();
}
if ( cursorX > m ) cursorX = m;
if ( markAnchorX > m ) markAnchorX = m;
if ( markDragX > m ) markDragX = m;
update();
updateCellWidth();
}
}
/*!
Returns the currently set line length limit, or -1 if there is
no limit (this is the default).
\sa setMaxLineLength()
*/
qt'QMultiLineEdit::maxLineLength() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3075)
int QMultiLineEdit::maxLineLength() const
{
return d->maxlinelen;
}
/*!
Sets the maximum number of lines to \a m. Use -1 for unlimited
(the default). Existing excess lines will be deleted.
\sa maxLines()
*/
qt'QMultiLineEdit::setMaxLines() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3086)
void QMultiLineEdit::setMaxLines(int m)
{
bool trunc = d->maxlines >= 0 && d->maxlines < m;
d->maxlines = m;
if ( trunc ) {
if ( cursorY > m ) {
cursorX = 0;
cursorY = m;
}
if ( markAnchorY > m ) {
markAnchorX = 0;
markAnchorY = m;
}
if ( markDragY > m ) {
markDragX = 0;
markDragY = m;
}
while ( contents->remove(m) )
;
updateCellWidth();
update();
}
}
/*!
Returns the currently set line limit, or -1 if there is
no limit (the default).
\sa setMaxLines()
*/
qt'QMultiLineEdit::maxLines() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3116)
int QMultiLineEdit::maxLines() const
{
return d->maxlines;
}
/*!
Sets the horizontal margin.
\sa hMargin()
*/
qt'QMultiLineEdit::setHMargin() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3126)
void QMultiLineEdit::setHMargin(int m)
{
if ( m != d->lr_marg ) {
d->lr_marg = m;
updateCellWidth();
update();
}
}
/*!
Returns the horizontal margin current set. The default is 3.
\sa setHMargin()
*/
qt'QMultiLineEdit::hMargin() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3140)
int QMultiLineEdit::hMargin() const
{
return d->lr_marg;
}
/*!
Not supported at this time.
*/
qt'QMultiLineEdit::setSelection() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3148)
void QMultiLineEdit::setSelection( int /*row_from*/, int /*col_from*/,
int /*row_to*/, int /*col_to*/ )
{
/*
markAnchorY = row_from;
markAnchorX = col_from;
markDragY = row_to;
markDragX = col_to;
markIsOn = TRUE;
*/
qFatal("Not implemented: setSelection");
}
/*!
Moves the cursor one word to the right. If \a mark is TRUE, the text
is marked.
\sa cursorWordBackward()
*/
qt'QMultiLineEdit::cursorWordForward() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3168)
void QMultiLineEdit::cursorWordForward( bool mark )
{
int x = cursorX;
int y = cursorY;
if ( x == lineLength( y ) || textLine(y).at(x).isSpace() ) {
while ( x < lineLength( y ) && textLine(y).at(x).isSpace() )
++x;
if ( x == lineLength( y ) ) {
if ( y < (int)contents->count() - 1) {
++y;
x = 0;
while ( x < lineLength( y ) && textLine(y).at(x).isSpace() )
++x;
}
}
}
else {
while ( x < lineLength( y ) && !textLine(y).at(x).isSpace() )
++x;
int xspace = x;
while ( xspace < lineLength( y ) && textLine(y).at(xspace).isSpace() )
++xspace;
if ( xspace < lineLength( y ) )
x = xspace;
}
cursorOn = TRUE;
int oldY = cursorY;
setCursorPosition( y, x, mark );
if ( oldY != cursorY )
updateCell( oldY, 0, FALSE );
updateCell( cursorY, 0, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
}
/*!
Moves the cursor one word to the left. If \a mark is TRUE, the text
is marked.
\sa cursorWordForward()
*/
qt'QMultiLineEdit::cursorWordBackward() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3208)
void QMultiLineEdit::cursorWordBackward( bool mark )
{
int x = cursorX;
int y = cursorY;
while ( x > 0 && textLine(y).at(x-1).isSpace() )
--x;
if ( x == 0 ) {
if ( y > 0 ) {
--y;
x = lineLength( y );
while ( x > 0 && textLine(y).at(x-1).isSpace() )
--x;
}
}
else {
while ( x > 0 && !textLine(y).at(x-1).isSpace() )
--x;
}
cursorOn = TRUE;
int oldY = cursorY;
setCursorPosition( y, x, mark );
if ( oldY != cursorY )
updateCell( oldY, 0, FALSE );
updateCell( cursorY, 0, FALSE );
d->blinkTimer->start( QApplication::cursorFlashTime() / 2, FALSE );
}
qt'QMultiLineEdit::wrapLine() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3244)
void QMultiLineEdit::wrapLine( int line, int removed )
{
QMultiLineEditRow* r = contents->at( line );
int yPos;
(void) rowYPos( line, &yPos );
QFontMetrics fm( font() );
int i = 0;
QString s = r->s;
int a = 0;
int l = line;
int w = 0;
int nlines = 0;
int lastSpace = -1;
bool doBreak = FALSE;
int linew = 0;
int lastw = 0;
int tabDist = -1; // lazy eval
while ( i < int(s.length()) ) {
doBreak = FALSE;
if ( s[i] == '\t' && d->align == Qt::AlignLeft ) {
if ( tabDist<0 )
tabDist = tabStopDist(fm);
linew = ( linew/tabDist + 1 ) * tabDist;
} else if ( s[i] != '\n' ) {
char c = s[i].latin1();
if ( c > 0 ) {
if ( !d->chartable[c] )
d->chartable[c] = fm.width( s[i] );
linew += d->chartable[c];
} else {
linew += fm.width( s[i] );
}
}
if ( WORD_WRAP &&
lastSpace >= a && s[i] != '\n' ) {
if ( DYNAMIC_WRAP ) {
if (linew >= contentsRect().width() - 2*d->lr_marg - d->marg_extra) {
DO_BREAK;
}
} else if ( FIXED_COLUMN_WRAP ) {
if ( d->wrapcol >= 0 && i-a >= d->wrapcol ) {
DO_BREAK;
}
} else if ( FIXED_WIDTH_WRAP ) {
if ( d->wrapcol >= 0 && linew > d->wrapcol - d->marg_extra ) {
DO_BREAK;
}
}
}
if ( s[i] == '\n' || doBreak ) {
r->s = s.mid( a, i - a + (doBreak?1:0) );
r->w = linew - fm.leftBearing(r->s[0]) + 2 * d->lr_marg + d->marg_extra;
if ( r->w > w )
w = r->w;
if ( cursorY > l )
++cursorY;
else if ( cursorY == line && cursorX >=a && cursorX <= i + (doBreak?1:0)) {
cursorY = l;
cursorX -= a;
}
if ( markAnchorY > l )
++markAnchorY;
else if ( markAnchorY == line && markAnchorX >=a && markAnchorX <= i + (doBreak?1:0)) {
markAnchorY = l;
markAnchorX -= a;
}
a = i + 1;
lastSpace = a;
linew = 0;
bool oldnewline = r->newline;
r->newline = !doBreak;
r = new QMultiLineEditRow( QString::null, 0, oldnewline );
++nlines;
contents->insert( l + 1, r );
++l;
}
if ( s[i].isSpace() || BREAK_WITHIN_WORDS ) {
lastSpace = i;
lastw = linew;
}
if ( lastSpace <= a )
lastw = linew;
++i;
}
if ( a < int(s.length()) ){
r->s = s.mid( a, i - a );
r->w = linew - fm.leftBearing( r->s[0] ) + 2 * d->lr_marg + d->marg_extra;
}
if ( cursorY == line && cursorX >= a ) {
cursorY = l;
cursorX -= a;
}
if ( markAnchorY == line && markAnchorX >= a ) {
markAnchorY = l;
markAnchorX -= a;
}
if ( r->w > w )
w = r->w;
setWidth( QMAX( maxLineWidth(), w ) );
bool oldAuto = autoUpdate();
setAutoUpdate( FALSE );
setNumRows( contents->count() );
setAutoUpdate( oldAuto );
yPos += (nlines+1) * cellHeight();
int sh = (nlines-removed) * cellHeight();
if ( autoUpdate() ) {
if ( sh && yPos >= contentsRect().top() && yPos < contentsRect().bottom() )
QWidget::scroll( 0, sh, QRect( contentsRect().left(), yPos,
contentsRect().width(),
contentsRect().bottom() - yPos + 1 ) );
for (int ul = 0; ul <= nlines; ++ul )
updateCell( line + ul, 0, FALSE );
}
}
qt'QMultiLineEdit::rebreakParagraph() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3362)
void QMultiLineEdit::rebreakParagraph( int line, int removed )
{
QMultiLineEditRow* r = contents->at( line );
if ( WORD_WRAP ) {
QMultiLineEditRow* other = 0;
while (line < int(contents->count())-1 && !r->newline ) {
other = contents->at( line + 1 );
if ( cursorY > line ) {
--cursorY;
if ( cursorY == line ) {
cursorX += r->s.length();
}
}
if ( markAnchorY > line ) {
--markAnchorY;
if ( markAnchorY == line ) {
markAnchorX += r->s.length();
}
}
r->s.append( other->s );
r->newline = other->newline;
contents->remove( line + 1 );
++removed;
}
}
wrapLine( line, removed );
}
qt'QMultiLineEdit::rebreakAll() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3390)
void QMultiLineEdit::rebreakAll()
{
if ( !WORD_WRAP )
return;
d->maxLineWidth = 0;
for (int i = 0; i < int(contents->count()); ++i ) {
if ( contents->at( i )->newline &&
contents->at( i )->w < contentsRect().width() - 2*d->lr_marg - d->marg_extra ) {
setWidth( QMAX( d->maxLineWidth, contents->at( i )->w ) );
continue;
}
rebreakParagraph( i );
while ( i < int(contents->count() )
&& !contents->at( i )->newline )
++i;
}
}
/*! \enum QMultiLineEdit::WordWrap
This enum describes the multiline edit's word wrap mode.
The following values are valid:
<ul>
<li> \c NoWrap - no word wrap at all.
<li> \c WidgetWidth - word wrap depending on the current
width of the editor widget
<li> \c FixedPixelWidth - wrap according to a fix amount
of pixels ( see wrapColumnOrWidth() )
<li> \c FixedColumnWidth - wrap according to a fix character
column. This is useful whenever you need formatted text that
can also be displayed gracefully on devices with monospaced
fonts, for example a standard VT100 terminal. In that case
wrapColumnOrWidth() should typically be set to 80.
</ul>
\sa setWordWrap()
*/
/*!
Sets the word wrap mode.
Per default, wrapping keeps words intact. To allow breaking within
words, set the wrap policy to \c Anywhere (see setWrapPolicy() ).
The default wrap mode is \c NoWrap.
\sa wordWrap(), setWrapColumnOrWidth(), setWrapPolicy()
*/
qt'QMultiLineEdit::setWordWrap() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3440)
void QMultiLineEdit::setWordWrap( WordWrap mode )
{
if ( mode == d->wordwrap )
return;
d->wordwrap = mode;
if ( BREAK_WITHIN_WORDS ) {
d->arrow = QPixmap( (const char **)arrow_xpm );
d->marg_extra = 8;
if ( DYNAMIC_WRAP )
clearTableFlags( Tbl_autoHScrollBar );
} else {
d->marg_extra = 0;
setTableFlags( Tbl_autoHScrollBar );
}
setText( text() );
}
/*!
Returns the current word wrap mode.
\sa setWordWrap()
*/
QMultiLineEdit::WordWrap QMultiLineEdit::wordWrap() const
{
return d->wordwrap;
}
/*!
Sets the wrap column or wrap width, depending on the word wrap mode.
\sa setWordWrap()
*/
qt'QMultiLineEdit::setWrapColumnOrWidth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3473)
void QMultiLineEdit::setWrapColumnOrWidth( int value )
{
if ( value == d->wrapcol )
return;
d->wrapcol = value;
if ( wordWrap() != NoWrap )
setText( text() );
}
/*!
Returns the wrap column or wrap width, depending on the word wrap
mode.
\sa setWordWrap(), setWrapColumnOrWidth()
*/
qt'QMultiLineEdit::wrapColumnOrWidth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3488)
int QMultiLineEdit::wrapColumnOrWidth() const
{
return d->wrapcol;
}
/*! \enum QMultiLineEdit::WrapPolicy
Defines where text can be wrapped in word wrap mode.
The following values are valid:
<ul>
<li> \c AtWhiteSpace - break only after whitespace
<li> \c Anywhere - break anywhere
</ul>
\sa setWrapPolicy()
*/
/*!
Defines where text can be wrapped in word wrap mode.
The default is \c AtWhiteSpace.
/sa setWordWrap(), wrapPolicy()
*/
qt'QMultiLineEdit::setWrapPolicy() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3514)
void QMultiLineEdit::setWrapPolicy( WrapPolicy policy )
{
if ( d->wrappolicy == policy )
return;
d->wrappolicy = policy;
WordWrap m = d->wordwrap;
if ( m != NoWrap ) { // trigger update
d->wordwrap = NoWrap;
setWordWrap( m );
}
}
/*!
Returns the current word wrap policy.
\sa setWrapPolicy()
*/
QMultiLineEdit::WrapPolicy QMultiLineEdit::wrapPolicy() const
{
return d->wrappolicy;
}
/*!
Returns wether \a row is the last row in a paragraph.
This function is only interesting in word wrap mode, otherwise its
return value is always TRUE.
\sa setWordWrap()
*/
qt'QMultiLineEdit::isEndOfParagraph() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3545)
bool QMultiLineEdit::isEndOfParagraph( int row ) const
{
return contents->at( row )->newline;
}
qt'QMultiLineEdit::positionToOffsetInternal() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3550)
int QMultiLineEdit::positionToOffsetInternal( int row, int col ) const
{
row = QMAX( QMIN( row, numLines() - 1), 0 ); // Sanity check
col = QMAX( QMIN( col, lineLength( row )), 0 ); // Sanity check
if ( row == 0 )
return QMIN( col, lineLength( 0 ));
else {
int lastI;
lastI = lineLength( row );
int i, tmp = 0;
for( i = 0; i < row ; i++ ) {
tmp += lineLength( i );
if ( contents->at( i )->newline )
++tmp;
}
tmp += QMIN( lastI, col );
return tmp;
}
}
// if position is <0 = returns row 0, col 0, if position >= amount of text
// returns pointer to end of text.
qt'QMultiLineEdit::offsetToPositionInternal() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3576)
void QMultiLineEdit::offsetToPositionInternal( int position,
int *row, int *col ) const
{
if (position <= 0) {
*row = 0;
*col = 0;
return;
}
else {
int charsLeft = position;
int i;
for( i = 0; contents->at( i ); ++i ) {
if (lineLength( i ) < charsLeft)
charsLeft -= lineLength( i );
else {
*row = i;
*col = charsLeft;
return;
}
if ( contents->at( i )->newline )
--charsLeft;
}
if (contents->at( i - 1) && !contents->at( i - 1 )->newline) {
*row = i - 1;
*col = lineLength( i - 1 );
}
else {
*row = i;
*col = 0;
}
return;
}
}
/*!
Processes an undo/redo command \a cmd, depending on \a undo
*/
qt'QMultiLineEdit::processCmd() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3616)
void QMultiLineEdit::processCmd( QMultiLineEditCommand* cmd, bool undo)
{
QDelTextCmd* delcmd = (QDelTextCmd*) cmd;
bool ins = TRUE;
if (cmd->type() == QMultiLineEditCommand::Delete )
ins = undo;
else if (cmd->type() == QMultiLineEditCommand::Insert )
ins = !undo;
else
return;
if ( ins ) {
int row, col;
offsetToPositionInternal( delcmd->mOffset, &row, &col );
setCursorPosition( row, col, FALSE );
insertAt( delcmd->mStr, row, col, FALSE );
offsetToPositionInternal( delcmd->mOffset+delcmd->mStr.length(), &row, &col );
setCursorPosition( row, col, FALSE );
} else { // del
int row, col, rowEnd, colEnd;
offsetToPositionInternal( delcmd->mOffset, &row, &col );
offsetToPositionInternal( delcmd->mOffset + delcmd->mStr.length(), &rowEnd, &colEnd );
markAnchorY = row;
markAnchorX = col;
setCursorPosition( rowEnd, colEnd, FALSE );
markDragY = rowEnd;
markDragX = colEnd;
markIsOn = TRUE;
del();
}
}
/*!
Undos the last text operation
*/
qt'QMultiLineEdit::undo() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3651)
void QMultiLineEdit::undo()
{
if ( d->undoList.isEmpty() || isReadOnly() )
return;
textDirty = FALSE;
int macroLevel = 0;
bool before = d->undo;
d->undo = FALSE;
do {
QMultiLineEditCommand *command = d->undoList.take();
if ( !command )
break;
processCmd( command, TRUE );
macroLevel += command->terminator();
if ( d->undoList.isEmpty() )
emit undoAvailable( FALSE );
addRedoCmd( command );
} while (macroLevel != 0);
d->undo = before;
if ( textDirty )
emit textChanged();
textDirty = FALSE;
}
/*!
Redos the last text operation
*/
qt'QMultiLineEdit::redo() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3678)
void QMultiLineEdit::redo()
{
if ( d->redoList.isEmpty() || isReadOnly() )
return;
textDirty = FALSE;
int macroLevel = 0;
bool before = d->undo;
d->undo = FALSE;
do {
QMultiLineEditCommand *command = d->redoList.take();
if ( !command )
break;
processCmd( command, FALSE );
macroLevel += command->terminator();
if ( d->redoList.isEmpty() )
emit redoAvailable( FALSE );
if ( d->undoList.isEmpty() )
emit undoAvailable(TRUE);
d->undoList.append( command );
} while (macroLevel != 0);
d->undo = before;
if ( textDirty )
emit textChanged();
textDirty = FALSE;
}
/*!
Inserts \a txt at line number \a line, after character number \a col
in the line.
If \a txt contains newline characters, new lines are inserted.
The cursor position is adjusted. If the insertion position is equal to
the cursor position, the cursor is placed after the end of the new text.
*/
qt'QMultiLineEdit::insertAt() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3714)
void QMultiLineEdit::insertAt( const QString &s, int line, int col, bool mark )
{
if ( d->undo ) {
d->undo = FALSE;
QString itxt = s;
int offset = positionToOffsetInternal( line, col );
if ( d->maxlen >= 0 && length() + int(s.length()) > d->maxlen )
itxt.truncate( d->maxlen - length() );
addUndoCmd( new QInsTextCmd( offset, itxt ) );
insertAtAux( s, line, col, mark ); // may perform del op
d->undo = TRUE;
}
else
insertAtAux( s, line, col, mark ); // may perform del op
}
qt'QMultiLineEdit::deleteNextChar() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3730)
void QMultiLineEdit::deleteNextChar( int offset, int row, int col )
{
int row2, col2;
setCursorPosition( row, col, FALSE );
offsetToPositionInternal( offset + 1, &row2, &col2 );
setCursorPosition( row2, col2, TRUE );
QString str = markedText();
addUndoCmd( new QDelTextCmd( offset, str ) );
setCursorPosition( row, col, FALSE );
}
/*!
Deletes text from the current cursor position to the end of the line.
*/
qt'QMultiLineEdit::killLine() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3747)
void QMultiLineEdit::killLine()
{
if ( d->undo ) {
d->undo = FALSE;
int curY, curX;
cursorPosition( &curY, &curX );
int offset = positionToOffsetInternal( curY, curX );
QMultiLineEditRow* r = contents->at( curY );
deselect();
addUndoCmd( new QBeginCommand );
if (curX == (int)r->s.length()) {
if ( ! atEnd() && r->newline )
deleteNextChar( offset, curY, curX );
}
else {
QString str = r->s.mid( curX, r->s.length() );
addUndoCmd( new QDelTextCmd( offset, str ) );
}
addUndoCmd( new QEndCommand );
killLineAux();
d->undo = TRUE;
}
else
killLineAux();
}
/*!
Deletes the character on the right side of the text cursor. If a
text has been marked by the user (e.g. by clicking and dragging) the
cursor is put at the beginning of the marked text and the marked
text is removed. \sa backspace()
*/
qt'QMultiLineEdit::del() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3782)
void QMultiLineEdit::del()
{
if (d->undo ) {
d->undo = FALSE;
bool oldAuto = autoUpdate();
setAutoUpdate( FALSE );
int markBeginX, markBeginY;
int markEndX, markEndY;
if ( getMarkedRegion( &markBeginY, &markBeginX, &markEndY, &markEndX ) ) {
addUndoCmd( new QBeginCommand );
int offset = positionToOffsetInternal( markBeginY, markBeginX );
QString str = markedText();
d->undoList.append( new QDelTextCmd( offset, str ) );
addUndoCmd( new QEndCommand );
}
else if ( ! atEnd() ) {
int crsorY, crsorX;
cursorPosition( &crsorY, &crsorX );
int offset = positionToOffsetInternal( crsorY, crsorX );
QMultiLineEditRow* r = contents->at( crsorY );
if (r) {
if (crsorX != (int)r->s.length())
deleteNextChar( offset, crsorY, crsorX );
else if (r->newline)
deleteNextChar( offset, crsorY, crsorX );
else
; // noop
}
}
setAutoUpdate( oldAuto );
delAux();
d->undo = TRUE;
}
else
delAux();
}
/*!
Sets undo enabled to \a enable
\sa isUndoEnabled()
*/
qt'QMultiLineEdit::setUndoEnabled() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3825)
void QMultiLineEdit::setUndoEnabled( bool enable )
{
if ( d->undo == enable )
return;
d->undo = enable;
if ( !enable ) {
CLEAR_UNDO;
}
}
/*!
Returns whether the multilineedit is currently undo enabled or not.
\sa setUndoEnabled()
*/
qt'QMultiLineEdit::isUndoEnabled() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3841)
bool QMultiLineEdit::isUndoEnabled() const
{
return d->undo;
}
/*!
Sets the maximum number of operations that can be stored on the undo stack.
\sa undoDepth()
*/
qt'QMultiLineEdit::setUndoDepth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3852)
void QMultiLineEdit::setUndoDepth( int depth)
{
d->undodepth = depth;
}
/*!
Returns the maximum number of operations that can be stored on the undo stack.
\sa setUndoDepth()
*/
qt'QMultiLineEdit::undoDepth() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3863)
int QMultiLineEdit::undoDepth() const
{
return d->undodepth;
}
qt'QMultiLineEdit::blinkTimerTimeout() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3868)
void QMultiLineEdit::blinkTimerTimeout()
{
cursorOn = !cursorOn;
updateCell( cursorY, 0, FALSE );
}
qt'QMultiLineEdit::scrollTimerTimeout() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3874)
void QMultiLineEdit::scrollTimerTimeout()
{
QPoint p = mapFromGlobal( QCursor::pos() );
if ( d->scrollAccel-- <= 0 && d->scrollTime ) {
d->scrollAccel = initialScrollAccel;
d->scrollTime--;
d->scrollTimer->stop();
d->scrollTimer->start( d->scrollTime );
}
int l = QMAX(1,(initialScrollTime-d->scrollTime)/5);
// auto scrolling is dual-use - for highlighting and DND
int margin = d->dnd_primed ? scroll_margin : 0;
bool mark = !d->dnd_primed;
bool clear_mark = d->dnd_primed ? FALSE : !mark;
for (int i=0; i<l; i++) {
if ( p.y() < margin ) {
cursorUp( mark, clear_mark );
} else if ( p.y() > height()-margin ) {
cursorDown( mark, clear_mark );
} else if ( p.x() < margin ) {
cursorLeft( mark, clear_mark, FALSE );
} else if ( p.x() > width()-margin ) {
cursorRight( mark, clear_mark, FALSE );
} else {
stopAutoScroll();
break;
}
}
}
qt'QMultiLineEdit::dndTimeout() (./qt-2.1.0/src/widgets/qmultilineedit.cpp:3906)
void QMultiLineEdit::dndTimeout()
{
doDrag();
}
qt'QMultiLineEdit::numLines() (./qt-2.1.0/src/widgets/qmultilineedit.h:349)
inline int QMultiLineEdit::numLines() const
{
return contents->count();
}