diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/qfxmouseregion.cpp | 40 | ||||
-rw-r--r-- | src/declarative/fx/qfxmouseregion.h | 16 | ||||
-rw-r--r-- | src/declarative/fx/qfxmouseregion_p.h | 1 |
3 files changed, 37 insertions, 20 deletions
diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp index 514701d..2a198f2 100644 --- a/src/declarative/fx/qfxmouseregion.cpp +++ b/src/declarative/fx/qfxmouseregion.cpp @@ -51,7 +51,7 @@ static const int PressAndHoldDelay = 800; QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Drag,QFxDrag) QFxDrag::QFxDrag(QObject *parent) -: QObject(parent), _target(0), _xmin(0), _xmax(0), _ymin(0), _ymax(0) +: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0) { } @@ -69,12 +69,12 @@ void QFxDrag::setTarget(QFxItem *t) _target = t; } -QString QFxDrag::axis() const +QFxDrag::Axis QFxDrag::axis() const { return _axis; } -void QFxDrag::setAxis(const QString &a) +void QFxDrag::setAxis(QFxDrag::Axis a) { _axis = a; } @@ -138,7 +138,7 @@ void QFxDrag::setYmax(qreal m) example extended so as to give a different color when you right click. \snippet doc/src/snippets/declarative/mouseregion.qml 1 - For basic key handling, see \l KeyActions. + For basic key handling, see the \l {Keys}{Keys attached property}. MouseRegion is an invisible item: it is never painted. @@ -287,8 +287,8 @@ void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) else { d->longPress = false; d->saveEvent(event); - d->dragX = drag()->axis().contains(QLatin1String("x")); - d->dragY = drag()->axis().contains(QLatin1String("y")); + d->dragX = drag()->axis() & QFxDrag::XAxis; + d->dragY = drag()->axis() & QFxDrag::YAxis; d->dragged = false; d->start = event->pos(); d->startScene = event->scenePos(); @@ -447,10 +447,22 @@ void QFxMouseRegion::timerEvent(QTimerEvent *event) } /*! + \qmlproperty bool hoverEnabled + This property holds whether hover events are handled. + + By default, mouse events are only handled in response to a button event, or when a button is + pressed. Hover enables handling of all mouse events even when no mouse button is + pressed. + + This property affects the containsMouse property and the onEntered, onExited and onPositionChanged signals. +*/ + +/*! \qmlproperty bool MouseRegion::containsMouse This property holds whether the mouse is currently inside the mouse region. - \warning This property is only partially implemented -- it is only valid when the mouse is pressed, and not for hover events. + \warning This property is only partially implemented -- it is only valid when the mouse is moved over the + region. If the region moves under the mouse, \e containsMouse will not change. */ bool QFxMouseRegion::hovered() const { @@ -540,18 +552,18 @@ QFxDrag *QFxMouseRegion::drag() /*! \qmlproperty Item MouseRegion::drag.target - \qmlproperty string MouseRegion::drag.axis - \qmlproperty real MouseRegion::drag.xmin - \qmlproperty real MouseRegion::drag.xmax - \qmlproperty real MouseRegion::drag.ymin - \qmlproperty real MouseRegion::drag.ymax + \qmlproperty Axis MouseRegion::drag.axis + \qmlproperty real MouseRegion::drag.minimumX + \qmlproperty real MouseRegion::drag.maximumX + \qmlproperty real MouseRegion::drag.minimumY + \qmlproperty real MouseRegion::drag.maximumY drag provides a convenient way to make an item draggable. \list \i \c target specifies the item to drag. - \i \c axis specifies whether dragging can be done horizontally (x), vertically (y), or both (x,y) - \i the min and max properties limit how far the target can be dragged along the corresponding axes. + \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 The following example uses drag to reduce the opacity of an image as it moves to the right: diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h index f2d22d3..84bb493 100644 --- a/src/declarative/fx/qfxmouseregion.h +++ b/src/declarative/fx/qfxmouseregion.h @@ -54,21 +54,26 @@ class Q_DECLARATIVE_EXPORT QFxDrag : public QObject { Q_OBJECT + Q_ENUMS(Axis) Q_PROPERTY(QFxItem *target READ target WRITE setTarget) - Q_PROPERTY(QString axis READ axis WRITE setAxis) //### enum + Q_PROPERTY(Axis axis READ axis WRITE setAxis) Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin) Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax) Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin) Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax) //### consider drag and drop + public: QFxDrag(QObject *parent=0); ~QFxDrag(); QFxItem *target() const; void setTarget(QFxItem *); - QString axis() const; - void setAxis(const QString &); + + enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; + Axis axis() const; + void setAxis(Axis); + qreal xmin() const; void setXmin(qreal); qreal xmax() const; @@ -80,7 +85,7 @@ public: private: QFxItem *_target; - QString _axis; + Axis _axis; qreal _xmin; qreal _xmax; qreal _ymin; @@ -100,8 +105,9 @@ class Q_DECLARATIVE_EXPORT QFxMouseRegion : public QFxItem Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) + Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) Q_PROPERTY(QFxDrag *drag READ drag) //### add flicking to QFxDrag or add a QFxFlick ??? - //### trackingEnabled? + public: QFxMouseRegion(QFxItem *parent=0); ~QFxMouseRegion(); diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h index 1501a81..d981b85 100644 --- a/src/declarative/fx/qfxmouseregion_p.h +++ b/src/declarative/fx/qfxmouseregion_p.h @@ -74,7 +74,6 @@ public: { Q_Q(QFxMouseRegion); q->setAcceptedMouseButtons(Qt::LeftButton); - q->setAcceptHoverEvents(true); } void saveEvent(QGraphicsSceneMouseEvent *event) { |