2012-02-03 17:26 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtgui/hbqt_hbqplaintextedit.cpp
* contrib/hbqt/qtgui/hbqt_hbqplaintextedit.h
+ Implemented: Drag & Drop of selected text.
It confirms to the standard Windows behavior per drop protocol,
and in addition, also confirms to the hbIDE's column-selection mode.
This commit is contained in:
@@ -16,6 +16,13 @@
|
||||
The license applies to all entries newer than 2009-04-28.
|
||||
*/
|
||||
|
||||
2012-02-03 17:26 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
|
||||
* contrib/hbqt/qtgui/hbqt_hbqplaintextedit.cpp
|
||||
* contrib/hbqt/qtgui/hbqt_hbqplaintextedit.h
|
||||
+ Implemented: Drag & Drop of selected text.
|
||||
It confirms to the standard Windows behavior per drop protocol,
|
||||
and in addition, also confirms to the hbIDE's column-selection mode.
|
||||
|
||||
2012-02-02 10:32 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
|
||||
* contrib/gtwvg/wvgcrt.prg
|
||||
* contrib/gtwvg/wvgwnd.prg
|
||||
|
||||
@@ -128,7 +128,8 @@ HBQPlainTextEdit::HBQPlainTextEdit( QWidget * parent ) : QPlainTextEdit( parent
|
||||
isAliasCompleter = false;
|
||||
isCodeCompletionActive = true;
|
||||
isCompletionTipsActive = true;
|
||||
|
||||
isInDrag = false;
|
||||
|
||||
#if 0
|
||||
QTextFrameFormat format( this->document()->rootFrame()->frameFormat() );
|
||||
format.setMargin( 0 );
|
||||
@@ -184,6 +185,8 @@ HBQPlainTextEdit::HBQPlainTextEdit( QWidget * parent ) : QPlainTextEdit( parent
|
||||
|
||||
highlighter = NULL;
|
||||
block = NULL;
|
||||
|
||||
setAcceptDrops( true );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@@ -258,7 +261,7 @@ HBQPlainTextEdit::~HBQPlainTextEdit()
|
||||
disconnect( this, SIGNAL( cursorPositionChanged() ) );
|
||||
|
||||
delete lineNumberArea;
|
||||
|
||||
|
||||
if( block )
|
||||
hb_itemRelease( block );
|
||||
}
|
||||
@@ -794,6 +797,93 @@ void HBQPlainTextEdit::hbPaste()
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
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();
|
||||
|
||||
hbCopy();
|
||||
if( event->dropAction() != Qt::CopyAction )
|
||||
{
|
||||
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 ) );
|
||||
setTextCursor( c );
|
||||
}
|
||||
else
|
||||
{
|
||||
setTextCursor( cursorForPosition( event->pos() ) );
|
||||
}
|
||||
selectionState = 0;
|
||||
hbClearSelection();
|
||||
|
||||
hbPaste();
|
||||
|
||||
QPlainTextEdit::dropEvent( event );
|
||||
c = textCursor();
|
||||
c.movePosition( QTextCursor::Left, QTextCursor::KeepAnchor, 1 );
|
||||
c.removeSelectedText();
|
||||
setTextCursor( c );
|
||||
return;
|
||||
}
|
||||
}
|
||||
QPlainTextEdit::dropEvent( event );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
void HBQPlainTextEdit::dragMoveEvent( QDragMoveEvent *event )
|
||||
{
|
||||
if( event->mimeData()->hasText() )
|
||||
{
|
||||
if( event->source() == this )
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
QPlainTextEdit::dragMoveEvent( event );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
void HBQPlainTextEdit::dragEnterEvent( QDragEnterEvent *event )
|
||||
{
|
||||
if( event->mimeData()->hasText() )
|
||||
{
|
||||
if( event->source() == this )
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
QPlainTextEdit::dragEnterEvent( event );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
void HBQPlainTextEdit::mouseDoubleClickEvent( QMouseEvent *event )
|
||||
{
|
||||
QPlainTextEdit::mouseDoubleClickEvent( event );
|
||||
@@ -860,15 +950,35 @@ void HBQPlainTextEdit::mousePressEvent( QMouseEvent *event )
|
||||
{
|
||||
if( event->buttons() & Qt::LeftButton )
|
||||
{
|
||||
setCursorWidth( 1 );
|
||||
if( ! isSelectionPersistent )
|
||||
QTextCursor c( cursorForPosition( event->pos() ) );
|
||||
int row = c.blockNumber();
|
||||
|
||||
if( selectionState == 1 && row >= rowBegins && row <= rowEnds )
|
||||
{
|
||||
selectionState = 0;
|
||||
hbClearSelection();
|
||||
event->ignore();
|
||||
QDrag * qDrag = new QDrag( this );
|
||||
QMimeData * qMimeData = new QMimeData();
|
||||
qMimeData->setText( " " );
|
||||
qDrag->setMimeData( qMimeData );
|
||||
qDrag->exec( Qt::MoveAction | Qt::CopyAction );
|
||||
delete qDrag;
|
||||
emit selectionChanged();
|
||||
QTextCursor c( textCursor() );
|
||||
setTextCursor( c );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectionState = 1;
|
||||
{
|
||||
setCursorWidth( 1 );
|
||||
if( ! isSelectionPersistent )
|
||||
{
|
||||
selectionState = 0;
|
||||
hbClearSelection();
|
||||
}
|
||||
else
|
||||
{
|
||||
selectionState = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
QPlainTextEdit::mousePressEvent( event );
|
||||
@@ -1043,30 +1153,11 @@ bool HBQPlainTextEdit::hbKeyPressSelectionByApplication( QKeyEvent * event )
|
||||
break;
|
||||
}
|
||||
case Qt::Key_Home:
|
||||
{
|
||||
QPlainTextEdit::keyPressEvent( event );
|
||||
columnEnds = textCursor().columnNumber();
|
||||
break;
|
||||
}
|
||||
case Qt::Key_End:
|
||||
{
|
||||
QPlainTextEdit::keyPressEvent( event );
|
||||
columnEnds = textCursor().columnNumber();
|
||||
break;
|
||||
#if 0
|
||||
QTextCursor c( textCursor() );
|
||||
c.movePosition( QTextCursor::EndOfLine, QTextCursor::MoveAnchor );
|
||||
if( c.columnNumber() <= columnEnds )
|
||||
{
|
||||
QPlainTextEdit::keyPressEvent( event );
|
||||
columnEnds = textCursor().columnNumber();;
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_PageUp:
|
||||
|
||||
@@ -59,7 +59,11 @@
|
||||
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
#include <QtCore/QtCore>
|
||||
#include <QtCore/QMimeData>
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtGui/QDragEnterEvent>
|
||||
#include <QtGui/QDragMoveEvent>
|
||||
#include <QtGui/QDropEvent>
|
||||
#include <QtGui/QTextBlock>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QMessageBox>
|
||||
@@ -168,7 +172,8 @@ private:
|
||||
bool isAliasCompleter;
|
||||
bool isCodeCompletionActive;
|
||||
bool isCompletionTipsActive;
|
||||
|
||||
bool isInDrag;
|
||||
|
||||
protected:
|
||||
bool event( QEvent * event );
|
||||
void resizeEvent( QResizeEvent * event );
|
||||
@@ -179,6 +184,9 @@ protected:
|
||||
void focusInEvent( QFocusEvent * event );
|
||||
void keyPressEvent( QKeyEvent * event );
|
||||
void keyReleaseEvent( QKeyEvent * event );
|
||||
void dragEnterEvent( QDragEnterEvent * event );
|
||||
void dragMoveEvent( QDragMoveEvent * event );
|
||||
void dropEvent( QDropEvent * event );
|
||||
|
||||
public slots:
|
||||
QString hbTextAlias();
|
||||
|
||||
Reference in New Issue
Block a user