Browse Source

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.
pull/1552/merge
Stefan Merettig 10 years ago committed by tux3
parent
commit
0a68cff60c
  1. 7
      src/widget/form/genericchatform.cpp
  2. 35
      src/widget/tool/flyoutoverlaywidget.cpp
  3. 3
      src/widget/tool/flyoutoverlaywidget.h

7
src/widget/form/genericchatform.cpp

@ -194,18 +194,18 @@ GenericChatForm::GenericChatForm(QWidget *parent) @@ -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) @@ -431,6 +431,7 @@ bool GenericChatForm::eventFilter(QObject* object, QEvent* event)
if (!fileRect.contains(pos))
hideFileMenu();
} break;
case QEvent::MouseButtonPress:

35
src/widget/tool/flyoutoverlaywidget.cpp

@ -74,18 +74,33 @@ bool FlyoutOverlayWidget::isShown() const @@ -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() @@ -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);
}

3
src/widget/tool/flyoutoverlaywidget.h

@ -36,6 +36,8 @@ public: @@ -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: @@ -47,6 +49,7 @@ signals:
private:
void finishedAnimation();
void startAnimation(bool forward);
QWidget *container;
QPropertyAnimation *animation;

Loading…
Cancel
Save