更新文档

master
feiyangqingyun 2023-05-09 21:04:57 +08:00
parent 9aa750272a
commit 04f586ebb9
4 changed files with 22 additions and 16 deletions

View File

@ -27,6 +27,7 @@ LightButton::LightButton(QWidget *parent) : QWidget(parent)
overlayColor = QColor(255, 255, 255); overlayColor = QColor(255, 255, 255);
canMove = false; canMove = false;
pressed = false;
this->installEventFilter(this); this->installEventFilter(this);
isAlarm = false; isAlarm = false;
@ -37,23 +38,21 @@ LightButton::LightButton(QWidget *parent) : QWidget(parent)
bool LightButton::eventFilter(QObject *watched, QEvent *event) bool LightButton::eventFilter(QObject *watched, QEvent *event)
{ {
if (canMove) { QMouseEvent *mouseEvent = (QMouseEvent *)event;
static QPoint lastPoint; if (mouseEvent->type() == QEvent::MouseButtonPress) {
static bool pressed = false; if (this->rect().contains(mouseEvent->pos()) && (mouseEvent->button() == Qt::LeftButton)) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); lastPoint = mouseEvent->pos();
pressed = true;
if (mouseEvent->type() == QEvent::MouseButtonPress) { }
if (this->rect().contains(mouseEvent->pos()) && (mouseEvent->button() == Qt::LeftButton)) { } else if (mouseEvent->type() == QEvent::MouseMove && pressed) {
lastPoint = mouseEvent->pos(); if (canMove) {
pressed = true;
}
} else if (mouseEvent->type() == QEvent::MouseMove && pressed) {
int dx = mouseEvent->pos().x() - lastPoint.x(); int dx = mouseEvent->pos().x() - lastPoint.x();
int dy = mouseEvent->pos().y() - lastPoint.y(); int dy = mouseEvent->pos().y() - lastPoint.y();
this->move(this->x() + dx, this->y() + dy); this->move(this->x() + dx, this->y() + dy);
} else if (mouseEvent->type() == QEvent::MouseButtonRelease && pressed) {
pressed = false;
} }
} else if (mouseEvent->type() == QEvent::MouseButtonRelease && pressed) {
pressed = false;
emit clicked();
} }
return QWidget::eventFilter(watched, event); return QWidget::eventFilter(watched, event);

View File

@ -71,6 +71,9 @@ private:
bool showOverlay; //是否显示遮罩层 bool showOverlay; //是否显示遮罩层
QColor overlayColor; //遮罩层颜色 QColor overlayColor; //遮罩层颜色
bool pressed; //鼠标是否按下
QPoint lastPoint; //鼠标最后按下坐标
bool isAlarm; //是否报警 bool isAlarm; //是否报警
QTimer *timerAlarm; //定时器切换颜色 QTimer *timerAlarm; //定时器切换颜色
@ -147,6 +150,10 @@ public Q_SLOTS:
void startAlarm(); void startAlarm();
void stopAlarm(); void stopAlarm();
void alarm(); void alarm();
Q_SIGNALS:
//单击信号
void clicked();
}; };
#endif // LIGHTBUTTON_H #endif // LIGHTBUTTON_H

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB