Gui: Gesture: QPinchGesture angle - sign, degrees, make cumulative
fixes pinch gesture rotation part on Qt5 (tested only on windows, Qt4 and Qt5)
This commit is contained in:
committed by
Yorik van Havre
parent
623a1b5ce8
commit
46d0d4c80c
@@ -84,8 +84,8 @@ SoGesturePinchEvent::SoGesturePinchEvent(QPinchGesture* qpinch, QWidget *widget)
|
||||
deltaZoom = qpinch->scaleFactor();
|
||||
totalZoom = qpinch->totalScaleFactor();
|
||||
|
||||
deltaAngle = qpinch->rotationAngle();
|
||||
totalAngle = qpinch->totalRotationAngle();
|
||||
deltaAngle = unbranchAngle((qpinch->rotationAngle()-qpinch->lastRotationAngle()) / 180.0 * M_PI);
|
||||
totalAngle = qpinch->totalRotationAngle() / 180 * M_PI;
|
||||
|
||||
state = SbGestureState(qpinch->state());
|
||||
|
||||
@@ -102,6 +102,18 @@ SbBool SoGesturePinchEvent::isSoGesturePinchEvent(const SoEvent *ev) const
|
||||
return ev->isOfType(SoGesturePinchEvent::getClassTypeId());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief SoGesturePinchEvent::unbranchAngle : utility function to bring an angle into -pi..pi region.
|
||||
* \param ang - in radians
|
||||
* \return
|
||||
*/
|
||||
double SoGesturePinchEvent::unbranchAngle(double ang)
|
||||
{
|
||||
const double Pi = 3.14159265358979323846;
|
||||
return ang - 2.0*Pi*floor((ang+Pi)/(2.0*Pi));
|
||||
}
|
||||
|
||||
|
||||
//----------------------------SoGestureSwipeEvent--------------------------------
|
||||
|
||||
SO_EVENT_SOURCE(SoGestureSwipeEvent);
|
||||
|
||||
@@ -91,6 +91,8 @@ public:
|
||||
double deltaAngle;
|
||||
double totalAngle;
|
||||
|
||||
static double unbranchAngle(double ang);
|
||||
|
||||
};
|
||||
|
||||
class SoGestureSwipeEvent : public SoGestureEvent {
|
||||
|
||||
@@ -129,7 +129,7 @@ QGestureRecognizer::Result WinNativeGestureRecognizerPinch::recognize(QGesture *
|
||||
}
|
||||
double ang = 0.0;
|
||||
if (bRotate)
|
||||
ang=GID_ROTATE_ANGLE_FROM_ARGUMENT(LOWORD(ev->argument));
|
||||
ang=GID_ROTATE_ANGLE_FROM_ARGUMENT(LOWORD(ev->argument)) / M_PI * 180.0;
|
||||
if (q->state() == Qt::NoGesture) {
|
||||
//start of a new gesture, prefill stuff
|
||||
//d->isNewSequence = true;
|
||||
@@ -146,11 +146,13 @@ QGestureRecognizer::Result WinNativeGestureRecognizerPinch::recognize(QGesture *
|
||||
q->setTotalRotationAngle(0.0); q->setLastRotationAngle(0.0); q->setRotationAngle(0.0);
|
||||
q->setTotalScaleFactor(1.0); q->setLastScaleFactor(1.0); q->setScaleFactor(1.0);
|
||||
if(bZoom) {
|
||||
q->lastFingerDistance = ev->argument;
|
||||
q->fingerDistance = ev->argument;
|
||||
q->myLastFingerDistance = ev->argument;
|
||||
q->myFingerDistance = ev->argument;
|
||||
q->myStartFingerDistance = ev->argument;
|
||||
} else if (bRotate) {
|
||||
q->myLastRotationAngle = 0;
|
||||
q->myRotationAngle = 0;
|
||||
q->myStartAngle = 0;
|
||||
}
|
||||
} else {//in the middle of gesture
|
||||
|
||||
@@ -158,24 +160,24 @@ QGestureRecognizer::Result WinNativeGestureRecognizerPinch::recognize(QGesture *
|
||||
q->setLastCenterPoint(q->centerPoint());
|
||||
q->setLastRotationAngle(q->rotationAngle());
|
||||
q->setLastScaleFactor(q->scaleFactor());
|
||||
q->lastFingerDistance = q->fingerDistance;
|
||||
q->myLastFingerDistance = q->myFingerDistance;
|
||||
q->myLastRotationAngle = q->myRotationAngle;
|
||||
|
||||
//update the current values
|
||||
if (bZoom)
|
||||
q->fingerDistance = ev->argument;
|
||||
q->myFingerDistance = ev->argument;
|
||||
if (bRotate)
|
||||
q->myRotationAngle = ang;
|
||||
if(ev->gestureType == QNativeGestureEvent::GestureEnd){
|
||||
q->fingerDistance = q->lastFingerDistance;//the end-of-gesture event holds no finger separation data, hence we are using the last value.
|
||||
q->myFingerDistance = q->myLastFingerDistance;//the end-of-gesture event holds no finger separation data, hence we are using the last value.
|
||||
q->myRotationAngle = q->myLastRotationAngle;
|
||||
}
|
||||
if (bZoom)
|
||||
q->setScaleFactor(
|
||||
(qreal)(q->fingerDistance) / (qreal)(q->lastFingerDistance)
|
||||
(qreal)(q->myFingerDistance) / (qreal)(q->myLastFingerDistance)
|
||||
);
|
||||
if (bRotate)
|
||||
q->setRotationAngle(qreal(unbranchAngle(q->myRotationAngle - q->myLastRotationAngle)));
|
||||
q->setRotationAngle(q->myRotationAngle);
|
||||
q->setCenterPoint(
|
||||
QPointF(
|
||||
qreal(ev->position.x()),
|
||||
@@ -183,20 +185,20 @@ QGestureRecognizer::Result WinNativeGestureRecognizerPinch::recognize(QGesture *
|
||||
)
|
||||
);
|
||||
|
||||
//compute the changes
|
||||
//detect changes
|
||||
QPinchGesture::ChangeFlags cf = 0;
|
||||
if ( q->scaleFactor() != 1.0 )
|
||||
cf |= QPinchGesture::ScaleFactorChanged;
|
||||
if (q->lastCenterPoint() != q->centerPoint())
|
||||
cf |= QPinchGesture::CenterPointChanged;
|
||||
if (q->rotationAngle() != 0.0)
|
||||
if (q->rotationAngle() != q->lastRotationAngle())
|
||||
cf |= QPinchGesture::RotationAngleChanged;
|
||||
q->setChangeFlags(cf);
|
||||
|
||||
//increment totals
|
||||
//update totals
|
||||
q->setTotalChangeFlags (q->totalChangeFlags() | q->changeFlags());
|
||||
q->setTotalScaleFactor (q->totalScaleFactor() * q->scaleFactor());
|
||||
q->setTotalRotationAngle (q->totalRotationAngle() + q->rotationAngle());
|
||||
q->setTotalRotationAngle (q->rotationAngle());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -207,7 +209,7 @@ void WinNativeGestureRecognizerPinch::reset(QGesture* gesture)
|
||||
{
|
||||
QGestureRecognizer::reset(gesture);//resets the state of the gesture, which is not write-accessible otherwise
|
||||
QPinchGestureN *q = static_cast<QPinchGestureN*>(gesture);
|
||||
q->lastFingerDistance = 0;
|
||||
q->myLastFingerDistance = 0;
|
||||
q->setTotalChangeFlags(0); q->setChangeFlags(0);
|
||||
|
||||
q->setLastCenterPoint(QPointF());
|
||||
@@ -220,8 +222,8 @@ void WinNativeGestureRecognizerPinch::reset(QGesture* gesture)
|
||||
q->setStartCenterPoint(q->centerPoint());
|
||||
q->setTotalRotationAngle(0.0); q->setLastRotationAngle(0.0); q->setRotationAngle(0.0);
|
||||
q->setTotalScaleFactor(1.0); q->setLastScaleFactor(1.0); q->setScaleFactor(1.0);
|
||||
q->lastFingerDistance = 0;
|
||||
q->fingerDistance = 0;
|
||||
q->myLastFingerDistance = 0;
|
||||
q->myFingerDistance = 0;
|
||||
}
|
||||
|
||||
//function prototype for dymanic linking
|
||||
@@ -269,17 +271,6 @@ void WinNativeGestureRecognizerPinch::TuneWindowsGestures(QWidget* target)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief WinNativeGestureRecognizerPinch::unbranchAngle utility function to bring an angle into -pi..pi region.
|
||||
* \param ang
|
||||
* \return
|
||||
*/
|
||||
double WinNativeGestureRecognizerPinch::unbranchAngle(double ang)
|
||||
{
|
||||
const double Pi = 3.14159265358979323846;
|
||||
return ang - 2.0*Pi*floor((ang+Pi)/(2.0*Pi));
|
||||
}
|
||||
|
||||
#endif //!defined(QT_NO_NATIVE_GESTURES)
|
||||
|
||||
#endif // GESTURE_MESS
|
||||
|
||||
@@ -50,10 +50,12 @@
|
||||
class QPinchGestureN: public QPinchGesture
|
||||
{
|
||||
public:
|
||||
int lastFingerDistance;//distance between fingers, in pixels
|
||||
int fingerDistance;
|
||||
double myRotationAngle;
|
||||
double myLastRotationAngle;
|
||||
int myFingerDistance = 0; //distance between fingers, in pixels
|
||||
int myLastFingerDistance = 0;
|
||||
int myStartFingerDistance = 0; //finger distance at gesture start
|
||||
double myRotationAngle = 0.0;
|
||||
double myLastRotationAngle = 0.0;
|
||||
double myStartAngle = 0.0;
|
||||
};
|
||||
|
||||
class WinNativeGestureRecognizerPinch : public QGestureRecognizer
|
||||
@@ -64,7 +66,6 @@ public:
|
||||
virtual Result recognize ( QGesture* gesture, QObject* watched, QEvent* event );
|
||||
virtual void reset ( QGesture* gesture );
|
||||
static void TuneWindowsGestures(QWidget* target);
|
||||
static double unbranchAngle(double ang);
|
||||
};
|
||||
|
||||
#endif //GESTUREMESS
|
||||
|
||||
Reference in New Issue
Block a user