diff --git a/HX_CameraLoopPlay/CameraLoopPlay.cpp b/HX_CameraLoopPlay/CameraLoopPlay.cpp index 35d83c2..9a68f2e 100644 --- a/HX_CameraLoopPlay/CameraLoopPlay.cpp +++ b/HX_CameraLoopPlay/CameraLoopPlay.cpp @@ -10,6 +10,7 @@ #include #include #include +#include // 相机列表JSON文件名称 const QString CameraJsonFileName = "camera.json"; @@ -24,6 +25,7 @@ CameraLoopPlay::CameraLoopPlay(QWidget* parent) setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); qRegisterMetaType("HWND"); + ui->widget_title->installEventFilter(this); m_cameraLoopThread = new QThread(this); m_cameraThread = new CameraThread(); @@ -63,7 +65,12 @@ CameraLoopPlay::~CameraLoopPlay() bool CameraLoopPlay::eventFilter(QObject* watched, QEvent* event) { - return false; + // 处理鼠标按下、释放和移动事件 + if (watched == ui->widget_title) { + mouseDragDblClickEvent(event); + } + + return QWidget::eventFilter(watched, event); } void CameraLoopPlay::on_pushButton_min_clicked() @@ -156,10 +163,10 @@ void CameraLoopPlay::addCameraWidgetToCameraFarmes(int rows, int cols) signalCameraWidget->label_cameraNumber->hide(); if (m_cameraDeviceInfoList.count() > index) { - signalCameraWidget->widget_camera->setCameraName( m_cameraDeviceInfoList[index].getName()); - signalCameraWidget->widget_camera->setCameraWidgetWidth( signalCameraWidget->widget_camera->width()); + signalCameraWidget->widget_camera->setCameraName(m_cameraDeviceInfoList[index].getName()); + signalCameraWidget->widget_camera->setCameraWidgetWidth(signalCameraWidget->widget_camera->width()); - signalCameraWidget->label_cameraNumber->setText( m_cameraDeviceInfoList[index].getName()); + signalCameraWidget->label_cameraNumber->setText(m_cameraDeviceInfoList[index].getName()); emit realPlaySignal((HWND)signalCameraWidget->label_camera->winId(), index); signalCameraWidget->label_camera->raise(); } @@ -265,10 +272,53 @@ void CameraLoopPlay::stopVideoStreamPlay() return; for (int i = 0; i < m_cameraDeviceInfoList.size(); i++) { int cameraIndex = m_cameraDeviceInfoList.at(i).getTreeindex(); - emit stopReadPlaySignal(cameraIndex-1); + emit stopReadPlaySignal(cameraIndex - 1); } } +bool CameraLoopPlay::mouseDragDblClickEvent(QEvent* event) +{ + QMouseEvent* mouseEvent = static_cast(event); + if (mouseEvent->type() == QEvent::MouseButtonPress) { + if (mouseEvent->button() == Qt::LeftButton) { + m_mousePressed = true; // 启动拖拽 + m_mousePoint = mouseEvent->globalPos() - this->pos(); + + this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | + Qt::WindowMinimizeButtonHint | Qt::Window | + Qt::WindowStaysOnTopHint); + this->showNormal(); // 确保窗口显示 + + return true; + } + } + else if (mouseEvent->type() == QEvent::MouseButtonRelease) { + m_mousePressed = false; + return true; + } + else if (mouseEvent->type() == QEvent::MouseMove) { + if (m_mousePressed && (mouseEvent->buttons() & Qt::LeftButton)) { + this->move(mouseEvent->globalPos() - m_mousePoint); + + // 每次移动时设置为最上方 + this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | + Qt::WindowMinimizeButtonHint | Qt::Window | + Qt::WindowStaysOnTopHint); + this->showNormal(); + return true; + } + } + // 处理鼠标双击事件,切换全屏 + else if (event->type() == QEvent::MouseButtonDblClick) { + if (mouseEvent->button() == Qt::LeftButton) { + this->showFullScreen(); + return true; + } + } + + return false; +} + void CameraLoopPlay::on_pushButton_close_clicked() { diff --git a/HX_CameraLoopPlay/CameraLoopPlay.h b/HX_CameraLoopPlay/CameraLoopPlay.h index 7d02130..66c202d 100644 --- a/HX_CameraLoopPlay/CameraLoopPlay.h +++ b/HX_CameraLoopPlay/CameraLoopPlay.h @@ -29,6 +29,7 @@ public: ~CameraLoopPlay(); protected: + bool eventFilter(QObject* watched, QEvent* event) override; signals: @@ -165,6 +166,11 @@ private: */ void stopVideoStreamPlay(); + /** + * @brief ק¼. + */ + bool mouseDragDblClickEvent(QEvent* event); + private: Ui::CameraLoopPlayClass *ui = nullptr; @@ -211,6 +217,12 @@ private: */ QList m_singleCameraWidgetList; - + /** + * @brief ק. + * @author XuChao (xxu715737@163.com) + * @date 2024-10-24 + */ + QPoint m_mousePoint; + bool m_mousePressed{ false }; }; diff --git a/HX_CameraLoopPlay/CameraLoopPlay.ui b/HX_CameraLoopPlay/CameraLoopPlay.ui index ad9881a..c51d77d 100644 --- a/HX_CameraLoopPlay/CameraLoopPlay.ui +++ b/HX_CameraLoopPlay/CameraLoopPlay.ui @@ -40,7 +40,7 @@ background-color: transparent; } - + 20 @@ -53,11 +53,11 @@ Qt::Horizontal - QSizePolicy::Maximum + QSizePolicy::Expanding - 750 + 40 20 @@ -83,46 +83,66 @@ 玉泉煤业工作面视频监控 - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - color: rgb(255, 255, 255); -background-color: transparent; -font: 16pt "Arial"; - - - - Qt::AlignCenter - - - - 32 - 32 - + + + 15 - - QPushButton{ + + 0 + + + 10 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 250 + 0 + + + + color: rgb(255, 255, 255); +background-color: transparent; +font: 16pt "Arial"; + + + + + + Qt::AlignCenter + + + + + + + + 32 + 32 + + + + QPushButton{ border-image: url(:/CameraLoopPlay/Resource/image/min.png); border:0; } @@ -130,22 +150,22 @@ QPushButton:hover{ border-image: url(:/CameraLoopPlay/Resource/image/min_honver.png); border:0; } - - - - - - - - - - - 32 - 32 - - - - QPushButton{ + + + + + + + + + + + 32 + 32 + + + + QPushButton{ border-image: url(:/CameraLoopPlay/Resource/image/close.png); border:0; } @@ -153,11 +173,13 @@ QPushButton:hover{ border-image: url(:/CameraLoopPlay/Resource/image/close_hover.png); border:0; } - - - - - + + + + + + + diff --git a/HX_CameraLoopPlay/CameraThread.cpp b/HX_CameraLoopPlay/CameraThread.cpp index 8b60595..b0682ca 100644 --- a/HX_CameraLoopPlay/CameraThread.cpp +++ b/HX_CameraLoopPlay/CameraThread.cpp @@ -39,7 +39,7 @@ void CameraThread::login(QString strIP, QString strUser, QString strPwd, int hWn NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {}; struLoginInfo.bUseAsynLogin = false; //ͬ¼ʽ - struLoginInfo.wPort = 8000; //豸˿ + struLoginInfo.wPort = 7889; //豸˿ strcpy_s(struLoginInfo.sDeviceAddress, strIP.toLatin1().data()); //豸ipַ strcpy_s(struLoginInfo.sUserName, strUser.toLatin1().data()); //豸¼û strcpy_s(struLoginInfo.sPassword, strPwd.toLatin1().data()); //豸¼