draganddrop: all classes build and are enabled

This commit is contained in:
Sebastian Kügler 2013-02-27 19:24:44 +01:00
parent b60983ca1f
commit 3ee1474c17
7 changed files with 48 additions and 53 deletions

View File

@ -4,18 +4,12 @@ include(KDE4Defaults)
set(declarativedragdrop_SRCS set(declarativedragdrop_SRCS
draganddropplugin.cpp draganddropplugin.cpp
# DeclarativeDragArea.cpp DeclarativeDragArea.cpp
DeclarativeDragDropEvent.cpp DeclarativeDragDropEvent.cpp
DeclarativeDropArea.cpp DeclarativeDropArea.cpp
DeclarativeMimeData.cpp DeclarativeMimeData.cpp
) )
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${KDE4_INCLUDES}
)
qt4_automoc(${declarativedragdrop_SRCS}) qt4_automoc(${declarativedragdrop_SRCS})
@ -24,6 +18,7 @@ target_link_libraries(draganddropplugin
${QT_QTCORE_LIBRARY} ${QT_QTCORE_LIBRARY}
${Qt5Quick_LIBRARIES} ${Qt5Quick_LIBRARIES}
${Qt5Qml_LIBRARIES} ${Qt5Qml_LIBRARIES}
${QT_QTGUI_LIBRARY}
) )
install(TARGETS draganddropplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/draganddrop) install(TARGETS draganddropplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/draganddrop)

View File

@ -29,8 +29,6 @@
#include <QMimeData> #include <QMimeData>
#include <QMouseEvent> #include <QMouseEvent>
#include <QApplication> #include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QQmlContext> #include <QQmlContext>
/*! /*!
@ -192,17 +190,23 @@ void DeclarativeDragArea::setDefaultAction(Qt::DropAction action)
} }
} }
void DeclarativeDragArea::mousePressEvent(QMouseEvent* event)
{
m_buttonDownPos = event->screenPos();
}
void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event) void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event)
{ {
if ( !m_enabled if ( !m_enabled
|| QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length() || QLineF(event->screenPos(), m_buttonDownPos).length()
< m_startDragDistance) { < m_startDragDistance) {
return; return;
} }
emit dragStarted(); emit dragStarted();
QDrag *drag = new QDrag(event->widget()); QDrag *drag = new QDrag(parent());
DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it. DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it.
drag->setMimeData(dataCopy); drag->setMimeData(dataCopy);
@ -210,22 +214,23 @@ void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event)
drag->setPixmap(QPixmap::fromImage(m_delegateImage)); drag->setPixmap(QPixmap::fromImage(m_delegateImage));
} else if (m_delegate) { } else if (m_delegate) {
// Render the delegate to a Pixmap // Render the delegate to a Pixmap
QQuickItem* item = qobject_cast<QQuickItem *>(m_delegate->create(m_delegate->creationContext())); // QQuickItem* item = qobject_cast<QQuickItem *>(m_delegate->create(m_delegate->creationContext()));
QGraphicsScene scene; // QGraphicsScene scene;
scene.addItem(item); // scene.addItem(item);
QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height()); // QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height());
pixmap.fill(Qt::transparent); // pixmap.fill(Qt::transparent);
//
QPainter painter(&pixmap); // QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing); // painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform); // painter.setRenderHint(QPainter::SmoothPixmapTransform);
scene.render(&painter); // scene.render(&painter);
painter.end(); // painter.end();
delete item; // delete item;
//
drag->setPixmap(pixmap); // drag->setPixmap(pixmap);
drag->setPixmap(QIcon::fromTheme("plasma").pixmap(64,64));
} }
drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); // TODO: Make a property for that drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); // TODO: Make a property for that
@ -236,8 +241,7 @@ void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event)
emit drop(action); emit drop(action);
} }
bool DeclarativeDragArea::childMouseEventFilter(QQuickItem *item, QEvent *event); bool DeclarativeDragArea::childMouseEventFilter(QQuickItem *item, QEvent *event)
{ {
if (!isEnabled()) { if (!isEnabled()) {
return false; return false;

View File

@ -132,7 +132,7 @@ signals:
protected: protected:
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *) {} void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *) {} void mouseReleaseEvent(QMouseEvent *) {}
bool childMouseEventFilter(QQuickItem *item, QEvent *event); bool childMouseEventFilter(QQuickItem *item, QEvent *event);
//bool sceneEventFilter(QGraphicsItem *item, QEvent *event); //bool sceneEventFilter(QGraphicsItem *item, QEvent *event);
@ -147,6 +147,7 @@ private:
DeclarativeMimeData* const m_data; DeclarativeMimeData* const m_data;
QImage m_delegateImage; QImage m_delegateImage;
int m_startDragDistance; int m_startDragDistance;
QPointF m_buttonDownPos;
}; };
#endif // DECLARATIVEDRAGAREA_H #endif // DECLARATIVEDRAGAREA_H

View File

@ -33,7 +33,13 @@ DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDropEvent* e, DeclarativeDro
m_data(e->mimeData()), m_data(e->mimeData()),
m_event(e) m_event(e)
{ {
init(); QPointF pos;
if (parent) {
pos = parent->mapFromScene(e->pos());
m_x = pos.x();
m_y = pos.y();
}
} }
DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDragLeaveEvent* e, DeclarativeDropArea* parent) : DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDragLeaveEvent* e, DeclarativeDropArea* parent) :
@ -45,17 +51,7 @@ DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDragLeaveEvent* e, Declarati
//m_data(e->mimeData()), //m_data(e->mimeData()),
m_event(0) m_event(0)
{ {
} Q_UNUSED(e);
void DeclarativeDragDropEvent::init()
{
QPointF pos;
if (parent()) {
//pos = parent->mapFromScene(e->scenePos());
m_x = pos.x();
m_y = pos.y();
}
} }
void DeclarativeDragDropEvent::accept(int action) void DeclarativeDragDropEvent::accept(int action)

View File

@ -110,7 +110,6 @@ public Q_SLOTS:
void accept(int action); void accept(int action);
private: private:
void init();
int m_x; int m_x;
int m_y; int m_y;
Qt::MouseButtons m_buttons; Qt::MouseButtons m_buttons;

View File

@ -24,19 +24,19 @@
#include <QtQml> #include <QtQml>
// #include "DeclarativeDragArea.h" #include "DeclarativeDragArea.h"
// #include "DeclarativeDragDropEvent.h" #include "DeclarativeDragDropEvent.h"
// #include "DeclarativeDropArea.h" #include "DeclarativeDropArea.h"
// #include "DeclarativeMimeData.h" #include "DeclarativeMimeData.h"
void DragAndDropPlugin::registerTypes(const char *uri) void DragAndDropPlugin::registerTypes(const char *uri)
{ {
Q_ASSERT(uri == QLatin1String("org.kde.draganddrop")); Q_ASSERT(uri == QLatin1String("org.kde.draganddrop"));
// qmlRegisterType<DeclarativeDropArea>(uri, 1, 0, "DropArea"); qmlRegisterType<DeclarativeDropArea>(uri, 1, 0, "DropArea");
// qmlRegisterType<DeclarativeDragArea>(uri, 1, 0, "DragArea"); qmlRegisterType<DeclarativeDragArea>(uri, 1, 0, "DragArea");
// qmlRegisterUncreatableType<DeclarativeMimeData>(uri, 1, 0, "MimeData", "MimeData cannot be created from QML."); qmlRegisterUncreatableType<DeclarativeMimeData>(uri, 1, 0, "MimeData", "MimeData cannot be created from QML.");
// qmlRegisterUncreatableType<DeclarativeDragDropEvent>(uri, 1, 0, "DragDropEvent", "DragDropEvent cannot be created from QML."); qmlRegisterUncreatableType<DeclarativeDragDropEvent>(uri, 1, 0, "DragDropEvent", "DragDropEvent cannot be created from QML.");
} }
//Q_EXPORT_PLUGIN2(draganddropplugin, DragAndDropPlugin) //Q_EXPORT_PLUGIN2(draganddropplugin, DragAndDropPlugin)