Skip to content

Commit

Permalink
Update anim widget to stop skipping around
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Jul 10, 2024
1 parent b997c97 commit 5a00cf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/mvc/AnnimateSlideWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AnnimateSlideWidget::AnnimateSlideWidget(QWidget *parent) : QWidget(parent)
_anim_widget = nullptr;
_anim_enabled = true;
_first = true;
_running = false;
}

//---------------------------------------------------------------------------
Expand All @@ -23,9 +24,11 @@ void AnnimateSlideWidget::setAnimWidget(QWidget* w, QWidget* container_widget)
_anim_widget = w;
_anim_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_anim_hide = new QPropertyAnimation(_anim_widget, "minimumWidth");
connect(_anim_hide, &QPropertyAnimation::finished, this, &AnnimateSlideWidget::onFinished);
_anim_hide->setDuration(100);

_anim_show = new QPropertyAnimation(_anim_widget, "minimumWidth");
connect(_anim_show, &QPropertyAnimation::finished, this, &AnnimateSlideWidget::onFinished);
_anim_show->setDuration(100);
}

Expand Down
12 changes: 10 additions & 2 deletions src/mvc/AnnimateSlideWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ class AnnimateSlideWidget : public QWidget

virtual void enterEvent(QEnterEvent *event) override
{
if(_anim_enabled)
if(_anim_enabled && false == _running)
{
_running = true;
animateSlideOut();
}
}

virtual void leaveEvent(QEvent *event) override
{
if(_anim_enabled)
if(_anim_enabled && false == _running)
{
_running = true;
animateSlideIn();
}
}
Expand Down Expand Up @@ -71,12 +73,18 @@ private slots:
_anim_show->start();
}

void onFinished()
{
_running = false;
}

private:
QWidget* _anim_widget;
QPropertyAnimation *_anim_hide;
QPropertyAnimation *_anim_show;
bool _anim_enabled;
bool _first;
bool _running;
int _saved_width;
};

Expand Down

0 comments on commit 5a00cf5

Please sign in to comment.