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);
|
||||
|
||||
QRectF rect = sceneDraw->itemsBoundingRect();
|
||||
//Correct BoundingRect
|
||||
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);
|
||||
}
|
||||
VAbstractTool::NewSceneRect(sceneDraw, view);
|
||||
VAbstractTool::NewSceneRect(sceneDetails, view);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -113,32 +113,8 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change,
|
|||
domElement.setAttribute(AttrX, QString().setNum(toMM(newPos.x())));
|
||||
domElement.setAttribute(AttrY, QString().setNum(toMM(newPos.y())));
|
||||
|
||||
QGraphicsScene *sc = this->scene();
|
||||
QRectF rect = sc->itemsBoundingRect();
|
||||
|
||||
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);
|
||||
QList<QGraphicsView*> list = this->scene()->views();
|
||||
VAbstractTool::NewSceneRect(this->scene(), list[0]);
|
||||
|
||||
//I don't now why but signal does not work.
|
||||
doc->FullUpdateTree();
|
||||
|
|
|
@ -74,6 +74,34 @@ VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QOb
|
|||
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)
|
||||
{
|
||||
qreal x1, y1, x2, y2;
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
*/
|
||||
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
|
||||
virtual ~VAbstractTool() {}
|
||||
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view);
|
||||
/**
|
||||
* @brief LineIntersectRect
|
||||
* @param rec
|
||||
|
|
|
@ -259,32 +259,8 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
|
|||
domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x())));
|
||||
domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y())));
|
||||
|
||||
QGraphicsScene *sc = this->scene();
|
||||
QRectF rect = sc->itemsBoundingRect();
|
||||
|
||||
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);
|
||||
QList<QGraphicsView*> list = this->scene()->views();
|
||||
VAbstractTool::NewSceneRect(this->scene(), list[0]);
|
||||
|
||||
doc->haveLiteChange();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <QWheelEvent>
|
||||
#include <QApplication>
|
||||
#include <QScrollBar>
|
||||
#include "../tools/vabstracttool.h"
|
||||
|
||||
VMainGraphicsView::VMainGraphicsView(QWidget *parent)
|
||||
:QGraphicsView(parent), _numScheduledScalings(0)
|
||||
|
@ -80,31 +81,7 @@ void VMainGraphicsView::scalingTime(qreal x)
|
|||
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);
|
||||
VAbstractTool::NewSceneRect(this->scene(), this);
|
||||
|
||||
emit NewFactor(factor);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user