drag and drop plugin by Gregory Schlomoff

CCMAIL: gregory.schlomoff@gmail.com
This commit is contained in:
Marco Martin 2011-07-05 21:13:22 +02:00
parent 7c947d8e96
commit 93bfcfe8fc
12 changed files with 818 additions and 0 deletions

View File

@ -0,0 +1,27 @@
project(draganddrop)
include(KDE4Defaults)
set(declarativedragdrop_SRCS
draganddropplugin.cpp
DeclarativeDragArea.cpp
DeclarativeDragDropEvent.cpp
DeclarativeDropArea.cpp
DeclarativeMimeData.cpp
)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${KDE4_INCLUDES}
)
qt4_automoc(${declarativedragdrop_SRCS})
kde4_add_library(dragdropplugin SHARED ${declarativedragdrop_SRCS})
target_link_libraries(dragdropplugin ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY})
install(TARGETS dragdropplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/draganddrop)
install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/draganddrop)

View File

@ -0,0 +1,186 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "DeclarativeDragArea.h"
#include "DeclarativeMimeData.h"
#include <QDrag>
#include <QMimeData>
#include <QGraphicsSceneMouseEvent>
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
/*!
A DragArea is used to make an item draggable.
*/
DeclarativeDragArea::DeclarativeDragArea(QDeclarativeItem *parent)
: QDeclarativeItem(parent),
m_delegate(0),
m_source(0),
m_target(0),
m_enabled(true),
m_supportedActions(Qt::MoveAction),
m_defaultAction(Qt::MoveAction),
m_data(new DeclarativeMimeData()) // m_data is owned by us, and we shouldn't pass it to Qt directly as it will automatically delete it after the drag and drop.
{
setAcceptedMouseButtons(Qt::LeftButton);
}
DeclarativeDragArea::~DeclarativeDragArea()
{
if (m_data) {
delete m_data;
}
}
/*!
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
{
return m_delegate;
}
void DeclarativeDragArea::setDelegate(QDeclarativeComponent *delegate)
{
if (m_delegate != delegate) {
m_delegate = delegate;
emit delegateChanged();
}
}
void DeclarativeDragArea::resetDelegate()
{
setDelegate(0);
}
/*!
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
{
return m_source;
}
void DeclarativeDragArea::setSource(QDeclarativeItem* source)
{
if (m_source != source) {
m_source = source;
emit sourceChanged();
}
}
void DeclarativeDragArea::resetSource()
{
setSource(0);
}
// target
QDeclarativeItem* DeclarativeDragArea::target() const
{
//TODO: implement me
return 0;
}
// data
DeclarativeMimeData* DeclarativeDragArea::data() const
{
return m_data;
}
// enabled
bool DeclarativeDragArea::isEnabled() const
{
return m_enabled;
}
void DeclarativeDragArea::setEnabled(bool enabled)
{
if (enabled != m_enabled) {
m_enabled = enabled;
emit enabledChanged();
}
}
// supported actions
Qt::DropActions DeclarativeDragArea::supportedActions() const
{
return m_supportedActions;
}
void DeclarativeDragArea::setSupportedActions(Qt::DropActions actions)
{
if (actions != m_supportedActions) {
m_supportedActions = actions;
emit supportedActionsChanged();
}
}
// default action
Qt::DropAction DeclarativeDragArea::defaultAction() const
{
return m_defaultAction;
}
void DeclarativeDragArea::setDefaultAction(Qt::DropAction action)
{
if (action != m_defaultAction) {
m_defaultAction = action;
emit defaultActionChanged();
}
}
void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if ( !m_enabled
|| QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length()
< QApplication::startDragDistance()) {
return;
}
QDrag *drag = new QDrag(event->widget());
DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it.
drag->setMimeData(dataCopy);
if (m_delegate) {
// Render the delegate to a Pixmap
QDeclarativeItem* item = qobject_cast<QDeclarativeItem *>(m_delegate->create());
QGraphicsScene scene;
scene.addItem(item);
QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
scene.render(&painter);
drag->setPixmap(pixmap);
drag->setHotSpot(QPoint(0, 0)); // TODO: Make a property for that
}
//setCursor(Qt::OpenHandCursor); //TODO? Make a property for the cursor
Qt::DropAction action = drag->exec(m_supportedActions, m_defaultAction);
emit drop(action);
}

View File

@ -0,0 +1,95 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef DECLARATIVEDRAGAREA_H
#define DECLARATIVEDRAGAREA_H
#include <QDeclarativeItem>
class QDeclarativeComponent;
class DeclarativeMimeData;
class DeclarativeDragArea : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(QDeclarativeComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged RESET resetDelegate)
Q_PROPERTY(QDeclarativeItem* source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource)
Q_PROPERTY(QDeclarativeItem* target READ source NOTIFY targetChanged)
Q_PROPERTY(DeclarativeMimeData* data READ data CONSTANT)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) //TODO: Should call setAcceptDrops()
Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged)
Q_PROPERTY(Qt::DropAction defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged)
public:
DeclarativeDragArea(QDeclarativeItem *parent=0);
~DeclarativeDragArea();
QDeclarativeComponent *delegate() const;
void setDelegate(QDeclarativeComponent* delegate);
void resetDelegate();
QDeclarativeItem* target() const;
QDeclarativeItem* source() const;
void setSource(QDeclarativeItem* source);
void resetSource();
bool isEnabled() const;
void setEnabled(bool enabled);
//supported actions
Qt::DropActions supportedActions() const;
void setSupportedActions(Qt::DropActions actions);
//default action
Qt::DropAction defaultAction() const;
void setDefaultAction(Qt::DropAction action);
DeclarativeMimeData* data() const;
signals:
void delegateChanged();
void sourceChanged();
void targetChanged();
void dataChanged();
void enabledChanged();
void drop(int action);
void supportedActionsChanged();
void defaultActionChanged();
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *) {}
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) {}
private:
QDeclarativeComponent* m_delegate;
QDeclarativeItem* m_source;
QDeclarativeItem* m_target;
DeclarativeMimeData* const m_data;
bool m_enabled;
Qt::DropActions m_supportedActions;
Qt::DropAction m_defaultAction;
};
#endif // DECLARATIVEDRAGAREA_H

View File

@ -0,0 +1,42 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "DeclarativeDragDropEvent.h"
DeclarativeDragDropEvent::DeclarativeDragDropEvent(QGraphicsSceneDragDropEvent* e, QObject* parent) :
QObject(parent),
m_event(e),
m_x(e->pos().x()),
m_y(e->pos().y()),
m_buttons(e->buttons()),
m_modifiers(e->modifiers()),
m_data(e->mimeData())
{
}
void DeclarativeDragDropEvent::accept(int action)
{
m_event->setDropAction( (Qt::DropAction) action );
m_event->accept();
}

View File

@ -0,0 +1,66 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef DECLARATIVEDRAGDROPEVENT_H
#define DECLARATIVEDRAGDROPEVENT_H
#include <QObject>
#include <QGraphicsSceneDragDropEvent>
#include "DeclarativeMimeData.h"
class DeclarativeDragDropEvent : public QObject
{
Q_OBJECT
Q_PROPERTY(int x READ x)
Q_PROPERTY(int y READ y)
Q_PROPERTY(int buttons READ buttons)
Q_PROPERTY(int modifiers READ modifiers)
Q_PROPERTY(DeclarativeMimeData* data READ data)
Q_PROPERTY(Qt::DropActions possibleActions READ possibleActions)
Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction)
public:
DeclarativeDragDropEvent(QGraphicsSceneDragDropEvent* e, QObject* parent = 0);
int x() const { return m_x; }
int y() const { return m_y; }
int buttons() const { return m_buttons; }
int modifiers() const { return m_modifiers; }
DeclarativeMimeData* data() { return &m_data; }
Qt::DropAction proposedAction() const { return m_event->proposedAction(); }
Qt::DropActions possibleActions() const { return m_event->possibleActions(); }
public slots:
void accept(int action);
private:
int m_x;
int m_y;
Qt::MouseButtons m_buttons;
Qt::KeyboardModifiers m_modifiers;
DeclarativeMimeData m_data;
QGraphicsSceneDragDropEvent* m_event;
};
#endif // DECLARATIVEDRAGDROPEVENT_H

View File

@ -0,0 +1,68 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "DeclarativeDropArea.h"
#include "DeclarativeDragDropEvent.h"
#include <QGraphicsSceneDragDropEvent>
#include <QMimeData>
DeclarativeDropArea::DeclarativeDropArea(QDeclarativeItem *parent)
: QDeclarativeItem(parent),
m_enabled(true)
{
setAcceptDrops(m_enabled);
}
void DeclarativeDropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
DeclarativeDragDropEvent dde(event, this);
emit dragEnter(&dde);
}
void DeclarativeDropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
DeclarativeDragDropEvent dde(event, this);
emit dragLeave(&dde);
}
void DeclarativeDropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
{
DeclarativeDragDropEvent dde(event, this);
emit drop(&dde);
}
bool DeclarativeDropArea::isEnabled() const
{
return m_enabled;
}
void DeclarativeDropArea::setEnabled(bool enabled)
{
if (enabled == m_enabled) {
return;
}
m_enabled = enabled;
setAcceptDrops(m_enabled);
emit enabledChanged();
}

View File

@ -0,0 +1,57 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef DECLARATIVEDROPAREA_H
#define DECLARATIVEDROPAREA_H
#include <QDeclarativeItem>
class DeclarativeDragDropEvent;
class DeclarativeDropArea : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
public:
DeclarativeDropArea(QDeclarativeItem *parent=0);
bool isEnabled() const;
void setEnabled(bool enabled);
signals:
void dragEnter(DeclarativeDragDropEvent* event);
void dragLeave(DeclarativeDragDropEvent* event);
void drop(DeclarativeDragDropEvent* event);
void enabledChanged();
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
private:
bool m_enabled;
};
#endif

View File

@ -0,0 +1,121 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "DeclarativeMimeData.h"
/*!
\qmlclass MimeData DeclarativeMimeData
This is a wrapper class around QMimeData, with a few extensions to provide better support for in-qml drag & drops.
*/
/*!
\internal
\class DeclarativeMimeData
Creates a new DeclarativeMimeData by cloning the QMimeData passed as parameter.
This is useful for two reasons :
- In DragArea, we want to clone our "working copy" of the DeclarativeMimeData instance, as Qt will automatically
delete it after the drag and drop operation.
- In the drop events, the QMimeData is const, and we have troubles passing const to QML. So we clone it to
remove the "constness"
This method will try to cast the QMimeData to DeclarativeMimeData, and will clone our extensions to QMimeData as well
*/
DeclarativeMimeData::DeclarativeMimeData(const QMimeData* copy)
: QMimeData(),
m_source(0)
{
// Copy the standard MIME data
foreach(QString format, copy->formats()) {
this->setData(format, copy->data(format));
}
// If the object we are copying actually is a DeclarativeMimeData, copy our extended properties as well
const DeclarativeMimeData* declarativeMimeData = qobject_cast<const DeclarativeMimeData*>(copy);
if (declarativeMimeData) {
this->setSource(declarativeMimeData->source());
}
}
/*!
\qmlproperty url MimeData::url
Returns the first URL from the urls property of QMimeData
TODO: We should use QDeclarativeListProperty<QUrls> to return the whole list instead of only the first element.
*/
QUrl DeclarativeMimeData::url() const
{
if ( this->hasUrls() && !this->urls().isEmpty()) {
return urls().first();
}
return QUrl();
}
void DeclarativeMimeData::setUrl(const QUrl &url)
{
if (this->url() == url)
return;
QList<QUrl> urlList;
urlList.append(url);
setUrls(urlList);
emit urlChanged();
}
// color
QColor DeclarativeMimeData::color() const
{
if ( this->hasColor()) {
return qvariant_cast<QColor>(this->colorData());
}
return QColor();
}
void DeclarativeMimeData::setColor(const QColor &color)
{
if (this->color() != color) {
this->setColorData(color);
emit colorChanged();
}
}
/*!
\qmlproperty item MimeData::source
Setting source to any existing qml item will enable the receiver of the drag and drop operation to know in which item
the operation originated.
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
{
return m_source;
}
void DeclarativeMimeData::setSource(QDeclarativeItem* source)
{
if (m_source != source) {
m_source = source;
emit sourceChanged();
}
}

View File

@ -0,0 +1,75 @@
/*
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
Original author: Gregory Schlomoff <greg@betterinbox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef DECLARATIVEMIMEDATA_H
#define DECLARATIVEMIMEDATA_H
#include <QMimeData>
#include <QColor>
#include <QUrl>
#include <QDeclarativeItem>
class DeclarativeMimeData : public QMimeData
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) //TODO: use QDeclarativeListProperty<QUrls> to return the whole list instead of only the first url
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(QDeclarativeItem* source READ source WRITE setSource NOTIFY sourceChanged)
//TODO: Image property
public:
DeclarativeMimeData() : QMimeData() {}
DeclarativeMimeData(const QMimeData* copy);
QUrl url() const;
void setUrl(const QUrl &url);
QColor color() const;
void setColor(const QColor &color);
QDeclarativeItem* source() const;
void setSource(QDeclarativeItem* source);
/*
QString text() const; //TODO: Reimplement this to issue the onChanged signals
void setText(const QString &text);
QString html() const;
void setHtml(const QString &html);
*/
signals:
void textChanged(); //FIXME not being used
void htmlChanged(); //FIXME not being used
void urlChanged();
void colorChanged();
void sourceChanged();
private:
QDeclarativeItem* m_source;
};
#endif // DECLARATIVEMIMEDATA_H

View File

@ -0,0 +1,43 @@
/*
Copyright 2011 by Marco Martin <mart@kde.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "draganddropplugin.h"
#include <QtDeclarative/qdeclarative.h>
#include "DeclarativeDragArea.h"
#include "DeclarativeDragDropEvent.h"
#include "DeclarativeDropArea.h"
#include "DeclarativeMimeData.h"
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.");
}
Q_EXPORT_PLUGIN2(draganddropplugin, DragAndDropPlugin)

View File

@ -0,0 +1,36 @@
/*
Copyright 2011 by Marco Martin <mart@kde.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef DRAGANDDROPPLUGIN_H
#define DRAGANDDROPPLUGIN_H
#include <QDeclarativeExtensionPlugin>
class DragAndDropPlugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
public:
void registerTypes(const char *uri);
};
#endif

View File

@ -0,0 +1,2 @@
plugin draganddropplugin