更新代码
parent
936387b210
commit
be766a304f
|
@ -13,6 +13,9 @@ DeviceButton::DeviceButton(QWidget *parent) : QWidget(parent)
|
||||||
buttonStyle = ButtonStyle_Police;
|
buttonStyle = ButtonStyle_Police;
|
||||||
buttonColor = ButtonColor_Green;
|
buttonColor = ButtonColor_Green;
|
||||||
|
|
||||||
|
isPressed = false;
|
||||||
|
lastPoint = QPoint();
|
||||||
|
|
||||||
type = "police";
|
type = "police";
|
||||||
imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type);
|
imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type);
|
||||||
isDark = false;
|
isDark = false;
|
||||||
|
@ -79,29 +82,26 @@ void DeviceButton::paintEvent(QPaintEvent *)
|
||||||
|
|
||||||
bool DeviceButton::eventFilter(QObject *watched, QEvent *event)
|
bool DeviceButton::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (canMove) {
|
//识别鼠标 按下+移动+松开+双击 等事件
|
||||||
static QPoint lastPoint;
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||||
static bool isPressed = false;
|
|
||||||
|
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
QMouseEvent *e = static_cast<QMouseEvent *>(event);
|
//限定鼠标左键
|
||||||
if (this->rect().contains(e->pos()) && (e->button() == Qt::LeftButton)) {
|
if (mouseEvent->button() == Qt::LeftButton) {
|
||||||
lastPoint = e->pos();
|
lastPoint = mouseEvent->pos();
|
||||||
isPressed = true;
|
isPressed = true;
|
||||||
|
emit clicked();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else if (event->type() == QEvent::MouseMove && isPressed) {
|
} else if (event->type() == QEvent::MouseMove) {
|
||||||
QMouseEvent *e = static_cast<QMouseEvent *>(event);
|
//允许拖动并且鼠标按下准备拖动
|
||||||
int dx = e->pos().x() - lastPoint.x();
|
if (canMove && isPressed) {
|
||||||
int dy = e->pos().y() - lastPoint.y();
|
int dx = mouseEvent->pos().x() - lastPoint.x();
|
||||||
|
int dy = mouseEvent->pos().y() - lastPoint.y();
|
||||||
this->move(this->x() + dx, this->y() + dy);
|
this->move(this->x() + dx, this->y() + dy);
|
||||||
return true;
|
return true;
|
||||||
} else if (event->type() == QEvent::MouseButtonRelease && isPressed) {
|
}
|
||||||
|
} else if (event->type() == QEvent::MouseButtonRelease) {
|
||||||
isPressed = false;
|
isPressed = false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
|
||||||
emit clicked();
|
|
||||||
} else if (event->type() == QEvent::MouseButtonDblClick) {
|
} else if (event->type() == QEvent::MouseButtonDblClick) {
|
||||||
emit doubleClicked();
|
emit doubleClicked();
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,9 @@ private:
|
||||||
ButtonStyle buttonStyle; //按钮样式
|
ButtonStyle buttonStyle; //按钮样式
|
||||||
ButtonColor buttonColor; //按钮颜色
|
ButtonColor buttonColor; //按钮颜色
|
||||||
|
|
||||||
|
bool isPressed; //鼠标是否按下
|
||||||
|
QPoint lastPoint; //鼠标按下最后坐标
|
||||||
|
|
||||||
QString type; //图片末尾类型
|
QString type; //图片末尾类型
|
||||||
QString imgName; //背景图片名称
|
QString imgName; //背景图片名称
|
||||||
bool isDark; //是否加深报警
|
bool isDark; //是否加深报警
|
||||||
|
@ -94,6 +97,7 @@ public Q_SLOTS:
|
||||||
void setButtonColor(const ButtonColor &buttonColor);
|
void setButtonColor(const ButtonColor &buttonColor);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
//鼠标单击双击事件
|
||||||
void clicked();
|
void clicked();
|
||||||
void doubleClicked();
|
void doubleClicked();
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,13 +8,13 @@ TcpClient1::TcpClient1(QObject *parent) : QTcpSocket(parent)
|
||||||
port = 6907;
|
port = 6907;
|
||||||
deviceID = "SSJC00000001";
|
deviceID = "SSJC00000001";
|
||||||
|
|
||||||
|
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
|
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||||
#else
|
#else
|
||||||
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||||
#endif
|
#endif
|
||||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
|
||||||
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpClient1::setIP(const QString &ip)
|
void TcpClient1::setIP(const QString &ip)
|
||||||
|
|
|
@ -8,13 +8,13 @@ TcpClient2::TcpClient2(QObject *parent) : QTcpSocket(parent)
|
||||||
port = 6908;
|
port = 6908;
|
||||||
deviceID = "SSJC00000001";
|
deviceID = "SSJC00000001";
|
||||||
|
|
||||||
|
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
|
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||||
#else
|
#else
|
||||||
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||||
#endif
|
#endif
|
||||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
|
||||||
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpClient2::setIP(const QString &ip)
|
void TcpClient2::setIP(const QString &ip)
|
||||||
|
|
|
@ -10,12 +10,12 @@ TcpClient::TcpClient(QTcpSocket *socket, QObject *parent) : QObject(parent)
|
||||||
port = socket->peerPort();
|
port = socket->peerPort();
|
||||||
|
|
||||||
connect(socket, SIGNAL(disconnected()), this, SLOT(slot_disconnected()));
|
connect(socket, SIGNAL(disconnected()), this, SLOT(slot_disconnected()));
|
||||||
|
connect(socket, SIGNAL(readyRead()), this, SLOT(slot_readData()));
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(slot_error()));
|
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(slot_error()));
|
||||||
#else
|
#else
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_error()));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_error()));
|
||||||
#endif
|
#endif
|
||||||
connect(socket, SIGNAL(readyRead()), this, SLOT(slot_readData()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TcpClient::getIP() const
|
QString TcpClient::getIP() const
|
||||||
|
|
|
@ -40,12 +40,12 @@ void frmTcpClient::initForm()
|
||||||
socket = new QTcpSocket(this);
|
socket = new QTcpSocket(this);
|
||||||
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||||
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
||||||
|
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
|
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
|
||||||
#else
|
#else
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
|
||||||
#endif
|
#endif
|
||||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
|
||||||
|
|
||||||
//定时器发送数据
|
//定时器发送数据
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
|
|
|
@ -36,12 +36,12 @@ void frmUdpClient::initForm()
|
||||||
|
|
||||||
//实例化对象并绑定信号槽
|
//实例化对象并绑定信号槽
|
||||||
socket = new QUdpSocket(this);
|
socket = new QUdpSocket(this);
|
||||||
|
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
|
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
|
||||||
#else
|
#else
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
|
||||||
#endif
|
#endif
|
||||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
|
||||||
|
|
||||||
//定时器发送数据
|
//定时器发送数据
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
|
|
|
@ -37,12 +37,12 @@ void frmUdpServer::initForm()
|
||||||
|
|
||||||
//实例化对象并绑定信号槽
|
//实例化对象并绑定信号槽
|
||||||
socket = new QUdpSocket(this);
|
socket = new QUdpSocket(this);
|
||||||
|
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
|
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
|
||||||
#else
|
#else
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
|
||||||
#endif
|
#endif
|
||||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
|
||||||
|
|
||||||
//定时器发送数据
|
//定时器发送数据
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
|
|
Loading…
Reference in New Issue