Commit 67fbd035 authored by Marco Martin's avatar Marco Martin
Browse files

new property: preventStealing

this, consistent with MouseArea::preventStealing, will make sure
that a droparea with it will take the exclusive of all dropevents,
all its parents (all up the hyerarchy to top) won't take any
as long as this is managing

CCBUG:333317
parent a3fb3d15
......@@ -30,7 +30,9 @@
DeclarativeDropArea::DeclarativeDropArea(QQuickItem *parent)
: QQuickItem(parent),
m_enabled(true)
m_enabled(true),
m_preventStealing(false),
m_temporaryInhibition(false)
{
setFlag(ItemAcceptsDrops, m_enabled);
setFlag(ItemHasContents, m_enabled);
......@@ -38,16 +40,46 @@ DeclarativeDropArea::DeclarativeDropArea(QQuickItem *parent)
}
void DeclarativeDropArea::temporaryInhibitParent(bool inhibit)
{
QQuickItem *candidate = parentItem();
while (candidate) {
if (DeclarativeDropArea *da = qobject_cast<DeclarativeDropArea *>(candidate)) {
da->m_temporaryInhibition = inhibit;
if (inhibit) {
emit da->dragLeaveEvent(0);
}
}
candidate = candidate->parentItem();
}
}
void DeclarativeDropArea::dragEnterEvent(QDragEnterEvent *event)
{
if (!m_enabled || m_temporaryInhibition) {
return;
}
DeclarativeDragDropEvent dde(event, this);
qDebug() << "enter.";
event->accept();
if (m_preventStealing) {
temporaryInhibitParent(true);
}
emit dragEnter(&dde);
}
void DeclarativeDropArea::dragLeaveEvent(QDragLeaveEvent *event)
{
QQuickItem *candidate = parentItem();
//do it anyways, in the unlikely case m_preventStealing
//was changed while drag
temporaryInhibitParent(false);
DeclarativeDragDropEvent dde(event, this);
qDebug() << "leave.";
emit dragLeave(&dde);
......@@ -55,6 +87,10 @@ void DeclarativeDropArea::dragLeaveEvent(QDragLeaveEvent *event)
void DeclarativeDropArea::dragMoveEvent(QDragMoveEvent *event)
{
if (!m_enabled || m_temporaryInhibition) {
return;
}
DeclarativeDragDropEvent dde(event, this);
//qDebug() << "move.";
event->accept();
......@@ -63,6 +99,15 @@ void DeclarativeDropArea::dragMoveEvent(QDragMoveEvent *event)
void DeclarativeDropArea::dropEvent(QDropEvent *event)
{
//do it anyways, in the unlikely case m_preventStealing
//was changed while drag, do it after a loop,
//so the parent dropevent doesn't get delivered
metaObject()->invokeMethod(this, "temporaryInhibitParent", Qt::QueuedConnection, Q_ARG(bool, false));
if (!m_enabled || m_temporaryInhibition) {
return;
}
DeclarativeDragDropEvent dde(event, this);
qDebug() << "Drop.";
emit drop(&dde);
......@@ -84,3 +129,18 @@ void DeclarativeDropArea::setEnabled(bool enabled)
setFlag(ItemAcceptsDrops, m_enabled);
emit enabledChanged();
}
bool DeclarativeDropArea::preventStealing() const
{
return m_preventStealing;
}
void DeclarativeDropArea::setPreventStealing(bool prevent)
{
if (prevent == m_preventStealing) {
return;
}
m_preventStealing = prevent;
emit preventStealingChanged();
}
......@@ -37,11 +37,19 @@ class DeclarativeDropArea : public QQuickItem
*/
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
/**
*
*/
Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
public:
DeclarativeDropArea(QQuickItem *parent=0);
bool isEnabled() const;
void setEnabled(bool enabled);
bool preventStealing() const;
void setPreventStealing(bool prevent);
Q_SIGNALS:
/**
* Emitted when the mouse cursor dragging something enters in the drag area
......@@ -71,16 +79,24 @@ Q_SIGNALS:
*/
void drop(DeclarativeDragDropEvent* event);
//Notifiers
void enabledChanged();
void preventStealingChanged();
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
private Q_SLOTS:
void temporaryInhibitParent(bool inhibit);
private:
bool m_enabled;
bool m_enabled : 1;
bool m_preventStealing : 1;
bool m_temporaryInhibition : 1;
};
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment