From c0c4ef5782d8310a8606ff2acbf424745dc126d2 Mon Sep 17 00:00:00 2001 From: "bob.pan" Date: Fri, 20 Aug 2021 11:37:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4UI=E6=98=BE=E7=A4=BA=E5=B1=82?= =?UTF-8?q?=E7=BA=A7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3part/tadpole/include/tpBase/lpdesigner.h | 2 +- src/ImageCompare/ImageCompareModel.cpp | 2 +- src/lpbdesigner/CDetectorUI.cpp | 8 +- src/lpbdesigner/CDetectorUI.h | 2 +- src/tpMain/algela/RoiImgViewer.cpp | 1020 ++++++++++----------- src/tpMain/algela/lpImgViewer.cpp | 9 - tpvs17/tpMain/lpMainWin.cpp | 12 +- 7 files changed, 522 insertions(+), 533 deletions(-) diff --git a/3part/tadpole/include/tpBase/lpdesigner.h b/3part/tadpole/include/tpBase/lpdesigner.h index 01dcd9a..8fee317 100644 --- a/3part/tadpole/include/tpBase/lpdesigner.h +++ b/3part/tadpole/include/tpBase/lpdesigner.h @@ -19,7 +19,7 @@ class IDetectorUI { public: virtual bool Initialize(IDetectorEngine* lpDE) = 0; - virtual bool ShowMainFrame() = 0; + virtual bool ShowMainFrame(class QWidget* parent = nullptr) = 0; }; diff --git a/src/ImageCompare/ImageCompareModel.cpp b/src/ImageCompare/ImageCompareModel.cpp index 76b37d5..6682f39 100644 --- a/src/ImageCompare/ImageCompareModel.cpp +++ b/src/ImageCompare/ImageCompareModel.cpp @@ -1871,7 +1871,7 @@ void ImageCompareModelInvoker::operator()(const cv::Range& range) const { int i0 = range.start; int i1 = range.end; - assert(abs(i1 - i0) == 1); + //assert(abs(i1 - i0) == 1); //if (abs(i1 - i0) == 1) // return; m_pModel->parallelDetect(i0, m_pData); diff --git a/src/lpbdesigner/CDetectorUI.cpp b/src/lpbdesigner/CDetectorUI.cpp index 92fbcae..7799439 100644 --- a/src/lpbdesigner/CDetectorUI.cpp +++ b/src/lpbdesigner/CDetectorUI.cpp @@ -28,7 +28,7 @@ bool CDetectorUI::Initialize(IDetectorEngine* lpDE) return true; } -bool CDetectorUI::ShowMainFrame() +bool CDetectorUI::ShowMainFrame(class QWidget* parent) { if (!m_pMainFrame->Initialize(m_pDE)) return false; @@ -36,6 +36,12 @@ bool CDetectorUI::ShowMainFrame() if (!m_pMainFrame->InitGraphView()) return false; + m_pMainFrame->setParent(parent); + m_pMainFrame->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + m_pMainFrame->setWindowIcon(QIcon(":/image/leaper")); + m_pMainFrame->setWindowModality(Qt::ApplicationModal); + m_pMainFrame->setAttribute(Qt::WA_ShowModal, true); + m_pMainFrame->show(); return true; } diff --git a/src/lpbdesigner/CDetectorUI.h b/src/lpbdesigner/CDetectorUI.h index 389fb85..e39fcfe 100644 --- a/src/lpbdesigner/CDetectorUI.h +++ b/src/lpbdesigner/CDetectorUI.h @@ -9,7 +9,7 @@ public: CDetectorUI(); virtual ~CDetectorUI(); bool Initialize(IDetectorEngine* lpDE); - virtual bool ShowMainFrame(); + virtual bool ShowMainFrame(class QWidget* parent = nullptr); private: CMainFrame* m_pMainFrame{ nullptr }; IDetectorEngine* m_pDE{ nullptr }; diff --git a/src/tpMain/algela/RoiImgViewer.cpp b/src/tpMain/algela/RoiImgViewer.cpp index 35d1508..5b082aa 100644 --- a/src/tpMain/algela/RoiImgViewer.cpp +++ b/src/tpMain/algela/RoiImgViewer.cpp @@ -1,670 +1,666 @@ #include "RoiImgViewer.h" #include -//#include "qtUtils.h" #include #include - - //#define DEBUG_PRINT - - RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/) - : lpImgViewer(parent) - , mMouseCaptureStatus(MouseCaptureNone) - , mDrawStatus(DrawNone) - , mMouseCaptureDistance(10) - , mpDrawingLineItem(NULL) - , mpDrawingRectItem(NULL) - , mpSelectedRoiNode(NULL) +RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/) + : lpImgViewer(parent) + , mMouseCaptureStatus(MouseCaptureNone) + , mDrawStatus(DrawNone) + , mMouseCaptureDistance(10) + , mpDrawingLineItem(NULL) + , mpDrawingRectItem(NULL) + , mpSelectedRoiNode(NULL) +{ + connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode())); +} + +QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img) +{ + if (lpImgViewer::setImg(img)) { - connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode())); + mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return mpImgItem; } - - QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img) + else { - if (lpImgViewer::setImg(img)) - { - mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); - return mpImgItem; - } - else - { - return NULL; - } + return NULL; } +} - QGraphicsItem* RoiImgViewer::firstSelectedItem() +QGraphicsItem* RoiImgViewer::firstSelectedItem() +{ + auto selectedItemList = scene()->selectedItems(); + if (selectedItemList.size()) { - auto selectedItemList = scene()->selectedItems(); - if (selectedItemList.size()) - { - return selectedItemList.front(); - } - else - { - return NULL; - } + return selectedItemList.front(); } - - void RoiImgViewer::setDrawStatus(DrawStatus s) + else { - - mDrawStatus = s; - // if(mpImgItem){ - // if(DrawNone == s){ - // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, true); - // printf("RoiImgViewer::setDrawStatus true\n"); - // } - // else{ - // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); - // printf("RoiImgViewer::setDrawStatus false\n"); - // } - // } + return NULL; } - - void RoiImgViewer::clearRois(int type /*= -1*/) +} + +void RoiImgViewer::setDrawStatus(DrawStatus s) +{ + + mDrawStatus = s; + // if(mpImgItem){ + // if(DrawNone == s){ + // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, true); + // printf("RoiImgViewer::setDrawStatus true\n"); + // } + // else{ + // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); + // printf("RoiImgViewer::setDrawStatus false\n"); + // } + // } +} + +void RoiImgViewer::clearRois(int type /*= -1*/) +{ + QGraphicsScene* pScene = scene(); + if (type < 0) { - QGraphicsScene* pScene = scene(); - if (type < 0) - { - foreach(auto itemList, mRoiItemMap) - { - foreach(auto pItem, itemList) - { - pScene->removeItem(pItem); - delete pItem; - } - } - mRoiItemMap.clear(); - } - else + foreach(auto itemList, mRoiItemMap) { - auto iterItem = mRoiItemMap.find(type); - if (iterItem != mRoiItemMap.end()) + foreach(auto pItem, itemList) { - foreach(auto pItem, mRoiItemMap[type]) - { - pScene->removeItem(pItem); - delete pItem; - } - mRoiItemMap.erase(iterItem); + pScene->removeItem(pItem); + delete pItem; } } - - if (type < 0 || type == QGraphicsRectItem::Type) - { - mRoiNodeList.clear(); - mpSelectedRoiNode = NULL; - } - - rejectDrawingItem(); + mRoiItemMap.clear(); } - - void RoiImgViewer::clearExistRois() + else { - QGraphicsScene* pScene = scene(); - - foreach(auto itemList, mRoiItemMap) + auto iterItem = mRoiItemMap.find(type); + if (iterItem != mRoiItemMap.end()) { - foreach(auto pItem, itemList) + foreach(auto pItem, mRoiItemMap[type]) { pScene->removeItem(pItem); delete pItem; } + mRoiItemMap.erase(iterItem); } - mRoiItemMap.clear(); + } + + if (type < 0 || type == QGraphicsRectItem::Type) + { mRoiNodeList.clear(); mpSelectedRoiNode = NULL; } - void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/) - { - DrawStatus backupDrawStatus = mDrawStatus; - QString backupChannelName = getChannel(); + rejectDrawingItem(); +} - setChannel(channelName); - setDrawStatus(DrawRect); - mDrawingRect = rect; - createDrawingItem(); +void RoiImgViewer::clearExistRois() +{ + QGraphicsScene* pScene = scene(); - qreal backupFixedSizeScale = fixedSizeScale(); - setFixedSizeScale(scale); - acceptDrawingItem(); - lastRectRoi()->id = id; - lastRectRoi()->isTemplate = isTemplate; - if (!isTemplate) + foreach(auto itemList, mRoiItemMap) + { + foreach(auto pItem, itemList) { - //setPenColor(lastRectRoi()->pItem, nonTmplColor); - QPen pen = lastRectRoi()->pItem->pen(); - pen.setColor(nonTmplColor); - lastRectRoi()->pItem->setPen(pen); + pScene->removeItem(pItem); + delete pItem; } - setFixedSizeScale(backupFixedSizeScale); - - mDrawStatus = backupDrawStatus; - setChannel(backupChannelName); } - - void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id) + mRoiItemMap.clear(); + mRoiNodeList.clear(); + mpSelectedRoiNode = NULL; +} + +void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/) +{ + DrawStatus backupDrawStatus = mDrawStatus; + QString backupChannelName = getChannel(); + + setChannel(channelName); + setDrawStatus(DrawRect); + mDrawingRect = rect; + createDrawingItem(); + + qreal backupFixedSizeScale = fixedSizeScale(); + setFixedSizeScale(scale); + acceptDrawingItem(); + lastRectRoi()->id = id; + lastRectRoi()->isTemplate = isTemplate; + if (!isTemplate) { - setDrawStatus(DrawRect); - // QPolygonF qrect = mapToScene(rect.toRect()); - // mDrawingRect = qrect.boundingRect(); - mDrawingRect = rect; - createDrawingItem(); - updateDrawingItem(); - //setFixedSizeScale(scale); - acceptDrawingItem(); - lastRectRoi()->id = id; + //setPenColor(lastRectRoi()->pItem, nonTmplColor); + QPen pen = lastRectRoi()->pItem->pen(); + pen.setColor(nonTmplColor); + lastRectRoi()->pItem->setPen(pen); } - - void RoiImgViewer::addRoiLine(QLineF line, QString id) + setFixedSizeScale(backupFixedSizeScale); + + mDrawStatus = backupDrawStatus; + setChannel(backupChannelName); +} + +void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id) +{ + setDrawStatus(DrawRect); + // QPolygonF qrect = mapToScene(rect.toRect()); + // mDrawingRect = qrect.boundingRect(); + mDrawingRect = rect; + createDrawingItem(); + updateDrawingItem(); + //setFixedSizeScale(scale); + acceptDrawingItem(); + lastRectRoi()->id = id; +} + +void RoiImgViewer::addRoiLine(QLineF line, QString id) +{ + setDrawStatus(DrawLine); + mDrawingLine = line; + createDrawingItem(); + updateDrawingItem(); + acceptDrawingItem(); + //lastRectRoi()->id = id; + setDrawStatus(DrawNone); +} + +LP_ROI_NODE* RoiImgViewer::lastRectRoi() +{ + if (mRoiNodeList.size()) { - setDrawStatus(DrawLine); - mDrawingLine = line; - createDrawingItem(); - updateDrawingItem(); - acceptDrawingItem(); - //lastRectRoi()->id = id; - setDrawStatus(DrawNone); + return &mRoiNodeList.last(); } - - LP_ROI_NODE* RoiImgViewer::lastRectRoi() + else { - if (mRoiNodeList.size()) - { - return &mRoiNodeList.last(); - } - else - { - return NULL; - } + return NULL; } +} - void RoiImgViewer::mousePressEvent(QMouseEvent *event) +void RoiImgViewer::mousePressEvent(QMouseEvent *event) +{ + QGraphicsItem* pItem = firstSelectedItem(); + if (!pItem) { - QGraphicsItem* pItem = firstSelectedItem(); - if (!pItem) - { - lpImgViewer::mousePressEvent(event); - pItem = firstSelectedItem(); - } + lpImgViewer::mousePressEvent(event); + pItem = firstSelectedItem(); + } - QPoint mousePos = event->pos(); - QPointF scenePos = mapToScene(mousePos); + QPoint mousePos = event->pos(); + QPointF scenePos = mapToScene(mousePos); - if (event->button() == Qt::LeftButton) - { + if (event->button() == Qt::LeftButton) + { - if (!pItem) + if (!pItem) + { + // nothing is selected, start drawing + switch (mDrawStatus) { - // nothing is selected, start drawing - switch (mDrawStatus) - { - case DrawLine: - mDrawingLine.setP1(scenePos); - mDrawingLine.setP2(scenePos); - break; - case DrawRect: - mDrawingRect.setTopLeft(scenePos); - mDrawingRect.setBottomRight(scenePos); - break; - default: - break; - } - createDrawingItem(); - return; + case DrawLine: + mDrawingLine.setP1(scenePos); + mDrawingLine.setP2(scenePos); + break; + case DrawRect: + mDrawingRect.setTopLeft(scenePos); + mDrawingRect.setBottomRight(scenePos); + break; + default: + break; } - else - { - // something is selected + createDrawingItem(); + return; + } + else + { + // something is selected - // map pos to selected item's local coordinates - QPointF itemMousePos = pItem->mapFromScene(scenePos); + // map pos to selected item's local coordinates + QPointF itemMousePos = pItem->mapFromScene(scenePos); #ifdef DEBUG_PRINT - printf("viewer mouse press pos %d %d\n", mousePos.x(), mousePos.y()); - printf("scene mouse press pos %f %f\n", scenePos.x(), scenePos.y()); - printf("item mouse press pos %f %f\n", itemMousePos.x(), itemMousePos.y()); + printf("viewer mouse press pos %d %d\n", mousePos.x(), mousePos.y()); + printf("scene mouse press pos %f %f\n", scenePos.x(), scenePos.y()); + printf("item mouse press pos %f %f\n", itemMousePos.x(), itemMousePos.y()); #endif - QGraphicsRectItem* pRectItem = dynamic_cast(pItem); - if (pRectItem) - { - QRectF r = pRectItem->rect(); + QGraphicsRectItem* pRectItem = dynamic_cast(pItem); + if (pRectItem) + { + QRectF r = pRectItem->rect(); #ifdef DEBUG_PRINT - printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); + printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); #endif - mMouseCaptureStatus = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); + mMouseCaptureStatus = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); - if (mMouseCaptureStatus != MouseCaptureNone) - { - pRectItem->setFlag(QGraphicsItem::ItemIsMovable, false); - return; - } - } - QGraphicsLineItem* pLineItem = dynamic_cast(pItem); - if (pLineItem) + if (mMouseCaptureStatus != MouseCaptureNone) { - QLineF l = pLineItem->line(); + pRectItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return; + } + } + QGraphicsLineItem* pLineItem = dynamic_cast(pItem); + if (pLineItem) + { + QLineF l = pLineItem->line(); - mMouseCaptureStatus = decideMouseCaptureStatus(l, itemMousePos, mMouseCaptureDistance); + mMouseCaptureStatus = decideMouseCaptureStatus(l, itemMousePos, mMouseCaptureDistance); - if (mMouseCaptureStatus != MouseCaptureNone) - { - pLineItem->setFlag(QGraphicsItem::ItemIsMovable, false); - return; - } + if (mMouseCaptureStatus != MouseCaptureNone) + { + pLineItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return; } } } - - lpImgViewer::mousePressEvent(event); } - void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt) - { - lpImgViewer::mouseMoveEvent(evt); + lpImgViewer::mousePressEvent(event); +} - QGraphicsItem* pItem = dynamic_cast( - firstSelectedItem()); +void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt) +{ + lpImgViewer::mouseMoveEvent(evt); - QPoint mousePos = evt->pos(); - QPointF scenePos = mapToScene(mousePos); + QGraphicsItem* pItem = dynamic_cast( + firstSelectedItem()); - if (!pItem) + QPoint mousePos = evt->pos(); + QPointF scenePos = mapToScene(mousePos); + + if (!pItem) + { + if (evt->buttons() == Qt::LeftButton) { - if (evt->buttons() == Qt::LeftButton) + switch (mDrawStatus) { - switch (mDrawStatus) - { - case DrawLine: - mDrawingLine.setP2(scenePos); - break; - case DrawRect: - mDrawingRect.setBottomRight(scenePos); - break; - default: - break; - } - updateDrawingItem(); + case DrawLine: + mDrawingLine.setP2(scenePos); + break; + case DrawRect: + mDrawingRect.setBottomRight(scenePos); + break; + default: + break; } + updateDrawingItem(); } - else - { - QPointF itemMousePos = pItem->mapFromScene(scenePos); + } + else + { + QPointF itemMousePos = pItem->mapFromScene(scenePos); - if (pItem->type() == QGraphicsRectItem().type()) - { - QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); - // map pos to selected item's local coordinates + if (pItem->type() == QGraphicsRectItem().type()) + { + QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + // map pos to selected item's local coordinates - QRectF r = pRectItem->rect(); + QRectF r = pRectItem->rect(); #ifdef DEBUG_PRINT - printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); - printf("viewer mouse move pos %d %d\n", evt->pos().x(), evt->pos().y()); - printf("scene mouse move pos %f %f\n", scenePos.x(), scenePos.y()); - printf("item mouse move pos %f %f\n", itemMousePos.x(), itemMousePos.y()); - printf("mouse capture status %d\n", mMouseCaptureStatus); + printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); + printf("viewer mouse move pos %d %d\n", evt->pos().x(), evt->pos().y()); + printf("scene mouse move pos %f %f\n", scenePos.x(), scenePos.y()); + printf("item mouse move pos %f %f\n", itemMousePos.x(), itemMousePos.y()); + printf("mouse capture status %d\n", mMouseCaptureStatus); #endif - if (evt->buttons() == Qt::LeftButton) + if (evt->buttons() == Qt::LeftButton) + { + QRectF oriRect = r; + switch (mMouseCaptureStatus) { - QRectF oriRect = r; - switch (mMouseCaptureStatus) - { - case MouseCaptureLeft: - r.setLeft(itemMousePos.x()); - r.setWidth(oriRect.right() - r.left()); - break; - case MouseCaptureRight: - r.setRight(itemMousePos.x()); - r.setWidth(r.right() - oriRect.left()); - break; - case MouseCaptureTop: - r.setTop(itemMousePos.y()); - r.setHeight(oriRect.bottom() - r.top()); - break; - case MouseCaptureBottom: - r.setBottom(itemMousePos.y()); - r.setHeight(r.bottom() - oriRect.top()); - break; - default: - case MouseCaptureNone: - break; - } - pRectItem->setRect(r); + case MouseCaptureLeft: + r.setLeft(itemMousePos.x()); + r.setWidth(oriRect.right() - r.left()); + break; + case MouseCaptureRight: + r.setRight(itemMousePos.x()); + r.setWidth(r.right() - oriRect.left()); + break; + case MouseCaptureTop: + r.setTop(itemMousePos.y()); + r.setHeight(oriRect.bottom() - r.top()); + break; + case MouseCaptureBottom: + r.setBottom(itemMousePos.y()); + r.setHeight(r.bottom() - oriRect.top()); + break; + default: + case MouseCaptureNone: + break; } + pRectItem->setRect(r); + } - MouseCaptureStatus s = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); + MouseCaptureStatus s = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); #ifdef DEBUG_PRINT - printf("cur mouse status %d\n", s); + printf("cur mouse status %d\n", s); #endif - if (s == MouseCaptureLeft || s == MouseCaptureRight) - { - setCursor(Qt::SizeHorCursor); - } - else if (s == MouseCaptureTop || s == MouseCaptureBottom) - { - setCursor(Qt::SizeVerCursor); - } - else - { - setCursor(Qt::ArrowCursor); - } + if (s == MouseCaptureLeft || s == MouseCaptureRight) + { + setCursor(Qt::SizeHorCursor); } - else if (pItem->type() == QGraphicsLineItem().type()) + else if (s == MouseCaptureTop || s == MouseCaptureBottom) { - QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); - + setCursor(Qt::SizeVerCursor); + } + else + { + setCursor(Qt::ArrowCursor); } } + else if (pItem->type() == QGraphicsLineItem().type()) + { + QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); + } } - void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event) +} + +void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { - if (event->button() == Qt::LeftButton) - { - mMouseCaptureStatus = MouseCaptureNone; + mMouseCaptureStatus = MouseCaptureNone; - QGraphicsItem* pItem = firstSelectedItem(); - if (!pItem) - { - // draw - switch (mDrawStatus) - { - case DrawLine: - if (mpDrawingLineItem) - { - emit roiAdded(mpDrawingLineItem); - } - break; - case DrawRect: - if (mpDrawingRectItem) - { - emit roiAdded(mpDrawingRectItem); - } - break; - default: - break; - } - acceptDrawingItem(); - } - else + QGraphicsItem* pItem = firstSelectedItem(); + if (!pItem) + { + // draw + switch (mDrawStatus) { - // edit - pItem->setFlag(QGraphicsItem::ItemIsMovable, true); - - int itemType = pItem->type(); - if (itemType == QGraphicsRectItem().type()) + case DrawLine: + if (mpDrawingLineItem) { - QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + emit roiAdded(mpDrawingLineItem); } - else if (itemType == QGraphicsLineItem().type()) + break; + case DrawRect: + if (mpDrawingRectItem) { - QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); + emit roiAdded(mpDrawingRectItem); } + break; + default: + break; + } + acceptDrawingItem(); + } + else + { + // edit + pItem->setFlag(QGraphicsItem::ItemIsMovable, true); - emit roiChanged(pItem); + int itemType = pItem->type(); + if (itemType == QGraphicsRectItem().type()) + { + QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + } + else if (itemType == QGraphicsLineItem().type()) + { + QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); } + + emit roiChanged(pItem); } - lpImgViewer::mouseReleaseEvent(event); } + lpImgViewer::mouseReleaseEvent(event); +} - void RoiImgViewer::wheelEvent(QWheelEvent *evt) +void RoiImgViewer::wheelEvent(QWheelEvent *evt) +{ + lpImgViewer::wheelEvent(evt); + + if (!mpSelectedRoiNode) { - lpImgViewer::wheelEvent(evt); + return; + } - if (!mpSelectedRoiNode) + mpSelectedRoiNode->fScale = mFixedSizeScale; +} + +void RoiImgViewer::keyPressEvent(QKeyEvent *event) +{ + if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) { + QGraphicsScene* pScene = scene(); + + foreach(auto itemList, mRoiItemMap) { - return; - } + foreach(auto pItem, itemList) + { + if (pItem == mpSelectedRoiNode->pItem) { + pScene->removeItem(pItem); - mpSelectedRoiNode->fScale = mFixedSizeScale; - } + auto i1 = std::find_if(itemList.begin(), itemList.end(), [&](QGraphicsItem* pi) + { + return pi == pItem; + }); + itemList.erase(i1); - void RoiImgViewer::keyPressEvent(QKeyEvent *event) - { - if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) { - QGraphicsScene* pScene = scene(); + auto i2 = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) + { + return roiNode.pItem == pItem; + }); + mRoiNodeList.erase(i2); - foreach(auto itemList, mRoiItemMap) - { - foreach(auto pItem, itemList) - { - if (pItem == mpSelectedRoiNode->pItem) { - pScene->removeItem(pItem); - - auto i1 = std::find_if(itemList.begin(), itemList.end(), [&](QGraphicsItem* pi) - { - return pi == pItem; - }); - itemList.erase(i1); - - auto i2 = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) - { - return roiNode.pItem == pItem; - }); - mRoiNodeList.erase(i2); - - delete pItem; - mpSelectedRoiNode = NULL; - return; - } + delete pItem; + mpSelectedRoiNode = NULL; + return; } } } } +} + +QRectF extRect(const QRectF& r, float w) +{ + return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w); +} - QRectF extRect(const QRectF& r, float w) +RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/) +{ + MouseCaptureStatus ret = MouseCaptureNone; + + QRectF validRect = extRect(r, capDis); + if (!validRect.contains(p)) { - return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w); + return ret; } - RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/) + if (abs(p.x() - r.left()) < capDis) { - MouseCaptureStatus ret = MouseCaptureNone; + ret = MouseCaptureLeft; + } + else if (abs(p.x() - r.right()) < capDis) + { + ret = MouseCaptureRight; + } + else if (abs(p.y() - r.top()) < capDis) + { + ret = MouseCaptureTop; + } + else if (abs(p.y() - r.bottom()) < capDis) + { + ret = MouseCaptureBottom; + } - QRectF validRect = extRect(r, capDis); - if (!validRect.contains(p)) - { - return ret; - } + return ret; +} + +RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/) +{ + return MouseCaptureNone; +} + +void RoiImgViewer::updateSelectedRoiNode() +{ + QGraphicsItem* pItem = firstSelectedItem(); - if (abs(p.x() - r.left()) < capDis) + LP_ROI_NODE *pRoiNode = findRoiNode(pItem); + if (pRoiNode != mpSelectedRoiNode) + { + mpSelectedRoiNode = pRoiNode; + emit roiSelectionChanged(mpSelectedRoiNode); + } +} + +void RoiImgViewer::updateDrawingItem() +{ + switch (mDrawStatus) + { + case DrawLine: + if (mpDrawingLineItem) { - ret = MouseCaptureLeft; + QPen pen = mpDrawingLineItem->pen(); + pen.setColor(Qt::yellow); + pen.setWidth(5); + mpDrawingLineItem->setPen(pen); + mpDrawingLineItem->setLine(mDrawingLine); } - else if (abs(p.x() - r.right()) < capDis) + else { - ret = MouseCaptureRight; + qWarning() << tr("line item is not created"); } - else if (abs(p.y() - r.top()) < capDis) + break; + case DrawRect: + if (mpDrawingRectItem) { - ret = MouseCaptureTop; + QPen pen = mpDrawingRectItem->pen(); + pen.setColor(Qt::yellow); + pen.setWidth(5); + mpDrawingRectItem->setPen(pen); + mpDrawingRectItem->setRect(mDrawingRect); } - else if (abs(p.y() - r.bottom()) < capDis) + else { - ret = MouseCaptureBottom; + qWarning() << tr("line item is not created"); } - - return ret; + break; + default: + break; } +} - RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/) +void RoiImgViewer::createDrawingItem() +{ + switch (mDrawStatus) { - return MouseCaptureNone; - } - - void RoiImgViewer::updateSelectedRoiNode() - { - QGraphicsItem* pItem = firstSelectedItem(); - - LP_ROI_NODE *pRoiNode = findRoiNode(pItem); - if (pRoiNode != mpSelectedRoiNode) + case DrawLine: + if (!mpDrawingLineItem) { - mpSelectedRoiNode = pRoiNode; - emit roiSelectionChanged(mpSelectedRoiNode); + mpDrawingLineItem = scene()->addLine(mDrawingLine); + mpDrawingLineItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); } - } - - void RoiImgViewer::updateDrawingItem() - { - switch (mDrawStatus) + else { - case DrawLine: - if (mpDrawingLineItem) - { - QPen pen = mpDrawingLineItem->pen(); - pen.setColor(Qt::yellow); - pen.setWidth(5); - mpDrawingLineItem->setPen(pen); - mpDrawingLineItem->setLine(mDrawingLine); - } - else - { - qWarning() << tr("line item is not created"); - } - break; - case DrawRect: - if (mpDrawingRectItem) - { - QPen pen = mpDrawingRectItem->pen(); - pen.setColor(Qt::yellow); - pen.setWidth(5); - mpDrawingRectItem->setPen(pen); - mpDrawingRectItem->setRect(mDrawingRect); - } - else - { - qWarning() << tr("line item is not created"); - } - break; - default: - break; + qWarning() << tr("line item is already created"); } - } - - void RoiImgViewer::createDrawingItem() - { - switch (mDrawStatus) + break; + case DrawRect: + if (!mpDrawingRectItem) { - case DrawLine: - if (!mpDrawingLineItem) - { - mpDrawingLineItem = scene()->addLine(mDrawingLine); - mpDrawingLineItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - } - else - { - qWarning() << tr("line item is already created"); - } - break; - case DrawRect: - if (!mpDrawingRectItem) - { - mpDrawingRectItem = scene()->addRect(mDrawingRect); - mpDrawingRectItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - } - else - { - qWarning() << tr("rect item is already created"); - } - break; - default: - break; + mpDrawingRectItem = scene()->addRect(mDrawingRect); + mpDrawingRectItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); } - } - - void RoiImgViewer::acceptDrawingItem() - { - //clearExistRois(); - switch (mDrawStatus) + else { - case DrawLine: - if (mpDrawingLineItem) - { - acceptRoiItem(mpDrawingLineItem); - mpDrawingLineItem = NULL; - } - break; - case DrawRect: - if (mpDrawingRectItem) - { - acceptRoiItem(mpDrawingRectItem); - mpDrawingRectItem = NULL; - } - break; - default: - break; + qWarning() << tr("rect item is already created"); } + break; + default: + break; } +} - void RoiImgViewer::rejectDrawingItem() +void RoiImgViewer::acceptDrawingItem() +{ + //clearExistRois(); + switch (mDrawStatus) { - switch (mDrawStatus) + case DrawLine: + if (mpDrawingLineItem) { - case DrawLine: - scene()->removeItem(mpDrawingLineItem); + acceptRoiItem(mpDrawingLineItem); mpDrawingLineItem = NULL; - break; - case DrawRect: - scene()->removeItem(mpDrawingRectItem); + } + break; + case DrawRect: + if (mpDrawingRectItem) + { + acceptRoiItem(mpDrawingRectItem); mpDrawingRectItem = NULL; - break; - default: - break; } + break; + default: + break; } +} - void RoiImgViewer::resetAllDrawingItems() +void RoiImgViewer::rejectDrawingItem() +{ + switch (mDrawStatus) { + case DrawLine: + scene()->removeItem(mpDrawingLineItem); mpDrawingLineItem = NULL; + break; + case DrawRect: + scene()->removeItem(mpDrawingRectItem); mpDrawingRectItem = NULL; + break; + default: + break; + } +} + +void RoiImgViewer::resetAllDrawingItems() +{ + mpDrawingLineItem = NULL; + mpDrawingRectItem = NULL; +} + +void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem) +{ + int type = pItem->type(); + if (mRoiItemMap.contains(type)) + { + mRoiItemMap[type].append(pItem); + } + else + { + QList itemList; + itemList << pItem; + mRoiItemMap.insert(type, itemList); } - void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem) + if (type == QGraphicsRectItem::Type) { - int type = pItem->type(); - if (mRoiItemMap.contains(type)) - { - mRoiItemMap[type].append(pItem); - } - else - { - QList itemList; - itemList << pItem; - mRoiItemMap.insert(type, itemList); - } + LP_ROI_NODE roi_node; + roi_node.fScale = fixedSizeScale(); + roi_node.szChannel = getChannel(); + roi_node.pItem = qgraphicsitem_cast(pItem); - if (type == QGraphicsRectItem::Type) - { - LP_ROI_NODE roi_node; - roi_node.fScale = fixedSizeScale(); - roi_node.szChannel = getChannel(); - roi_node.pItem = qgraphicsitem_cast(pItem); + //roi_node.id = uniqueTimeID(); + qint64 msecs = QDateTime::currentMSecsSinceEpoch(); + roi_node.id = QString::number(msecs, 16); - //roi_node.id = uniqueTimeID(); - qint64 msecs = QDateTime::currentMSecsSinceEpoch(); - roi_node.id = QString::number(msecs, 16); + roi_node.isTemplate = true; + mRoiNodeList.append(roi_node); + } - roi_node.isTemplate = true; - mRoiNodeList.append(roi_node); - } +} +LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem) +{ + auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) + { + return roiNode.pItem == pItem; + }); + if (i == mRoiNodeList.end()) + { + return NULL; } - - LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem) + else { - auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) - { - return roiNode.pItem == pItem; - }); - if (i == mRoiNodeList.end()) - { - return NULL; - } - else - { - return &(*i); - } + return &(*i); } +} diff --git a/src/tpMain/algela/lpImgViewer.cpp b/src/tpMain/algela/lpImgViewer.cpp index 1d1de4d..40f7cce 100644 --- a/src/tpMain/algela/lpImgViewer.cpp +++ b/src/tpMain/algela/lpImgViewer.cpp @@ -5,8 +5,6 @@ #include #include - - lpImgViewer::lpImgViewer(QWidget* parent /*= 0*/) : QGraphicsView(parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), mMinScaleThre(0.01), mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) @@ -25,16 +23,11 @@ lpImgViewer::lpImgViewer(QGraphicsScene *scene, QWidget *parent /*= 0*/) setTransformationAnchor(QGraphicsView::AnchorUnderMouse); } - void lpImgViewer::setInitScale(qreal val) { scaleImg2(val); } - - - - QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img) { if (mpImg) @@ -50,8 +43,6 @@ QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img) mImgOriSize = img.size(); mMinScaleThre = 1.0 / std::min(mImgOriSize.width(), mImgOriSize.height()); - //qreal scale = std::min((qreal)size().width() / img.width(), (qreal)size().height() / img.height()); - if (isAutoResetTransform()) { mpImgItem->setPos(0, 0); diff --git a/tpvs17/tpMain/lpMainWin.cpp b/tpvs17/tpMain/lpMainWin.cpp index 8be3409..31731a5 100644 --- a/tpvs17/tpMain/lpMainWin.cpp +++ b/tpvs17/tpMain/lpMainWin.cpp @@ -191,13 +191,9 @@ lpMainWin::lpMainWin(QWidget *parent) //当某个模板加入训练或者不加入训练时修改原来工作单中的模板信息 connect(m_pModelMgrDlg, SIGNAL(sgModifyModel(QString)), this, SLOT(modWorkMgr(QString))); connect(m_pModelMgrDlg, SIGNAL(sgUpdatedefect()), this, SLOT(onUpdateDefect())); - /* - void sgAddNewModel(QString strName);//添加模板 - void sgDelOldModel(QString strName);//删除模板 - void sgModeModeName(QString strOld, QString strNew);//修改模板名 - */ - connect(m_pModelMgrDlg, SIGNAL(sgAddNewModel(QString)), this, SLOT(onSlotAddNewModel(QString))); - connect(m_pModelMgrDlg, SIGNAL(sgDelOldModel(QString)), this, SLOT(onSlotDelOldModel(QString))); + + connect(m_pModelMgrDlg, SIGNAL(sgAddNewModel(QString)), this, SLOT(onSlotAddNewModel(QString)));//新建模板型号 + connect(m_pModelMgrDlg, SIGNAL(sgDelOldModel(QString)), this, SLOT(onSlotDelOldModel(QString)));//删除模板型号 @@ -1050,7 +1046,7 @@ Q_SLOT void lpMainWin::onActionClicked() } else if ("action_designer" == strObj) { if (m_pDesigner) { - m_pDesigner->ShowMainFrame(); + m_pDesigner->ShowMainFrame(this); } } }