summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-08-21 03:18:53 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-08-21 03:18:53 (GMT)
commit61486c42722a6ab5701c331645d6c25bce81a17e (patch)
tree77b1e914fda0e4fd113bfbf96d7b87556a58d7b8 /src
parent549b45cd6b8201daaf889986278c75a6c7f62cf8 (diff)
parent1d9ae86dda99d8f0eb4949d3779777e795eb52be (diff)
downloadQt-61486c42722a6ab5701c331645d6c25bce81a17e.zip
Qt-61486c42722a6ab5701c331645d6c25bce81a17e.tar.gz
Qt-61486c42722a6ab5701c331645d6c25bce81a17e.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/declarative/QmlChanges.txt2
-rw-r--r--src/declarative/fx/qfxmouseregion.cpp69
-rw-r--r--src/declarative/fx/qfxmouseregion.h4
3 files changed, 66 insertions, 9 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index 3ef81f4..f15d19e 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -32,6 +32,7 @@ Follow: followValue -> value
Additions:
MouseRegion: add "acceptedButtons" property
MouseRegion: add "hoverEnabled" property
+MouseRegion: add "pressedButtons" property
Timer: add start() and stop() slots
Deletions:
@@ -63,5 +64,4 @@ PropertyAction::property
PropertyAction::target (if possible)
Additions:
-MouseRegion: add "pressedButtons" property
Connection: add "slot" property
diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp
index 1c0adc4..d3c776f 100644
--- a/src/declarative/fx/qfxmouseregion.cpp
+++ b/src/declarative/fx/qfxmouseregion.cpp
@@ -260,8 +260,19 @@ QFxMouseRegion::~QFxMouseRegion()
/*!
\qmlproperty real MouseRegion::mouseX
\qmlproperty real MouseRegion::mouseY
+ These properties hold the coordinates of the mouse.
- The coordinates of the mouse while pressed. The coordinates are relative to the item that was pressed.
+ If the hoverEnabled property is false then these properties will only be valid
+ while a button is pressed, and will remain valid as long as the button is held
+ even if the mouse is moved outside the region.
+
+ If hoverEnabled is true then these properties will be valid:
+ \list
+ \i when no button is pressed, but the mouse is within the MouseRegion (containsMouse is true).
+ \i if a button is pressed and held, even if it has since moved out of the region.
+ \endlist
+
+ The coordinates are relative to the MouseRegion.
*/
qreal QFxMouseRegion::mouseX() const
{
@@ -293,6 +304,38 @@ void QFxMouseRegion::setEnabled(bool a)
emit enabledChanged();
}
}
+/*!
+ \qmlproperty MouseButtons MouseRegion::pressedButtons
+ This property holds the mouse buttons currently pressed.
+
+ It contains a bitwise combination of:
+ \list
+ \o Qt.LeftButton
+ \o Qt.RightButton
+ \o Qt.MidButton
+ \endlist
+
+ The code below displays "right" when the right mouse buttons is pressed:
+ \code
+ Text {
+ text: mr.pressedButtons & Qt.RightButton ? "right" : ""
+ horizontalAlignment: "AlignHCenter"
+ verticalAlignment: "AlignVCenter"
+ MouseRegion {
+ id: mr
+ acceptedButtons: Qt.LeftButton | Qt.RightButton
+ anchors.fill: parent
+ }
+ }
+ \endcode
+
+ \sa acceptedButtons
+*/
+Qt::MouseButtons QFxMouseRegion::pressedButtons() const
+{
+ Q_D(const QFxMouseRegion);
+ return d->lastButtons;
+}
void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
@@ -389,9 +432,9 @@ void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QFxMouseRegion);
- if (!d->absorb)
+ if (!d->absorb) {
QFxItem::mouseReleaseEvent(event);
- else {
+ } else {
d->saveEvent(event);
setPressed(false);
// If we don't accept hover, we need to reset containsMouse.
@@ -403,9 +446,9 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void QFxMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QFxMouseRegion);
- if (!d->absorb)
+ if (!d->absorb) {
QFxItem::mouseDoubleClickEvent(event);
- else {
+ } else {
QFxItem::mouseDoubleClickEvent(event);
if (event->isAccepted()) {
// Only deliver the event if we have accepted the press.
@@ -421,8 +464,19 @@ void QFxMouseRegion::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Q_D(QFxMouseRegion);
if (!d->absorb)
QFxItem::hoverEnterEvent(event);
- else {
+ else
setHovered(true);
+}
+
+void QFxMouseRegion::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+{
+ Q_D(QFxMouseRegion);
+ if (!d->absorb) {
+ QFxItem::hoverEnterEvent(event);
+ } else {
+ d->lastPos = event->pos();
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress);
+ emit positionChanged(&me);
}
}
@@ -431,9 +485,8 @@ void QFxMouseRegion::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_D(QFxMouseRegion);
if (!d->absorb)
QFxItem::hoverLeaveEvent(event);
- else {
+ else
setHovered(false);
- }
}
bool QFxMouseRegion::sceneEvent(QEvent *event)
diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h
index ae54ff6..7fb34b5 100644
--- a/src/declarative/fx/qfxmouseregion.h
+++ b/src/declarative/fx/qfxmouseregion.h
@@ -104,6 +104,7 @@ class Q_DECLARATIVE_EXPORT QFxMouseRegion : public QFxItem
Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
+ Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged)
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 ???
@@ -121,6 +122,8 @@ public:
bool hovered() const;
bool pressed() const;
+ Qt::MouseButtons pressedButtons() const;
+
Qt::MouseButtons acceptedButtons() const;
void setAcceptedButtons(Qt::MouseButtons buttons);
@@ -150,6 +153,7 @@ protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
bool sceneEvent(QEvent *);
void timerEvent(QTimerEvent *event);