diff --git a/src/declarativeimports/draganddrop/CMakeLists.txt b/src/declarativeimports/draganddrop/CMakeLists.txt index d9a3813b0..7350bccbd 100644 --- a/src/declarativeimports/draganddrop/CMakeLists.txt +++ b/src/declarativeimports/draganddrop/CMakeLists.txt @@ -19,9 +19,13 @@ INCLUDE_DIRECTORIES( qt4_automoc(${declarativedragdrop_SRCS}) -kde4_add_library(draganddropplugin SHARED ${declarativedragdrop_SRCS}) -target_link_libraries(draganddropplugin ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY}) +add_library(draganddropplugin SHARED ${declarativedragdrop_SRCS}) +target_link_libraries(draganddropplugin + ${QT_QTCORE_LIBRARY} + ${Qt5Quick_LIBRARIES} + ${Qt5Qml_LIBRARIES} +) -install(TARGETS draganddropplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/draganddrop) +install(TARGETS draganddropplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/draganddrop) -install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/draganddrop) +install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/draganddrop) diff --git a/src/declarativeimports/draganddrop/DeclarativeDragArea.cpp b/src/declarativeimports/draganddrop/DeclarativeDragArea.cpp index 9fa714185..d73496437 100644 --- a/src/declarativeimports/draganddrop/DeclarativeDragArea.cpp +++ b/src/declarativeimports/draganddrop/DeclarativeDragArea.cpp @@ -25,19 +25,20 @@ #include "DeclarativeMimeData.h" #include +#include #include -#include +#include #include #include #include -#include +#include /*! A DragArea is used to make an item draggable. */ -DeclarativeDragArea::DeclarativeDragArea(QDeclarativeItem *parent) - : QDeclarativeItem(parent), +DeclarativeDragArea::DeclarativeDragArea(QQuickItem *parent) + : QQuickItem(parent), m_delegate(0), m_source(0), m_target(0), @@ -48,7 +49,8 @@ DeclarativeDragArea::DeclarativeDragArea(QDeclarativeItem *parent) { m_startDragDistance = QApplication::startDragDistance(); setAcceptedMouseButtons(Qt::LeftButton); - setFiltersChildEvents(true); + //setFiltersChildEvents(true); + setFiltersChildMouseEvents(true); } DeclarativeDragArea::~DeclarativeDragArea() @@ -62,12 +64,12 @@ DeclarativeDragArea::~DeclarativeDragArea() The delegate is the item that will be displayed next to the mouse cursor during the drag and drop operation. It usually consists of a large, semi-transparent icon representing the data being dragged. */ -QDeclarativeComponent* DeclarativeDragArea::delegate() const +QQmlComponent* DeclarativeDragArea::delegate() const { return m_delegate; } -void DeclarativeDragArea::setDelegate(QDeclarativeComponent *delegate) +void DeclarativeDragArea::setDelegate(QQmlComponent *delegate) { if (m_delegate != delegate) { m_delegate = delegate; @@ -83,12 +85,12 @@ void DeclarativeDragArea::resetDelegate() The QML element that is the source of this drag and drop operation. This can be defined to any item, and will be available to the DropArea as event.data.source */ -QDeclarativeItem* DeclarativeDragArea::source() const +QQuickItem* DeclarativeDragArea::source() const { return m_source; } -void DeclarativeDragArea::setSource(QDeclarativeItem* source) +void DeclarativeDragArea::setSource(QQuickItem* source) { if (m_source != source) { m_source = source; @@ -102,7 +104,7 @@ void DeclarativeDragArea::resetSource() } // target -QDeclarativeItem* DeclarativeDragArea::target() const +QQuickItem* DeclarativeDragArea::target() const { //TODO: implement me return 0; @@ -190,7 +192,7 @@ void DeclarativeDragArea::setDefaultAction(Qt::DropAction action) } } -void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event) { if ( !m_enabled || QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length() @@ -208,7 +210,7 @@ void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) drag->setPixmap(QPixmap::fromImage(m_delegateImage)); } else if (m_delegate) { // Render the delegate to a Pixmap - QDeclarativeItem* item = qobject_cast(m_delegate->create(m_delegate->creationContext())); + QQuickItem* item = qobject_cast(m_delegate->create(m_delegate->creationContext())); QGraphicsScene scene; scene.addItem(item); @@ -234,16 +236,17 @@ void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) emit drop(action); } -bool DeclarativeDragArea::sceneEventFilter(QGraphicsItem *item, QEvent *event) +bool DeclarativeDragArea::childMouseEventFilter(QQuickItem *item, QEvent *event); + { if (!isEnabled()) { return false; } - if (event->type() == QEvent::GraphicsSceneMouseMove) { - QGraphicsSceneMouseEvent *me = static_cast(event); + if (event->type() == QEvent::MouseMove) { + QMouseEvent *me = static_cast(event); mouseMoveEvent(me); } - return QDeclarativeItem::sceneEventFilter(item, event); + return QQuickItem::childMouseEventFilter(item, event); } diff --git a/src/declarativeimports/draganddrop/DeclarativeDragArea.h b/src/declarativeimports/draganddrop/DeclarativeDragArea.h index 06f5c705c..c136cdcc5 100644 --- a/src/declarativeimports/draganddrop/DeclarativeDragArea.h +++ b/src/declarativeimports/draganddrop/DeclarativeDragArea.h @@ -24,12 +24,13 @@ #ifndef DECLARATIVEDRAGAREA_H #define DECLARATIVEDRAGAREA_H -#include +#include +#include -class QDeclarativeComponent; +class QQmlComponent; class DeclarativeMimeData; -class DeclarativeDragArea : public QDeclarativeItem +class DeclarativeDragArea : public QQuickItem { Q_OBJECT @@ -37,16 +38,16 @@ class DeclarativeDragArea : public QDeclarativeItem * The delegate is the item that will be displayed next to the mouse cursor during the drag and drop operation. * It usually consists of a large, semi-transparent icon representing the data being dragged. */ - Q_PROPERTY(QDeclarativeComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged RESET resetDelegate) + Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged RESET resetDelegate) /** * The QML element that is the source of the resulting drag and drop operation. This can be defined to any item, and will * be available to the DropArea as event.data.source */ - Q_PROPERTY(QDeclarativeItem* source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource) + Q_PROPERTY(QQuickItem* source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource) //TODO: to be implemented - Q_PROPERTY(QDeclarativeItem* target READ source NOTIFY targetChanged) + Q_PROPERTY(QQuickItem* target READ source NOTIFY targetChanged) /** * the mime data of the drag operation @@ -86,18 +87,18 @@ class DeclarativeDragArea : public QDeclarativeItem Q_PROPERTY(QVariant delegateImage READ delegateImage WRITE setDelegateImage NOTIFY delegateImageChanged) public: - DeclarativeDragArea(QDeclarativeItem *parent=0); + DeclarativeDragArea(QQuickItem *parent=0); ~DeclarativeDragArea(); - QDeclarativeComponent *delegate() const; - void setDelegate(QDeclarativeComponent* delegate); + QQmlComponent *delegate() const; + void setDelegate(QQmlComponent* delegate); void resetDelegate(); QVariant delegateImage() const; void setDelegateImage(const QVariant &image); - QDeclarativeItem* target() const; - QDeclarativeItem* source() const; - void setSource(QDeclarativeItem* source); + QQuickItem* target() const; + QQuickItem* source() const; + void setSource(QQuickItem* source); void resetSource(); bool isEnabled() const; @@ -130,15 +131,16 @@ signals: void delegateImageChanged(); protected: - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mousePressEvent(QGraphicsSceneMouseEvent *) {} - void mouseReleaseEvent(QGraphicsSceneMouseEvent *) {} - bool sceneEventFilter(QGraphicsItem *item, QEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *) {} + void mouseReleaseEvent(QMouseEvent *) {} + bool childMouseEventFilter(QQuickItem *item, QEvent *event); + //bool sceneEventFilter(QGraphicsItem *item, QEvent *event); private: - QDeclarativeComponent* m_delegate; - QDeclarativeItem* m_source; - QDeclarativeItem* m_target; + QQmlComponent* m_delegate; + QQuickItem* m_source; + QQuickItem* m_target; bool m_enabled; Qt::DropActions m_supportedActions; Qt::DropAction m_defaultAction; diff --git a/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.cpp b/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.cpp index aeb70df66..8bab8204b 100644 --- a/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.cpp +++ b/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.cpp @@ -23,7 +23,7 @@ #include "DeclarativeDragDropEvent.h" -DeclarativeDragDropEvent::DeclarativeDragDropEvent(QGraphicsSceneDragDropEvent* e, DeclarativeDropArea* parent) : +DeclarativeDragDropEvent::DeclarativeDragDropEvent(QEvent* e, DeclarativeDropArea* parent) : QObject(parent), m_x(e->pos().x()), m_y(e->pos().y()), diff --git a/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.h b/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.h index cb19af2d9..4ae38c5aa 100644 --- a/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.h +++ b/src/declarativeimports/draganddrop/DeclarativeDragDropEvent.h @@ -95,7 +95,7 @@ class DeclarativeDragDropEvent : public QObject public: - DeclarativeDragDropEvent(QGraphicsSceneDragDropEvent* e, DeclarativeDropArea* parent = 0); + DeclarativeDragDropEvent(QEvent* e, DeclarativeDropArea* parent = 0); int x() const { return m_x; } int y() const { return m_y; } diff --git a/src/declarativeimports/draganddrop/DeclarativeDropArea.cpp b/src/declarativeimports/draganddrop/DeclarativeDropArea.cpp index f1ef54e9c..155692844 100644 --- a/src/declarativeimports/draganddrop/DeclarativeDropArea.cpp +++ b/src/declarativeimports/draganddrop/DeclarativeDropArea.cpp @@ -27,31 +27,34 @@ #include #include -DeclarativeDropArea::DeclarativeDropArea(QDeclarativeItem *parent) - : QDeclarativeItem(parent), +DeclarativeDropArea::DeclarativeDropArea(QQuickItem *parent) + : QQuickItem(parent), m_enabled(true) { - setAcceptDrops(m_enabled); +// setAcceptDrops(m_enabled); + if (m_enabled) { + setFlag(ItemAcceptsDrops); + } } -void DeclarativeDropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event) { +void DeclarativeDropArea::dragEnterEvent(QDragEnterEvent *event) { DeclarativeDragDropEvent dde(event, this); emit dragEnter(&dde); } -void DeclarativeDropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) +void DeclarativeDropArea::dragLeaveEvent(QDragLeaveEvent *event) { DeclarativeDragDropEvent dde(event, this); emit dragLeave(&dde); } -void DeclarativeDropArea::dragMoveEvent(QGraphicsSceneDragDropEvent *event) +void DeclarativeDropArea::dragMoveEvent(QDragMoveEvent *event) { DeclarativeDragDropEvent dde(event, this); emit dragMove(&dde); } -void DeclarativeDropArea::dropEvent(QGraphicsSceneDragDropEvent *event) +void DeclarativeDropArea::dropEvent(QDropEvent *event) { DeclarativeDragDropEvent dde(event, this); emit drop(&dde); diff --git a/src/declarativeimports/draganddrop/DeclarativeDropArea.h b/src/declarativeimports/draganddrop/DeclarativeDropArea.h index d0cf96dd5..0e38de380 100644 --- a/src/declarativeimports/draganddrop/DeclarativeDropArea.h +++ b/src/declarativeimports/draganddrop/DeclarativeDropArea.h @@ -24,11 +24,11 @@ #ifndef DECLARATIVEDROPAREA_H #define DECLARATIVEDROPAREA_H -#include +#include class DeclarativeDragDropEvent; -class DeclarativeDropArea : public QDeclarativeItem +class DeclarativeDropArea : public QQuickItem { Q_OBJECT @@ -38,7 +38,7 @@ class DeclarativeDropArea : public QDeclarativeItem Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) public: - DeclarativeDropArea(QDeclarativeItem *parent=0); + DeclarativeDropArea(QQuickItem *parent=0); bool isEnabled() const; void setEnabled(bool enabled); @@ -74,10 +74,10 @@ Q_SIGNALS: void enabledChanged(); protected: - void dragEnterEvent(QGraphicsSceneDragDropEvent *event); - void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); - void dragMoveEvent(QGraphicsSceneDragDropEvent *event); - void dropEvent(QGraphicsSceneDragDropEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); private: bool m_enabled; diff --git a/src/declarativeimports/draganddrop/DeclarativeMimeData.cpp b/src/declarativeimports/draganddrop/DeclarativeMimeData.cpp index 28532a2de..c966eafdf 100644 --- a/src/declarativeimports/draganddrop/DeclarativeMimeData.cpp +++ b/src/declarativeimports/draganddrop/DeclarativeMimeData.cpp @@ -132,11 +132,11 @@ void DeclarativeMimeData::setData(const QString &mimeType, const QString &data) In the case of inter-application drag and drop operations, the source will not be available, and will be 0. Be sure to test it in your QML code, before using it, or it will generate errors in the console. */ -QDeclarativeItem* DeclarativeMimeData::source() const +QQuickItem* DeclarativeMimeData::source() const { return m_source; } -void DeclarativeMimeData::setSource(QDeclarativeItem* source) +void DeclarativeMimeData::setSource(QQuickItem* source) { if (m_source != source) { m_source = source; diff --git a/src/declarativeimports/draganddrop/DeclarativeMimeData.h b/src/declarativeimports/draganddrop/DeclarativeMimeData.h index 834293888..060c1c5c4 100644 --- a/src/declarativeimports/draganddrop/DeclarativeMimeData.h +++ b/src/declarativeimports/draganddrop/DeclarativeMimeData.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include class DeclarativeMimeData : public QMimeData { @@ -62,7 +62,7 @@ class DeclarativeMimeData : public QMimeData /** * The graphical item on the scene that started the drag event. It may be null. */ - Q_PROPERTY(QDeclarativeItem* source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QQuickItem* source READ source WRITE setSource NOTIFY sourceChanged) //TODO: Image property public: @@ -80,8 +80,8 @@ public: Q_INVOKABLE void setData(const QString &mimeType, const QString &data); - QDeclarativeItem* source() const; - void setSource(QDeclarativeItem* source); + QQuickItem* source() const; + void setSource(QQuickItem* source); /* @@ -100,7 +100,7 @@ signals: void sourceChanged(); private: - QDeclarativeItem* m_source; + QQuickItem* m_source; }; #endif // DECLARATIVEMIMEDATA_H diff --git a/src/declarativeimports/draganddrop/draganddropplugin.cpp b/src/declarativeimports/draganddrop/draganddropplugin.cpp index cd585db82..6835fb72e 100644 --- a/src/declarativeimports/draganddrop/draganddropplugin.cpp +++ b/src/declarativeimports/draganddrop/draganddropplugin.cpp @@ -22,7 +22,7 @@ #include "draganddropplugin.h" -#include +#include #include "DeclarativeDragArea.h" #include "DeclarativeDragDropEvent.h" @@ -34,9 +34,9 @@ void DragAndDropPlugin::registerTypes(const char *uri) Q_ASSERT(uri == QLatin1String("org.kde.draganddrop")); qmlRegisterType(uri, 1, 0, "DropArea"); - qmlRegisterType(uri, 1, 0, "DragArea"); - qmlRegisterUncreatableType(uri, 1, 0, "MimeData", "MimeData cannot be created from QML."); - qmlRegisterUncreatableType(uri, 1, 0, "DragDropEvent", "DragDropEvent cannot be created from QML."); +// qmlRegisterType(uri, 1, 0, "DragArea"); +// qmlRegisterUncreatableType(uri, 1, 0, "MimeData", "MimeData cannot be created from QML."); +// qmlRegisterUncreatableType(uri, 1, 0, "DragDropEvent", "DragDropEvent cannot be created from QML."); } Q_EXPORT_PLUGIN2(draganddropplugin, DragAndDropPlugin) diff --git a/src/declarativeimports/draganddrop/draganddropplugin.h b/src/declarativeimports/draganddrop/draganddropplugin.h index ddcb8a85d..249b6d980 100644 --- a/src/declarativeimports/draganddrop/draganddropplugin.h +++ b/src/declarativeimports/draganddrop/draganddropplugin.h @@ -23,9 +23,9 @@ #ifndef DRAGANDDROPPLUGIN_H #define DRAGANDDROPPLUGIN_H -#include +#include -class DragAndDropPlugin : public QDeclarativeExtensionPlugin +class DragAndDropPlugin : public QQmlExtensionPlugin { Q_OBJECT