feat:鼠标拖拽事件
This commit is contained in:
parent
709b20ef53
commit
646637e209
|
@ -10,6 +10,7 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
// 相机列表JSON文件名称
|
// 相机列表JSON文件名称
|
||||||
const QString CameraJsonFileName = "camera.json";
|
const QString CameraJsonFileName = "camera.json";
|
||||||
|
@ -24,6 +25,7 @@ CameraLoopPlay::CameraLoopPlay(QWidget* parent)
|
||||||
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
|
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
|
||||||
|
|
||||||
qRegisterMetaType<HWND>("HWND");
|
qRegisterMetaType<HWND>("HWND");
|
||||||
|
ui->widget_title->installEventFilter(this);
|
||||||
|
|
||||||
m_cameraLoopThread = new QThread(this);
|
m_cameraLoopThread = new QThread(this);
|
||||||
m_cameraThread = new CameraThread();
|
m_cameraThread = new CameraThread();
|
||||||
|
@ -63,7 +65,12 @@ CameraLoopPlay::~CameraLoopPlay()
|
||||||
|
|
||||||
bool CameraLoopPlay::eventFilter(QObject* watched, QEvent* event)
|
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()
|
void CameraLoopPlay::on_pushButton_min_clicked()
|
||||||
|
@ -156,10 +163,10 @@ void CameraLoopPlay::addCameraWidgetToCameraFarmes(int rows, int cols)
|
||||||
signalCameraWidget->label_cameraNumber->hide();
|
signalCameraWidget->label_cameraNumber->hide();
|
||||||
|
|
||||||
if (m_cameraDeviceInfoList.count() > index) {
|
if (m_cameraDeviceInfoList.count() > index) {
|
||||||
signalCameraWidget->widget_camera->setCameraName( m_cameraDeviceInfoList[index].getName());
|
signalCameraWidget->widget_camera->setCameraName(m_cameraDeviceInfoList[index].getName());
|
||||||
signalCameraWidget->widget_camera->setCameraWidgetWidth( signalCameraWidget->widget_camera->width());
|
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);
|
emit realPlaySignal((HWND)signalCameraWidget->label_camera->winId(), index);
|
||||||
signalCameraWidget->label_camera->raise();
|
signalCameraWidget->label_camera->raise();
|
||||||
}
|
}
|
||||||
|
@ -265,10 +272,53 @@ void CameraLoopPlay::stopVideoStreamPlay()
|
||||||
return;
|
return;
|
||||||
for (int i = 0; i < m_cameraDeviceInfoList.size(); i++) {
|
for (int i = 0; i < m_cameraDeviceInfoList.size(); i++) {
|
||||||
int cameraIndex = m_cameraDeviceInfoList.at(i).getTreeindex();
|
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()
|
void CameraLoopPlay::on_pushButton_close_clicked()
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
~CameraLoopPlay();
|
~CameraLoopPlay();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool eventFilter(QObject* watched, QEvent* event) override;
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -165,6 +166,11 @@ private:
|
||||||
*/
|
*/
|
||||||
void stopVideoStreamPlay();
|
void stopVideoStreamPlay();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 鼠标拖拽事件.
|
||||||
|
*/
|
||||||
|
bool mouseDragDblClickEvent(QEvent* event);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CameraLoopPlayClass *ui = nullptr;
|
Ui::CameraLoopPlayClass *ui = nullptr;
|
||||||
|
@ -211,6 +217,12 @@ private:
|
||||||
*/
|
*/
|
||||||
QList<Ui::SingleCameraWidget*> m_singleCameraWidgetList;
|
QList<Ui::SingleCameraWidget*> m_singleCameraWidgetList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 窗口拖拽.
|
||||||
|
* @author XuChao (xxu715737@163.com)
|
||||||
|
* @date 2024-10-24
|
||||||
|
*/
|
||||||
|
QPoint m_mousePoint;
|
||||||
|
bool m_mousePressed{ false };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="1,1,1">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>20</number>
|
<number>20</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -53,11 +53,11 @@
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeType">
|
<property name="sizeType">
|
||||||
<enum>QSizePolicy::Maximum</enum>
|
<enum>QSizePolicy::Expanding</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>750</width>
|
<width>40</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
@ -83,8 +83,22 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>玉泉煤业工作面视频监控</string>
|
<string>玉泉煤业工作面视频监控</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>15</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_2">
|
<spacer name="horizontalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -100,6 +114,12 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_clander">
|
<widget class="QLabel" name="label_clander">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>250</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">color: rgb(255, 255, 255);
|
<string notr="true">color: rgb(255, 255, 255);
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
@ -160,6 +180,8 @@ QPushButton:hover{
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -39,7 +39,7 @@ void CameraThread::login(QString strIP, QString strUser, QString strPwd, int hWn
|
||||||
NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {};
|
NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {};
|
||||||
|
|
||||||
struLoginInfo.bUseAsynLogin = false; //同步登录方式
|
struLoginInfo.bUseAsynLogin = false; //同步登录方式
|
||||||
struLoginInfo.wPort = 8000; //设备服务端口
|
struLoginInfo.wPort = 7889; //设备服务端口
|
||||||
strcpy_s(struLoginInfo.sDeviceAddress, strIP.toLatin1().data()); //设备ip地址
|
strcpy_s(struLoginInfo.sDeviceAddress, strIP.toLatin1().data()); //设备ip地址
|
||||||
strcpy_s(struLoginInfo.sUserName, strUser.toLatin1().data()); //设备登录用户名
|
strcpy_s(struLoginInfo.sUserName, strUser.toLatin1().data()); //设备登录用户名
|
||||||
strcpy_s(struLoginInfo.sPassword, strPwd.toLatin1().data()); //设备登录密码
|
strcpy_s(struLoginInfo.sPassword, strPwd.toLatin1().data()); //设备登录密码
|
||||||
|
|
Loading…
Reference in New Issue