Refactoring calculation scene rect.
--HG-- branch : develop
This commit is contained in:
parent
129f9b9e24
commit
f98ca6eea1
|
@ -1035,25 +1035,8 @@ void MainWindow::ActionOpen()
|
||||||
{
|
{
|
||||||
OpenPattern(fName);
|
OpenPattern(fName);
|
||||||
|
|
||||||
QRectF rect = sceneDraw->itemsBoundingRect();
|
VAbstractTool::NewSceneRect(sceneDraw, view);
|
||||||
//Correct BoundingRect
|
VAbstractTool::NewSceneRect(sceneDetails, view);
|
||||||
rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y());
|
|
||||||
|
|
||||||
QRect rec = view->contentsRect();
|
|
||||||
//Correct contentsRect
|
|
||||||
rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y());
|
|
||||||
|
|
||||||
if(rec.contains(rect.toRect()))
|
|
||||||
{
|
|
||||||
sceneDraw->setSceneRect(rec);
|
|
||||||
sceneDetails->setSceneRect(rec);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rect = rect.united(rec);
|
|
||||||
sceneDraw->setSceneRect(rect);
|
|
||||||
sceneDetails->setSceneRect(rect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,32 +113,8 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change,
|
||||||
domElement.setAttribute(AttrX, QString().setNum(toMM(newPos.x())));
|
domElement.setAttribute(AttrX, QString().setNum(toMM(newPos.x())));
|
||||||
domElement.setAttribute(AttrY, QString().setNum(toMM(newPos.y())));
|
domElement.setAttribute(AttrY, QString().setNum(toMM(newPos.y())));
|
||||||
|
|
||||||
QGraphicsScene *sc = this->scene();
|
QList<QGraphicsView*> list = this->scene()->views();
|
||||||
QRectF rect = sc->itemsBoundingRect();
|
VAbstractTool::NewSceneRect(this->scene(), list[0]);
|
||||||
|
|
||||||
QList<QGraphicsView*> list = sc->views();
|
|
||||||
QRect rec0 = list[0]->rect();
|
|
||||||
rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);
|
|
||||||
|
|
||||||
QTransform t = list[0]->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 = list[0]->mapToScene(rec1.toRect());
|
|
||||||
rec1 = polygone.boundingRect();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rec1 = rec0;
|
|
||||||
}
|
|
||||||
|
|
||||||
rec1 = rec1.united(rect.toRect());
|
|
||||||
sc->setSceneRect(rec1);
|
|
||||||
|
|
||||||
//I don't now why but signal does not work.
|
//I don't now why but signal does not work.
|
||||||
doc->FullUpdateTree();
|
doc->FullUpdateTree();
|
||||||
|
|
|
@ -74,6 +74,34 @@ VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QOb
|
||||||
connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
|
connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VAbstractTool::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view)
|
||||||
|
{
|
||||||
|
QRectF rect = sc->itemsBoundingRect();
|
||||||
|
|
||||||
|
QRect rec0 = view->rect();
|
||||||
|
rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);
|
||||||
|
|
||||||
|
QTransform t = view->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 = view->mapToScene(rec1.toRect());
|
||||||
|
rec1 = polygone.boundingRect();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rec1 = rec0;
|
||||||
|
}
|
||||||
|
|
||||||
|
rec1 = rec1.united(rect.toRect());
|
||||||
|
sc->setSceneRect(rec1);
|
||||||
|
}
|
||||||
|
|
||||||
QPointF VAbstractTool::LineIntersectRect(QRectF rec, QLineF line)
|
QPointF VAbstractTool::LineIntersectRect(QRectF rec, QLineF line)
|
||||||
{
|
{
|
||||||
qreal x1, y1, x2, y2;
|
qreal x1, y1, x2, y2;
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
*/
|
*/
|
||||||
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
|
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
|
||||||
virtual ~VAbstractTool() {}
|
virtual ~VAbstractTool() {}
|
||||||
|
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view);
|
||||||
/**
|
/**
|
||||||
* @brief LineIntersectRect
|
* @brief LineIntersectRect
|
||||||
* @param rec
|
* @param rec
|
||||||
|
|
|
@ -259,32 +259,8 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
|
||||||
domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x())));
|
domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x())));
|
||||||
domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y())));
|
domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y())));
|
||||||
|
|
||||||
QGraphicsScene *sc = this->scene();
|
QList<QGraphicsView*> list = this->scene()->views();
|
||||||
QRectF rect = sc->itemsBoundingRect();
|
VAbstractTool::NewSceneRect(this->scene(), list[0]);
|
||||||
|
|
||||||
QList<QGraphicsView*> list = sc->views();
|
|
||||||
QRect rec0 = list[0]->rect();
|
|
||||||
rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);
|
|
||||||
|
|
||||||
QTransform t = list[0]->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 = list[0]->mapToScene(rec1.toRect());
|
|
||||||
rec1 = polygone.boundingRect();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rec1 = rec0;
|
|
||||||
}
|
|
||||||
|
|
||||||
rec1 = rec1.united(rect.toRect());
|
|
||||||
sc->setSceneRect(rec1);
|
|
||||||
|
|
||||||
doc->haveLiteChange();
|
doc->haveLiteChange();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include "../tools/vabstracttool.h"
|
||||||
|
|
||||||
VMainGraphicsView::VMainGraphicsView(QWidget *parent)
|
VMainGraphicsView::VMainGraphicsView(QWidget *parent)
|
||||||
:QGraphicsView(parent), _numScheduledScalings(0)
|
:QGraphicsView(parent), _numScheduledScalings(0)
|
||||||
|
@ -80,31 +81,7 @@ void VMainGraphicsView::scalingTime(qreal x)
|
||||||
horizontalScrollBar()->setValue(move.x() + horizontalScrollBar()->value());
|
horizontalScrollBar()->setValue(move.x() + horizontalScrollBar()->value());
|
||||||
verticalScrollBar()->setValue(move.y() + verticalScrollBar()->value());
|
verticalScrollBar()->setValue(move.y() + verticalScrollBar()->value());
|
||||||
|
|
||||||
QGraphicsScene *sc = this->scene();
|
VAbstractTool::NewSceneRect(this->scene(), this);
|
||||||
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);
|
emit NewFactor(factor);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user