diff --git a/harbour/ChangeLog b/harbour/ChangeLog index af5cca827c..1ea13cdb23 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,14 @@ The license applies to all entries newer than 2009-04-28. */ +2012-02-13 12:07 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/qtgui/hbqt_hbqplaintextedit.cpp + * contrib/hbqt/qtgui/hbqt_hbqplaintextedit.h + * Fixed: drag & drop behavior. Now hbIDE confirms to standard + Windows norms to select/drag/copy|paste operations. + Additionally it also confirms to hbIDE's column-selected + text and retains its standard behavior. + 2012-02-12 16:44 UTC+0100 Viktor Szakats (harbour syenar.net) * INSTALL + added to self-contained source code example text: diff --git a/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.cpp b/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.cpp index ca80e08876..bd3849c149 100644 --- a/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.cpp +++ b/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.cpp @@ -802,36 +802,60 @@ void HBQPlainTextEdit::dropEvent( QDropEvent *event ) if( event->dropAction() == Qt::CopyAction || event->dropAction() == Qt::MoveAction ) { if( event->source() == this ) - { - QTextCursor c = cursorForPosition( event->pos() ); - int row = c.blockNumber(); + { + QPoint p( event->pos() ); - hbCopy(); - if( event->dropAction() != Qt::CopyAction ) + event->ignore(); + + QTextCursor c = cursorForPosition( p ); + int row = c.blockNumber(); + int col = c.columnNumber(); + + if( row >= rowBegins && row <= rowEnds ) { - int linesBefore = blockCount(); - this->hbCut( Qt::Key_Delete ); - int linesAfter = blockCount(); - - QTextCursor c( textCursor() ); - c.movePosition( QTextCursor::Start ); - c.movePosition( QTextCursor::Down, QTextCursor::MoveAnchor, row + ( linesAfter - linesBefore ) ); + selectionState = 0; + hbClearSelection(); setTextCursor( c ); } else - { - setTextCursor( cursorForPosition( event->pos() ) ); - } - selectionState = 0; - hbClearSelection(); + { + hbCopy(); + if( event->dropAction() != Qt::CopyAction ) + { + int rBgn = rowBegins; + int rEnd = rowEnds; + int linesBefore = blockCount(); + hbCut( Qt::Key_Delete ); + int linesAfter = blockCount(); + QTextCursor cc( textCursor() ); + cc.movePosition( QTextCursor::Start ); + + if( rBgn > row ) + { + cc.movePosition( QTextCursor::Down, QTextCursor::MoveAnchor, row ); + } + else if( row > rEnd ) + { + cc.movePosition( QTextCursor::Down, QTextCursor::MoveAnchor, row - ( linesBefore - linesAfter ) ); + } + cc.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor, col ); + setTextCursor( cc ); + } + else + { + setTextCursor( c ); + } + selectionState = 0; + hbClearSelection(); + hbPaste(); + } + emit selectionChanged(); - hbPaste(); + /* It is a hack. Without this editing caret is lost ??? */ + QMimeData * data = new QMimeData(); + QDropEvent * ev = new QDropEvent( p, Qt::CopyAction, data, 0, 0 ); + QPlainTextEdit::dropEvent( ev ); - QPlainTextEdit::dropEvent( event ); - c = textCursor(); - c.movePosition( QTextCursor::Left, QTextCursor::KeepAnchor, 1 ); - c.removeSelectedText(); - setTextCursor( c ); return; } } @@ -950,26 +974,25 @@ void HBQPlainTextEdit::mousePressEvent( QMouseEvent *event ) { if( event->buttons() & Qt::LeftButton ) { + setCursorWidth( 1 ); + QTextCursor c( cursorForPosition( event->pos() ) ); int row = c.blockNumber(); - if( selectionState == 1 && row >= rowBegins && row <= rowEnds ) + if( row >= rowBegins && row <= rowEnds ) { event->ignore(); QDrag * qDrag = new QDrag( this ); QMimeData * qMimeData = new QMimeData(); - qMimeData->setText( " " ); + hbCopy(); + qMimeData->setText( QApplication::clipboard()->text() ); qDrag->setMimeData( qMimeData ); qDrag->exec( Qt::MoveAction | Qt::CopyAction ); delete qDrag; - emit selectionChanged(); - QTextCursor c( textCursor() ); - setTextCursor( c ); return; } else { - setCursorWidth( 1 ); if( ! isSelectionPersistent ) { selectionState = 0; diff --git a/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.h b/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.h index dbacc072fc..a0b992c57c 100644 --- a/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.h +++ b/harbour/contrib/hbqt/qtgui/hbqt_hbqplaintextedit.h @@ -59,6 +59,7 @@ #include #include +#include #include #include #include