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,46 +83,66 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>玉泉煤业工作面视频监控</string>
|
<string>玉泉煤业工作面视频监控</string>
|
||||||
</property>
|
</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 "Arial";</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_min">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<property name="minimumSize">
|
<property name="spacing">
|
||||||
<size>
|
<number>15</number>
|
||||||
<width>32</width>
|
|
||||||
<height>32</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="leftMargin">
|
||||||
<string notr="true">QPushButton{
|
<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 "Arial";</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-image: url(:/CameraLoopPlay/Resource/image/min.png);
|
||||||
border:0;
|
border:0;
|
||||||
}
|
}
|
||||||
|
@ -130,22 +150,22 @@ QPushButton:hover{
|
||||||
border-image: url(:/CameraLoopPlay/Resource/image/min_honver.png);
|
border-image: url(:/CameraLoopPlay/Resource/image/min_honver.png);
|
||||||
border:0;
|
border:0;
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_close">
|
<widget class="QPushButton" name="pushButton_close">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>32</width>
|
<width>32</width>
|
||||||
<height>32</height>
|
<height>32</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">QPushButton{
|
<string notr="true">QPushButton{
|
||||||
border-image: url(:/CameraLoopPlay/Resource/image/close.png);
|
border-image: url(:/CameraLoopPlay/Resource/image/close.png);
|
||||||
border:0;
|
border:0;
|
||||||
}
|
}
|
||||||
|
@ -153,11 +173,13 @@ QPushButton:hover{
|
||||||
border-image: url(:/CameraLoopPlay/Resource/image/close_hover.png);
|
border-image: url(:/CameraLoopPlay/Resource/image/close_hover.png);
|
||||||
border:0;
|
border:0;
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -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