feat:鼠标拖拽事件

This commit is contained in:
“Diviner66”, 2024-10-24 21:46:49 +08:00
parent 709b20ef53
commit 646637e209
4 changed files with 148 additions and 64 deletions

View File

@ -10,6 +10,7 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QMouseEvent>
// 相机列表JSON文件名称
const QString CameraJsonFileName = "camera.json";
@ -24,6 +25,7 @@ CameraLoopPlay::CameraLoopPlay(QWidget* parent)
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
qRegisterMetaType<HWND>("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<QMouseEvent*>(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()
{

View File

@ -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<Ui::SingleCameraWidget*> m_singleCameraWidgetList;
/**
* @brief .
* @author XuChao (xxu715737@163.com)
* @date 2024-10-24
*/
QPoint m_mousePoint;
bool m_mousePressed{ false };
};

View File

@ -40,7 +40,7 @@
background-color: transparent;
}</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="1,1,1">
<property name="spacing">
<number>20</number>
</property>
@ -53,11 +53,11 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>750</width>
<width>40</width>
<height>20</height>
</size>
</property>
@ -83,46 +83,66 @@
<property name="text">
<string>玉泉煤业工作面视频监控</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_clander">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: transparent;
font: 16pt &quot;Arial&quot;;</string>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_min">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>15</number>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_clander">
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: transparent;
font: 16pt &quot;Arial&quot;;</string>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_min">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">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;
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_close">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_close">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">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;
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>

View File

@ -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()); //设备登录密码