- _view.set_scale_offset(_view.scale(),
- event->delta() * _view.scale()
- + _view.offset());
- }
-}
-
-bool Viewport::touchEvent(QTouchEvent *event)
-{
- QList<QTouchEvent::TouchPoint> touchPoints = event->touchPoints();
-
- if (touchPoints.count() != 2) {
- _pinch_zoom_active = false;
- return false;
- }
-
- const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
- const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
-
- if (!_pinch_zoom_active ||
- (event->touchPointStates() & Qt::TouchPointPressed)) {
- _pinch_offset0 = _view.offset() + _view.scale() * touchPoint0.pos().x();
- _pinch_offset1 = _view.offset() + _view.scale() * touchPoint1.pos().x();
- _pinch_zoom_active = true;
- }
-
- double w = touchPoint1.pos().x() - touchPoint0.pos().x();
- if (abs(w) >= 1.0) {
- double scale = (_pinch_offset1 - _pinch_offset0) / w;
- if (scale < 0)
- scale = -scale;
- double offset = _pinch_offset0 - touchPoint0.pos().x() * scale;
- if (scale > 0)
- _view.set_scale_offset(scale, offset);
- }
-
- if (event->touchPointStates() & Qt::TouchPointReleased) {
- _pinch_zoom_active = false;
-
- if (touchPoint0.state() & Qt::TouchPointReleased) {
- // Primary touch released
- _mouse_down_valid = false;
- } else {
- // Update the mouse down fields so that continued
- // dragging with the primary touch will work correctly
- _mouse_down_point = touchPoint0.pos().toPoint();
- _mouse_down_offset = _view.offset();
- _mouse_down_valid = true;
- }