Start port of drag and drop import
This commit is contained in:
parent
6777a7dc56
commit
f79c3833bd
@ -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)
|
||||
|
@ -25,19 +25,20 @@
|
||||
#include "DeclarativeMimeData.h"
|
||||
|
||||
#include <QDrag>
|
||||
#include <QIcon>
|
||||
#include <QMimeData>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QDeclarativeContext>
|
||||
#include <QQmlContext>
|
||||
|
||||
/*!
|
||||
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<QDeclarativeItem *>(m_delegate->create(m_delegate->creationContext()));
|
||||
QQuickItem* item = qobject_cast<QQuickItem *>(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<QGraphicsSceneMouseEvent *>(event);
|
||||
if (event->type() == QEvent::MouseMove) {
|
||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
||||
mouseMoveEvent(me);
|
||||
}
|
||||
|
||||
return QDeclarativeItem::sceneEventFilter(item, event);
|
||||
return QQuickItem::childMouseEventFilter(item, event);
|
||||
}
|
||||
|
@ -24,12 +24,13 @@
|
||||
#ifndef DECLARATIVEDRAGAREA_H
|
||||
#define DECLARATIVEDRAGAREA_H
|
||||
|
||||
#include <QDeclarativeItem>
|
||||
#include <QQuickItem>
|
||||
#include <QImage>
|
||||
|
||||
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;
|
||||
|
@ -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()),
|
||||
|
@ -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; }
|
||||
|
@ -27,31 +27,34 @@
|
||||
#include <QGraphicsSceneDragDropEvent>
|
||||
#include <QMimeData>
|
||||
|
||||
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);
|
||||
|
@ -24,11 +24,11 @@
|
||||
#ifndef DECLARATIVEDROPAREA_H
|
||||
#define DECLARATIVEDROPAREA_H
|
||||
|
||||
#include <QDeclarativeItem>
|
||||
#include <QQuickItem>
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QColor>
|
||||
#include <QUrl>
|
||||
#include <QDeclarativeItem>
|
||||
#include <QQuickItem>
|
||||
|
||||
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
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "draganddropplugin.h"
|
||||
|
||||
#include <QtDeclarative/qdeclarative.h>
|
||||
#include <QtQml>
|
||||
|
||||
#include "DeclarativeDragArea.h"
|
||||
#include "DeclarativeDragDropEvent.h"
|
||||
@ -34,9 +34,9 @@ void DragAndDropPlugin::registerTypes(const char *uri)
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.draganddrop"));
|
||||
|
||||
qmlRegisterType<DeclarativeDropArea>(uri, 1, 0, "DropArea");
|
||||
qmlRegisterType<DeclarativeDragArea>(uri, 1, 0, "DragArea");
|
||||
qmlRegisterUncreatableType<DeclarativeMimeData>(uri, 1, 0, "MimeData", "MimeData cannot be created from QML.");
|
||||
qmlRegisterUncreatableType<DeclarativeDragDropEvent>(uri, 1, 0, "DragDropEvent", "DragDropEvent cannot be created from QML.");
|
||||
// qmlRegisterType<DeclarativeDragArea>(uri, 1, 0, "DragArea");
|
||||
// qmlRegisterUncreatableType<DeclarativeMimeData>(uri, 1, 0, "MimeData", "MimeData cannot be created from QML.");
|
||||
// qmlRegisterUncreatableType<DeclarativeDragDropEvent>(uri, 1, 0, "DragDropEvent", "DragDropEvent cannot be created from QML.");
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN2(draganddropplugin, DragAndDropPlugin)
|
||||
|
@ -23,9 +23,9 @@
|
||||
#ifndef DRAGANDDROPPLUGIN_H
|
||||
#define DRAGANDDROPPLUGIN_H
|
||||
|
||||
#include <QDeclarativeExtensionPlugin>
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class DragAndDropPlugin : public QDeclarativeExtensionPlugin
|
||||
class DragAndDropPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user