45 #include <QApplication> 46 #include <QGraphicsScene> 171 : m_target(0), m_minScale(1.0), m_maxScale(1.0)
172 , m_minRotation(0.0), m_maxRotation(0.0)
173 , m_axis(NoDrag), m_xmin(-FLT_MAX), m_xmax(FLT_MAX)
174 , m_ymin(-FLT_MAX), m_ymax(FLT_MAX), m_active(false)
304 if (a !=
d->absorb) {
315 switch (event->
type()) {
317 d->touchEventsActive =
true;
320 if (
d->touchEventsActive) {
322 d->touchPoints.clear();
335 d->touchEventsActive =
false;
336 d->touchPoints.clear();
349 if (
d->touchPoints.count() == 0) {
351 d->stealMouse =
false;
365 d->pinchStartDist = 0;
366 d->pinchActivated =
false;
367 if (
d->pinch &&
d->pinch->target())
368 d->pinch->setActive(
false);
374 if (
d->touchPoints.count() == 2
376 d->id1 = touchPoint1.
id();
377 d->sceneStartPoint1 = touchPoint1.
scenePos();
378 d->sceneStartPoint2 = touchPoint2.
scenePos();
380 d->pinchRejected =
false;
381 d->pinchActivated =
true;
382 }
else if (
d->pinchActivated && !
d->pinchRejected) {
388 qreal dist = sqrt(dx*dx + dy*dy);
389 QPointF sceneCenter = (p1 + p2)/2;
391 if (
d->touchPoints.count() == 1) {
393 if (
d->id1 == touchPoint1.
id())
394 sceneCenter =
d->sceneLastCenter + touchPoint1.
scenePos() -
d->lastPoint1;
396 sceneCenter =
d->sceneLastCenter + touchPoint2.
scenePos() -
d->lastPoint2;
397 angle =
d->pinchLastAngle;
399 d->id1 = touchPoint1.
id();
403 if (
d->touchPoints.count() >= 2
404 && (
qAbs(p1.
x()-
d->sceneStartPoint1.x()) > dragThreshold
405 ||
qAbs(p1.
y()-
d->sceneStartPoint1.y()) > dragThreshold
406 ||
qAbs(p2.
x()-
d->sceneStartPoint2.x()) > dragThreshold
407 ||
qAbs(p2.
y()-
d->sceneStartPoint2.y()) > dragThreshold)) {
408 d->sceneStartCenter = sceneCenter;
409 d->sceneLastCenter = sceneCenter;
411 d->pinchStartDist = dist;
412 d->pinchStartAngle =
angle;
413 d->pinchLastScale = 1.0;
414 d->pinchLastAngle =
angle;
415 d->pinchRotation = 0.0;
431 d->stealMouse =
true;
436 if (
d->pinch &&
d->pinch->target()) {
438 d->pinchStartScale =
d->pinch->target()->scale();
439 d->pinchStartRotation =
d->pinch->target()->rotation();
440 d->pinch->setActive(
true);
443 d->pinchRejected =
true;
446 }
else if (
d->pinchStartDist > 0) {
447 qreal scale = dist ? dist /
d->pinchStartDist :
d->pinchLastScale;
453 d->pinchRotation += da;
465 d->pinchLastScale =
scale;
466 d->sceneLastCenter = sceneCenter;
467 d->pinchLastAngle =
angle;
471 if (
d->pinch &&
d->pinch->target()) {
475 QPointF pos = sceneCenter -
d->sceneStartCenter +
d->pinchStartPos;
478 if (x <
pinch()->xmin())
480 else if (x >
pinch()->xmax())
486 if (y <
pinch()->ymin())
488 else if (y >
pinch()->ymax())
492 if (
d->pinchStartRotation >=
pinch()->minimumRotation()
493 &&
d->pinchStartRotation <=
pinch()->maximumRotation()) {
494 qreal r =
d->pinchRotation +
d->pinchStartRotation;
506 d->stealMouse =
false;
511 event->setAccepted(
true);
527 d->stealMouse =
false;
555 bool stealThisEvent =
d->stealMouse;
558 for (
int i = 0x1; i <= 0x10; i <<= 1) {
583 if (grabber && stealThisEvent && !grabber->
keepMouseGrab() && grabber !=
this)
586 return stealThisEvent;
589 d->stealMouse =
false;
606 return sendMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e));
611 d->touchPoints.clear();
619 d->touchPoints.clear();
630 const QRectF &oldGeometry)
The QVariant class acts like a union for the most common Qt data types.
int id() const
Returns the id number of this touch point.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
QDeclarativeParserStatus ** d
Qt::TouchPointState state() const
Returns the current state of this touch point.
void setPoint1(QPointF p)
virtual bool event(QEvent *)
~QDeclarativePinchAreaPrivate()
bool sceneEventFilter(QGraphicsItem *i, QEvent *e)
Filters events for the item watched.
The QPointF class defines a point in the plane using floating point precision.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
void setPreviousCenter(QPointF c)
QPointF pos() const
Returns the position of the item in parent coordinates.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
QDeclarativePinch * pinch()
void pinchFinished(QDeclarativePinchEvent *pinch)
T * qobject_cast(QObject *object)
QPointF scenePos() const
Returns the scene position of this touch point.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
QGraphicsItem * mouseGrabberItem() const
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse...
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is not called during initial widget p...
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
Q_DECL_CONSTEXPR T qAbs(const T &t)
void setPreviousScale(qreal s)
void setStartCenter(QPointF c)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setStartPoint2(QPointF p)
qreal scale() const
Returns the scale factor of the item.
qreal x() const
Returns the x-coordinate of this point.
The QLineF class provides a two-dimensional vector using floating point precision.
QPointF lastScenePos() const
Returns the last recorded mouse cursor position in scene coordinates.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
The QDeclarativeItem class provides the most basic of all visual items in QML.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
const T & at(int i) const
Returns the item at index position i in the list.
qreal angle() const
Returns the angle of the line in degrees.
static int startDragDistance()
void setPoint2(QPointF p)
void setX(qreal x)
Set's the x coordinate of the item's position.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
void pinchUpdated(QDeclarativePinchEvent *pinch)
bool sendMouseEvent(QGraphicsSceneMouseEvent *event)
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item's scene's coordinate system, to this item's coordinate sy...
QPointF pos
the position of the item
void setStartPoint1(QPointF p)
qreal angle(const QPointF &p1, const QPointF &p2)
qreal y() const
This convenience function is equivalent to calling pos().
virtual QVariant itemChange(GraphicsItemChange, const QVariant &)
Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is not called during initial widget p...
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
void setPreviousAngle(qreal a)
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
QPointF pos() const
Returns the position of this touch point, relative to the widget or QGraphicsItem that received the e...
QObject * parent() const
Returns a pointer to the parent object.
bool sceneEvent(QEvent *)
qreal x() const
This convenience function is equivalent to calling pos().
void setY(qreal y)
Set's the y coordinate of the item's position.
const QList< QTouchEvent::TouchPoint > & touchPoints() const
Returns the list of touch points contained in the touch event.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
void setPointCount(int count)
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
virtual bool sceneEvent(QEvent *)
qreal y() const
Returns the y-coordinate of this point.
The TouchPoint class provides information about a touch point in a QTouchEvent.
bool keepMouseGrab() const
Returns a value indicating whether mouse input should remain with this item exclusively.
QPointF buttonDownPos(Qt::MouseButton button) const
Returns the mouse cursor position in item coordinates where the specified button was clicked...
void setScale(qreal scale)
Sets the scale factor of the item.
The QTouchEvent class contains parameters that describe a touch event.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
void ungrabMouse()
Releases the mouse grab.
void setRotation(qreal angle)
Sets the clockwise rotation angle, in degrees, around the Z axis.
QDeclarativePinchArea(QDeclarativeItem *parent=0)
The QEvent class is the base class of all event classes.
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
Filters events for the item watched.
Type type() const
Returns the event type.
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item's coordinate system, to the scene's coordinate system...
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
void pinchStarted(QDeclarativePinchEvent *pinch)
void grabMouse()
Grabs the mouse input.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
void setKeepMouseGrab(bool)
The flag indicating whether the mouse should remain with this item is set to keep.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...