更新文档

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

View File

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

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB