123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #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<QGraphicsItem*> 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;
- }
- }
|