+ 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);
+ }