From 8a2639b7aa447fce705964a5e4dc16a8b5031c4d Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 12 Jan 2014 21:23:44 +0200 Subject: [PATCH 1/7] Bug in uniontool with splinepath. --HG-- branch : feature --- src/container/vcontainer.cpp | 32 ++++++++++++------------ src/mainwindow.cpp | 40 +++++++++++++++++++++++------- src/mainwindow.h | 1 + src/tools/vtooldetail.cpp | 23 +++++++++++++++++ src/tools/vtooluniondetails.cpp | 25 ++++++++++--------- src/widgets/vmaingraphicsscene.cpp | 8 ++++-- 6 files changed, 90 insertions(+), 39 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 9cc2f9419..db16f5e60 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -241,22 +241,22 @@ QVector VContainer::CorrectEquidistantPoints(const QVector &po correctPoints.append(points.at(i)); } } - if(correctPoints.size()<3) - { - return correctPoints; - } - //Remove point on line - QPointF point; - for(qint32 i = 1; i ()), dialogCutSplinePath (QSharedPointer()), dialogUnionDetails(QSharedPointer()), dialogCutArc(QSharedPointer()), dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), - mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0) + mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true) { ui->setupUi(this); static const char * GENERIC_ICON_TO_CHECK = "document-open"; @@ -709,11 +709,14 @@ void MainWindow::currentDrawChanged( int index ) { doc->setCurrentData(); doc->ChangeActivDraw(comboBoxDraws->itemText(index)); - qint64 id = doc->SPointActiveDraw(); - if (id != 0) + if(drawMode) { - const VPointF *p = pattern->GeometricObject(id); - view->centerOn(p->toQPointF()); + qint64 id = doc->SPointActiveDraw(); + if (id != 0) + { + const VPointF *p = pattern->GeometricObject(id); + view->centerOn(p->toQPointF()); + } } } } @@ -920,6 +923,7 @@ void MainWindow::ActionDraw(bool checked) mode = Draw::Calculation; comboBoxDraws->setEnabled(true); comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace + drawMode = true; SetEnableTool(true); doc->setCurrentData(); @@ -942,10 +946,12 @@ void MainWindow::ActionDetails(bool checked) view->setScene(sceneDetails); RestoreCurrentScene(); + drawMode = false; currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1); comboBoxDraws->setEnabled(false); + mode = Draw::Modeling; SetEnableTool(true); currentToolBoxIndex = ui->toolBox->currentIndex(); @@ -1014,10 +1020,26 @@ void MainWindow::ActionOpen() if (fileName.isEmpty() && changeInFile == false) { OpenPattern(fName); - sceneDraw->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(), - view->contentsRect().height()-view->contentsRect().y())); - sceneDetails->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(), - view->contentsRect().height()-view->contentsRect().y())); + + 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); + } } else { diff --git a/src/mainwindow.h b/src/mainwindow.h index 04f775398..72122d673 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -511,6 +511,7 @@ private: Draw::Draws mode; qint32 currentDrawIndex; qint32 currentToolBoxIndex; + bool drawMode; /** * @brief ToolBarOption */ diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 72d6b4de4..740512790 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -247,6 +247,29 @@ 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(); + //Correct BoundingRect + rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y()); + qDebug()<<"rect"< list = sc->views(); + QRect rec = list[0]->contentsRect(); + qDebug()<<"rec"<setSceneRect(rec); + } + else + { + rect = rect.united(rec); + sc->setSceneRect(rect); + } + doc->haveLiteChange(); } } diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index c81edeb96..685571f19 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -139,10 +139,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); qint64 idP1 = data->AddGObject(p1); - VPointF p2 = VPointF(spline->GetP2().x(), spline->GetP2().y(), "A", 0, 0); + VPointF p2 = VPointF(spline->GetP2()); BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); - VPointF p3 = VPointF(spline->GetP3().x(), spline->GetP3().y(), "A", 0, 0); + VPointF p3 = VPointF(spline->GetP3()); BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); VPointF *p4 = new VPointF(spline->GetP4()); @@ -150,9 +150,9 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); qint64 idP4 = data->AddGObject(p4); - VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); + VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0, + Draw::Modeling); Q_ASSERT(spl != 0); - spl->setMode(Draw::Modeling); idObject = data->AddGObject(spl); VSpline *spl1 = new VSpline(*spl); @@ -208,10 +208,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai if (i==1) { path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), - splinePath->at(i-1).KAsm1())); + splinePath->at(i-1).KAsm2())); } - path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), - splinePath->at(i).KAsm1())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, + splinePath->at(i).KAsm2())); } while(k>=0) { @@ -310,9 +310,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c ++idCount; data->UpdateGObject(idDetail+idCount, p4); - VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); + VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0, + Draw::Modeling); + Q_ASSERT(spl != 0); - spl->setMode(Draw::Modeling); ++idCount; data->UpdateGObject(idDetail+idCount, spl); @@ -364,10 +365,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c if (i==1) { path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), - splinePath->at(i-1).KAsm1())); + splinePath->at(i-1).KAsm2())); } - path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), - splinePath->at(i).KAsm1())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, + splinePath->at(i).KAsm2())); } while(k>=0) diff --git a/src/widgets/vmaingraphicsscene.cpp b/src/widgets/vmaingraphicsscene.cpp index 9bb9d9abd..e2bd07775 100644 --- a/src/widgets/vmaingraphicsscene.cpp +++ b/src/widgets/vmaingraphicsscene.cpp @@ -31,10 +31,14 @@ #include VMainGraphicsScene::VMainGraphicsScene() - :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} + :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()) +{ +} VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent) - :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} + :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()) +{ +} void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { From 502b66df29308481eaf0aacee1421dadb438d7ee Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 12 Jan 2014 21:53:15 +0200 Subject: [PATCH 2/7] Detail doesn't save parameter closed and seam allowance. --HG-- branch : feature --- src/container/vcontainer.cpp | 2 +- src/container/vcontainer.h | 2 +- src/dialogs/dialogdetail.cpp | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index db16f5e60..5328f1a58 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -774,7 +774,7 @@ void VContainer::UpdateGObject(qint64 id, VGObject* obj) UpdateObject(gObjects, id, obj); } -void VContainer::UpdateDetail(qint64 id, VDetail detail) +void VContainer::UpdateDetail(qint64 id, const VDetail &detail) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); details[id] = detail; diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index a250d2e2c..3db6e1744 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -223,7 +223,7 @@ public: * @param id id of existing detail * @param detail detail */ - void UpdateDetail(qint64 id, VDetail detail); + void UpdateDetail(qint64 id, const VDetail &detail); /** * @brief UpdateStandartTableCell update standart table row by name * @param name name of row diff --git a/src/dialogs/dialogdetail.cpp b/src/dialogs/dialogdetail.cpp index 7051ed1a6..1d57d7505 100644 --- a/src/dialogs/dialogdetail.cpp +++ b/src/dialogs/dialogdetail.cpp @@ -165,6 +165,8 @@ void DialogDetail::setDetails(const VDetail &value) ui.lineEditNameDetail->setText(details.getName()); ui.checkBoxSeams->setChecked(details.getSupplement()); ui.checkBoxClosed->setChecked(details.getClosed()); + ClickedClosed(details.getClosed()); + ClickedSeams(details.getSupplement()); ui.doubleSpinBoxSeams->setValue(details.getWidth()); ui.listWidget->setCurrentRow(0); ui.listWidget->setFocus(Qt::OtherFocusReason); From bc97dc7855dfac3481d87841f07d2749e5bc2091 Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 12 Jan 2014 22:04:15 +0200 Subject: [PATCH 3/7] Set enabled for tool button in different mode. --HG-- branch : feature --- src/mainwindow.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5eaa9a3e6..e9c70baf0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -701,6 +701,7 @@ void MainWindow::ToolBarDraws() ui->toolBarDraws->addAction(ui->actionLayout); connect(ui->actionLayout, &QAction::triggered, this, &MainWindow::ActionLayout); + ui->actionLayout->setEnabled(false); } void MainWindow::currentDrawChanged( int index ) @@ -928,6 +929,11 @@ void MainWindow::ActionDraw(bool checked) SetEnableTool(true); doc->setCurrentData(); ui->toolBox->setCurrentIndex(currentToolBoxIndex); + + ui->actionHistory->setEnabled(true); + ui->actionLayout->setEnabled(false); + ui->actionOptionDraw->setEnabled(true); + ui->actionNewDraw->setEnabled(true); } else { @@ -956,6 +962,11 @@ void MainWindow::ActionDetails(bool checked) SetEnableTool(true); currentToolBoxIndex = ui->toolBox->currentIndex(); ui->toolBox->setCurrentIndex(4); + + ui->actionHistory->setEnabled(false); + ui->actionLayout->setEnabled(true); + ui->actionOptionDraw->setEnabled(false); + ui->actionNewDraw->setEnabled(false); } else { From aa4feb648a8925398244e4d649813cd70bd620ff Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 12 Jan 2014 22:08:52 +0200 Subject: [PATCH 4/7] Disable tool when we change pattern piece. --HG-- branch : feature --- src/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e9c70baf0..a6df28fe0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -712,6 +712,7 @@ void MainWindow::currentDrawChanged( int index ) doc->ChangeActivDraw(comboBoxDraws->itemText(index)); if(drawMode) { + ArrowTool(); qint64 id = doc->SPointActiveDraw(); if (id != 0) { From 1cffddc672b9634b5c3805e2efd9c7068f789b71 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 13 Jan 2014 00:34:36 +0200 Subject: [PATCH 5/7] Fixed method CheckLoops. --HG-- branch : feature --- src/container/vcontainer.cpp | 33 ++++++++++++++++----------------- src/tools/vabstracttool.h | 2 +- src/tools/vtooldetail.cpp | 23 ++++++++++------------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 5328f1a58..ab3b8e490 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -241,22 +241,22 @@ QVector VContainer::CorrectEquidistantPoints(const QVector &po correctPoints.append(points.at(i)); } } -// if(correctPoints.size()<3) -// { -// return correctPoints; -// } -// //Remove point on line -// QPointF point; -// for(qint32 i = 1; i VContainer::CheckLoops(const QVector &points) const /*We found loop.*/ ekvPoints.append(points.at(i)); ekvPoints.append(crosPoint); - ekvPoints.append(points.at(j+1)); i = j + 2; } } diff --git a/src/tools/vabstracttool.h b/src/tools/vabstracttool.h index f3c036024..638c092ee 100644 --- a/src/tools/vabstracttool.h +++ b/src/tools/vabstracttool.h @@ -304,7 +304,7 @@ protected: * @brief RemoveAllChild * @param domElement */ - void RemoveAllChild(QDomElement &domElement); + void RemoveAllChild(QDomElement &domElement); virtual void DeleteTool(QGraphicsItem *tool); template /** diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 740512790..0999c4c59 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -251,24 +251,21 @@ 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()); + //rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y()); qDebug()<<"rect"< list = sc->views(); QRect rec = list[0]->contentsRect(); - qDebug()<<"rec"<transform(); + qDebug()<<"m11="<setSceneRect(rec); doc->haveLiteChange(); } From 666dd664eb9b62d9bedcaa47db12ead3010df68e Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 13 Jan 2014 02:48:31 +0200 Subject: [PATCH 6/7] Delete nodes from detail. Fix for union details. --HG-- branch : feature --- src/container/vcontainer.h | 1 + src/dialogs/dialogdetail.cpp | 10 +++++++ src/dialogs/dialogdetail.h | 1 + src/dialogs/dialogdetail.ui | 14 ++++++++-- src/geometry/vdetail.cpp | 23 +++++++++++++++ src/geometry/vdetail.h | 1 + src/tools/nodeDetails/vabstractnode.cpp | 34 +++++++++++++++++++++++ src/tools/nodeDetails/vabstractnode.h | 1 + src/tools/nodeDetails/vnodearc.cpp | 6 ++++ src/tools/nodeDetails/vnodearc.h | 1 + src/tools/nodeDetails/vnodepoint.cpp | 6 ++++ src/tools/nodeDetails/vnodepoint.h | 1 + src/tools/nodeDetails/vnodespline.cpp | 6 ++++ src/tools/nodeDetails/vnodespline.h | 1 + src/tools/nodeDetails/vnodesplinepath.cpp | 6 ++++ src/tools/nodeDetails/vnodesplinepath.h | 1 + src/tools/vabstracttool.cpp | 4 ++- src/tools/vtooldetail.cpp | 11 ++++++++ src/xml/vdomdocument.cpp | 1 + 19 files changed, 126 insertions(+), 3 deletions(-) diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index 3db6e1744..c91009ada 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -279,6 +279,7 @@ public: * @brief ClearLineAngles clear angles of lines */ inline void ClearLineAngles() {lineAngles.clear();} + inline void ClearDetails() {details.clear();} /** * @brief SetSize set value of size * @param size value of size in mm diff --git a/src/dialogs/dialogdetail.cpp b/src/dialogs/dialogdetail.cpp index 1d57d7505..d0801cfff 100644 --- a/src/dialogs/dialogdetail.cpp +++ b/src/dialogs/dialogdetail.cpp @@ -56,6 +56,8 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent) connect(ui.checkBoxSeams, &QCheckBox::clicked, this, &DialogDetail::ClickedSeams); connect(ui.checkBoxClosed, &QCheckBox::clicked, this, &DialogDetail::ClickedClosed); connect(ui.lineEditNameDetail, &QLineEdit::textChanged, this, &DialogDetail::NamePointChanged); + + connect(ui.toolButtonDelete, &QToolButton::clicked, this, &DialogDetail::DeleteItem); } void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type) @@ -80,6 +82,7 @@ void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type) qWarning()<setEnabled(true); this->show(); } } @@ -170,6 +173,7 @@ void DialogDetail::setDetails(const VDetail &value) ui.doubleSpinBoxSeams->setValue(details.getWidth()); ui.listWidget->setCurrentRow(0); ui.listWidget->setFocus(Qt::OtherFocusReason); + ui.toolButtonDelete->setEnabled(true); } void DialogDetail::BiasXChanged(qreal d) @@ -215,3 +219,9 @@ void DialogDetail::ObjectChanged(int row) ui.doubleSpinBoxBiasX->setValue(toMM(node.getMx())); ui.doubleSpinBoxBiasY->setValue(toMM(node.getMy())); } + +void DialogDetail::DeleteItem() +{ + qint32 row = ui.listWidget->currentRow(); + delete ui.listWidget->item( row ); +} diff --git a/src/dialogs/dialogdetail.h b/src/dialogs/dialogdetail.h index 476b7cc90..4328afef9 100644 --- a/src/dialogs/dialogdetail.h +++ b/src/dialogs/dialogdetail.h @@ -91,6 +91,7 @@ public slots: * @param row number of row */ void ObjectChanged(int row); + void DeleteItem(); private: /** * @brief ui keeps information about user interface diff --git a/src/dialogs/dialogdetail.ui b/src/dialogs/dialogdetail.ui index 3775555bd..6519b344d 100644 --- a/src/dialogs/dialogdetail.ui +++ b/src/dialogs/dialogdetail.ui @@ -6,8 +6,8 @@ 0 0 - 544 - 327 + 565 + 324 @@ -211,6 +211,16 @@ + + + + false + + + Delete + + + diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index 59dfd3a3a..d771cdd59 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -232,6 +232,29 @@ VDetail VDetail::RemoveEdge(const ptrdiff_t &index) const return det; } +QList VDetail::Missing(const VDetail &det) const +{ + QList list; + if(nodes.size() == det.CountNode()) + { + return list; + } + + qint32 j = 0; + for(qint32 i = 0; i < nodes.size(); ++i) + { + if(nodes[i].getId() == det.at(j).getId()) + { + ++j; + } + else + { + list.append(nodes[i].getId()); + } + } + return list; +} + QVector VDetail::listNodePoint() const { QVector list; diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index 9edbdfdbf..4825a8a13 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -183,6 +183,7 @@ public: ptrdiff_t Edge(const qint64 &p1, const qint64 &p2)const; void NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2)const; VDetail RemoveEdge(const ptrdiff_t &index) const; + QList Missing(const VDetail &det) const; private: qint64 _id; /** diff --git a/src/tools/nodeDetails/vabstractnode.cpp b/src/tools/nodeDetails/vabstractnode.cpp index 0b964aea2..4a9464eb2 100644 --- a/src/tools/nodeDetails/vabstractnode.cpp +++ b/src/tools/nodeDetails/vabstractnode.cpp @@ -39,6 +39,40 @@ VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 & _referens = 0; } +void VAbstractNode::DeleteNode() +{ + if (_referens <= 1) + { + //remove from xml file + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + QDomNode element = domElement.parentNode(); + if (element.isNull() == false) + { + if (element.isElement()) + { + RemoveReferens();//deincrement referens + element.removeChild(domElement);//remove form file + emit toolhaveChange();//set enabled save button + } + else + { + qWarning()<<"parent isn't element"< 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 */