Profile: add speed parameter to Animation::* functions

For now always use the preferences value, so that this is a
no-op. This is a preparation for storing the speed in the
profile widget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-07-10 22:23:25 +02:00 committed by Robert C. Helling
parent 74244b3cfe
commit 2d9dc40171
5 changed files with 34 additions and 33 deletions

View file

@ -1,14 +1,13 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "profile-widget/animationfunctions.h" #include "profile-widget/animationfunctions.h"
#include "core/pref.h" #include "core/pref.h"
#include "core/settings/qPrefDisplay.h"
#include <QPropertyAnimation> #include <QPropertyAnimation>
namespace Animations { namespace Animations {
void hide(QObject *obj) void hide(QObject *obj, int speed)
{ {
if (qPrefDisplay::animation_speed() != 0) { if (speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
animation->setStartValue(1); animation->setStartValue(1);
animation->setEndValue(0); animation->setEndValue(0);
@ -18,9 +17,9 @@ namespace Animations {
} }
} }
void show(QObject *obj) void show(QObject *obj, int speed)
{ {
if (qPrefDisplay::animation_speed() != 0) { if (speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
animation->setStartValue(0); animation->setStartValue(0);
animation->setEndValue(1); animation->setEndValue(1);
@ -30,9 +29,9 @@ namespace Animations {
} }
} }
void animDelete(QObject *obj) void animDelete(QObject *obj, int speed)
{ {
if (qPrefDisplay::animation_speed() != 0) { if (speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
obj->connect(animation, &QPropertyAnimation::finished, &QObject::deleteLater); obj->connect(animation, &QPropertyAnimation::finished, &QObject::deleteLater);
animation->setStartValue(1); animation->setStartValue(1);
@ -43,9 +42,9 @@ namespace Animations {
} }
} }
void moveTo(QObject *obj, qreal x, qreal y) void moveTo(QObject *obj, int speed, qreal x, qreal y)
{ {
if (qPrefDisplay::animation_speed() != 0) { if (speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
animation->setDuration(prefs.animation_speed); animation->setDuration(prefs.animation_speed);
animation->setStartValue(obj->property("pos").toPointF()); animation->setStartValue(obj->property("pos").toPointF());
@ -56,9 +55,9 @@ namespace Animations {
} }
} }
void scaleTo(QObject *obj, qreal scale) void scaleTo(QObject *obj, int speed, qreal scale)
{ {
if (qPrefDisplay::animation_speed() != 0) { if (speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "scale"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "scale");
animation->setDuration(prefs.animation_speed); animation->setDuration(prefs.animation_speed);
animation->setStartValue(obj->property("scale").toReal()); animation->setStartValue(obj->property("scale").toReal());
@ -70,8 +69,8 @@ namespace Animations {
} }
} }
void moveTo(QObject *obj, const QPointF &pos) void moveTo(QObject *obj, int speed, const QPointF &pos)
{ {
moveTo(obj, pos.x(), pos.y()); moveTo(obj, speed, pos.x(), pos.y());
} }
} }

View file

@ -8,12 +8,12 @@
class QObject; class QObject;
namespace Animations { namespace Animations {
void hide(QObject *obj); void hide(QObject *obj, int speed);
void show(QObject *obj); void show(QObject *obj, int speed);
void moveTo(QObject *obj, qreal x, qreal y); void moveTo(QObject *obj, int speed, qreal x, qreal y);
void moveTo(QObject *obj, const QPointF &pos); void moveTo(QObject *obj, int speed, const QPointF &pos);
void animDelete(QObject *obj); void animDelete(QObject *obj, int speed);
void scaleTo(QObject *obj, qreal scale); void scaleTo(QObject *obj, int speed, qreal scale);
} }
#endif // ANIMATIONFUNCTIONS_H #endif // ANIMATIONFUNCTIONS_H

View file

@ -10,6 +10,7 @@
#include "profile-widget/animationfunctions.h" #include "profile-widget/animationfunctions.h"
#include "profile-widget/divelineitem.h" #include "profile-widget/divelineitem.h"
#include "profile-widget/profilewidget2.h" #include "profile-widget/profilewidget2.h"
#include "core/settings/qPrefDisplay.h" // TODO: Remove
QPen DiveCartesianAxis::gridPen() QPen DiveCartesianAxis::gridPen()
{ {
@ -130,7 +131,7 @@ void emptyList(QList<T *> &list, int steps)
{ {
while (list.size() > steps) { while (list.size() > steps) {
T *removedItem = list.takeLast(); T *removedItem = list.takeLast();
Animations::animDelete(removedItem); Animations::animDelete(removedItem, qPrefDisplay::animation_speed());
} }
} }
@ -177,9 +178,9 @@ void DiveCartesianAxis::updateTicks(color_index_t color)
labels[i]->setText(textForValue(currValueText)); labels[i]->setText(textForValue(currValueText));
if (orientation == LeftToRight || orientation == RightToLeft) { if (orientation == LeftToRight || orientation == RightToLeft) {
Animations::moveTo(labels[i],childPos, m.y1() + tick_size); Animations::moveTo(labels[i], qPrefDisplay::animation_speed(), childPos, m.y1() + tick_size);
} else { } else {
Animations::moveTo(labels[i],m.x1() - tick_size, childPos); Animations::moveTo(labels[i], qPrefDisplay::animation_speed() ,m.x1() - tick_size, childPos);
} }
} }
@ -189,9 +190,9 @@ void DiveCartesianAxis::updateTicks(color_index_t color)
begin - i * stepSize; begin - i * stepSize;
if (orientation == LeftToRight || orientation == RightToLeft) { if (orientation == LeftToRight || orientation == RightToLeft) {
Animations::moveTo(lines[i],childPos, m.y1()); Animations::moveTo(lines[i], qPrefDisplay::animation_speed(), childPos, m.y1());
} else { } else {
Animations::moveTo(lines[i],m.x1(), childPos); Animations::moveTo(lines[i], qPrefDisplay::animation_speed(), m.x1(), childPos);
} }
} }
@ -212,11 +213,11 @@ void DiveCartesianAxis::updateTicks(color_index_t color)
if (orientation == RightToLeft || orientation == LeftToRight) { if (orientation == RightToLeft || orientation == LeftToRight) {
label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
label->setPos(scene()->sceneRect().width() + 10, m.y1() + tick_size); // position it outside of the scene); label->setPos(scene()->sceneRect().width() + 10, m.y1() + tick_size); // position it outside of the scene);
Animations::moveTo(label,childPos, m.y1() + tick_size); Animations::moveTo(label, qPrefDisplay::animation_speed(),childPos , m.y1() + tick_size);
} else { } else {
label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
label->setPos(m.x1() - tick_size, scene()->sceneRect().height() + 10); label->setPos(m.x1() - tick_size, scene()->sceneRect().height() + 10);
Animations::moveTo(label,m.x1() - tick_size, childPos); Animations::moveTo(label, qPrefDisplay::animation_speed(), m.x1() - tick_size, childPos);
} }
} }
@ -237,13 +238,13 @@ void DiveCartesianAxis::updateTicks(color_index_t color)
if (orientation == RightToLeft || orientation == LeftToRight) { if (orientation == RightToLeft || orientation == LeftToRight) {
line->setLine(0, -line_size, 0, 0); line->setLine(0, -line_size, 0, 0);
line->setPos(scene()->sceneRect().width() + 10, m.y1()); // position it outside of the scene); line->setPos(scene()->sceneRect().width() + 10, m.y1()); // position it outside of the scene);
Animations::moveTo(line,childPos, m.y1()); Animations::moveTo(line, qPrefDisplay::animation_speed(), childPos, m.y1());
} else { } else {
QPointF p1 = mapFromScene(3, 0); QPointF p1 = mapFromScene(3, 0);
QPointF p2 = mapFromScene(line_size, 0); QPointF p2 = mapFromScene(line_size, 0);
line->setLine(p1.x(), 0, p2.x(), 0); line->setLine(p1.x(), 0, p2.x(), 0);
line->setPos(m.x1(), scene()->sceneRect().height() + 10); line->setPos(m.x1(), scene()->sceneRect().height() + 10);
Animations::moveTo(line,m.x1(), childPos); Animations::moveTo(line, qPrefDisplay::animation_speed(), m.x1(), childPos);
} }
} }

View file

@ -288,7 +288,7 @@ void DiveEventItem::recalculatePos(int speed)
qreal x = hAxis->posAtValue(internalEvent->time.seconds); qreal x = hAxis->posAtValue(internalEvent->time.seconds);
qreal y = vAxis->posAtValue(depth); qreal y = vAxis->posAtValue(depth);
if (speed > 0) if (speed > 0)
Animations::moveTo(this, x, y); Animations::moveTo(this, speed, x, y);
else else
setPos(x, y); setPos(x, y);
if (isVisible() && shouldBeHidden()) if (isVisible() && shouldBeHidden())

View file

@ -4,6 +4,7 @@
#include "qt-models/divepicturemodel.h" #include "qt-models/divepicturemodel.h"
#include "core/pref.h" #include "core/pref.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/settings/qPrefDisplay.h"
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/preferences/preferencesdialog.h" #include "desktop-widgets/preferences/preferencesdialog.h"
#endif #endif
@ -93,12 +94,12 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent*) void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent*)
{ {
Animations::scaleTo(this, 1.0); Animations::scaleTo(this, qPrefDisplay::animation_speed(), 1.0);
setZValue(baseZValue + 5.0); setZValue(baseZValue + 5.0);
button->setOpacity(0); button->setOpacity(0);
button->show(); button->show();
Animations::show(button); Animations::show(button, qPrefDisplay::animation_speed());
} }
void DivePictureItem::setFileUrl(const QString &s) void DivePictureItem::setFileUrl(const QString &s)
@ -108,9 +109,9 @@ void DivePictureItem::setFileUrl(const QString &s)
void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent*) void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent*)
{ {
Animations::scaleTo(this, 0.2); Animations::scaleTo(this, qPrefDisplay::animation_speed(), 0.2);
setZValue(baseZValue); setZValue(baseZValue);
Animations::hide(button); Animations::hide(button, qPrefDisplay::animation_speed());
} }
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)