You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.6 KiB
143 lines
3.6 KiB
15 years ago
|
/**********************************************************************
|
||
|
** Copyright (C) 2002 Trolltech AS. All rights reserved.
|
||
|
**
|
||
14 years ago
|
** This file is part of TQt Designer.
|
||
15 years ago
|
**
|
||
|
** This file may be distributed and/or modified under the terms of the
|
||
|
** GNU General Public License version 2 as published by the Free Software
|
||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||
|
** packaging of this file.
|
||
|
**
|
||
14 years ago
|
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
|
||
|
** licenses may use this file in accordance with the TQt Commercial License
|
||
15 years ago
|
** Agreement provided with the Software.
|
||
|
**
|
||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
|
**
|
||
|
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
||
|
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
||
14 years ago
|
** information about TQt Commercial License Agreements.
|
||
15 years ago
|
**
|
||
|
** Contact info@trolltech.com if any conditions of this licensing are
|
||
|
** not clear to you.
|
||
|
**
|
||
|
**********************************************************************/
|
||
|
|
||
|
#include "listdnd.h"
|
||
15 years ago
|
#include <tqwidget.h>
|
||
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
15 years ago
|
ListDnd::ListDnd( TQScrollView * eventSource, const char * name )
|
||
|
: TQObject( eventSource, name ),
|
||
15 years ago
|
dragInside( FALSE ), dragDelete( TRUE ), dropConfirmed( FALSE ), dMode( Both )
|
||
|
{
|
||
|
src = eventSource;
|
||
|
src->setAcceptDrops( TRUE );
|
||
|
src->installEventFilter( this );
|
||
|
src->viewport()->installEventFilter( this );
|
||
|
|
||
14 years ago
|
line = new TQWidget( src->viewport(), 0, TQt::WStyle_NoBorder | WStyle_StaysOnTop );
|
||
|
line->setBackgroundColor( TQt::black );
|
||
15 years ago
|
line->resize( src->viewport()->width(), 2 );
|
||
|
line->hide();
|
||
|
}
|
||
|
|
||
|
void ListDnd::setDragMode( int mode )
|
||
|
{
|
||
|
dMode = mode;
|
||
|
}
|
||
|
|
||
|
int ListDnd::dragMode() const
|
||
|
{
|
||
|
return dMode;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ListDnd::eventFilter( TQObject *, TQEvent * event )
|
||
15 years ago
|
{
|
||
|
switch ( event->type() ) {
|
||
15 years ago
|
case TQEvent::DragEnter:
|
||
|
return dragEnterEvent( (TQDragEnterEvent *) event );
|
||
|
case TQEvent::DragLeave:
|
||
|
return dragLeaveEvent( (TQDragLeaveEvent *) event );
|
||
|
case TQEvent::DragMove:
|
||
|
return dragMoveEvent( (TQDragMoveEvent *) event );
|
||
|
case TQEvent::Drop:
|
||
|
return dropEvent( (TQDropEvent *) event );
|
||
|
case TQEvent::MouseButtonPress:
|
||
|
return mousePressEvent( (TQMouseEvent *) event );
|
||
|
case TQEvent::MouseMove:
|
||
|
return mouseMoveEvent( (TQMouseEvent *) event );
|
||
15 years ago
|
default:
|
||
|
break;
|
||
|
}
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
bool ListDnd::dragEnterEvent( TQDragEnterEvent * event )
|
||
15 years ago
|
{
|
||
|
if ( dMode == None ) {
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
bool ok = ( ( ( dMode & Both ) == Both ) ||
|
||
|
( ( dMode & Internal ) && ( event->source() == src ) ) ||
|
||
|
( ( dMode & External ) && ( event->source() != src ) ) );
|
||
|
|
||
|
if ( ok && canDecode( event ) ) {
|
||
|
event->accept();
|
||
|
dragInside = TRUE;
|
||
|
if ( !( dMode & NullDrop ) ) {
|
||
|
updateLine( event->pos() );
|
||
|
line->show();
|
||
|
}
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ListDnd::dragLeaveEvent( TQDragLeaveEvent * )
|
||
15 years ago
|
{
|
||
|
dragInside = FALSE;
|
||
|
line->hide();
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ListDnd::dragMoveEvent( TQDragMoveEvent * event )
|
||
15 years ago
|
{
|
||
|
if ( dragInside && dMode && !( dMode & NullDrop ) ) {
|
||
|
updateLine( event->pos() );
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ListDnd::dropEvent( TQDropEvent * )
|
||
15 years ago
|
{
|
||
|
// do nothing
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ListDnd::mousePressEvent( TQMouseEvent * event )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( event->button() == Qt::LeftButton )
|
||
15 years ago
|
mousePressPos = event->pos();
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ListDnd::mouseMoveEvent( TQMouseEvent * )
|
||
15 years ago
|
{
|
||
|
// do nothing
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
15 years ago
|
void ListDnd::updateLine( const TQPoint & )
|
||
15 years ago
|
{
|
||
|
// do nothing
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ListDnd::canDecode( TQDragEnterEvent * )
|
||
15 years ago
|
{
|
||
|
// do nothing
|
||
|
return FALSE;
|
||
|
}
|