#include <dragwidget.h>
Inheritance diagram for DragWidget:


Definition at line 32 of file dragwidget.h.
Public Member Functions | |
| DragWidget (QWidget *parent=0) | |
| DragWidget (QWidget *parent=0) | |
| DragWidget (QWidget *parent=0) | |
Protected Member Functions | |
| void | dragEnterEvent (QDragEnterEvent *event) |
| void | dropEvent (QDropEvent *event) |
| void | mousePressEvent (QMouseEvent *event) |
| void | dragEnterEvent (QDragEnterEvent *event) |
| void | dropEvent (QDropEvent *event) |
| void | dragMoveEvent (QDragMoveEvent *event) |
| void | dragEnterEvent (QDragEnterEvent *event) |
| void | dragMoveEvent (QDragMoveEvent *event) |
| void | dropEvent (QDropEvent *event) |
| DragWidget::DragWidget | ( | QWidget * | parent = 0 |
) |
Definition at line 28 of file dragwidget.cpp.
References QWidget::move(), QWidget::QPixmap, QWidget::setAcceptDrops(), QWidget::setAttribute(), QFrame::setFrameStyle(), QWidget::setMinimumSize(), QLabel::setPixmap(), QWidget::show(), QFrame::StyledPanel, QFrame::Sunken, and Qt::WA_DeleteOnClose.
00029 : QFrame(parent) 00030 { 00031 setMinimumSize(200, 200); 00032 setFrameStyle(QFrame::Sunken | QFrame::StyledPanel); 00033 setAcceptDrops(true); 00034 00035 QLabel *boatIcon = new QLabel(this); 00036 boatIcon->setPixmap(QPixmap(":/images/boat.png")); 00037 boatIcon->move(20, 20); 00038 boatIcon->show(); 00039 boatIcon->setAttribute(Qt::WA_DeleteOnClose); 00040 00041 QLabel *carIcon = new QLabel(this); 00042 carIcon->setPixmap(QPixmap(":/images/car.png")); 00043 carIcon->move(120, 20); 00044 carIcon->show(); 00045 carIcon->setAttribute(Qt::WA_DeleteOnClose); 00046 00047 QLabel *houseIcon = new QLabel(this); 00048 houseIcon->setPixmap(QPixmap(":/images/house.png")); 00049 houseIcon->move(20, 120); 00050 houseIcon->show(); 00051 houseIcon->setAttribute(Qt::WA_DeleteOnClose); 00052 }
Here is the call graph for this function:

| DragWidget::DragWidget | ( | QWidget * | parent = 0 |
) |
| DragWidget::DragWidget | ( | QWidget * | parent = 0 |
) |
| void DragWidget::dragEnterEvent | ( | QDragEnterEvent * | event | ) | [protected, virtual] |
This event handler is called when a drag is in progress and the mouse enters this widget. The event is passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
Definition at line 54 of file dragwidget.cpp.
References QWidget::event(), and Qt::MoveAction.
00055 { 00056 if (event->mimeData()->hasFormat("application/x-dnditemdata")) { 00057 if (event->source() == this) { 00058 event->setDropAction(Qt::MoveAction); 00059 event->accept(); 00060 } else { 00061 event->acceptProposedAction(); 00062 } 00063 } else { 00064 event->ignore(); 00065 } 00066 }
Here is the call graph for this function:

| void DragWidget::dropEvent | ( | QDropEvent * | event | ) | [protected, virtual] |
This event handler is called when the drag is dropped on this widget which are passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
Definition at line 68 of file dragwidget.cpp.
References QWidget::event(), QWidget::move(), Qt::MoveAction, QIODevice::ReadOnly, QWidget::setAttribute(), QLabel::setPixmap(), QWidget::show(), and Qt::WA_DeleteOnClose.
00069 { 00070 if (event->mimeData()->hasFormat("application/x-dnditemdata")) { 00071 QByteArray itemData = event->mimeData()->data("application/x-dnditemdata"); 00072 QDataStream dataStream(&itemData, QIODevice::ReadOnly); 00073 00074 QPixmap pixmap; 00075 QPoint offset; 00076 dataStream >> pixmap >> offset; 00077 00078 QLabel *newIcon = new QLabel(this); 00079 newIcon->setPixmap(pixmap); 00080 newIcon->move(event->pos() - offset); 00081 newIcon->show(); 00082 newIcon->setAttribute(Qt::WA_DeleteOnClose); 00083 00084 if (event->source() == this) { 00085 event->setDropAction(Qt::MoveAction); 00086 event->accept(); 00087 } else { 00088 event->acceptProposedAction(); 00089 } 00090 } else { 00091 event->ignore(); 00092 } 00093 }
Here is the call graph for this function:

| void DragWidget::mousePressEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.
If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.
The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.
Reimplemented from QWidget.
Definition at line 95 of file dragwidget.cpp.
References QPainter::begin(), QWidget::childAt(), QWidget::close(), Qt::CopyAction, QPainter::end(), QWidget::event(), QPainter::fillRect(), Qt::MoveAction, QLabel::pixmap(), QWidget::pos(), QPixmap::rect(), QDrag::setHotSpot(), QDrag::setMimeData(), QLabel::setPixmap(), QDrag::setPixmap(), QWidget::show(), QDrag::start(), and QIODevice::WriteOnly.
00096 { 00097 QLabel *child = static_cast<QLabel*>(childAt(event->pos())); 00098 if (!child) 00099 return; 00100 00101 QPixmap pixmap = *child->pixmap(); 00102 00103 QByteArray itemData; 00104 QDataStream dataStream(&itemData, QIODevice::WriteOnly); 00105 dataStream << pixmap << QPoint(event->pos() - child->pos()); 00106 00107 QMimeData *mimeData = new QMimeData; 00108 mimeData->setData("application/x-dnditemdata", itemData); 00109 00110 QDrag *drag = new QDrag(this); 00111 drag->setMimeData(mimeData); 00112 drag->setPixmap(pixmap); 00113 drag->setHotSpot(event->pos() - child->pos()); 00114 00115 QPixmap tempPixmap = pixmap; 00116 QPainter painter; 00117 painter.begin(&tempPixmap); 00118 painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127)); 00119 painter.end(); 00120 00121 child->setPixmap(tempPixmap); 00122 00123 if (drag->start(Qt::CopyAction | Qt::MoveAction) == Qt::MoveAction) 00124 child->close(); 00125 else { 00126 child->show(); 00127 child->setPixmap(pixmap); 00128 } 00129 }
Here is the call graph for this function:

| void DragWidget::dragEnterEvent | ( | QDragEnterEvent * | event | ) | [protected, virtual] |
This event handler is called when a drag is in progress and the mouse enters this widget. The event is passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
| void DragWidget::dropEvent | ( | QDropEvent * | event | ) | [protected, virtual] |
This event handler is called when the drag is dropped on this widget which are passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
| void DragWidget::dragMoveEvent | ( | QDragMoveEvent * | event | ) | [protected, virtual] |
This event handler is called if a drag is in progress, and when any of the following conditions occurs: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. The event is passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
Definition at line 77 of file dragwidget.cpp.
References QObject::children(), and QWidget::event().
00078 { 00079 if (event->mimeData()->hasText()) { 00080 if (children().contains(event->source())) { 00081 event->setDropAction(Qt::MoveAction); 00082 event->accept(); 00083 } else { 00084 event->acceptProposedAction(); 00085 } 00086 } else { 00087 event->ignore(); 00088 } 00089 }
Here is the call graph for this function:

| void DragWidget::dragEnterEvent | ( | QDragEnterEvent * | event | ) | [protected, virtual] |
This event handler is called when a drag is in progress and the mouse enters this widget. The event is passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
| void DragWidget::dragMoveEvent | ( | QDragMoveEvent * | event | ) | [protected, virtual] |
This event handler is called if a drag is in progress, and when any of the following conditions occurs: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. The event is passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
| void DragWidget::dropEvent | ( | QDropEvent * | event | ) | [protected, virtual] |
This event handler is called when the drag is dropped on this widget which are passed in the event parameter.
See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.
Reimplemented from QWidget.
1.5.1