|
Packit Bot |
052d53 |
/*************************************************************************
|
|
Packit Bot |
052d53 |
* Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr> *
|
|
Packit Bot |
052d53 |
* *
|
|
Packit Bot |
052d53 |
* This program is free software; you can redistribute it and/or modify *
|
|
Packit Bot |
052d53 |
* it under the terms of the GNU General Public License as published by *
|
|
Packit Bot |
052d53 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
Packit Bot |
052d53 |
* (at your option) any later version. *
|
|
Packit Bot |
052d53 |
* *
|
|
Packit Bot |
052d53 |
* This program is distributed in the hope that it will be useful, *
|
|
Packit Bot |
052d53 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
Packit Bot |
052d53 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
Packit Bot |
052d53 |
* GNU General Public License for more details. *
|
|
Packit Bot |
052d53 |
* *
|
|
Packit Bot |
052d53 |
* You should have received a copy of the GNU General Public License *
|
|
Packit Bot |
052d53 |
* along with this program; if not, write to the *
|
|
Packit Bot |
052d53 |
* Free Software Foundation, Inc., *
|
|
Packit Bot |
052d53 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
Packit Bot |
052d53 |
*************************************************************************/
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#ifndef ADWAITA_ANIMATION_DATA_H
|
|
Packit Bot |
052d53 |
#define ADWAITA_ANIMATION_DATA_H
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include "adwaitaanimation.h"
|
|
Packit Bot |
052d53 |
#include "adwaitaqt_export.h"
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include <QEvent>
|
|
Packit Bot |
052d53 |
#include <QObject>
|
|
Packit Bot |
052d53 |
#include <QWidget>
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include <cmath>
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
namespace Adwaita
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
//* base class
|
|
Packit Bot |
052d53 |
class ADWAITAQT_EXPORT AnimationData : public QObject
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
Q_OBJECT
|
|
Packit Bot |
052d53 |
public:
|
|
Packit Bot |
052d53 |
//* constructor
|
|
Packit Bot |
052d53 |
AnimationData(QObject *parent, QWidget *target)
|
|
Packit Bot |
052d53 |
: QObject(parent)
|
|
Packit Bot |
052d53 |
, _target(target)
|
|
Packit Bot |
052d53 |
, _enabled(true)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
Q_ASSERT(_target);
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* destructor
|
|
Packit Bot |
052d53 |
virtual ~AnimationData()
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* duration
|
|
Packit Bot |
052d53 |
virtual void setDuration(int) = 0;
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* steps
|
|
Packit Bot |
052d53 |
static void setSteps(int value)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
_steps = value;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* enability
|
|
Packit Bot |
052d53 |
virtual bool enabled() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _enabled;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* enability
|
|
Packit Bot |
052d53 |
virtual void setEnabled(bool value)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
_enabled = value;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* target
|
|
Packit Bot |
052d53 |
const WeakPointer<QWidget> &target() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _target;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* invalid opacity
|
|
Packit Bot |
052d53 |
static const qreal OpacityInvalid;
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
protected:
|
|
Packit Bot |
052d53 |
//* setup animation
|
|
Packit Bot |
052d53 |
virtual void setupAnimation(const Animation::Pointer &animation, const QByteArray &property);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* apply step
|
|
Packit Bot |
052d53 |
virtual qreal digitize(const qreal &value) const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (_steps > 0) {
|
|
Packit Bot |
052d53 |
return std::floor(value * _steps) / _steps;
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
return value;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* trigger target update
|
|
Packit Bot |
052d53 |
virtual void setDirty() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (_target) {
|
|
Packit Bot |
052d53 |
_target.data()->update();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
private:
|
|
Packit Bot |
052d53 |
//* guarded target
|
|
Packit Bot |
052d53 |
WeakPointer<QWidget> _target;
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* enability
|
|
Packit Bot |
052d53 |
bool _enabled;
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* steps
|
|
Packit Bot |
052d53 |
static int _steps;
|
|
Packit Bot |
052d53 |
};
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
} // namespace Adwaita
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#endif // ADWAITA_ANIMATION_DATA_H
|