From 2fffdecc866b1d72da5855879ce14bdede87dbe8 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 16 Oct 2013 12:17:34 +0300 Subject: [PATCH] Zooming points, line and label of points after zooming scene. --HG-- branch : develop --- mainwindow.cpp | 2 + options.h | 2 +- tools/drawTools/vdrawtool.cpp | 8 ++++ tools/drawTools/vdrawtool.h | 2 + tools/drawTools/vtoolalongline.cpp | 6 +++ tools/drawTools/vtoolalongline.h | 1 + tools/drawTools/vtoolarc.cpp | 22 +++++++--- tools/drawTools/vtoolarc.h | 41 +++++++++-------- tools/drawTools/vtoolbisector.cpp | 6 +++ tools/drawTools/vtoolbisector.h | 1 + tools/drawTools/vtoolendline.cpp | 3 +- tools/drawTools/vtoolline.cpp | 42 ++++++++++++------ tools/drawTools/vtoolline.h | 18 ++++---- tools/drawTools/vtoollineintersect.cpp | 18 +++++--- tools/drawTools/vtoollineintersect.h | 46 +++++++++----------- tools/drawTools/vtoollinepoint.cpp | 14 ++++-- tools/drawTools/vtoollinepoint.h | 1 + tools/drawTools/vtoolnormal.cpp | 20 ++++++--- tools/drawTools/vtoolnormal.h | 41 ++++++++--------- tools/drawTools/vtoolpoint.cpp | 35 ++++++++++----- tools/drawTools/vtoolpoint.h | 1 + tools/drawTools/vtoolpointofcontact.cpp | 12 +++-- tools/drawTools/vtoolpointofcontact.h | 44 ++++++++++--------- tools/drawTools/vtoolshoulderpoint.cpp | 10 ++++- tools/drawTools/vtoolshoulderpoint.h | 45 +++++++++---------- tools/drawTools/vtoolsinglepoint.cpp | 5 +++ tools/drawTools/vtoolsinglepoint.h | 1 + tools/drawTools/vtoolspline.cpp | 23 +++++++--- tools/drawTools/vtoolspline.h | 53 +++++++++++----------- tools/drawTools/vtoolsplinepath.cpp | 23 +++++++--- tools/drawTools/vtoolsplinepath.h | 58 ++++++++++++------------- widgets/vgraphicssimpletextitem.cpp | 10 ++++- widgets/vgraphicssimpletextitem.h | 6 ++- widgets/vmaingraphicsscene.cpp | 9 +++- widgets/vmaingraphicsscene.h | 3 ++ widgets/vmaingraphicsview.cpp | 1 + widgets/vmaingraphicsview.h | 1 + xml/vdomdocument.cpp | 1 + 38 files changed, 386 insertions(+), 249 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 1bd08ccd2..19ae78c59 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -62,6 +62,7 @@ MainWindow::MainWindow(QWidget *parent) : view = new VMainGraphicsView(); ui->LayoutView->addWidget(view); view->setScene(currentScene); + connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding); policy.setHorizontalStretch(12); view->setSizePolicy(policy); @@ -162,6 +163,7 @@ void MainWindow::ActionNewDraw(){ VToolSinglePoint *spoint = new VToolSinglePoint(doc, data, id, Tool::FromGui); sceneDraw->addItem(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); + connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); QHash* tools = doc->getTools(); tools->insert(id, spoint); VDrawTool::AddRecord(id, Tool::SinglePointTool, doc); diff --git a/options.h b/options.h index d2620f3dd..1d04de588 100644 --- a/options.h +++ b/options.h @@ -28,7 +28,7 @@ #define PaperSize 50000 #define toPixel(mm) ((mm / 25.4) * PrintDPI) #define toMM(pix) ((pix / PrintDPI) * 25.4) -#define widthMainLine toPixel(0.8) +#define widthMainLine toPixel(1.2) #define widthHairLine widthMainLine/3 namespace Scene{ diff --git a/tools/drawTools/vdrawtool.cpp b/tools/drawTools/vdrawtool.cpp index 89164341b..197d800b9 100644 --- a/tools/drawTools/vdrawtool.cpp +++ b/tools/drawTools/vdrawtool.cpp @@ -22,6 +22,8 @@ #include "vdrawtool.h" #include +qreal VDrawTool::factor = 1; + VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) : VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), nameActivDraw(doc->GetNameActivDraw()){ @@ -78,6 +80,12 @@ void VDrawTool::ChangedNameDraw(const QString oldName, const QString newName){ } } +void VDrawTool::SetFactor(qreal factor){ + if(factor <= 2 && factor >= 0.5){ + this->factor = factor; + } +} + void VDrawTool::AddToCalculation(const QDomElement &domElement){ QDomElement calcElement; bool ok = doc->GetActivCalculationElement(calcElement); diff --git a/tools/drawTools/vdrawtool.h b/tools/drawTools/vdrawtool.h index 15415bed2..91a7a4527 100644 --- a/tools/drawTools/vdrawtool.h +++ b/tools/drawTools/vdrawtool.h @@ -38,11 +38,13 @@ public slots: virtual void ChangedActivDraw(const QString newName); void ChangedNameDraw(const QString oldName, const QString newName); virtual void FullUpdateFromGui(int result)=0; + virtual void SetFactor(qreal factor); signals: void RemoveTool(QGraphicsItem *tool); protected: bool ignoreContextMenuEvent; QString nameActivDraw; + static qreal factor; void AddToCalculation(const QDomElement &domElement); template void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, diff --git a/tools/drawTools/vtoolalongline.cpp b/tools/drawTools/vtoolalongline.cpp index c7e9ee7e4..8d54e14bc 100644 --- a/tools/drawTools/vtoolalongline.cpp +++ b/tools/drawTools/vtoolalongline.cpp @@ -63,6 +63,11 @@ void VToolAlongLine::FullUpdateFromGui(int result){ dialogAlongLine.clear(); } +void VToolAlongLine::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogAlongLine, this, event); } @@ -145,6 +150,7 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS scene->addItem(point); connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolAlongLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolAlongLine::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); diff --git a/tools/drawTools/vtoolalongline.h b/tools/drawTools/vtoolalongline.h index aede99661..ce02b8b30 100644 --- a/tools/drawTools/vtoolalongline.h +++ b/tools/drawTools/vtoolalongline.h @@ -42,6 +42,7 @@ public: public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); diff --git a/tools/drawTools/vtoolarc.cpp b/tools/drawTools/vtoolarc.cpp index c85aba0da..a5e845d25 100644 --- a/tools/drawTools/vtoolarc.cpp +++ b/tools/drawTools/vtoolarc.cpp @@ -30,7 +30,7 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources path.addPath(arc.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); @@ -126,14 +126,16 @@ void VToolArc::FullUpdateFromGui(int result){ void VToolArc::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); + currentColor = Qt::black; VDrawTool::ChangedActivDraw(newName); } else { - this->setPen(QPen(Qt::gray, widthHairLine)); + this->setPen(QPen(Qt::gray, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setAcceptHoverEvents (false); + currentColor = Qt::gray; VDrawTool::ChangedActivDraw(newName); } } @@ -141,15 +143,20 @@ void VToolArc::ChangedActivDraw(const QString newName){ void VToolArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ if(id == this->id){ if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); + this->setPen(QPen(baseColor, widthHairLine/factor)); currentColor = baseColor; } else { - this->setPen(QPen(color, widthHairLine)); + this->setPen(QPen(color, widthHairLine/factor)); currentColor = color; } } } +void VToolArc::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogArc, this, event); } @@ -177,12 +184,12 @@ void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ void VToolArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } void VToolArc::RemoveReferens(){ @@ -191,6 +198,7 @@ void VToolArc::RemoveReferens(){ } void VToolArc::RefreshGeometry(){ + this->setPen(QPen(currentColor, widthHairLine/factor)); VArc arc = VAbstractTool::data.GetArc(id); QPainterPath path; path.addPath(arc.GetPath()); diff --git a/tools/drawTools/vtoolarc.h b/tools/drawTools/vtoolarc.h index f78f26bbc..bca594770 100644 --- a/tools/drawTools/vtoolarc.h +++ b/tools/drawTools/vtoolarc.h @@ -30,31 +30,30 @@ class VToolArc :public VDrawTool, public QGraphicsPathItem{ Q_OBJECT public: - VToolArc(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const qint64 ¢er, const QString &radius, - const QString &f1, const QString &f2, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, + const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - virtual void ChangedActivDraw(const QString newName); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void ChangedActivDraw(const QString newName); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogArc; - void RefreshGeometry(); + void RefreshGeometry(); }; #endif // VTOOLARC_H diff --git a/tools/drawTools/vtoolbisector.cpp b/tools/drawTools/vtoolbisector.cpp index 02e4e5cb2..7e243a9f9 100644 --- a/tools/drawTools/vtoolbisector.cpp +++ b/tools/drawTools/vtoolbisector.cpp @@ -109,6 +109,7 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 scene->addItem(point); connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolBisector::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); @@ -145,6 +146,11 @@ void VToolBisector::FullUpdateFromGui(int result){ dialogBisector.clear(); } +void VToolBisector::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogBisector, this, event); } diff --git a/tools/drawTools/vtoolbisector.h b/tools/drawTools/vtoolbisector.h index 1c88f670d..3a982bbc1 100644 --- a/tools/drawTools/vtoolbisector.h +++ b/tools/drawTools/vtoolbisector.h @@ -44,6 +44,7 @@ public: public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); diff --git a/tools/drawTools/vtoolendline.cpp b/tools/drawTools/vtoolendline.cpp index c65e2ec9a..2e0d24abb 100644 --- a/tools/drawTools/vtoolendline.cpp +++ b/tools/drawTools/vtoolendline.cpp @@ -69,7 +69,7 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr QString errorMsg; qreal result = cal.eval(formula, &errorMsg); if(errorMsg.isEmpty()){ - line.setLength(result*PrintDPI/25.4); + line.setLength(toPixel(result)); line.setAngle(angle); qint64 id = _id; if(typeCreation == Tool::FromGui){ @@ -89,6 +89,7 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(basePointId); } diff --git a/tools/drawTools/vtoolline.cpp b/tools/drawTools/vtoolline.cpp index 760c273b6..7f4c07bd5 100644 --- a/tools/drawTools/vtoolline.cpp +++ b/tools/drawTools/vtoolline.cpp @@ -33,6 +33,7 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); + this->setPen(QPen(Qt::black, widthHairLine/factor)); if(typeCreation == Tool::FromGui){ AddToFile(); @@ -74,6 +75,7 @@ void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 scene->addItem(line); connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(line, &VToolLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VToolLine::SetFactor); doc->AddTool(id, line); doc->IncrementReferens(firstPoint); doc->IncrementReferens(secondPoint); @@ -81,14 +83,7 @@ void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 } void VToolLine::FullUpdateFromFile(){ - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - firstPoint = domElement.attribute("firstPoint", "").toLongLong(); - secondPoint = domElement.attribute("secondPoint", "").toLongLong(); - } - VPointF first = VAbstractTool::data.GetPoint(firstPoint); - VPointF second = VAbstractTool::data.GetPoint(secondPoint); - this->setLine(QLineF(first.toQPointF(), second.toQPointF())); + RefreshGeometry(); } void VToolLine::FullUpdateFromGui(int result){ @@ -106,23 +101,30 @@ void VToolLine::FullUpdateFromGui(int result){ void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ if(id == this->id){ if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); + this->setPen(QPen(baseColor, widthHairLine/factor)); currentColor = baseColor; } else { - this->setPen(QPen(color, widthHairLine)); + this->setPen(QPen(color, widthHairLine/factor)); currentColor = color; } } } +void VToolLine::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + void VToolLine::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setAcceptHoverEvents (true); + currentColor = Qt::black; VDrawTool::ChangedActivDraw(newName); } else { - this->setPen(QPen(Qt::gray, widthHairLine)); + this->setPen(QPen(Qt::gray, widthHairLine/factor)); this->setAcceptHoverEvents (false); + currentColor = Qt::gray; VDrawTool::ChangedActivDraw(newName); } } @@ -143,12 +145,12 @@ void VToolLine::AddToFile(){ void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } void VToolLine::RemoveReferens(){ @@ -156,3 +158,15 @@ void VToolLine::RemoveReferens(){ doc->DecrementReferens(secondPoint); } +void VToolLine::RefreshGeometry(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + firstPoint = domElement.attribute("firstPoint", "").toLongLong(); + secondPoint = domElement.attribute("secondPoint", "").toLongLong(); + } + VPointF first = VAbstractTool::data.GetPoint(firstPoint); + VPointF second = VAbstractTool::data.GetPoint(secondPoint); + this->setLine(QLineF(first.toQPointF(), second.toQPointF())); + this->setPen(QPen(currentColor, widthHairLine/factor)); +} + diff --git a/tools/drawTools/vtoolline.h b/tools/drawTools/vtoolline.h index a7b31824e..dab4b6d47 100644 --- a/tools/drawTools/vtoolline.h +++ b/tools/drawTools/vtoolline.h @@ -29,19 +29,20 @@ class VToolLine: public VDrawTool, public QGraphicsLineItem{ Q_OBJECT public: - VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, - qint64 secondPoint, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, + qint64 secondPoint, Tool::Sources typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString newName); virtual void FullUpdateFromGui(int result); virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); @@ -52,6 +53,7 @@ private: qint64 firstPoint; qint64 secondPoint; QSharedPointer dialogLine; + void RefreshGeometry(); }; #endif // VTOOLLINE_H diff --git a/tools/drawTools/vtoollineintersect.cpp b/tools/drawTools/vtoollineintersect.cpp index 35067c399..132013d5a 100644 --- a/tools/drawTools/vtoollineintersect.cpp +++ b/tools/drawTools/vtoollineintersect.cpp @@ -24,7 +24,8 @@ VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, Tool::Sources typeCreation, QGraphicsItem *parent): + const qint64 &p2Line2, Tool::Sources typeCreation, + QGraphicsItem *parent): VToolPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()){ if(typeCreation == Tool::FromGui){ @@ -57,8 +58,9 @@ void VToolLineIntersect::Create(QSharedPointer &dialog, VMa void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation){ VPointF p1Line1 = data->GetPoint(p1Line1Id); VPointF p2Line1 = data->GetPoint(p2Line1Id); VPointF p1Line2 = data->GetPoint(p1Line2Id); @@ -94,6 +96,7 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const scene->addItem(point); connect(point, &VToolLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolLineIntersect::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolLineIntersect::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(p1Line1Id); doc->IncrementReferens(p2Line1Id); @@ -129,6 +132,11 @@ void VToolLineIntersect::FullUpdateFromGui(int result){ dialogLineIntersect.clear(); } +void VToolLineIntersect::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogLineIntersect, this, event); } @@ -140,8 +148,8 @@ void VToolLineIntersect::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "lineIntersect"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "p1Line1", p1Line1); AddAttribute(domElement, "p2Line1", p2Line1); diff --git a/tools/drawTools/vtoollineintersect.h b/tools/drawTools/vtoollineintersect.h index 1c5b36cfd..90e4d07f6 100644 --- a/tools/drawTools/vtoollineintersect.h +++ b/tools/drawTools/vtoollineintersect.h @@ -28,34 +28,30 @@ class VToolLineIntersect:public VToolPoint{ Q_OBJECT public: - VToolLineIntersect(VDomDocument *doc, VContainer *data, - const qint64 &id, - const qint64 &p1Line1, - const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, - VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const qint64 &p1Line1Id, - const qint64 &p2Line1Id, const qint64 &p1Line2Id, - const qint64 &p2Line2Id, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, + const qint64 &p2Line2, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, + const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 p1Line1; - qint64 p2Line1; - qint64 p1Line2; - qint64 p2Line2; + qint64 p1Line1; + qint64 p2Line1; + qint64 p1Line2; + qint64 p2Line2; QSharedPointer dialogLineIntersect; }; diff --git a/tools/drawTools/vtoollinepoint.cpp b/tools/drawTools/vtoollinepoint.cpp index b7536c1ae..af55544d4 100644 --- a/tools/drawTools/vtoollinepoint.cpp +++ b/tools/drawTools/vtoollinepoint.cpp @@ -30,7 +30,7 @@ VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 QPointF point1 = data->GetPoint(basePointId).toQPointF(); QPointF point2 = data->GetPoint(id).toQPointF(); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); - mainLine->setPen(QPen(Qt::black, widthHairLine)); + mainLine->setPen(QPen(Qt::black, widthHairLine/factor)); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); if(typeLine == "none"){ mainLine->setVisible(false); @@ -41,15 +41,18 @@ VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 void VToolLinePoint::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ - mainLine->setPen(QPen(Qt::black, widthHairLine)); + mainLine->setPen(QPen(Qt::black, widthHairLine/factor)); + currentColor = Qt::black; VToolPoint::ChangedActivDraw(newName); } else { - mainLine->setPen(QPen(Qt::gray, widthHairLine)); + mainLine->setPen(QPen(Qt::gray, widthHairLine/factor)); + currentColor = Qt::gray; VToolPoint::ChangedActivDraw(newName); } } void VToolLinePoint::RefreshGeometry(){ + mainLine->setPen(QPen(currentColor, widthHairLine/factor)); VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id)); QPointF point = VDrawTool::data.GetPoint(id).toQPointF(); QPointF basePoint = VDrawTool::data.GetPoint(basePointId).toQPointF(); @@ -64,3 +67,8 @@ void VToolLinePoint::RefreshGeometry(){ void VToolLinePoint::RemoveReferens(){ doc->DecrementReferens(basePointId); } + +void VToolLinePoint::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} diff --git a/tools/drawTools/vtoollinepoint.h b/tools/drawTools/vtoollinepoint.h index a298bc5f1..3d82b33f5 100644 --- a/tools/drawTools/vtoollinepoint.h +++ b/tools/drawTools/vtoollinepoint.h @@ -32,6 +32,7 @@ public: const qint64 &basePointId, const qreal &angle, QGraphicsItem * parent = 0); public slots: virtual void ChangedActivDraw(const QString newName); + virtual void SetFactor(qreal factor); protected: QString typeLine; QString formula; diff --git a/tools/drawTools/vtoolnormal.cpp b/tools/drawTools/vtoolnormal.cpp index b742c3fe7..0ae377eb0 100644 --- a/tools/drawTools/vtoolnormal.cpp +++ b/tools/drawTools/vtoolnormal.cpp @@ -21,8 +21,7 @@ #include "vtoolnormal.h" -VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, +VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qreal &angle, const qint64 &firstPointId, const qint64 &secondPointId, Tool::Sources typeCreation, QGraphicsItem *parent): VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), @@ -62,7 +61,8 @@ void VToolNormal::Create(QSharedPointer &dialog, VMainGraphicsScen void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const QString typeLine, const QString pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation){ VPointF firstPoint = data->GetPoint(firstPointId); VPointF secondPoint = data->GetPoint(secondPointId); Calculator cal(data); @@ -70,7 +70,7 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 qreal result = cal.eval(formula, &errorMsg); if(errorMsg.isEmpty()){ QPointF fPoint = VToolNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - result*PrintDPI/25.4, angle); + toPixel(result), angle); qint64 id = _id; if(typeCreation == Tool::FromGui){ id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); @@ -89,6 +89,7 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 scene->addItem(point); connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolNormal::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolNormal::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); @@ -112,7 +113,7 @@ void VToolNormal::FullUpdateFromFile(){ formula = domElement.attribute("length", ""); basePointId = domElement.attribute("firstPoint", "").toLongLong(); secondPointId = domElement.attribute("secondPoint", "").toLongLong(); - angle = domElement.attribute("angle", "").toInt(); + angle = domElement.attribute("angle", "").toDouble(); } RefreshGeometry(); } @@ -133,6 +134,11 @@ void VToolNormal::FullUpdateFromGui(int result){ dialogNormal.clear(); } +void VToolNormal::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogNormal, this, event); } @@ -144,8 +150,8 @@ void VToolNormal::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "normal"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); diff --git a/tools/drawTools/vtoolnormal.h b/tools/drawTools/vtoolnormal.h index 217328744..41bda6144 100644 --- a/tools/drawTools/vtoolnormal.h +++ b/tools/drawTools/vtoolnormal.h @@ -29,29 +29,30 @@ class VToolNormal : public VToolLinePoint { Q_OBJECT public: - VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const QString typeLine, const QString pointName, - const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); - static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, - const qreal &length, const qreal &angle = 0); + VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qreal &angle, const qint64 &firstPointId, + const qint64 &secondPointId, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const QString typeLine, const QString pointName, + const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation); + static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, + const qreal &angle = 0); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 secondPointId; + qint64 secondPointId; QSharedPointer dialogNormal; }; diff --git a/tools/drawTools/vtoolpoint.cpp b/tools/drawTools/vtoolpoint.cpp index afd581fd4..faf1daf03 100644 --- a/tools/drawTools/vtoolpoint.cpp +++ b/tools/drawTools/vtoolpoint.cpp @@ -28,12 +28,11 @@ VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem *parent):VDrawTool(doc, data, id), - QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), lineName(0){ + QGraphicsEllipseItem(parent), radius(toPixel(2)), namePoint(0), lineName(0){ namePoint = new VGraphicsSimpleTextItem(this); lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); - this->setPen(QPen(Qt::black, widthHairLine)); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); @@ -61,7 +60,7 @@ void VToolPoint::UpdateNamePosition(qreal mx, qreal my){ void VToolPoint::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); namePoint->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -69,10 +68,11 @@ void VToolPoint::ChangedActivDraw(const QString newName){ namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); namePoint->setBrush(QBrush(Qt::black)); namePoint->setAcceptHoverEvents(true); - lineName->setPen(QPen(Qt::black, widthHairLine)); + lineName->setPen(QPen(Qt::black, widthHairLine/factor)); + currentColor = Qt::black; VDrawTool::ChangedActivDraw(newName); } else { - this->setPen(QPen(Qt::gray, widthHairLine)); + this->setPen(QPen(Qt::gray, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setAcceptHoverEvents (false); namePoint->setFlag(QGraphicsItem::ItemIsMovable, false); @@ -80,7 +80,8 @@ void VToolPoint::ChangedActivDraw(const QString newName){ namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); namePoint->setBrush(QBrush(Qt::gray)); namePoint->setAcceptHoverEvents(false); - lineName->setPen(QPen(Qt::gray, widthHairLine)); + lineName->setPen(QPen(Qt::gray, widthHairLine/factor)); + currentColor = Qt::gray; VDrawTool::ChangedActivDraw(newName); } } @@ -88,15 +89,20 @@ void VToolPoint::ChangedActivDraw(const QString newName){ void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ if(id == this->id){ if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); + this->setPen(QPen(baseColor, widthHairLine/factor)); currentColor = baseColor; } else { - this->setPen(QPen(color, widthHairLine)); + this->setPen(QPen(color, widthHairLine/factor)); currentColor = color; } } } +void VToolPoint::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ if(event->button() == Qt::LeftButton){ emit ChoosedTool(id, Scene::Point); @@ -106,21 +112,25 @@ void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } void VToolPoint::RefreshPointGeometry(const VPointF &point){ - QRectF rec = QRectF(0, 0, radius*2, radius*2); + this->setPen(QPen(currentColor, widthHairLine/factor)); + QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); this->setPos(point.toQPointF()); disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); + QFont font = namePoint->font(); + font.setPointSize(static_cast(namePoint->FontSize()/factor)); + namePoint->setFont(font); namePoint->setText(point.name()); namePoint->setPos(QPointF(point.mx(), point.my())); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, @@ -131,9 +141,10 @@ void VToolPoint::RefreshPointGeometry(const VPointF &point){ void VToolPoint::RefreshLine(){ QRectF nameRec = namePoint->sceneBoundingRect(); QPointF p1, p2; - LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); + LineIntersectCircle(QPointF(), radius/factor, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); + lineName->setPen(QPen(currentColor, widthHairLine/factor)); if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ lineName->setVisible(false); } else { diff --git a/tools/drawTools/vtoolpoint.h b/tools/drawTools/vtoolpoint.h index 4b740bd74..35b8f1abd 100644 --- a/tools/drawTools/vtoolpoint.h +++ b/tools/drawTools/vtoolpoint.h @@ -36,6 +36,7 @@ public slots: virtual void ChangedActivDraw(const QString newName); virtual void FullUpdateFromGui(int result) = 0; virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: qreal radius; VGraphicsSimpleTextItem *namePoint; diff --git a/tools/drawTools/vtoolpointofcontact.cpp b/tools/drawTools/vtoolpointofcontact.cpp index 9cc003477..d4bf3d522 100644 --- a/tools/drawTools/vtoolpointofcontact.cpp +++ b/tools/drawTools/vtoolpointofcontact.cpp @@ -91,7 +91,7 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const QString errorMsg; qreal result = cal.eval(radius, &errorMsg); if(errorMsg.isEmpty()){ - QPointF fPoint = VToolPointOfContact::FindPoint(result*PrintDPI/25.4, centerP.toQPointF(), + QPointF fPoint = VToolPointOfContact::FindPoint(toPixel(result), centerP.toQPointF(), firstP.toQPointF(), secondP.toQPointF()); qint64 id = _id; if(typeCreation == Tool::FromGui){ @@ -115,6 +115,7 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const scene->addItem(point); connect(point, &VToolPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolPointOfContact::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfContact::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(center); doc->IncrementReferens(firstPointId); @@ -149,6 +150,11 @@ void VToolPointOfContact::FullUpdateFromGui(int result){ dialogPointOfContact.clear(); } +void VToolPointOfContact::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogPointOfContact, this, event); } @@ -160,8 +166,8 @@ void VToolPointOfContact::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "pointOfContact"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "radius", radius); AddAttribute(domElement, "center", center); diff --git a/tools/drawTools/vtoolpointofcontact.h b/tools/drawTools/vtoolpointofcontact.h index 4ed8e0c97..049e6efbc 100644 --- a/tools/drawTools/vtoolpointofcontact.h +++ b/tools/drawTools/vtoolpointofcontact.h @@ -28,30 +28,32 @@ class VToolPointOfContact : public VToolPoint { public: - VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &radius, const qint64 ¢er, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, - const QPointF &secondPoint); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); - static void Create(const qint64 _id, const QString &radius, const qint64 ¢er, const qint64 &firstPointId, - const qint64 &secondPointId, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + Tool::Sources typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, + const QPointF &secondPoint); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, const QString &pointName, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - QString radius; - qint64 center; - qint64 firstPointId; - qint64 secondPointId; + QString radius; + qint64 center; + qint64 firstPointId; + qint64 secondPointId; QSharedPointer dialogPointOfContact; }; diff --git a/tools/drawTools/vtoolshoulderpoint.cpp b/tools/drawTools/vtoolshoulderpoint.cpp index 9e01ff4ec..4e3307a51 100644 --- a/tools/drawTools/vtoolshoulderpoint.cpp +++ b/tools/drawTools/vtoolshoulderpoint.cpp @@ -117,6 +117,7 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const scene->addItem(point); connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolShoulderPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolShoulderPoint::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(p1Line); doc->IncrementReferens(p2Line); @@ -153,6 +154,11 @@ void VToolShoulderPoint::FullUpdateFromGui(int result){ dialogShoulderPoint.clear(); } +void VToolShoulderPoint::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogShoulderPoint, this, event); } @@ -164,8 +170,8 @@ void VToolShoulderPoint::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "shoulder"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); diff --git a/tools/drawTools/vtoolshoulderpoint.h b/tools/drawTools/vtoolshoulderpoint.h index 91f682ecb..ccf92fe3e 100644 --- a/tools/drawTools/vtoolshoulderpoint.h +++ b/tools/drawTools/vtoolshoulderpoint.h @@ -25,32 +25,33 @@ #include "vtoollinepoint.h" #include "dialogs/dialogshoulderpoint.h" -class VToolShoulderPoint : public VToolLinePoint -{ +class VToolShoulderPoint : public VToolLinePoint{ public: - VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, - const qreal &length); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); - static void Create(const qint64 _id, const QString &formula, const qint64 &p1Line, const qint64 &p2Line, - const qint64 &pShoulder, const QString &typeLine, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint64 &p1Line, + const qint64 &p2Line, const qint64 &pShoulder, + Tool::Sources typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, + const qreal &length); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const QString &formula, const qint64 &p1Line, + const qint64 &p2Line, const qint64 &pShoulder, const QString &typeLine, + const QString &pointName, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 p2Line; - qint64 pShoulder; + qint64 p2Line; + qint64 pShoulder; QSharedPointer dialogShoulderPoint; }; diff --git a/tools/drawTools/vtoolsinglepoint.cpp b/tools/drawTools/vtoolsinglepoint.cpp index f244d0104..b77d4973d 100644 --- a/tools/drawTools/vtoolsinglepoint.cpp +++ b/tools/drawTools/vtoolsinglepoint.cpp @@ -124,3 +124,8 @@ void VToolSinglePoint::ChangedActivDraw(const QString newName){ VToolPoint::ChangedActivDraw(newName); } } + +void VToolSinglePoint::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} diff --git a/tools/drawTools/vtoolsinglepoint.h b/tools/drawTools/vtoolsinglepoint.h index f5b2dad67..2a610bc92 100644 --- a/tools/drawTools/vtoolsinglepoint.h +++ b/tools/drawTools/vtoolsinglepoint.h @@ -36,6 +36,7 @@ public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); virtual void ChangedActivDraw(const QString newName); + virtual void SetFactor(qreal factor); signals: void FullUpdateTree(); protected: diff --git a/tools/drawTools/vtoolspline.cpp b/tools/drawTools/vtoolspline.cpp index 71535e5f1..25efb8ab6 100644 --- a/tools/drawTools/vtoolspline.cpp +++ b/tools/drawTools/vtoolspline.cpp @@ -34,7 +34,7 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, path.addPath(spl.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); @@ -108,6 +108,7 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c scene->addItem(spl); connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSpline::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSpline::SetFactor); doc->AddTool(id, spl); doc->IncrementReferens(p1); doc->IncrementReferens(p4); @@ -202,12 +203,12 @@ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ void VToolSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } void VToolSpline::RemoveReferens(){ @@ -217,6 +218,7 @@ void VToolSpline::RemoveReferens(){ } void VToolSpline::RefreshGeometry(){ + this->setPen(QPen(currentColor, widthHairLine/factor)); VSpline spl = VAbstractTool::data.GetSpline(id); QPainterPath path; path.addPath(spl.GetPath()); @@ -244,15 +246,17 @@ void VToolSpline::RefreshGeometry(){ void VToolSpline::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); + currentColor = Qt::black; emit setEnabledPoint(true); VDrawTool::ChangedActivDraw(newName); } else { - this->setPen(QPen(Qt::gray, widthHairLine)); + this->setPen(QPen(Qt::gray, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setAcceptHoverEvents (false); + currentColor = Qt::gray; emit setEnabledPoint(false); VDrawTool::ChangedActivDraw(newName); } @@ -261,11 +265,16 @@ void VToolSpline::ChangedActivDraw(const QString newName){ void VToolSpline::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ if(id == this->id){ if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); + this->setPen(QPen(baseColor, widthHairLine/factor)); currentColor = baseColor; } else { - this->setPen(QPen(color, widthHairLine)); + this->setPen(QPen(color, widthHairLine/factor)); currentColor = color; } } } + +void VToolSpline::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} diff --git a/tools/drawTools/vtoolspline.h b/tools/drawTools/vtoolspline.h index b421b35a0..daddf741e 100644 --- a/tools/drawTools/vtoolspline.h +++ b/tools/drawTools/vtoolspline.h @@ -28,42 +28,41 @@ #include "widgets/vcontrolpointspline.h" #include "geometry/vsplinepath.h" -class VToolSpline:public VDrawTool, public QGraphicsPathItem -{ +class VToolSpline:public VDrawTool, public QGraphicsPathItem{ Q_OBJECT public: - VToolSpline (VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0 ); + VToolSpline (VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, + QGraphicsItem * parent = 0 ); virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, - const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, + const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); signals: - void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, - const QPointF &controlPoint, const QPointF &splinePoint ); - void setEnabledPoint ( bool enable ); + void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, + const QPointF &controlPoint, const QPointF &splinePoint ); + void setEnabledPoint ( bool enable ); public slots: - virtual void FullUpdateFromFile (); - virtual void FullUpdateFromGui ( int result ); - void ControlPointChangePosition ( const qint32 &indexSpline, - SplinePoint::Position position, - const QPointF pos); - virtual void ChangedActivDraw ( const QString newName ); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile (); + virtual void FullUpdateFromGui ( int result ); + void ControlPointChangePosition ( const qint32 &indexSpline, SplinePoint::Position position, + const QPointF pos); + virtual void ChangedActivDraw ( const QString newName ); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile (); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile (); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSpline; QVector controlPoints; - void RefreshGeometry (); + void RefreshGeometry (); }; #endif // VTOOLSPLINE_H diff --git a/tools/drawTools/vtoolsplinepath.cpp b/tools/drawTools/vtoolsplinepath.cpp index 399367688..ca9fb7b0d 100644 --- a/tools/drawTools/vtoolsplinepath.cpp +++ b/tools/drawTools/vtoolsplinepath.cpp @@ -32,7 +32,7 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, path.addPath(splPath.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); @@ -96,6 +96,7 @@ void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGra scene->addItem(spl); connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSplinePath::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSplinePath::SetFactor); doc->AddTool(id, spl); } } @@ -187,15 +188,17 @@ void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path){ void VToolSplinePath::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); + currentColor = Qt::black; emit setEnabledPoint(true); VDrawTool::ChangedActivDraw(newName); } else { - this->setPen(QPen(Qt::gray, widthHairLine)); + this->setPen(QPen(Qt::gray, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setAcceptHoverEvents (false); + currentColor = Qt::gray; emit setEnabledPoint(false); VDrawTool::ChangedActivDraw(newName); } @@ -204,15 +207,20 @@ void VToolSplinePath::ChangedActivDraw(const QString newName){ void VToolSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ if(id == this->id){ if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); + this->setPen(QPen(baseColor, widthHairLine/factor)); currentColor = baseColor; } else { - this->setPen(QPen(color, widthHairLine)); + this->setPen(QPen(color, widthHairLine/factor)); currentColor = color; } } } +void VToolSplinePath::SetFactor(qreal factor){ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ ContextMenu(dialogSplinePath, this, event); } @@ -252,12 +260,12 @@ void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ void VToolSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } void VToolSplinePath::RemoveReferens(){ @@ -268,6 +276,7 @@ void VToolSplinePath::RemoveReferens(){ } void VToolSplinePath::RefreshGeometry(){ + this->setPen(QPen(currentColor, widthHairLine/factor)); VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); QPainterPath path; path.addPath(splPath.GetPath()); diff --git a/tools/drawTools/vtoolsplinepath.h b/tools/drawTools/vtoolsplinepath.h index b880bdfd2..b614f8896 100644 --- a/tools/drawTools/vtoolsplinepath.h +++ b/tools/drawTools/vtoolsplinepath.h @@ -30,42 +30,40 @@ class VToolSplinePath:public VDrawTool, public QGraphicsPathItem{ Q_OBJECT public: - VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); - static void Create(const qint64 _id, const VSplinePath &path, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation); signals: - void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, - const QPointF &controlPoint, const QPointF &splinePoint); - void setEnabledPoint(bool enable); + void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, + const QPointF &controlPoint, const QPointF &splinePoint); + void setEnabledPoint(bool enable); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - void ControlPointChangePosition(const qint32 &indexSpline, - SplinePoint::Position position, - const QPointF pos); - virtual void ChangedActivDraw(const QString newName); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + void ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, + const QPointF pos); + virtual void ChangedActivDraw(const QString newName); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSplinePath; QVector controlPoints; - void RefreshGeometry(); - void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); - void UpdatePathPoint(QDomNode& node, VSplinePath &path); - void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, - const qint32 &indexSpline); + void RefreshGeometry(); + void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); + void UpdatePathPoint(QDomNode& node, VSplinePath &path); + void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline); }; #endif // VTOOLSPLINEPATH_H diff --git a/widgets/vgraphicssimpletextitem.cpp b/widgets/vgraphicssimpletextitem.cpp index a37aba2fc..6522aa093 100644 --- a/widgets/vgraphicssimpletextitem.cpp +++ b/widgets/vgraphicssimpletextitem.cpp @@ -22,16 +22,22 @@ #include "vgraphicssimpletextitem.h" #include #include +#include -VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent):QGraphicsSimpleTextItem(parent){ +VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent):QGraphicsSimpleTextItem(parent), + fontSize(0){ this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setAcceptHoverEvents(true); + QFont font = this->font(); + font.setPointSize(font.pointSize()+3); + fontSize = font.pointSize(); + this->setFont(font); } VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent ) - :QGraphicsSimpleTextItem(text, parent){ + :QGraphicsSimpleTextItem(text, parent), fontSize(0){ this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); diff --git a/widgets/vgraphicssimpletextitem.h b/widgets/vgraphicssimpletextitem.h index e3f31d0bf..6f9dc20ef 100644 --- a/widgets/vgraphicssimpletextitem.h +++ b/widgets/vgraphicssimpletextitem.h @@ -24,18 +24,20 @@ #include -class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem -{ +class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem{ Q_OBJECT public: VGraphicsSimpleTextItem(QGraphicsItem * parent = 0); VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent = 0 ); + qint32 FontSize()const {return fontSize;} signals: void NameChangePosition(const QPointF pos); protected: QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + qint32 fontSize; }; #endif // VGRAPHICSSIMPLETEXTITEM_H diff --git a/widgets/vmaingraphicsscene.cpp b/widgets/vmaingraphicsscene.cpp index 74fee4735..3f9e932b0 100644 --- a/widgets/vmaingraphicsscene.cpp +++ b/widgets/vmaingraphicsscene.cpp @@ -25,11 +25,11 @@ #include #include -VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene(), horScrollBar(0), verScrollBar(0){ +VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1){ } VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent): - QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0){ + QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1){ } void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event){ @@ -50,6 +50,11 @@ void VMainGraphicsScene::RemoveTool(QGraphicsItem *tool){ this->removeItem(tool); } +void VMainGraphicsScene::SetFactor(qreal factor){ + scaleFactor=scaleFactor*factor; + emit NewFactor(scaleFactor); +} + qint32 VMainGraphicsScene::getVerScrollBar() const{ return verScrollBar; } diff --git a/widgets/vmaingraphicsscene.h b/widgets/vmaingraphicsscene.h index 41ec68d89..5acf6d555 100644 --- a/widgets/vmaingraphicsscene.h +++ b/widgets/vmaingraphicsscene.h @@ -42,6 +42,7 @@ public: public slots: void ChoosedItem(qint64 id, Scene::Scenes type); void RemoveTool(QGraphicsItem *tool); + void SetFactor(qreal factor); protected: void mouseMoveEvent(QGraphicsSceneMouseEvent* event); void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -49,9 +50,11 @@ signals: void mouseMove(QPointF scenePos); void mousePress(QPointF scenePos); void ChoosedObject(qint64 id, Scene::Scenes type); + void NewFactor(qreal factor); private: qint32 horScrollBar; qint32 verScrollBar; + qreal scaleFactor; }; #endif // VMAINGRAPHICSSCENE_H diff --git a/widgets/vmaingraphicsview.cpp b/widgets/vmaingraphicsview.cpp index ca232aa95..a8558bec3 100644 --- a/widgets/vmaingraphicsview.cpp +++ b/widgets/vmaingraphicsview.cpp @@ -60,6 +60,7 @@ void VMainGraphicsView::scalingTime(qreal x){ verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5)); } } + emit NewFactor(factor); } void VMainGraphicsView::animFinished(){ diff --git a/widgets/vmaingraphicsview.h b/widgets/vmaingraphicsview.h index 39d1687ff..df53f39cb 100644 --- a/widgets/vmaingraphicsview.h +++ b/widgets/vmaingraphicsview.h @@ -29,6 +29,7 @@ class VMainGraphicsView : public QGraphicsView{ public: explicit VMainGraphicsView(QWidget *parent = 0); signals: + void NewFactor(qreal factor); public slots: void scalingTime(qreal x); void animFinished(); diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 87942ff27..8c7118c84 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -584,6 +584,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen Q_ASSERT(spoint != 0); scene->addItem(spoint); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); tools[id] = spoint; } return;