summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-20 00:56:04 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-20 01:11:13 (GMT)
commitfca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9 (patch)
tree61c30b5562b53fa5997c05abfb66c248e5082482 /src/declarative
parent8efa7be3fd66119753730be643d0882afe329348 (diff)
downloadQt-fca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9.zip
Qt-fca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9.tar.gz
Qt-fca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9.tar.bz2
Add drag.active property to MouseArea in qml
The drag.active property specifies if the target item is being dragged. Task-number: QTBUG-9833 Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp35
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p.h6
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p_p.h4
3 files changed, 36 insertions, 9 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index bdb4868..969c60e 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -50,7 +50,8 @@ QT_BEGIN_NAMESPACE
static const int PressAndHoldDelay = 800;
QDeclarativeDrag::QDeclarativeDrag(QObject *parent)
-: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0)
+: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0),
+_active(false)
{
}
@@ -144,6 +145,19 @@ void QDeclarativeDrag::setYmax(qreal m)
emit maximumYChanged();
}
+bool QDeclarativeDrag::active() const
+{
+ return _active;
+}
+
+void QDeclarativeDrag::setActive(bool drag)
+{
+ if (_active == drag)
+ return;
+ _active = drag;
+ emit activeChanged();
+}
+
QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate()
{
delete drag;
@@ -389,7 +403,8 @@ void QDeclarativeMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
d->dragX = drag()->axis() & QDeclarativeDrag::XAxis;
d->dragY = drag()->axis() & QDeclarativeDrag::YAxis;
}
- d->dragged = false;
+ if (d->drag)
+ d->drag->setActive(false);
setHovered(true);
d->startScene = event->scenePos();
// we should only start timer if pressAndHold is connected to.
@@ -438,7 +453,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
qreal dx = qAbs(curLocalPos.x() - startLocalPos.x());
qreal dy = qAbs(curLocalPos.y() - startLocalPos.y());
if ((d->dragX && !(dx < dragThreshold)) || (d->dragY && !(dy < dragThreshold)))
- d->dragged = true;
+ d->drag->setActive(true);
if (!keepMouseGrab()) {
if ((!d->dragY && dy < dragThreshold && d->dragX && dx > dragThreshold)
|| (!d->dragX && dx < dragThreshold && d->dragY && dy > dragThreshold)
@@ -447,7 +462,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
}
- if (d->dragX && d->dragged) {
+ if (d->dragX && d->drag->active()) {
qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX;
if (x < drag()->xmin())
x = drag()->xmin();
@@ -455,7 +470,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
x = drag()->xmax();
drag()->target()->setX(x);
}
- if (d->dragY && d->dragged) {
+ if (d->dragY && d->drag->active()) {
qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY;
if (y < drag()->ymin())
y = drag()->ymin();
@@ -481,6 +496,8 @@ void QDeclarativeMouseArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
} else {
d->saveEvent(event);
setPressed(false);
+ if (d->drag)
+ d->drag->setActive(false);
// If we don't accept hover, we need to reset containsMouse.
if (!acceptHoverEvents())
setHovered(false);
@@ -559,7 +576,8 @@ void QDeclarativeMouseArea::timerEvent(QTimerEvent *event)
Q_D(QDeclarativeMouseArea);
if (event->timerId() == d->pressAndHoldTimer.timerId()) {
d->pressAndHoldTimer.stop();
- if (d->pressed && d->dragged == false && d->hovered == true) {
+ bool dragged = d->drag && d->drag->active();
+ if (d->pressed && dragged == false && d->hovered == true) {
d->longPress = true;
QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
emit pressAndHold(&me);
@@ -659,7 +677,8 @@ void QDeclarativeMouseArea::setAcceptedButtons(Qt::MouseButtons buttons)
bool QDeclarativeMouseArea::setPressed(bool p)
{
Q_D(QDeclarativeMouseArea);
- bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true;
+ bool dragged = d->drag && d->drag->active();
+ bool isclick = d->pressed == true && p == false && dragged == false && d->hovered == true;
if (d->pressed != p) {
d->pressed = p;
@@ -693,6 +712,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag()
/*!
\qmlproperty Item MouseArea::drag.target
+ \qmlproperty bool MouseArea::drag.active
\qmlproperty Axis MouseArea::drag.axis
\qmlproperty real MouseArea::drag.minimumX
\qmlproperty real MouseArea::drag.maximumX
@@ -703,6 +723,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag()
\list
\i \c target specifies the item to drag.
+ \i \c active specifies if the target item is being currently dragged.
\i \c axis specifies whether dragging can be done horizontally (XAxis), vertically (YAxis), or both (XandYAxis)
\i the minimum and maximum properties limit how far the target can be dragged along the corresponding axes.
\endlist
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
index 630840f..4f7df62 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
@@ -61,6 +61,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDrag : public QObject
Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
+ Q_PROPERTY(bool active READ active NOTIFY activeChanged)
//### consider drag and drop
public:
@@ -84,6 +85,9 @@ public:
qreal ymax() const;
void setYmax(qreal);
+ bool active() const;
+ void setActive(bool);
+
Q_SIGNALS:
void targetChanged();
void axisChanged();
@@ -91,6 +95,7 @@ Q_SIGNALS:
void maximumXChanged();
void minimumYChanged();
void maximumYChanged();
+ void activeChanged();
private:
QGraphicsObject *_target;
@@ -99,6 +104,7 @@ private:
qreal _xmax;
qreal _ymin;
qreal _ymax;
+ bool _active;
Q_DISABLE_COPY(QDeclarativeDrag)
};
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
index 4973957..4e909ff 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
@@ -67,7 +67,8 @@ class QDeclarativeMouseAreaPrivate : public QDeclarativeItemPrivate
public:
QDeclarativeMouseAreaPrivate()
- : absorb(true), hovered(false), pressed(false), longPress(false), drag(0)
+ : absorb(true), hovered(false), pressed(false), longPress(false),
+ moved(false), drag(0)
{
}
@@ -100,7 +101,6 @@ public:
bool moved : 1;
bool dragX : 1;
bool dragY : 1;
- bool dragged : 1;
QDeclarativeDrag *drag;
QPointF startScene;
qreal startX;