Pinch to zoom

Hey guys, so I am trying to fix this pinch to zoom without actually being able to test it right now... I know, it's ridiculous. Currently, my laptop's touch screen isn't recognizing multiple presses and someone else is using the target hardware for their own testing. So I was hoping you guys would take a look at the code that I believe is controlling the whole pinch to zoom feature and tell me if you think I am right about the change I need to make.

Essentially (apparently) the logic for the pinch zoom is backwards. When you pinch and move your fingers outwards apparently it is zooming out. That should be flipped and I think the way of doing it would be to simply swap x with y and y with x on the fourth line of pinchAreaStarted but I am not sure. I am not looking for any guarantees but if after looking at the code you agree then let me know and if you disagree then let me know XD

I believe this is all the relevant code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  bool MapItem::pinchAreaStarted(QPointF, QPointF startCenter, QPointF, qreal scale, qreal, qreal angle, qreal, qreal, QPointF, QPointF, QPointF, QPointF, int, bool accepted)
{
//qDebug() << "MapItem::PinchAreaStarted";
    int x = (int)startCenter.x();
    int y = (int)(height() - startCenter.y());

    _.ui.pinch        = true;  _.ui.pinchStart        = { x, y };
    _.ui.press        = false; _.ui.pressStart        = { INT_MAX, INT_MAX };
    _.ui.pressAndHold = false; _.ui.pressAndHoldStart = { INT_MAX, INT_MAX };
    _.ui.dragging     = false;    
    OnZoom(_.ui.pinchStart, scale, angle, true);

    return accepted;
}

void MapItem::OnZoom(QPoint, qreal scale, qreal, bool first)
{
    if (first) { Q_ASSERT(events.empty()); _.zoomStart = _.CurrentZoomLevel(); }
#if 0
    qreal factor = scale < 1 ? 2 : 0.5;
    qreal zoom = _.zoomStart + (scale /*- 1.0*/) * factor;
#else
    qreal factor = scale < 1 ? 1 : .1;
    qreal zoom = _.zoomStart + (scale < 1 ? scale - 1 : scale) * factor;
#endif
    _.SetZoomLevel(zoom);
}

void SetZoomLevel(qreal zoom) {
    pThis->events.enqueue({MapItem::Z, {zoom, NAN}});
    Update();
}

void Zoom(bool in) {
    pThis->events.enqueue({MapItem::Z, { (in?-1:1) * std::numeric_limits<qreal>::max(), NAN}});
    Update();
}


Once again, your best guess is all I am looking for, thanks for the help in advanced.
Last edited on
I have not been able to test it yet but I believe the problem was actually with the Zoom function. I changed the logic s/t:

1
2
3
4
void Zoom(bool in) {
    pThis->events.enqueue({MapItem::Z, { (in?-1:1) * std::numeric_limits<qreal>::max(), NAN}});
    Update();
}


is now:

1
2
3
4
void Zoom(bool in) {
    pThis->events.enqueue({MapItem::Z, { (in?1:-1) * std::numeric_limits<qreal>::max(), NAN}});
    Update();
}


I was able to test and see that this fixed the scroll wheel logic (new bug I found) but I still haven't tested to see if it also fixed the pinch to zoom problem. I will mark this as solved for now and if it turns out I was incorrect then perhaps I will come back and badger you guys some more later.
Topic archived. No new replies allowed.