aboutsummaryrefslogtreecommitdiffstats
path: root/profile-widget/animationfunctions.cpp
blob: 0b84fbcd55cdeb7b567ac9f8678d88375857845b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: GPL-2.0
#include "profile-widget/animationfunctions.h"
#include "core/pref.h"
#include "core/settings/qPrefAnimations.h"
#include <QPropertyAnimation>

namespace Animations {

	void hide(QObject *obj)
	{
		if (qPrefAnimations::animation_speed() != 0) {
			QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
			animation->setStartValue(1);
			animation->setEndValue(0);
			animation->start(QAbstractAnimation::DeleteWhenStopped);
		} else {
			obj->setProperty("opacity", 0);
		}
	}

	void show(QObject *obj)
	{
		if (qPrefAnimations::animation_speed() != 0) {
			QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
			animation->setStartValue(0);
			animation->setEndValue(1);
			animation->start(QAbstractAnimation::DeleteWhenStopped);
		} else {
			obj->setProperty("opacity", 1);
		}
	}

	void animDelete(QObject *obj)
	{
		if (qPrefAnimations::animation_speed() != 0) {
			QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
			obj->connect(animation, &QPropertyAnimation::finished, &QObject::deleteLater);
			animation->setStartValue(1);
			animation->setEndValue(0);
			animation->start(QAbstractAnimation::DeleteWhenStopped);
		} else {
			delete obj;
		}
	}

	void moveTo(QObject *obj, qreal x, qreal y)
	{
		if (qPrefAnimations::animation_speed() != 0) {
			QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
			animation->setDuration(prefs.animation_speed);
			animation->setStartValue(obj->property("pos").toPointF());
			animation->setEndValue(QPointF(x, y));
			animation->start(QAbstractAnimation::DeleteWhenStopped);
		} else {
			obj->setProperty("pos", QPointF(x, y));
		}
	}

	void scaleTo(QObject *obj, qreal scale)
	{
		if (qPrefAnimations::animation_speed() != 0) {
			QPropertyAnimation *animation = new QPropertyAnimation(obj, "scale");
			animation->setDuration(prefs.animation_speed);
			animation->setStartValue(obj->property("scale").toReal());
			animation->setEndValue(QVariant::fromValue(scale));
			animation->setEasingCurve(QEasingCurve::InCubic);
			animation->start(QAbstractAnimation::DeleteWhenStopped);
		} else {
			obj->setProperty("scale", QVariant::fromValue(scale));
		}
	}

	void moveTo(QObject *obj, const QPointF &pos)
	{
		moveTo(obj, pos.x(), pos.y());
	}
}