class KDNDWidget

A widget for drag support. More...

Definition#include <drag.h>
InheritsQWidget (qt)
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Members

Protected Members


Detailed Description

A widget for drag support.

If you require only drop support you dont need this widget, you just need KDndDropZone.

KDNDWidget ( QWidget *_parent=0, const char *_name=0, WFlags f=0 )

Constructor.

~KDNDWidget ()
[virtual]

Destructor.

void startDrag ( KDNDIcon *_icon, char *_data, int _size, int _type, int _dx, int _dy )
[virtual]

Start a drag.

Call this function when you notice that the user wants to drag something around, usually from a dndMouseMoveEvent.

Parameters:
_iconThe icon that the user can drag around.
_dataA pointer to the data being dragged. A deep copy is made of this data, so you don't need to maintain its value after you call this function.
_sizeThe length of the data pointed to by _data.
_typeThe type of the data that is being dragged, eg DndURL.
_dx,_dy The difference between the icons upper left corner and the mouse pointer. For example when the user clicks the mouse over the middle of a pixmap, _dx and _dy would be ' - pixmap.width() / 2 ' and ' - pixmap.height() / 2 '. This is just provided for look and feel.

Window findRootWindow ( QPoint & p )
[protected virtual]

Finds the root window belonging to the global point p.

void mouseMoveEvent ( QMouseEvent * )
[protected virtual]

This function MUST be called by your implementation if you overload it.

In nearly all cases, you probably mean to call dndMouseMoveEvent().

See also: dndMouseMoveEvent

void mouseReleaseEvent ( QMouseEvent * )
[protected virtual]

This function MUST be called by your implementation if you overload it.

In nearly all cases, you probably mean to call dndMouseReleaseEvent().

See also: dndMouseReleaseEvent

void rootDropEvent ( int _x, int _y )
[protected virtual]

A root drop occurred.

At the point (_x,_y) the user dropped the icon. If there is now window below this point, this function is called. Usually it emits a XEvent, so that every application gets informed about this. This function is only called if the drag started in this widget.

See KApplication for details on receiving root drop events.

void rootDropEvent ()
[protected virtual]

Perform internal housekeeping after a root drop event.

If you must overload rootDropEvent(...), call this function at the end to do some clean up.

void dragEndEvent ()
[protected virtual]

Called when a drag is ended.

This function is only called if the drag started in this widget. Overload it to do your own clean up.

void dndMouseMoveEvent ( QMouseEvent * )
[protected virtual]

Overload this instead of mouseMoveEvent. Ususally drags are started in this functions. A implementation might look like this:


 void KFileView::dndMouseMoveEvent( QMouseEvent * _mouse )
    {
    // 'pressed' is set in mousePressedEvent(...)
    if ( !pressed )
	return;

    int x = _mouse->pos().x();
    int y = _mouse->pos().y();

    if ( abs( x - press_x ) > Dnd_X_Precision || abs( y - press_y ) > Dnd_Y_Precision )
    {
        QString data = "Transfer me";
	QPoint p = mapToGlobal( _mouse->pos() );
	QPixmap pixmap = typ->getPixmap( filename );
	int dx = - pixmap.width() / 2;
	int dy = - pixmap.height() / 2;

	startDrag( new KDNDIcon( pixmap, p.x() + dx, p.y() + dy ), data.data(), data.length(), DndText, dx, dy );
    }
    else
    {
      Do something different
    }

The function is only called if the mouse movement was not part of a drag process.

void dndMouseReleaseEvent ( QMouseEvent * )
[protected virtual]

Your mouse release event function.

Usually you will only set 'pressed' ( see dndMouseMoveEvent) to FALSE here. The function is only called if the release event had nothing to do with DND.

bool drag
[protected]

Are we just doing DND ?

char * dndData
[protected]

The data that is currently dragged.

int dndSize
[protected]

data size

int dndType
[protected]

data type

int dndOffsetX
[protected]

The offset we got from 'startDrag'

int dndOffsetY
[protected]

The offset we got from 'startDrag'

KDNDIcon * dndIcon
[protected]

The icon we are moving around

Window dndLastWindow
[protected]

The last window we entered with the mouse pointer.