1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Screen grabber: Hide mid-animation when leaving file button

The flyout is now more responsive and will start collapsing while it's
expanding, when the user leaves the attach file button mid-animation.
This commit is contained in:
Stefan Merettig 2015-04-02 16:56:16 +02:00 committed by tux3
parent f0d524e960
commit 0a68cff60c
3 changed files with 36 additions and 9 deletions

View File

@ -194,18 +194,18 @@ GenericChatForm::GenericChatForm(QWidget *parent)
void GenericChatForm::showFileMenu() void GenericChatForm::showFileMenu()
{ {
if (!fileFlyout->isShown()) { if (!fileFlyout->isShown() && !fileFlyout->isBeingShown()) {
QPoint pos = fileButton->pos(); QPoint pos = fileButton->pos();
QSize size = fileFlyout->size(); QSize size = fileFlyout->size();
fileFlyout->move(pos.x() - size.width(), pos.y()); fileFlyout->move(pos.x() - size.width(), pos.y());
fileFlyout->animateShow();
} }
fileFlyout->animateShow();
} }
void GenericChatForm::hideFileMenu() void GenericChatForm::hideFileMenu()
{ {
if(fileFlyout->isShown()) if(fileFlyout->isShown() || fileFlyout->isBeingShown())
fileFlyout->animateHide(); fileFlyout->animateHide();
} }
@ -431,6 +431,7 @@ bool GenericChatForm::eventFilter(QObject* object, QEvent* event)
if (!fileRect.contains(pos)) if (!fileRect.contains(pos))
hideFileMenu(); hideFileMenu();
} break; } break;
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:

View File

@ -74,18 +74,33 @@ bool FlyoutOverlayWidget::isShown() const
return (percent == 1); 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() void FlyoutOverlayWidget::animateShow()
{ {
if (percent == 1.0f)
return;
if (animation->state() != QAbstractAnimation::Running)
this->startPos = pos(); this->startPos = pos();
animation->setDirection(QAbstractAnimation::Forward);
animation->start(); startAnimation(true);
} }
void FlyoutOverlayWidget::animateHide() void FlyoutOverlayWidget::animateHide()
{ {
if (animation->state() != QAbstractAnimation::Running)
this->startPos = pos(); this->startPos = pos();
animation->setDirection(QAbstractAnimation::Backward);
animation->start(); startAnimation(false);
} }
void FlyoutOverlayWidget::finishedAnimation() void FlyoutOverlayWidget::finishedAnimation()
@ -98,3 +113,11 @@ void FlyoutOverlayWidget::finishedAnimation()
QTimer::singleShot(50, this, &FlyoutOverlayWidget::hidden); 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);
}

View File

@ -36,6 +36,8 @@ public:
void setFlyoutPercent(qreal progress); void setFlyoutPercent(qreal progress);
bool isShown() const; bool isShown() const;
bool isBeingAnimated() const;
bool isBeingShown() const;
void animateShow(); void animateShow();
void animateHide(); void animateHide();
@ -47,6 +49,7 @@ signals:
private: private:
void finishedAnimation(); void finishedAnimation();
void startAnimation(bool forward);
QWidget *container; QWidget *container;
QPropertyAnimation *animation; QPropertyAnimation *animation;