From 0ff1e80132fd5c2c6cb217948b73bf5351669a6a Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Thu, 3 Oct 2019 11:00:28 +0800 Subject: [PATCH] add useless animation --- mainwindow.cpp | 28 ++++++++++++++++++++++++++++ mainwindow.h | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index 4a030a5..281a4c0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -73,6 +74,13 @@ MainWindow::MainWindow(QWidget *parent) : m_graphicsView->checkAndDoFitInView(); }); + m_opacityEffect = new QGraphicsOpacityEffect(m_bottomButtonGroup); + m_bottomButtonGroup->setGraphicsEffect(m_opacityEffect); + m_btnGrpAnimation = new QPropertyAnimation(m_opacityEffect, "opacity"); + m_btnGrpAnimation->setDuration(300); + + m_opacityEffect->setOpacity(0); + centerWindow(); } @@ -115,6 +123,26 @@ void MainWindow::showEvent(QShowEvent *event) return QMainWindow::showEvent(event); } +void MainWindow::enterEvent(QEvent *event) +{ + m_btnGrpAnimation->stop(); + m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity()); + m_btnGrpAnimation->setEndValue(1); + m_btnGrpAnimation->start(); + + return QMainWindow::enterEvent(event); +} + +void MainWindow::leaveEvent(QEvent *event) +{ + m_btnGrpAnimation->stop(); + m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity()); + m_btnGrpAnimation->setEndValue(0); + m_btnGrpAnimation->start(); + + return QMainWindow::leaveEvent(event); +} + void MainWindow::mousePressEvent(QMouseEvent *event) { if (event->buttons() & Qt::LeftButton) { diff --git a/mainwindow.h b/mainwindow.h index a90fd63..7d3c8e9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -6,6 +6,10 @@ #include #include +QT_BEGIN_NAMESPACE +class QGraphicsOpacityEffect; +QT_END_NAMESPACE + class GraphicsView; class BottomButtonGroup; class MainWindow : public QMainWindow @@ -21,6 +25,8 @@ public: protected slots: void showEvent(QShowEvent *event) override; + void enterEvent(QEvent *event) override; + void leaveEvent(QEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; @@ -35,6 +41,8 @@ protected slots: private: QPoint m_oldMousePos; + QGraphicsOpacityEffect *m_opacityEffect; + QPropertyAnimation *m_btnGrpAnimation; QPropertyAnimation *m_fadeOutAnimation; QPropertyAnimation *m_floatUpAnimation; QParallelAnimationGroup *m_exitAnimationGroup;