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