Implement wxGestureEvent support for wxQt
Do it generically in wxWindow and also provide a special version for wxGLCanvas for which the standard implementation doesn't work well.
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
#include "wx/qt/private/converter.h"
|
||||
#include "wx/qt/private/utils.h"
|
||||
|
||||
#include <QtWidgets/QGestureEvent>
|
||||
#include <QtGui/QCursor>
|
||||
|
||||
class QPaintEvent;
|
||||
|
||||
template< typename Handler >
|
||||
@@ -327,6 +330,132 @@ protected:
|
||||
virtual bool winEvent ( MSG * message, long * result ) { }
|
||||
virtual bool x11Event ( XEvent * event ) { } */
|
||||
|
||||
virtual bool event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::Gesture)
|
||||
{
|
||||
return gestureEvent(static_cast<QGestureEvent*>(event), event);
|
||||
}
|
||||
|
||||
return Widget::event(event);
|
||||
}
|
||||
|
||||
bool gestureEvent(QGestureEvent *gesture, QEvent *event)
|
||||
{
|
||||
if (QGesture *tah = gesture->gesture(Qt::TapAndHoldGesture))
|
||||
{
|
||||
// Set the policy so that accepted gestures are taken by the first window that gets them
|
||||
tah->setGestureCancelPolicy ( QGesture::CancelAllInContext );
|
||||
tapandholdTriggered(static_cast<QTapAndHoldGesture *>(tah), event);
|
||||
}
|
||||
|
||||
if (QGesture *pan = gesture->gesture(Qt::PanGesture))
|
||||
{
|
||||
panTriggered(static_cast<QPanGesture *>(pan), event);
|
||||
}
|
||||
|
||||
if (QGesture *pinch = gesture->gesture(Qt::PinchGesture))
|
||||
{
|
||||
pinchTriggered(static_cast<QPinchGesture *>(pinch), event);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void tapandholdTriggered(QTapAndHoldGesture *gesture, QEvent *event)
|
||||
{
|
||||
wxWindow *win = wxWindow::QtRetrieveWindowPointer( this );
|
||||
|
||||
if (gesture->state() == Qt::GestureFinished)
|
||||
{
|
||||
if ( win )
|
||||
{
|
||||
wxLongPressEvent ev(win->GetId());
|
||||
ev.SetPosition( wxQtConvertPoint( gesture->position().toPoint() ) );
|
||||
|
||||
ev.SetGestureEnd();
|
||||
win->ProcessWindowEvent( ev );
|
||||
event->accept();
|
||||
}
|
||||
|
||||
}
|
||||
else if (gesture->state() == Qt::GestureStarted)
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void panTriggered(QPanGesture *gesture, QEvent *event)
|
||||
{
|
||||
wxWindow *win = wxWindow::QtRetrieveWindowPointer( this );
|
||||
|
||||
if (win)
|
||||
{
|
||||
wxPanGestureEvent evp(win->GetId());
|
||||
QPoint pos = QCursor::pos();
|
||||
evp.SetPosition( wxQtConvertPoint( pos ) );
|
||||
|
||||
QPoint offset = gesture->offset().toPoint();
|
||||
QPoint offset_last = gesture->lastOffset().toPoint();
|
||||
QPoint delta(offset.x() - offset_last.x(), offset.y() - offset_last.y());
|
||||
|
||||
evp.SetDelta( wxQtConvertPoint( delta ) );
|
||||
|
||||
switch(gesture->state())
|
||||
{
|
||||
case Qt::GestureStarted:
|
||||
evp.SetGestureStart();
|
||||
break;
|
||||
case Qt::GestureFinished:
|
||||
case Qt::GestureCanceled:
|
||||
evp.SetGestureEnd();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
win->ProcessWindowEvent( evp );
|
||||
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void pinchTriggered(QPinchGesture *gesture, QEvent *event)
|
||||
{
|
||||
wxWindow *win = wxWindow::QtRetrieveWindowPointer( this );
|
||||
if (win)
|
||||
{
|
||||
|
||||
qreal this_sf = gesture->scaleFactor();
|
||||
QPoint center_point = gesture->centerPoint().toPoint();
|
||||
|
||||
wxZoomGestureEvent evp(win->GetId());
|
||||
evp.SetPosition( wxQtConvertPoint( center_point ) );
|
||||
evp.SetZoomFactor( this_sf);
|
||||
|
||||
switch(gesture->state())
|
||||
{
|
||||
case Qt::GestureStarted:
|
||||
evp.SetGestureStart();
|
||||
break;
|
||||
case Qt::GestureFinished:
|
||||
case Qt::GestureCanceled:
|
||||
evp.SetGestureEnd();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
win->ProcessWindowEvent( evp );
|
||||
|
||||
event->accept();
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user