diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a6df28fe0..8f1c41184 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -920,6 +920,7 @@ void MainWindow::ActionDraw(bool checked) currentScene = sceneDraw; view->setScene(currentScene); + connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); RestoreCurrentScene(); mode = Draw::Calculation; @@ -951,6 +952,7 @@ void MainWindow::ActionDetails(bool checked) currentScene = sceneDetails; view->setScene(sceneDetails); + disconnect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); RestoreCurrentScene(); drawMode = false; diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index 3c37b53fc..5154af819 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -115,23 +115,31 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, QGraphicsScene *sc = this->scene(); QRectF rect = sc->itemsBoundingRect(); - //Correct BoundingRect - rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y()); QList list = sc->views(); - QRect rec = list[0]->contentsRect(); - //Correct contentsRect - rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y()); + QRect rec0 = list[0]->rect(); + rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2); - if(rec.contains(rect.toRect())) + QTransform t = list[0]->transform(); + + QRectF rec1; + if(t.m11() < 1) { - sc->setSceneRect(rec); + rec1 = QRect(0, 0, rec0.width()/t.m11(), rec0.height()/t.m22()); + + rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y()); + QPolygonF polygone = list[0]->mapToScene(rec1.toRect()); + rec1 = polygone.boundingRect(); + } else { - rect = rect.united(rec); - sc->setSceneRect(rect); + rec1 = rec0; } + + rec1 = rec1.united(rect.toRect()); + sc->setSceneRect(rec1); + //I don't now why but signal does not work. doc->FullUpdateTree(); } diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 7f00c0771..50f7daf0e 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -261,22 +261,30 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QGraphicsScene *sc = this->scene(); QRectF rect = sc->itemsBoundingRect(); - //Correct BoundingRect - //rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y()); - qDebug()<<"rect"< list = sc->views(); - QRect rec = list[0]->contentsRect(); + QRect rec0 = list[0]->rect(); + rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2); + QTransform t = list[0]->transform(); - qDebug()<<"m11="<setSceneRect(rec); + + QRectF rec1; + if(t.m11() < 1) + { + rec1 = QRect(0, 0, rec0.width()/t.m11(), rec0.height()/t.m22()); + + rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y()); + QPolygonF polygone = list[0]->mapToScene(rec1.toRect()); + rec1 = polygone.boundingRect(); + + } + else + { + rec1 = rec0; + } + + rec1 = rec1.united(rect.toRect()); + sc->setSceneRect(rec1); doc->haveLiteChange(); } diff --git a/src/widgets/vmaingraphicsview.cpp b/src/widgets/vmaingraphicsview.cpp index 02fe36dcf..7b9b4f71a 100644 --- a/src/widgets/vmaingraphicsview.cpp +++ b/src/widgets/vmaingraphicsview.cpp @@ -43,48 +43,88 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent) void VMainGraphicsView::wheelEvent(QWheelEvent *event) { - int numDegrees = event->delta() / 8; - int numSteps = numDegrees / 15; // see QWheelEvent documentation + int numSteps = event->delta() / 8 / 15; // see QWheelEvent documentation + _numScheduledScalings += numSteps; if (_numScheduledScalings * numSteps < 0) { // if user moved the wheel in another direction, we reset _numScheduledScalings = numSteps; // previously scheduled scalings } - QTimeLine *anim = new QTimeLine(350, this); + QTimeLine *anim = new QTimeLine(300, this); Q_ASSERT(anim != 0); anim->setUpdateInterval(20); - connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scalingTime); + if (QApplication::keyboardModifiers() == Qt::ControlModifier) + {// If you press CTRL this code will be executed + connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scalingTime); + } + else + { + connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scrollingTime); + } connect(anim, &QTimeLine::finished, this, &VMainGraphicsView::animFinished); anim->start(); } void VMainGraphicsView::scalingTime(qreal x) +{ + Q_UNUSED(x); + const QPointF p0scene = mapToScene(mapFromGlobal(QCursor::pos())); + + qreal factor = 1.0 + static_cast(_numScheduledScalings) / 50.0; + scale(factor, factor); + + const QPointF p1mouse = mapFromScene(p0scene); + const QPointF move = p1mouse - this->mapFromGlobal(QCursor::pos()); // The move + horizontalScrollBar()->setValue(move.x() + horizontalScrollBar()->value()); + verticalScrollBar()->setValue(move.y() + verticalScrollBar()->value()); + + QGraphicsScene *sc = this->scene(); + QRectF rect = sc->itemsBoundingRect(); + + QRect rec0 = this->rect(); + rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2); + + QTransform t = this->transform(); + + QRectF rec1; + if(t.m11() < 1) + { + rec1 = QRect(0, 0, rec0.width()/t.m11(), rec0.height()/t.m22()); + + rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y()); + QPolygonF polygone = this->mapToScene(rec1.toRect()); + rec1 = polygone.boundingRect(); + + } + else + { + rec1 = rec0; + } + + rec1 = rec1.united(rect.toRect()); + sc->setSceneRect(rec1); + + emit NewFactor(factor); +} + +void VMainGraphicsView::scrollingTime(qreal x) { Q_UNUSED(x); qreal factor = 1.0; - if (QApplication::keyboardModifiers() == Qt::ControlModifier) - {// If you press CTRL this code will be executed - factor = 1.0 + static_cast(_numScheduledScalings) / 300.0; - scale(factor, factor); + if (_numScheduledScalings < 0) + { + verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5)); emit NewFactor(factor); } else { - if (_numScheduledScalings < 0) - { - verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5)); +// if (verticalScrollBar()->value() > 0) +// { + verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5)); emit NewFactor(factor); - } - else - { - if (verticalScrollBar()->value() > 0) - { - verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5)); - emit NewFactor(factor); - } - } +// } } } diff --git a/src/widgets/vmaingraphicsview.h b/src/widgets/vmaingraphicsview.h index a42d53967..63cc710cf 100644 --- a/src/widgets/vmaingraphicsview.h +++ b/src/widgets/vmaingraphicsview.h @@ -55,6 +55,7 @@ public slots: * @param x */ void scalingTime(qreal x); + void scrollingTime(qreal x); /** * @brief animFinished */