Gui: remove WinNativeGestureRecognizers because this was a workaround for Qt4 under Windows
This commit is contained in:
@@ -1263,7 +1263,6 @@ SET(FreeCADGui_CPP_SRCS
|
||||
WaitCursor.cpp
|
||||
ManualAlignment.cpp
|
||||
TransactionObject.cpp
|
||||
WinNativeGestureRecognizers.cpp
|
||||
)
|
||||
SET(FreeCADGui_SRCS
|
||||
Application.h
|
||||
@@ -1296,7 +1295,6 @@ SET(FreeCADGui_SRCS
|
||||
WaitCursor.h
|
||||
ManualAlignment.h
|
||||
TransactionObject.h
|
||||
WinNativeGestureRecognizers.h
|
||||
${FreeCADGui_SDK_MOC_HDRS}
|
||||
)
|
||||
|
||||
|
||||
@@ -145,7 +145,6 @@
|
||||
#include <QGesture>
|
||||
|
||||
#include "SoTouchEvents.h"
|
||||
#include "WinNativeGestureRecognizers.h"
|
||||
#include "Document.h"
|
||||
#include "ViewParams.h"
|
||||
|
||||
@@ -237,35 +236,6 @@ public:
|
||||
~ViewerEventFilter() {}
|
||||
|
||||
bool eventFilter(QObject* obj, QEvent* event) {
|
||||
|
||||
#ifdef GESTURE_MESS
|
||||
if (obj->isWidgetType()) {
|
||||
View3DInventorViewer* v = dynamic_cast<View3DInventorViewer*>(obj);
|
||||
if(v) {
|
||||
/* Internally, Qt seems to set up the gestures upon showing the
|
||||
* widget (but after this event is processed), thus invalidating
|
||||
* our settings. This piece takes care to retune gestures on the
|
||||
* next event after the show event.
|
||||
*/
|
||||
if(v->winGestureTuneState == View3DInventorViewer::ewgtsNeedTuning) {
|
||||
try{
|
||||
WinNativeGestureRecognizerPinch::TuneWindowsGestures(v);
|
||||
v->winGestureTuneState = View3DInventorViewer::ewgtsTuned;
|
||||
} catch (Base::Exception &e) {
|
||||
Base::Console().Warning("Failed to TuneWindowsGestures. Error: %s\n",e.what());
|
||||
v->winGestureTuneState = View3DInventorViewer::ewgtsDisabled;
|
||||
} catch (...) {
|
||||
Base::Console().Warning("Failed to TuneWindowsGestures. Unknown error.\n");
|
||||
v->winGestureTuneState = View3DInventorViewer::ewgtsDisabled;
|
||||
}
|
||||
}
|
||||
if (event->type() == QEvent::Show && v->winGestureTuneState == View3DInventorViewer::ewgtsTuned)
|
||||
v->winGestureTuneState = View3DInventorViewer::ewgtsNeedTuning;
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Bug #0000607: Some mice also support horizontal scrolling which however might
|
||||
// lead to some unwanted zooming when pressing the MMB for panning.
|
||||
// Thus, we filter out horizontal scrolling.
|
||||
@@ -574,20 +544,9 @@ void View3DInventorViewer::init()
|
||||
getEventFilter()->registerInputDevice(new SpaceNavigatorDevice);
|
||||
getEventFilter()->registerInputDevice(new GesturesDevice(this));
|
||||
|
||||
this->winGestureTuneState = View3DInventorViewer::ewgtsDisabled;
|
||||
try{
|
||||
this->grabGesture(Qt::PanGesture);
|
||||
this->grabGesture(Qt::PinchGesture);
|
||||
#ifdef GESTURE_MESS
|
||||
{
|
||||
static WinNativeGestureRecognizerPinch* recognizer;//static to avoid creating more than one recognizer, thus causing memory leak and gradual slowdown
|
||||
if(recognizer == 0){
|
||||
recognizer = new WinNativeGestureRecognizerPinch;
|
||||
recognizer->registerRecognizer(recognizer); //From now on, Qt owns the pointer.
|
||||
}
|
||||
}
|
||||
this->winGestureTuneState = View3DInventorViewer::ewgtsNeedTuning;
|
||||
#endif
|
||||
} catch (Base::Exception &e) {
|
||||
Base::Console().Warning("Failed to set up gestures. Error: %s\n", e.what());
|
||||
} catch (...) {
|
||||
@@ -1504,8 +1463,6 @@ void View3DInventorViewer::setNavigationType(Base::Type t)
|
||||
if (t.isBad())
|
||||
return;
|
||||
|
||||
this->winGestureTuneState = View3DInventorViewer::ewgtsNeedTuning; //triggers enable/disable rotation gesture when preferences change
|
||||
|
||||
if (this->navigation && this->navigation->getTypeId() == t)
|
||||
return; // nothing to do
|
||||
|
||||
|
||||
@@ -401,13 +401,6 @@ protected:
|
||||
void printDimension();
|
||||
void selectAll();
|
||||
|
||||
enum eWinGestureTuneState{
|
||||
ewgtsDisabled, //suppress tuning/re-tuning after errors
|
||||
ewgtsNeedTuning, //gestures are to be re-tuned upon next event
|
||||
ewgtsTuned
|
||||
};
|
||||
eWinGestureTuneState winGestureTuneState;//See ViewerEventFilter::eventFilter function for explanation
|
||||
|
||||
private:
|
||||
static void setViewportCB(void * userdata, SoAction * action);
|
||||
static void clearBufferCB(void * userdata, SoAction * action);
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Victor Titov (DeepSOIC) <vv.titov@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QEvent>
|
||||
# include <QGraphicsItem>
|
||||
# include <QWidget>
|
||||
# ifdef FC_OS_WIN32
|
||||
# include <Windows.h>
|
||||
# define _USE_MATH_DEFINES
|
||||
# include <cmath>
|
||||
# endif
|
||||
# include <cassert>
|
||||
#endif
|
||||
|
||||
#include "WinNativeGestureRecognizers.h"
|
||||
#ifdef GESTURE_MESS
|
||||
//this implementation is a bit incompatible with Qt5, since
|
||||
//nativegesture members were transformed into properties, and
|
||||
//the whole event was made public
|
||||
|
||||
|
||||
#include <qgesture.h>
|
||||
|
||||
#include <Base/Exception.h>
|
||||
#include <App/Application.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#if !defined(QT_NO_NATIVE_GESTURES)
|
||||
|
||||
//#include <private/qevent_p.h>
|
||||
//this include is not available on conda Qt, see https://forum.freecadweb.org/viewtopic.php?f=4&t=21405&p=167395#p167395
|
||||
//copy-pasted from this header:
|
||||
class QNativeGestureEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
None,
|
||||
GestureBegin,
|
||||
GestureEnd,
|
||||
Pan,
|
||||
Zoom,
|
||||
Rotate,
|
||||
Swipe
|
||||
};
|
||||
|
||||
QNativeGestureEvent()
|
||||
: QEvent(QEvent::NativeGesture), gestureType(None), percentage(0)
|
||||
#ifdef Q_WS_WIN
|
||||
, sequenceId(0), argument(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
Type gestureType;
|
||||
float percentage;
|
||||
QPoint position;
|
||||
float angle;
|
||||
#ifdef Q_WS_WIN
|
||||
ulong sequenceId;
|
||||
quint64 argument;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
QGesture* WinNativeGestureRecognizerPinch::create(QObject* target)
|
||||
{
|
||||
if (!target)
|
||||
return new QPinchGestureN; // a special case
|
||||
if (!target->isWidgetType())
|
||||
return 0;
|
||||
if (qobject_cast<QGraphicsObject *>(target))
|
||||
return 0;
|
||||
|
||||
//QWidget* q = static_cast<QWidget *>(target);
|
||||
/*QWidgetPrivate *d = q->d_func();
|
||||
d->nativeGesturePanEnabled = true;
|
||||
d->winSetupGestures();*/ //fails to compile =(, but we can rely on this being done by grabGesture(Pan...
|
||||
|
||||
return new QPinchGestureN;
|
||||
}
|
||||
|
||||
QGestureRecognizer::Result WinNativeGestureRecognizerPinch::recognize(QGesture *gesture, QObject *watched, QEvent *event)
|
||||
{
|
||||
QPinchGestureN* q = static_cast<QPinchGestureN*> (gesture);
|
||||
//QPinchGesturePrivate* d = q->d_func();//this fails to compile =( But we can get away without it.
|
||||
|
||||
QGestureRecognizer::Result result = QGestureRecognizer::Ignore;
|
||||
if (event->type() == QEvent::NativeGesture) {
|
||||
bool bZoom = false;
|
||||
bool bRotate = false;
|
||||
QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event);
|
||||
switch(ev->gestureType) {
|
||||
case QNativeGestureEvent::GestureBegin:
|
||||
break;
|
||||
case QNativeGestureEvent::Zoom:
|
||||
case QNativeGestureEvent::Rotate:
|
||||
bZoom = ev->gestureType == QNativeGestureEvent::Zoom;
|
||||
bRotate = ev->gestureType == QNativeGestureEvent::Rotate;
|
||||
result = QGestureRecognizer::TriggerGesture;
|
||||
event->accept();
|
||||
break;
|
||||
case QNativeGestureEvent::GestureEnd:
|
||||
if (q->state() == Qt::NoGesture)
|
||||
return QGestureRecognizer::Ignore; // some other gesture has ended
|
||||
result = QGestureRecognizer::FinishGesture;
|
||||
break;
|
||||
default:
|
||||
return QGestureRecognizer::Ignore;
|
||||
}
|
||||
double ang = 0.0;
|
||||
if (bRotate)
|
||||
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;
|
||||
q->setTotalChangeFlags(0); q->setChangeFlags(0);
|
||||
|
||||
q->setLastCenterPoint(QPointF());
|
||||
q->setCenterPoint(
|
||||
QPointF(
|
||||
qreal(ev->position.x()),
|
||||
qreal(ev->position.y())
|
||||
)
|
||||
);
|
||||
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);
|
||||
if(bZoom) {
|
||||
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
|
||||
|
||||
//store new last values
|
||||
q->setLastCenterPoint(q->centerPoint());
|
||||
q->setLastRotationAngle(q->rotationAngle());
|
||||
q->setLastScaleFactor(q->scaleFactor());
|
||||
q->myLastFingerDistance = q->myFingerDistance;
|
||||
q->myLastRotationAngle = q->myRotationAngle;
|
||||
|
||||
//update the current values
|
||||
if (bZoom)
|
||||
q->myFingerDistance = ev->argument;
|
||||
if (bRotate)
|
||||
q->myRotationAngle = ang;
|
||||
if(ev->gestureType == QNativeGestureEvent::GestureEnd){
|
||||
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->myFingerDistance) / (qreal)(q->myLastFingerDistance)
|
||||
);
|
||||
if (bRotate)
|
||||
q->setRotationAngle(q->myRotationAngle);
|
||||
q->setCenterPoint(
|
||||
QPointF(
|
||||
qreal(ev->position.x()),
|
||||
qreal(ev->position.y())
|
||||
)
|
||||
);
|
||||
|
||||
//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() != q->lastRotationAngle())
|
||||
cf |= QPinchGesture::RotationAngleChanged;
|
||||
q->setChangeFlags(cf);
|
||||
|
||||
//update totals
|
||||
q->setTotalChangeFlags (q->totalChangeFlags() | q->changeFlags());
|
||||
q->setTotalScaleFactor (q->totalScaleFactor() * q->scaleFactor());
|
||||
q->setTotalRotationAngle (q->rotationAngle());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
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->myLastFingerDistance = 0;
|
||||
q->setTotalChangeFlags(0); q->setChangeFlags(0);
|
||||
|
||||
q->setLastCenterPoint(QPointF());
|
||||
q->setCenterPoint(
|
||||
QPointF(
|
||||
0.0,
|
||||
0.0
|
||||
)
|
||||
);
|
||||
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->myLastFingerDistance = 0;
|
||||
q->myFingerDistance = 0;
|
||||
}
|
||||
|
||||
//function prototype for dymanic linking
|
||||
typedef BOOL ( __stdcall * ptrSetGestureConfig) (
|
||||
HWND , // window for which configuration is specified
|
||||
DWORD , // reserved, must be 0
|
||||
UINT , // count of GESTURECONFIG structures
|
||||
PGESTURECONFIG , // array of GESTURECONFIG structures, dwIDs will be processed in the
|
||||
// order specified and repeated occurrences will overwrite previous ones
|
||||
UINT ); // sizeof(GESTURECONFIG)
|
||||
|
||||
void WinNativeGestureRecognizerPinch::TuneWindowsGestures(QWidget* target)
|
||||
{
|
||||
//modify windows-specific gesture options
|
||||
#if WINVER >= _WIN32_WINNT_WIN7
|
||||
//dynamic linking - required to be able to run on windows pre-7
|
||||
HINSTANCE hinstLib = LoadLibraryA("user32.dll");
|
||||
if (hinstLib == 0)
|
||||
throw Base::RuntimeError("LoadLibrary(user32.dll) failed. Could not tune Windows gestures.");
|
||||
|
||||
ptrSetGestureConfig dllSetGestureConfig = reinterpret_cast<ptrSetGestureConfig> (GetProcAddress(hinstLib,"SetGestureConfig"));
|
||||
if (dllSetGestureConfig == 0)
|
||||
throw Base::RuntimeError("DLL entry point for SetGestureConfig not found in user32.dll. Could not tune Windows gestures.");
|
||||
|
||||
HWND w = target->winId();
|
||||
|
||||
//fill in the options
|
||||
const UINT nCfg = 2;
|
||||
GESTURECONFIG cfgs[nCfg];
|
||||
ZeroMemory(&cfgs, sizeof(cfgs));
|
||||
cfgs[0].dwID = GID_PAN;
|
||||
cfgs[0].dwWant = GC_PAN;
|
||||
cfgs[0].dwBlock = GC_PAN_WITH_GUTTER;//disables stickiness to pure vertical/pure horizontal pans
|
||||
|
||||
bool enableGestureTilt = !(App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/View")->GetBool("DisableTouchTilt",true));
|
||||
if(enableGestureTilt){
|
||||
cfgs[1].dwID = GID_ROTATE;
|
||||
cfgs[1].dwWant = GC_ROTATE;
|
||||
} else {
|
||||
cfgs[1].dwID = GID_ROTATE;
|
||||
cfgs[1].dwBlock = GC_ROTATE;
|
||||
}
|
||||
|
||||
//set the options
|
||||
bool ret = dllSetGestureConfig(w, 0, nCfg, cfgs, sizeof(GESTURECONFIG));
|
||||
assert(ret);
|
||||
if(!ret){
|
||||
DWORD err = GetLastError();
|
||||
QString errMsg = QString::fromLatin1("Error in SetGestureConfig. GetLastError = %1").arg(err);
|
||||
throw Base::RuntimeError(errMsg.toLatin1());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif //!defined(QT_NO_NATIVE_GESTURES)
|
||||
|
||||
#endif // GESTURE_MESS
|
||||
@@ -1,64 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Victor Titov (DeepSOIC) <vv.titov@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
/*! This file adds support for pinch gestures in Windows 8 to Qt4.8. I think it
|
||||
* may not be necessary for Qt5. I also think this was actually not absolutely
|
||||
* necessary, and it may be possible to force Qt gesture recognition from plain
|
||||
* touch input. --DeepSOIC
|
||||
*/
|
||||
|
||||
#ifndef WINNATIVEGESTURERECOGNIZERS_H
|
||||
#define WINNATIVEGESTURERECOGNIZERS_H
|
||||
|
||||
#include <QGestureRecognizer>
|
||||
#include <QPinchGesture>
|
||||
|
||||
#ifdef GESTURE_MESS
|
||||
|
||||
/*!
|
||||
* \brief The QPinchGestureN class is a special version of QPinchGesture,
|
||||
* containing a few extra fields for state tracking.
|
||||
*/
|
||||
class QPinchGestureN: public QPinchGesture
|
||||
{
|
||||
public:
|
||||
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
|
||||
{
|
||||
public:
|
||||
WinNativeGestureRecognizerPinch(){}
|
||||
virtual QGesture* create ( QObject* target );
|
||||
virtual Result recognize ( QGesture* gesture, QObject* watched, QEvent* event );
|
||||
virtual void reset ( QGesture* gesture );
|
||||
static void TuneWindowsGestures(QWidget* target);
|
||||
};
|
||||
|
||||
#endif //GESTUREMESS
|
||||
|
||||
#endif // WINNATIVEGESTURERECOGNIZERS_H
|
||||
Reference in New Issue
Block a user