QGraphicsView resizing after scaling or moving item.
--HG-- branch : feature
This commit is contained in:
parent
666dd664eb
commit
0996dab823
|
@ -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;
|
||||
|
|
|
@ -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<QGraphicsView*> 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();
|
||||
}
|
||||
|
|
|
@ -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"<<rect;
|
||||
|
||||
QList<QGraphicsView*> 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="<<t.m11();
|
||||
qDebug()<<"m22="<<t.m22();
|
||||
//Correct contentsRect
|
||||
rec = QRect(0, 0, rec.width()/t.m11() - rec.x(), rec.height()/t.m22() - rec.y());
|
||||
// rec = QRectF(rec.x()/t.m11(), rec.y()/t.m22(), rec.width()/t.m11(), rec.height()/t.m22());
|
||||
qDebug()<<"rec"<<rec;
|
||||
rec = rec.united(rect.toRect());
|
||||
qDebug()<<"rec1"<<rec;
|
||||
sc->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();
|
||||
}
|
||||
|
|
|
@ -43,19 +43,26 @@ 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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -63,15 +70,49 @@ void VMainGraphicsView::wheelEvent(QWheelEvent *event)
|
|||
void VMainGraphicsView::scalingTime(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<qreal>(_numScheduledScalings) / 300.0;
|
||||
const QPointF p0scene = mapToScene(mapFromGlobal(QCursor::pos()));
|
||||
|
||||
qreal factor = 1.0 + static_cast<qreal>(_numScheduledScalings) / 50.0;
|
||||
scale(factor, factor);
|
||||
emit NewFactor(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 (_numScheduledScalings < 0)
|
||||
{
|
||||
verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5));
|
||||
|
@ -79,12 +120,11 @@ void VMainGraphicsView::scalingTime(qreal x)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (verticalScrollBar()->value() > 0)
|
||||
{
|
||||
// if (verticalScrollBar()->value() > 0)
|
||||
// {
|
||||
verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5));
|
||||
emit NewFactor(factor);
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ public slots:
|
|||
* @param x
|
||||
*/
|
||||
void scalingTime(qreal x);
|
||||
void scrollingTime(qreal x);
|
||||
/**
|
||||
* @brief animFinished
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user