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()
{
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:

View File

@ -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);
}

View File

@ -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;