|
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_SPINBOX_DATA_H
|
|
Packit Bot |
052d53 |
#define ADWAITA_SPINBOX_DATA_H
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include "adwaitaanimationdata.h"
|
|
Packit Bot |
052d53 |
#include "adwaitaqt_export.h"
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include <QStyle>
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
namespace Adwaita
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
//* handles spinbox arrows hover
|
|
Packit Bot |
052d53 |
class ADWAITAQT_EXPORT SpinBoxData : public AnimationData
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
Q_OBJECT
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* declare opacity property
|
|
Packit Bot |
052d53 |
Q_PROPERTY(qreal upArrowOpacity READ upArrowOpacity WRITE setUpArrowOpacity)
|
|
Packit Bot |
052d53 |
Q_PROPERTY(qreal downArrowOpacity READ downArrowOpacity WRITE setDownArrowOpacity)
|
|
Packit Bot |
052d53 |
Q_PROPERTY(qreal upArrowPressed READ upArrowPressed WRITE setUpArrowPressed)
|
|
Packit Bot |
052d53 |
Q_PROPERTY(qreal downArrowPressed READ downArrowPressed WRITE setDownArrowPressed)
|
|
Packit Bot |
052d53 |
public:
|
|
Packit Bot |
052d53 |
//* constructor
|
|
Packit Bot |
052d53 |
SpinBoxData(QObject *, QWidget *, int);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* destructor
|
|
Packit Bot |
052d53 |
virtual ~SpinBoxData()
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* animation state
|
|
Packit Bot |
052d53 |
virtual bool updateState(QStyle::SubControl subControl, bool value, bool pressed)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (subControl == QStyle::SC_SpinBoxUp) {
|
|
Packit Bot |
052d53 |
return _upArrowData.updateState(value, pressed);
|
|
Packit Bot |
052d53 |
} else if (subControl == QStyle::SC_SpinBoxDown) {
|
|
Packit Bot |
052d53 |
return _downArrowData.updateState(value, pressed);
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
return false;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* animation state
|
|
Packit Bot |
052d53 |
virtual bool isAnimated(QStyle::SubControl subControl) const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return ((subControl == QStyle::SC_SpinBoxUp && upArrowAnimation().data()->isRunning()) || (subControl == QStyle::SC_SpinBoxDown && downArrowAnimation().data()->isRunning()));
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
virtual qreal opacity(QStyle::SubControl subControl) const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (subControl == QStyle::SC_SpinBoxUp) {
|
|
Packit Bot |
052d53 |
return upArrowOpacity();
|
|
Packit Bot |
052d53 |
} else if (subControl == QStyle::SC_SpinBoxDown) {
|
|
Packit Bot |
052d53 |
return downArrowOpacity();
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
return OpacityInvalid;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
virtual qreal pressed(QStyle::SubControl subControl) const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (subControl == QStyle::SC_SpinBoxUp) {
|
|
Packit Bot |
052d53 |
return upArrowPressed();
|
|
Packit Bot |
052d53 |
} else if (subControl == QStyle::SC_SpinBoxDown) {
|
|
Packit Bot |
052d53 |
return downArrowPressed();
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
return OpacityInvalid;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* duration
|
|
Packit Bot |
052d53 |
virtual void setDuration(int duration)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
upArrowAnimation().data()->setDuration(duration);
|
|
Packit Bot |
052d53 |
downArrowAnimation().data()->setDuration(duration);
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//*@name up arrow animation
|
|
Packit Bot |
052d53 |
//@{
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
qreal upArrowOpacity() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _upArrowData._opacity;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
void setUpArrowOpacity(qreal value)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
value = digitize(value);
|
|
Packit Bot |
052d53 |
if (_upArrowData._opacity == value) {
|
|
Packit Bot |
052d53 |
return;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
_upArrowData._opacity = value;
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* animation
|
|
Packit Bot |
052d53 |
Animation::Pointer upArrowAnimation() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _upArrowData._hoverAnimation;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//@}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//*@name down arrow animation
|
|
Packit Bot |
052d53 |
//@{
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
qreal downArrowOpacity() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _downArrowData._opacity;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
void setDownArrowOpacity(qreal value)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
value = digitize(value);
|
|
Packit Bot |
052d53 |
if (_downArrowData._opacity == value) {
|
|
Packit Bot |
052d53 |
return;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
_downArrowData._opacity = value;
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* animation
|
|
Packit Bot |
052d53 |
Animation::Pointer downArrowAnimation() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _downArrowData._hoverAnimation;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//*@name up arrow pressed animation
|
|
Packit Bot |
052d53 |
//@{
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
qreal upArrowPressed() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _upArrowData._pressed;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
void setUpArrowPressed(qreal value)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
value = digitize(value);
|
|
Packit Bot |
052d53 |
if (_upArrowData._pressed == value) {
|
|
Packit Bot |
052d53 |
return;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
_upArrowData._pressed = value;
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* animation
|
|
Packit Bot |
052d53 |
Animation::Pointer upArrowPressedAnimation() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _upArrowData._pressedAnimation;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//*@name down arrow pressed animation
|
|
Packit Bot |
052d53 |
//@{
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
qreal downArrowPressed() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _downArrowData._pressed;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
void setDownArrowPressed(qreal value)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
value = digitize(value);
|
|
Packit Bot |
052d53 |
if (_downArrowData._pressed == value) {
|
|
Packit Bot |
052d53 |
return;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
_downArrowData._pressed = value;
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* animation
|
|
Packit Bot |
052d53 |
Animation::Pointer downArrowPressedAnimation() const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
return _downArrowData._pressedAnimation;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//@}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
private:
|
|
Packit Bot |
052d53 |
//* container for needed animation data
|
|
Packit Bot |
052d53 |
class ADWAITAQT_EXPORT Data
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
public:
|
|
Packit Bot |
052d53 |
//* default constructor
|
|
Packit Bot |
052d53 |
Data()
|
|
Packit Bot |
052d53 |
: _hoverState(false)
|
|
Packit Bot |
052d53 |
, _pressedState(false)
|
|
Packit Bot |
052d53 |
, _opacity(0)
|
|
Packit Bot |
052d53 |
, _pressed(0)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* state
|
|
Packit Bot |
052d53 |
bool updateState(bool, bool);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* arrow state
|
|
Packit Bot |
052d53 |
bool _hoverState;
|
|
Packit Bot |
052d53 |
bool _pressedState;
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* animation
|
|
Packit Bot |
052d53 |
Animation::Pointer _hoverAnimation;
|
|
Packit Bot |
052d53 |
Animation::Pointer _pressedAnimation;
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* opacity
|
|
Packit Bot |
052d53 |
qreal _opacity;
|
|
Packit Bot |
052d53 |
qreal _pressed;
|
|
Packit Bot |
052d53 |
};
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* up arrow data
|
|
Packit Bot |
052d53 |
Data _upArrowData;
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//* down arrow data
|
|
Packit Bot |
052d53 |
Data _downArrowData;
|
|
Packit Bot |
052d53 |
};
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
} // namespace Adwaita
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#endif // ADWAITA_SPINBOX_DATA_H
|