diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index e5dad9c40..c7adcf338 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -194,18 +194,18 @@ GenericChatForm::GenericChatForm(QWidget *parent) void GenericChatForm::showFileMenu() { - if (!fileFlyout->isShown()) { + if (!fileFlyout->isShown() && !fileFlyout->isBeingShown()) { QPoint pos = fileButton->pos(); QSize size = fileFlyout->size(); fileFlyout->move(pos.x() - size.width(), pos.y()); - fileFlyout->animateShow(); } + fileFlyout->animateShow(); } void GenericChatForm::hideFileMenu() { - if(fileFlyout->isShown()) + if(fileFlyout->isShown() || fileFlyout->isBeingShown()) fileFlyout->animateHide(); } @@ -431,6 +431,7 @@ bool GenericChatForm::eventFilter(QObject* object, QEvent* event) if (!fileRect.contains(pos)) hideFileMenu(); + } break; case QEvent::MouseButtonPress: diff --git a/src/widget/tool/flyoutoverlaywidget.cpp b/src/widget/tool/flyoutoverlaywidget.cpp index c97e82afc..af0951a57 100644 --- a/src/widget/tool/flyoutoverlaywidget.cpp +++ b/src/widget/tool/flyoutoverlaywidget.cpp @@ -74,18 +74,33 @@ bool FlyoutOverlayWidget::isShown() const return (percent == 1); } +bool FlyoutOverlayWidget::isBeingAnimated() const +{ + return (animation->state() == QAbstractAnimation::Running); +} + +bool FlyoutOverlayWidget::isBeingShown() const +{ + return (isBeingAnimated() && animation->direction() == QAbstractAnimation::Forward); +} + void FlyoutOverlayWidget::animateShow() { - this->startPos = pos(); - animation->setDirection(QAbstractAnimation::Forward); - animation->start(); + if (percent == 1.0f) + return; + + if (animation->state() != QAbstractAnimation::Running) + this->startPos = pos(); + + startAnimation(true); } void FlyoutOverlayWidget::animateHide() { - this->startPos = pos(); - animation->setDirection(QAbstractAnimation::Backward); - animation->start(); + if (animation->state() != QAbstractAnimation::Running) + this->startPos = pos(); + + startAnimation(false); } void FlyoutOverlayWidget::finishedAnimation() @@ -98,3 +113,11 @@ void FlyoutOverlayWidget::finishedAnimation() QTimer::singleShot(50, this, &FlyoutOverlayWidget::hidden); } + +void FlyoutOverlayWidget::startAnimation(bool forward) +{ + animation->setDirection(forward ? QAbstractAnimation::Forward : QAbstractAnimation::Backward); + animation->start(); + animation->setCurrentTime(animation->duration() * percent); + +} diff --git a/src/widget/tool/flyoutoverlaywidget.h b/src/widget/tool/flyoutoverlaywidget.h index a712dcd06..9b4be531c 100644 --- a/src/widget/tool/flyoutoverlaywidget.h +++ b/src/widget/tool/flyoutoverlaywidget.h @@ -36,6 +36,8 @@ public: void setFlyoutPercent(qreal progress); bool isShown() const; + bool isBeingAnimated() const; + bool isBeingShown() const; void animateShow(); void animateHide(); @@ -47,6 +49,7 @@ signals: private: void finishedAnimation(); + void startAnimation(bool forward); QWidget *container; QPropertyAnimation *animation;