#include "CameraItem.h" #include "CameraModifyScene.h" #include "IncCamera.h" bool* CameraItem::pCameraItemModified = nullptr; CameraItem::CameraItem(QGraphicsItem* parent) { nItemColIndex = 0; pIntersectInstance = NULL; bActive = false; } CameraItem::CameraItem() { bSelected = false; nItemColIndex = 0; pCurrentFrame = nullptr; bActive = false; } CameraItem::~CameraItem() { m_VideoStreamCatcher.Stop(); } CameraItem::CameraItem(const CameraItem& other) { //set the CurrentPos CurrentPos = other.CurrentPos; //set the CameraItem is unselected bSelected = other.bSelected; //set the CameraItem index nItemColIndex = other.nItemColIndex; //init the intersect rect IntersectRect = QRect(0, 0, 0, 0); //init the overlap bounding m_vvOverlapBounding.clear(); bActive = other.bActive; } bool CameraItem::Init(int nIndex,QPointF Pos) { //set the CurrentPos //CurrentPos = Pos; //set the CameraItem is unselected bSelected = false; //set the CameraItem index nItemColIndex = nIndex; bool bRet = m_VideoStreamCatcher.Init(m_CameraInfo.GetCompleteIpAddress()); if (bRet) { m_vvOverlapBounding.resize(m_VideoStreamCatcher.m_nVideoHeight); for (int i = 0; i < m_VideoStreamCatcher.m_nVideoHeight; i++) { m_vvOverlapBounding[i].resize(2); m_vvOverlapBounding[i][0] = 0; m_vvOverlapBounding[i][1] = m_VideoStreamCatcher.m_nVideoWidth; } } //set the Stream Catcher bActive = bRet; return bRet; } QRectF CameraItem::boundingRect() const { //set a CameraItem rect width is 100, height is 100 return QRectF(CurrentPos,QSize(CAMERAITEM_WIDTH,CAMERAITEM_HEIGHT)); } void CameraItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { QPen pen; pen.setColor(QColor(255, 0, 0, 255)); if (bSelected) { pen.setWidth(15); } else { pen.setWidth(8); } //set a painter to draw the CameraItem painter->setPen(pen); painter->drawRect(CurrentPos.x(), CurrentPos.y(), CAMERAITEM_WIDTH, CAMERAITEM_HEIGHT); } void CameraItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mousePressEvent(event); QPointF Point = event->pos(); if (!boundingRect().contains(Point)) return; if (bActive) { //get the scene pointer QGraphicsScene* pScene = this->scene(); //set the all CameraItem is unselected QList ItemsInScene = pScene->items(); QPoint CurPoint = event->pos().toPoint(); for each (auto iter in ItemsInScene) { QRect testRc = iter->boundingRect().toRect(); if (iter->boundingRect().contains(CurPoint)) ((CameraItem*)iter)->bSelected = true; else ((CameraItem*)iter)->bSelected = false; } //set the Current CameraItem is selected //bSelected = true; scene()->update(); //emit the CameraItemSelected signal emit CameraItemPressed(this); } else { //create a IncCamera IncCamera* pIncCamera = new IncCamera(); //set the IncCamera block the main thread pIncCamera->setWindowModality(Qt::ApplicationModal); //Show IncCamera pIncCamera->show(); //block the main thread until the IncCamera close while (pIncCamera->isVisible()) { QCoreApplication::processEvents(); } //if the IncCamera is closed by push the cancel button break the function if (pIncCamera->GetIsOKBtnClicked() != true) { return; } //wait the IncCamera close,get the information from the IncCamera,and push the information to the CameraInfoList //m_CameraItemList.push_back(pIncCamera->GetCameraInfo()); m_CameraInfo = pIncCamera->GetCameraInfo(); //init the CameraItem if (!Init(nItemColIndex, QPointF(0, 0))) { //if the CameraItem init failed,delete the CameraItem and return QString Title = "错误"; QString Text = "当前输入的链接无法初始化解码器"; QMessageBox box; box.setWindowTitle(Title); box.setText(Text); box.addButton(QMessageBox::Cancel); box.show(); return; } bSelected = true; //reset the pano buffer //ResetPanoImageBuffer(); *pCameraItemModified = true; //emit the signal to the CameraItem bas been selected emit ((CameraModifyScene*)scene())->CameraItemSelected(this); //open the thread catch stream m_VideoStreamCatcher.Start(); delete pIncCamera; // bActive = true; } }