aboutsummaryrefslogtreecommitdiff
path: root/installer/fadestackedwidget.cpp
diff options
context:
space:
mode:
authorVictor Tran <vicr12345@gmail.com>2018-07-12 18:12:14 +1000
committerVictor Tran <vicr12345@gmail.com>2018-07-12 18:12:14 +1000
commit2adcd4f24eca2fa529c42fc1165319bcc4ea179e (patch)
tree1c1c8292e9e864640b19c7ff1ae4acaeb90244be /installer/fadestackedwidget.cpp
downloadtheInstaller-2adcd4f24eca2fa529c42fc1165319bcc4ea179e.tar.gz
theInstaller-2adcd4f24eca2fa529c42fc1165319bcc4ea179e.tar.bz2
theInstaller-2adcd4f24eca2fa529c42fc1165319bcc4ea179e.zip
Initial commit
Diffstat (limited to 'installer/fadestackedwidget.cpp')
-rw-r--r--installer/fadestackedwidget.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/installer/fadestackedwidget.cpp b/installer/fadestackedwidget.cpp
new file mode 100644
index 0000000..e925c99
--- /dev/null
+++ b/installer/fadestackedwidget.cpp
@@ -0,0 +1,57 @@
+#include "fadestackedwidget.h"
+
+FadeStackedWidget::FadeStackedWidget(QWidget *parent) : QStackedWidget(parent)
+{
+
+}
+
+void FadeStackedWidget::setCurrentIndex(int index) {
+ //Do some checks before setting the current index.
+ if (currentIndex() != index) {
+ doSetCurrentIndex(index);
+ }
+}
+
+void FadeStackedWidget::doSetCurrentIndex(int index) {
+ QWidget* currentWidget = widget(currentIndex());
+ QWidget* nextWidget = widget(index);
+ if (nextWidget == nullptr) {
+ QStackedWidget::setCurrentIndex(index);
+ } else {
+ if (doingNewAnimation) {
+ anim->stop();
+ anim->deleteLater();
+ }
+
+ doingNewAnimation = true;
+ QGraphicsOpacityEffect* currentOpacity = new QGraphicsOpacityEffect();
+ QGraphicsOpacityEffect* nextOpacity = new QGraphicsOpacityEffect();
+ currentWidget->setGraphicsEffect(currentOpacity);
+ nextWidget->setGraphicsEffect(nextOpacity);
+
+ anim = new QVariantAnimation();
+ anim->setStartValue((float) 1);
+ anim->setEndValue((float) 0);
+ anim->setDuration(500);
+ anim->setEasingCurve(QEasingCurve::InCubic);
+ connect(anim, &QVariantAnimation::finished, [=] {
+ if (anim->direction() == QVariantAnimation::Forward) {
+ anim->setDirection(QVariantAnimation::Backward);
+ QStackedWidget::setCurrentIndex(index);
+ anim->start();
+ } else {
+ doingNewAnimation = false;
+ anim->deleteLater();
+ anim = nullptr;
+ }
+ });
+ connect(anim, &QVariantAnimation::valueChanged, [=](QVariant value) {
+ if (anim->direction() == QVariantAnimation::Forward) {
+ currentOpacity->setOpacity(value.toFloat());
+ } else {
+ nextOpacity->setOpacity(value.toFloat());
+ }
+ });
+ anim->start();
+ }
+}