draganddrop: all classes build and are enabled
This commit is contained in:
parent
b60983ca1f
commit
3ee1474c17
@ -4,18 +4,12 @@ include(KDE4Defaults)
|
||||
|
||||
set(declarativedragdrop_SRCS
|
||||
draganddropplugin.cpp
|
||||
# DeclarativeDragArea.cpp
|
||||
DeclarativeDragArea.cpp
|
||||
DeclarativeDragDropEvent.cpp
|
||||
DeclarativeDropArea.cpp
|
||||
DeclarativeMimeData.cpp
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${KDE4_INCLUDES}
|
||||
)
|
||||
|
||||
qt4_automoc(${declarativedragdrop_SRCS})
|
||||
|
||||
|
||||
@ -24,6 +18,7 @@ target_link_libraries(draganddropplugin
|
||||
${QT_QTCORE_LIBRARY}
|
||||
${Qt5Quick_LIBRARIES}
|
||||
${Qt5Qml_LIBRARIES}
|
||||
${QT_QTGUI_LIBRARY}
|
||||
)
|
||||
|
||||
install(TARGETS draganddropplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/draganddrop)
|
||||
|
@ -29,8 +29,6 @@
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#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)
|
||||
{
|
||||
if ( !m_enabled
|
||||
|| QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length()
|
||||
|| QLineF(event->screenPos(), m_buttonDownPos).length()
|
||||
< m_startDragDistance) {
|
||||
return;
|
||||
}
|
||||
|
||||
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.
|
||||
drag->setMimeData(dataCopy);
|
||||
|
||||
@ -210,22 +214,23 @@ void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event)
|
||||
drag->setPixmap(QPixmap::fromImage(m_delegateImage));
|
||||
} else if (m_delegate) {
|
||||
// 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;
|
||||
scene.addItem(item);
|
||||
// QGraphicsScene scene;
|
||||
// scene.addItem(item);
|
||||
|
||||
QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height());
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
QPainter painter(&pixmap);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
scene.render(&painter);
|
||||
painter.end();
|
||||
delete item;
|
||||
|
||||
drag->setPixmap(pixmap);
|
||||
// QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height());
|
||||
// pixmap.fill(Qt::transparent);
|
||||
//
|
||||
// QPainter painter(&pixmap);
|
||||
// painter.setRenderHint(QPainter::Antialiasing);
|
||||
// painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
// scene.render(&painter);
|
||||
// painter.end();
|
||||
// delete item;
|
||||
//
|
||||
// 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
|
||||
@ -236,8 +241,7 @@ void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event)
|
||||
emit drop(action);
|
||||
}
|
||||
|
||||
bool DeclarativeDragArea::childMouseEventFilter(QQuickItem *item, QEvent *event);
|
||||
|
||||
bool DeclarativeDragArea::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
||||
{
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
|
@ -132,7 +132,7 @@ signals:
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mousePressEvent(QMouseEvent *) {}
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *) {}
|
||||
bool childMouseEventFilter(QQuickItem *item, QEvent *event);
|
||||
//bool sceneEventFilter(QGraphicsItem *item, QEvent *event);
|
||||
@ -147,6 +147,7 @@ private:
|
||||
DeclarativeMimeData* const m_data;
|
||||
QImage m_delegateImage;
|
||||
int m_startDragDistance;
|
||||
QPointF m_buttonDownPos;
|
||||
};
|
||||
|
||||
#endif // DECLARATIVEDRAGAREA_H
|
||||
|
@ -33,7 +33,13 @@ DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDropEvent* e, DeclarativeDro
|
||||
m_data(e->mimeData()),
|
||||
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) :
|
||||
@ -45,17 +51,7 @@ DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDragLeaveEvent* e, Declarati
|
||||
//m_data(e->mimeData()),
|
||||
m_event(0)
|
||||
{
|
||||
}
|
||||
|
||||
void DeclarativeDragDropEvent::init()
|
||||
{
|
||||
QPointF pos;
|
||||
|
||||
if (parent()) {
|
||||
//pos = parent->mapFromScene(e->scenePos());
|
||||
m_x = pos.x();
|
||||
m_y = pos.y();
|
||||
}
|
||||
Q_UNUSED(e);
|
||||
}
|
||||
|
||||
void DeclarativeDragDropEvent::accept(int action)
|
||||
|
@ -110,7 +110,6 @@ public Q_SLOTS:
|
||||
void accept(int action);
|
||||
|
||||
private:
|
||||
void init();
|
||||
int m_x;
|
||||
int m_y;
|
||||
Qt::MouseButtons m_buttons;
|
||||
|
@ -105,7 +105,7 @@ void DeclarativeMimeData::setUrls(const QVariantList &urls)
|
||||
// color
|
||||
QColor DeclarativeMimeData::color() const
|
||||
{
|
||||
if ( this->hasColor()) {
|
||||
if (this->hasColor()) {
|
||||
return qvariant_cast<QColor>(this->colorData());
|
||||
}
|
||||
return QColor();
|
||||
|
@ -24,19 +24,19 @@
|
||||
|
||||
#include <QtQml>
|
||||
|
||||
// #include "DeclarativeDragArea.h"
|
||||
// #include "DeclarativeDragDropEvent.h"
|
||||
// #include "DeclarativeDropArea.h"
|
||||
// #include "DeclarativeMimeData.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.");
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user