feat:鼠标拖拽事件
This commit is contained in:
parent
709b20ef53
commit
646637e209
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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 };
|
||||
|
||||
};
|
||||
|
|
|
@ -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,8 +83,22 @@
|
|||
<property name="text">
|
||||
<string>玉泉煤业工作面视频监控</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
|
@ -100,6 +114,12 @@
|
|||
</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;
|
||||
|
@ -160,6 +180,8 @@ QPushButton:hover{
|
|||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -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()); //设备登录密码
|
||||
|
|
Loading…
Reference in New Issue