From 50f82eee27609a870591be3b7b801f6341b20b62 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 2 Oct 2014 16:34:49 +0300 Subject: [PATCH] Allow a user interact only with items from active pattern piece. --HG-- branch : develop --- src/app/tools/drawTools/vabstractspline.cpp | 19 +---- src/app/tools/drawTools/vdrawtool.cpp | 6 +- src/app/tools/drawTools/vdrawtool.h | 83 ++++++++----------- src/app/tools/drawTools/vtoolcut.cpp | 15 +--- src/app/tools/drawTools/vtoolline.cpp | 14 +--- src/app/tools/drawTools/vtoollinepoint.cpp | 10 +-- src/app/tools/drawTools/vtoolpoint.cpp | 22 +---- src/app/tools/drawTools/vtoolsinglepoint.cpp | 14 +--- .../widgets/vtooloptionspropertybrowser.cpp | 5 ++ 9 files changed, 55 insertions(+), 133 deletions(-) diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index 305eb11d9..b483a3cdb 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -80,22 +80,11 @@ void VAbstractSpline::Disable(bool disable) */ void VAbstractSpline::ChangedActivDraw(const QString &newName) { - bool selectable = false; - if (nameActivDraw == newName) - { - selectable = true; - currentColor = Qt::black; - } - else - { - selectable = false; - currentColor = Qt::gray; - } - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); - this->setFlag(QGraphicsItem::ItemIsSelectable, selectable); - this->setAcceptHoverEvents (selectable); - emit setEnabledPoint(selectable); VDrawTool::ChangedActivDraw(newName); + const bool selectable = (nameActivDraw == newName); + this->setEnabled(selectable); + this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + emit setEnabledPoint(selectable); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index e0688525a..8dbea68e3 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -46,7 +46,7 @@ qreal VDrawTool::factor = 1; * @param id object id in container. */ VDrawTool::VDrawTool(VPattern *doc, VContainer *data, quint32 id) - :VAbstractTool(doc, data, id), ignoreContextMenuEvent(false), ignoreFullUpdate(false), + :VAbstractTool(doc, data, id), ignoreFullUpdate(false), nameActivDraw(doc->GetNameActivPP()), dialog(nullptr) { connect(this->doc, &VPattern::ChangedActivPP, this, &VDrawTool::ChangedActivDraw); @@ -83,11 +83,11 @@ void VDrawTool::ChangedActivDraw(const QString &newName) { if (nameActivDraw == newName) { - ignoreContextMenuEvent = false; + currentColor = Qt::black; } else { - ignoreContextMenuEvent = true; + currentColor = Qt::gray; } } diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index a4f25e27e..86e6f83ce 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -54,7 +54,6 @@ public: /** @brief setDialog set dialog when user want change tool option. */ virtual void setDialog() {} virtual void DialogLinkDestroy(); - void ignoreContextMenu(bool enable); static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data); public slots: virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); @@ -64,8 +63,6 @@ public slots: virtual void FullUpdateFromGuiApply(); virtual void SetFactor(qreal factor); protected: - /** @brief ignoreContextMenuEvent ignore or not context menu events. */ - bool ignoreContextMenuEvent; /** @brief ignoreFullUpdate ignore or not full updates. */ bool ignoreFullUpdate; @@ -95,50 +92,48 @@ protected: { SCASSERT(tool != nullptr); SCASSERT(event != nullptr); - if (ignoreContextMenuEvent == false) + + QMenu menu; + QAction *actionOption = menu.addAction(tr("Options")); + QAction *actionRemove = nullptr; + actionRemove = menu.addAction(tr("Delete")); + if (showRemove) { - QMenu menu; - QAction *actionOption = menu.addAction(tr("Options")); - QAction *actionRemove = nullptr; - actionRemove = menu.addAction(tr("Delete")); - if (showRemove) - { - if (_referens > 1) - { - actionRemove->setEnabled(false); - } - else - { - actionRemove->setEnabled(true); - } - } - else + if (_referens > 1) { actionRemove->setEnabled(false); } - - QAction *selectedAction = menu.exec(event->screenPos()); - if (selectedAction == actionOption) + else { - qApp->getSceneView()->itemClicked(nullptr); - dialog = new Dialog(getData(), id, qApp->getMainWindow()); - dialog->setModal(true); - - connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGuiOk); - connect(dialog, &DialogTool::DialogApplied, tool, &Tool::FullUpdateFromGuiApply); - if (ignoreFullUpdate == false) - { - connect(doc, &VPattern::FullUpdateFromFile, dialog, &DialogTool::UpdateList); - } - - tool->setDialog(); - - dialog->show(); + actionRemove->setEnabled(true); } - if (selectedAction == actionRemove) + } + else + { + actionRemove->setEnabled(false); + } + + QAction *selectedAction = menu.exec(event->screenPos()); + if (selectedAction == actionOption) + { + qApp->getSceneView()->itemClicked(nullptr); + dialog = new Dialog(getData(), id, qApp->getMainWindow()); + dialog->setModal(true); + + connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGuiOk); + connect(dialog, &DialogTool::DialogApplied, tool, &Tool::FullUpdateFromGuiApply); + if (ignoreFullUpdate == false) { - DeleteTool(); + connect(doc, &VPattern::FullUpdateFromFile, dialog, &DialogTool::UpdateList); } + + tool->setDialog(); + + dialog->show(); + } + if (selectedAction == actionRemove) + { + DeleteTool(); } } template @@ -183,14 +178,4 @@ private: Q_DISABLE_COPY(VDrawTool) }; -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ignoreContextMenu set ignore contect menu tool. - * @param enable true - ignore. - */ -inline void VDrawTool::ignoreContextMenu(bool enable) -{ - ignoreContextMenuEvent = enable; -} - #endif // VDRAWTOOL_H diff --git a/src/app/tools/drawTools/vtoolcut.cpp b/src/app/tools/drawTools/vtoolcut.cpp index 984cf2729..ff2365dcd 100644 --- a/src/app/tools/drawTools/vtoolcut.cpp +++ b/src/app/tools/drawTools/vtoolcut.cpp @@ -59,20 +59,11 @@ VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QSt */ void VToolCut::ChangedActivDraw(const QString &newName) { - bool flag = true; - if (nameActivDraw == newName) - { - currentColor = Qt::black; - flag = true; - } - else - { - currentColor = Qt::gray; - flag = false; - } + VToolPoint::ChangedActivDraw(newName); + const bool flag = (nameActivDraw == newName); + this->setEnabled(flag); firstCurve->ChangedActivDraw(flag); secondCurve->ChangedActivDraw(flag); - VToolPoint::ChangedActivDraw(newName); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index 082ee3c95..74a9b5ecc 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -237,20 +237,8 @@ void VToolLine::Disable(bool disable) */ void VToolLine::ChangedActivDraw(const QString &newName) { - bool selectable = false; - if (nameActivDraw == newName) - { - selectable = true; - currentColor = Qt::black; - } - else - { - selectable = false; - currentColor = Qt::gray; - } - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine))); - this->setAcceptHoverEvents (selectable); VDrawTool::ChangedActivDraw(newName); + this->setEnabled(nameActivDraw == newName); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 7a60f5bb3..788fc9656 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -63,16 +63,8 @@ VToolLinePoint::VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &i */ void VToolLinePoint::ChangedActivDraw(const QString &newName) { - if (nameActivDraw == newName) - { - currentColor = Qt::black; - } - else - { - currentColor = Qt::gray; - } - mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyle(typeLine))); VToolPoint::ChangedActivDraw(newName); + this->setEnabled(nameActivDraw == newName); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 8a40360a1..e6d1d693a 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -132,27 +132,9 @@ void VToolPoint::UpdateNamePosition(qreal mx, qreal my) */ void VToolPoint::ChangedActivDraw(const QString &newName) { - bool selectable = false; - if (nameActivDraw == newName) - { - selectable = true; - currentColor = baseColor; - } - else - { - selectable = false; - currentColor = Qt::gray; - } - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); - this->setFlag(QGraphicsItem::ItemIsSelectable, selectable); - this->setAcceptHoverEvents (selectable); - namePoint->setFlag(QGraphicsItem::ItemIsMovable, selectable); - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, selectable); - namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, selectable); - namePoint->setBrush(QBrush(currentColor)); - namePoint->setAcceptHoverEvents(selectable); - lineName->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); VDrawTool::ChangedActivDraw(newName); + this->setEnabled(nameActivDraw == newName); + namePoint->setBrush(QBrush(currentColor)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index b44c0e15e..325fde6d1 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -306,18 +306,8 @@ void VToolSinglePoint::FullUpdateFromFile() */ void VToolSinglePoint::ChangedActivDraw(const QString &newName) { - if (nameActivDraw == newName) - { - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - VToolPoint::ChangedActivDraw(newName); - setColorLabel(Qt::black); - } - else - { - this->setFlag(QGraphicsItem::ItemIsSelectable, false); - VToolPoint::ChangedActivDraw(newName); - setColorLabel(Qt::gray); - } + VToolPoint::ChangedActivDraw(newName); + this->setEnabled(nameActivDraw == newName); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 2de4e8d18..cea5ee35e 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -297,6 +297,11 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) { + if (item != nullptr && item->isEnabled()==false) + { + return; + } + if (currentItem == item) { UpdateOptions();