diff options
author | Andy Nichols <andy.nichols@qt.io> | 2016-05-31 12:11:36 +0200 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2016-05-31 12:24:30 +0200 |
commit | 91e1a65cdb5b4fc802c80c75e255a72671d97645 (patch) | |
tree | e981fac1afb7e38c9f6aba28e2c1b646e461950b /src/quick/items | |
parent | 5956771cb9fc6468eaf002ebe8a7a3396807c2c1 (diff) | |
parent | e5c76615b72abcae628ca7561c16eab71f1d3a0e (diff) |
Merge remote-tracking branch 'origin/dev' into scenegraphng
Change-Id: I35715e07b6f837f21cd8e8898f19d97af92c6b69
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquickevents.cpp | 22 | ||||
-rw-r--r-- | src/quick/items/qquickevents_p_p.h | 67 | ||||
-rw-r--r-- | src/quick/items/qquickitem.cpp | 6 | ||||
-rw-r--r-- | src/quick/items/qquickitem_p.h | 2 | ||||
-rw-r--r-- | src/quick/items/qquickmousearea.cpp | 29 | ||||
-rw-r--r-- | src/quick/items/qquickmousearea_p_p.h | 3 | ||||
-rw-r--r-- | src/quick/items/qquickopenglshadereffectnode.cpp | 2 | ||||
-rw-r--r-- | src/quick/items/qquickrendercontrol.cpp | 2 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 13 | ||||
-rw-r--r-- | src/quick/items/qquickwindow_p.h | 2 |
10 files changed, 114 insertions, 34 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index 5061c19f1e..14c0adf393 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -415,4 +415,26 @@ Item { \endqml */ +/*! + \qmlproperty int QtQuick::WheelEvent::inverted + + Returns whether the delta values delivered with the event are inverted. + + Normally, a vertical wheel will produce a WheelEvent with positive delta + values if the top of the wheel is rotating away from the hand operating it. + Similarly, a horizontal wheel movement will produce a QWheelEvent with + positive delta values if the top of the wheel is moved to the left. + + However, on some platforms this is configurable, so that the same + operations described above will produce negative delta values (but with the + same magnitude). For instance, in a QML component (such as a tumbler or a + slider) where it is appropriate to synchronize the movement or rotation of + an item with the direction of the wheel, regardless of the system settings, + the wheel event handler can use the inverted property to decide whether to + negate the angleDelta or pixelDelta values. + + \note Many platforms provide no such information. On such platforms + \l inverted always returns false. +*/ + QT_END_NAMESPACE diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h index b28ab555b0..6d4b49b3cd 100644 --- a/src/quick/items/qquickevents_p_p.h +++ b/src/quick/items/qquickevents_p_p.h @@ -73,10 +73,22 @@ class QQuickKeyEvent : public QObject Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) public: - QQuickKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) - : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); } - QQuickKeyEvent(const QKeyEvent &ke) - : event(ke) { event.setAccepted(false); } + QQuickKeyEvent() + : event(QEvent::None, 0, 0) + {} + + void reset(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, + const QString &text = QString(), bool autorep = false, ushort count = 1) + { + event = QKeyEvent(type, key, modifiers, text, autorep, count); + event.setAccepted(false); + } + + void reset(const QKeyEvent &ke) + { + event = ke; + event.setAccepted(false); + } int key() const { return event.key(); } QString text() const { return event.text(); } @@ -109,10 +121,21 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMouseEvent : public QObject Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) public: - QQuickMouseEvent(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers - , bool isClick=false, bool wasHeld=false) - : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers) - , _source(Qt::MouseEventNotSynthesized), _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {} + QQuickMouseEvent() {} + + void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons, + Qt::KeyboardModifiers modifiers, bool isClick = false, bool wasHeld = false) + { + _x = x; + _y = y; + _button = button; + _buttons = buttons; + _modifiers = modifiers; + _source = Qt::MouseEventNotSynthesized; + _wasHeld = wasHeld; + _isClick = isClick; + _accepted = true; + } qreal x() const { return _x; } qreal y() const { return _y; } @@ -139,9 +162,9 @@ private: Qt::MouseButtons _buttons; Qt::KeyboardModifiers _modifiers; Qt::MouseEventSource _source; - bool _wasHeld; - bool _isClick; - bool _accepted; + bool _wasHeld : 1; + bool _isClick : 1; + bool _accepted : 1; }; class QQuickWheelEvent : public QObject @@ -153,13 +176,24 @@ class QQuickWheelEvent : public QObject Q_PROPERTY(QPoint pixelDelta READ pixelDelta) Q_PROPERTY(int buttons READ buttons) Q_PROPERTY(int modifiers READ modifiers) + Q_PROPERTY(bool inverted READ inverted) Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) public: - QQuickWheelEvent(qreal x, qreal y, const QPoint& angleDelta, const QPoint& pixelDelta, - Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) - : _x(x), _y(y), _angleDelta(angleDelta), _pixelDelta(pixelDelta), _buttons(buttons), - _modifiers(modifiers), _accepted(true) {} + QQuickWheelEvent() {} + + void reset(qreal x, qreal y, const QPoint &angleDelta, const QPoint &pixelDelta, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, bool inverted) + { + _x = x; + _y = y; + _angleDelta = angleDelta; + _pixelDelta = pixelDelta; + _buttons = buttons; + _modifiers = modifiers; + _accepted = true; + _inverted = inverted; + } qreal x() const { return _x; } qreal y() const { return _y; } @@ -167,7 +201,7 @@ public: QPoint pixelDelta() const { return _pixelDelta; } int buttons() const { return _buttons; } int modifiers() const { return _modifiers; } - + bool inverted() const { return _inverted; } bool isAccepted() { return _accepted; } void setAccepted(bool accepted) { _accepted = accepted; } @@ -178,6 +212,7 @@ private: QPoint _pixelDelta; Qt::MouseButtons _buttons; Qt::KeyboardModifiers _modifiers; + bool _inverted; bool _accepted; }; diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index d0d10a5849..9a13198d7d 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -1355,7 +1355,8 @@ void QQuickKeysAttached::keyPressed(QKeyEvent *event, bool post) d->inPress = false; } - QQuickKeyEvent ke(*event); + QQuickKeyEvent &ke = d->theKeyEvent; + ke.reset(*event); QByteArray keySignal = keyToSignal(event->key()); if (!keySignal.isEmpty()) { keySignal += "(QQuickKeyEvent*)"; @@ -1398,7 +1399,8 @@ void QQuickKeysAttached::keyReleased(QKeyEvent *event, bool post) d->inRelease = false; } - QQuickKeyEvent ke(*event); + QQuickKeyEvent &ke = d->theKeyEvent; + ke.reset(*event); emit released(&ke); event->setAccepted(ke.isAccepted()); diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h index 846063a58b..477071f7b3 100644 --- a/src/quick/items/qquickitem_p.h +++ b/src/quick/items/qquickitem_p.h @@ -56,6 +56,7 @@ #include "qquickanchors_p.h" #include "qquickanchors_p_p.h" #include "qquickitemchangelistener_p.h" +#include "qquickevents_p_p.h" #include "qquickwindow_p.h" @@ -777,6 +778,7 @@ public: QQuickItem *imeItem; QList<QQuickItem *> targets; QQuickItem *item; + QQuickKeyEvent theKeyEvent; }; class QQuickKeysAttached : public QObject, public QQuickItemKeyFilter diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index 920a86881b..66aff5c2f4 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -40,7 +40,6 @@ #include "qquickmousearea_p.h" #include "qquickmousearea_p_p.h" #include "qquickwindow.h" -#include "qquickevents_p_p.h" #include "qquickdrag_p.h" #include <private/qqmldata_p.h> @@ -761,7 +760,8 @@ void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) } #endif - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + QQuickMouseEvent &me = d->quickMouseEvent; + me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); me.setSource(event->source()); emit mouseXChanged(&me); me.setPosition(d->lastPos); @@ -802,7 +802,8 @@ void QQuickMouseArea::mouseDoubleClickEvent(QMouseEvent *event) Q_D(QQuickMouseArea); if (d->enabled) { d->saveEvent(event); - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); + QQuickMouseEvent &me = d->quickMouseEvent; + me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); me.setSource(event->source()); me.setAccepted(d->isDoubleClickConnected()); emit this->doubleClicked(&me); @@ -822,7 +823,8 @@ void QQuickMouseArea::hoverEnterEvent(QHoverEvent *event) d->lastPos = event->posF(); d->lastModifiers = event->modifiers(); setHovered(true); - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); + QQuickMouseEvent &me = d->quickMouseEvent; + me.reset(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); emit mouseXChanged(&me); me.setPosition(d->lastPos); emit mouseYChanged(&me); @@ -835,10 +837,11 @@ void QQuickMouseArea::hoverMoveEvent(QHoverEvent *event) Q_D(QQuickMouseArea); if (!d->enabled && !d->pressed) { QQuickItem::hoverMoveEvent(event); - } else { + } else if (d->lastPos != event->posF()) { d->lastPos = event->posF(); d->lastModifiers = event->modifiers(); - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); + QQuickMouseEvent &me = d->quickMouseEvent; + me.reset(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); emit mouseXChanged(&me); me.setPosition(d->lastPos); emit mouseYChanged(&me); @@ -865,8 +868,9 @@ void QQuickMouseArea::wheelEvent(QWheelEvent *event) return; } - QQuickWheelEvent we(event->posF().x(), event->posF().y(), event->angleDelta(), - event->pixelDelta(), event->buttons(), event->modifiers()); + QQuickWheelEvent &we = d->quickWheelEvent; + we.reset(event->posF().x(), event->posF().y(), event->angleDelta(), event->pixelDelta(), + event->buttons(), event->modifiers(), event->inverted()); we.setAccepted(d->isWheelConnected()); emit wheel(&we); if (!we.isAccepted()) @@ -997,7 +1001,8 @@ void QQuickMouseArea::timerEvent(QTimerEvent *event) #endif if (d->pressed && dragged == false && d->hovered == true) { d->longPress = true; - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + QQuickMouseEvent &me = d->quickMouseEvent; + me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); me.setSource(Qt::MouseEventSynthesizedByQt); me.setAccepted(d->isPressAndHoldConnected()); emit pressAndHold(&me); @@ -1078,8 +1083,7 @@ void QQuickMouseArea::setHoverEnabled(bool h) \qmlproperty bool QtQuick::MouseArea::containsMouse This property holds whether the mouse is currently inside the mouse area. - \warning This property is not updated if the area moves under the mouse: \e containsMouse will not change. - In addition, if hoverEnabled is false, containsMouse will only be valid + \warning If hoverEnabled is false, containsMouse will only be valid when the mouse is pressed while the mouse cursor is inside the MouseArea. */ bool QQuickMouseArea::hovered() const @@ -1175,7 +1179,8 @@ bool QQuickMouseArea::setPressed(Qt::MouseButton button, bool p, Qt::MouseEventS Qt::MouseButtons oldPressed = d->pressed; if (wasPressed != p) { - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); + QQuickMouseEvent &me = d->quickMouseEvent; + me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); me.setSource(source); if (p) { d->pressed |= button; diff --git a/src/quick/items/qquickmousearea_p_p.h b/src/quick/items/qquickmousearea_p_p.h index 2d841b9ae1..794a8cc6ff 100644 --- a/src/quick/items/qquickmousearea_p_p.h +++ b/src/quick/items/qquickmousearea_p_p.h @@ -52,6 +52,7 @@ // #include "qquickitem_p.h" +#include "qquickevents_p_p.h" #include <QtGui/qevent.h> #include <QtCore/qbasictimer.h> @@ -107,6 +108,8 @@ public: #ifndef QT_NO_CURSOR QCursor *cursor; #endif + QQuickMouseEvent quickMouseEvent; + QQuickWheelEvent quickWheelEvent; }; QT_END_NAMESPACE diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp index c4dd8d5c63..02b76b2dbc 100644 --- a/src/quick/items/qquickopenglshadereffectnode.cpp +++ b/src/quick/items/qquickopenglshadereffectnode.cpp @@ -456,7 +456,7 @@ void QQuickOpenGLShaderEffectMaterial::cleanupMaterialCache() { QQuickOpenGLShaderEffectMaterialCache *cache = QQuickOpenGLShaderEffectMaterialCache::get(false); if (cache) { - qDeleteAll(cache->cache.values()); + qDeleteAll(cache->cache); delete cache; } } diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp index ec9a104812..dbe1add345 100644 --- a/src/quick/items/qquickrendercontrol.cpp +++ b/src/quick/items/qquickrendercontrol.cpp @@ -254,7 +254,7 @@ void QQuickRenderControl::polishItems() return; QQuickWindowPrivate *cd = QQuickWindowPrivate::get(d->window); - cd->flushDelayedTouchEvent(); + cd->flushFrameSynchronousEvents(); if (!d->window) return; cd->polishItems(); diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index b9fb0721b3..6333bf704a 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -2028,7 +2028,7 @@ void QQuickWindowPrivate::deliverTouchEvent(QTouchEvent *event) } } -void QQuickWindowPrivate::flushDelayedTouchEvent() +void QQuickWindowPrivate::flushFrameSynchronousEvents() { if (delayedTouch) { deliverDelayedTouchEvent(); @@ -2039,6 +2039,17 @@ void QQuickWindowPrivate::flushDelayedTouchEvent() if (ut && ut->hasStartAnimationPending()) ut->startAnimations(); } + + // Once per frame, send a synthetic hover, in case items have changed position. + // For instance, during animation (including the case of a ListView + // whose delegates contain MouseAreas), a MouseArea needs to know + // whether it has moved into a position where it is now under the cursor. + if (!mouseGrabberItem && !lastMousePosition.isNull()) { + bool accepted = false; + bool delivered = deliverHoverEvent(contentItem, lastMousePosition, lastMousePosition, QGuiApplication::keyboardModifiers(), accepted); + if (!delivered) + clearHover(); // take care of any exits + } } void QQuickWindowPrivate::reallyDeliverTouchEvent(QTouchEvent *event) diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index 1486e20e1e..daff9ef473 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -160,7 +160,7 @@ public: void reallyDeliverTouchEvent(QTouchEvent *); bool deliverTouchCancelEvent(QTouchEvent *); void deliverDelayedTouchEvent(); - void flushDelayedTouchEvent(); + void flushFrameSynchronousEvents(); bool deliverHoverEvent(QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, bool &accepted); bool deliverMatchingPointsToItem(QQuickItem *item, QTouchEvent *event, QSet<int> *acceptedNewPoints, const QSet<int> &matchingNewPoints, const QList<QTouchEvent::TouchPoint> &matchingPoints, QSet<QQuickItem*> *filtered); static QTouchEvent *touchEventForItem(QQuickItem *target, const QTouchEvent &originalEvent, bool alwaysCheckBounds = false); |