更新文档

This commit is contained in:
feiyangqingyun
2023-05-09 21:05:34 +08:00
parent 5f9a397611
commit 65ab62cc57
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;
static bool pressed = false;
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->type() == QEvent::MouseButtonPress) { if (mouseEvent->type() == QEvent::MouseButtonPress) {
if (this->rect().contains(mouseEvent->pos()) && (mouseEvent->button() == Qt::LeftButton)) { if (this->rect().contains(mouseEvent->pos()) && (mouseEvent->button() == Qt::LeftButton)) {
lastPoint = mouseEvent->pos(); lastPoint = mouseEvent->pos();
pressed = true; pressed = true;
} }
} else if (mouseEvent->type() == QEvent::MouseMove && pressed) { } else if (mouseEvent->type() == QEvent::MouseMove && pressed) {
if (canMove) {
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) { } else if (mouseEvent->type() == QEvent::MouseButtonRelease && pressed) {
pressed = false; 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