|
@@ -9,8 +9,15 @@ MyView::MyView(QWidget *parent) :
|
|
beishu(1.00000)
|
|
beishu(1.00000)
|
|
{
|
|
{
|
|
setDragMode(QGraphicsView::ScrollHandDrag);
|
|
setDragMode(QGraphicsView::ScrollHandDrag);
|
|
|
|
+
|
|
|
|
+// grabGesture(Qt::PanGesture);
|
|
|
|
+ grabGesture(Qt::PinchGesture);
|
|
|
|
+ // grabGesture(Qt::SwipeGesture);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
void MyView::mousePressEvent(QMouseEvent *event)
|
|
void MyView::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
{
|
|
// qDebug("x is %d",event->pos().x());
|
|
// qDebug("x is %d",event->pos().x());
|
|
@@ -19,6 +26,7 @@ void MyView::mousePressEvent(QMouseEvent *event)
|
|
}
|
|
}
|
|
void MyView::mouseMoveEvent(QMouseEvent *event)
|
|
void MyView::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
{
|
|
|
|
+ if(mbInPinch == true)return;
|
|
QGraphicsView::mouseMoveEvent(event);
|
|
QGraphicsView::mouseMoveEvent(event);
|
|
|
|
|
|
// QScrollBar * ps = verticalScrollBar();
|
|
// QScrollBar * ps = verticalScrollBar();
|
|
@@ -145,3 +153,60 @@ void MyView::mouseDoubleClickEvent(QMouseEvent *event)
|
|
emit dbclickxy(viewx,viewy);
|
|
emit dbclickxy(viewx,viewy);
|
|
qDebug("view x is %d view y is %d ",viewx,viewy);
|
|
qDebug("view x is %d view y is %d ",viewx,viewy);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+bool MyView::event(QEvent *event)
|
|
|
|
+{
|
|
|
|
+ if (event->type() == QEvent::Gesture)
|
|
|
|
+ {
|
|
|
|
+ // qDebug("gestrue event");
|
|
|
|
+ // return true;
|
|
|
|
+ return gestureEvent(static_cast<QGestureEvent*>(event));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return QGraphicsView::event(event);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool MyView::gestureEvent(QGestureEvent *event)
|
|
|
|
+{
|
|
|
|
+ if (QGesture *pinch = event->gesture(Qt::PinchGesture))
|
|
|
|
+ pinchTriggered(static_cast<QPinchGesture *>(pinch));
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MyView::pinchTriggered(QPinchGesture *gesture)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ static double currentStepScaleFactor = 1;
|
|
|
|
+ static double oldfactor = 1;
|
|
|
|
+ QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
|
|
|
|
+ if (changeFlags & QPinchGesture::ScaleFactorChanged) {
|
|
|
|
+ currentStepScaleFactor = gesture->totalScaleFactor();
|
|
|
|
+ mbInPinch = true;
|
|
|
|
+ }
|
|
|
|
+ if (gesture->state() == Qt::GestureFinished) {
|
|
|
|
+// scaleFactor *= currentStepScaleFactor;
|
|
|
|
+// qDebug("scale is %f ",currentStepScaleFactor);
|
|
|
|
+
|
|
|
|
+ currentStepScaleFactor = 1;
|
|
|
|
+ oldfactor = 1;
|
|
|
|
+ mbInPinch = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int width,hgt;
|
|
|
|
+ width = sceneRect().width();
|
|
|
|
+ hgt = sceneRect().height();
|
|
|
|
+ QScrollBar * psV = verticalScrollBar();
|
|
|
|
+ QScrollBar * psH = horizontalScrollBar();
|
|
|
|
+
|
|
|
|
+ int centery = (psV->value() + psV->size().height()/2)/beishu;
|
|
|
|
+ int centerx = (psH->value() + psH->size().width()/2)/beishu;
|
|
|
|
+
|
|
|
|
+ double fscale = currentStepScaleFactor/oldfactor;
|
|
|
|
+ scale(fscale,fscale);
|
|
|
|
+ beishu *= fscale;
|
|
|
|
+ oldfactor = currentStepScaleFactor;
|
|
|
|
+
|
|
|
|
+ centerOn(centerx,centery);
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|