From 76d1c02423c95bc88fb7d35e21358474bacf6cb3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 17 Jun 2016 16:13:49 +0300 Subject: [PATCH] Call details context menu through label. --HG-- branch : develop --- src/libs/vtools/tools/nodeDetails/vnodepoint.cpp | 3 +++ src/libs/vtools/tools/nodeDetails/vnodepoint.h | 7 +++++++ src/libs/vtools/tools/vtooldetail.cpp | 8 ++++++-- src/libs/vtools/tools/vtooldetail.h | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index 67cab4032..995b85a77 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -58,6 +58,9 @@ VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quin lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VNodePoint::NameChangePosition); + connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent *event) { + emit ShowContextMenu(event); + }); this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.h b/src/libs/vtools/tools/nodeDetails/vnodepoint.h index 727e8c8f0..fcf12a3ac 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.h +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.h @@ -53,6 +53,13 @@ public: enum { Type = UserType + static_cast(Tool::NodePoint)}; virtual QString getTagName() const Q_DECL_OVERRIDE; +signals: + /** + * @brief ShowContextMenu emit when need show tool context menu. + * @param event context menu event. + */ + void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); + public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; void NameChangePosition(const QPointF &pos); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index b6e311cf1..0c918a14b 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -84,8 +84,11 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 switch (detail.at(i).getTypeTool()) { case (Tool::NodePoint): - InitTool(scene, detail.at(i)); + { + VNodePoint *tool = InitTool(scene, detail.at(i)); + connect(tool, &VNodePoint::ShowContextMenu, this, &VToolDetail::contextMenuEvent); break; + } case (Tool::NodeArc): doc->IncrementReferens(detail.at(i).getId()); break; @@ -690,7 +693,7 @@ void VToolDetail::DeleteTool(bool ask) //--------------------------------------------------------------------------------------------------------------------- template //cppcheck-suppress unusedFunction -void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node) +Tool* VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node) { QHash* tools = doc->getTools(); SCASSERT(tools != nullptr); @@ -700,6 +703,7 @@ void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node) tool->setParentItem(this); tool->SetParentType(ParentType::Item); doc->IncrementReferens(node.getId()); + return tool; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 0d989c0a5..18dba00c2 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -122,7 +122,7 @@ private: * @param scene pointer to scene. * @param node node of detail. */ - void InitTool(VMainGraphicsScene *scene, const VNodeDetail &node); + Tool* InitTool(VMainGraphicsScene *scene, const VNodeDetail &node); virtual void DeleteTool(bool ask = true) Q_DECL_OVERRIDE; };