@vishnu said:
May i know the use of it?
yes it's a bool at false in constructor
you have forget event in prototype :
'virtual bool QWidget::event(QEvent*)' without object in => 'virtual bool QWidget::event(QEvent* !!! event !!! )' without object
CustomPlot::CustomPlot(QWidget *parent)
:QCustomPlot(parent)
{
setAttribute(Qt::WA_AcceptTouchEvents);
_release2touch = false;
_touchDevice = false;
}
bool CustomPlot::event(QEvent* event)
{
if(_touchDevice)
{
if(event->type() == QEvent::MouseButtonDblClick ||
event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease ||
event->type() == QEvent::MouseMove ||
event->type() == QEvent::MouseTrackingChange)
{
event->ignore();
return true;
}
if(event->type() == QEvent::Wheel)
_touchDevice = false;
}
if(event->type() == QEvent::TouchBegin ||
event->type() == QEvent::TouchUpdate ||
event->type() == QEvent::TouchEnd ){
if(!_touchDevice)
_touchDevice = true;
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
if(touchPoints.count() == 1 && touchEvent->touchPointStates().testFlag(Qt::TouchPointReleased))
_release2touch = false;
if (touchPoints.count() == 1 && !_release2touch)
{
switch (event->type()) {
case QEvent::TouchBegin:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QTouchEvent::TouchPoint touchPoints = touchEvent->touchPoints().first();
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress,
touchPoints.pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
mousePressEvent(e); //==> meilleure methode
}break;
case QEvent::TouchUpdate:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QTouchEvent::TouchPoint touchPoints = touchEvent->touchPoints().first();
QMouseEvent *e = new QMouseEvent(QEvent::MouseMove,
touchPoints.pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
mouseMoveEvent(e);
}break;
case QEvent::TouchEnd:{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QTouchEvent::TouchPoint touchPoints = touchEvent->touchPoints().first();
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonRelease,
touchPoints.pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
mouseReleaseEvent(e);
}break;
default:
break;
}
}else if (touchPoints.count() == 2) {
_release2touch = true;
// determine scale factor
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();// touchPoints.last();
double currentScaleFactor =
QLineF(touchPoint0.pos(), touchPoint1.pos()).length() /
QLineF(touchPoint0.lastPos(), touchPoint1.lastPos()).length();
QPointF centreZoom = QPointF((touchPoint0.pos().x()+ touchPoint1.pos().x())/2 ,
(touchPoint0.pos().y()+ touchPoint1.pos().y())/2);
QPointF lastCenterZoom = QPointF((touchPoint0.lastPos().x()+ touchPoint1.lastPos().x())/2 ,
(touchPoint0.lastPos().y()+ touchPoint1.lastPos().y())/2);
if (touchEvent->touchPointStates().testFlag(Qt::TouchPointReleased))
currentScaleFactor = 1;
if(currentScaleFactor<1)
currentScaleFactor = currentScaleFactor + (1-currentScaleFactor)/8;
else
currentScaleFactor = currentScaleFactor+ (currentScaleFactor-1)/8;
currentScaleFactor =1/currentScaleFactor;
double diffX = this->xAxis->pixelToCoord(lastCenterZoom.x())
- this->xAxis->pixelToCoord(centreZoom.x());
double diffY = this->yAxis->pixelToCoord(lastCenterZoom.y())
- this->yAxis->pixelToCoord(centreZoom.y());
if(!touchEvent->touchPointStates().testFlag(Qt::TouchPointReleased)){
this->xAxis->moveRange(diffX);
this->yAxis->moveRange(diffY);
this->xAxis->scaleRange(currentScaleFactor,this->xAxis->pixelToCoord(centreZoom.x()));
this->yAxis->scaleRange(currentScaleFactor,this->yAxis->pixelToCoord(centreZoom.y()));
this->replot();
}
}
return true;
}
return QWidget::event(event);
}