Blame style/animations/adwaitaspinboxdata.cpp

Packit 8e9c33
/*************************************************************************
Packit 8e9c33
 * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr>    *
Packit 8e9c33
 *                                                                       *
Packit 8e9c33
 * This program is free software; you can redistribute it and/or modify  *
Packit 8e9c33
 * it under the terms of the GNU General Public License as published by  *
Packit 8e9c33
 * the Free Software Foundation; either version 2 of the License, or     *
Packit 8e9c33
 * (at your option) any later version.                                   *
Packit 8e9c33
 *                                                                       *
Packit 8e9c33
 * This program is distributed in the hope that it will be useful,       *
Packit 8e9c33
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
Packit 8e9c33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
Packit 8e9c33
 * GNU General Public License for more details.                          *
Packit 8e9c33
 *                                                                       *
Packit 8e9c33
 * You should have received a copy of the GNU General Public License     *
Packit 8e9c33
 * along with this program; if not, write to the                         *
Packit 8e9c33
 * Free Software Foundation, Inc.,                                       *
Packit 8e9c33
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
Packit 8e9c33
 *************************************************************************/
Packit 8e9c33
Packit 8e9c33
#include "adwaitaspinboxdata.h"
Packit 8e9c33
Packit 8e9c33
namespace Adwaita
Packit 8e9c33
{
Packit 8e9c33
Packit 8e9c33
    //________________________________________________
Packit 8e9c33
    SpinBoxData::SpinBoxData( QObject* parent, QWidget* target, int duration ):
Packit 8e9c33
        AnimationData( parent, target )
Packit 8e9c33
    {
Packit 8e9c33
        _upArrowData._hoverAnimation = new Animation( duration, this );
Packit 8e9c33
        _downArrowData._hoverAnimation = new Animation( duration, this );
Packit 8e9c33
        _upArrowData._pressedAnimation = new Animation( duration, this );
Packit 8e9c33
        _downArrowData._pressedAnimation = new Animation( duration, this );
Packit 8e9c33
        setupAnimation( upArrowAnimation(), "upArrowOpacity" );
Packit 8e9c33
        setupAnimation( downArrowAnimation(), "downArrowOpacity" );
Packit 8e9c33
        setupAnimation( upArrowPressedAnimation(), "upArrowPressed" );
Packit 8e9c33
        setupAnimation( downArrowPressedAnimation(), "downArrowPressed" );
Packit 8e9c33
    }
Packit 8e9c33
Packit 8e9c33
    //______________________________________________
Packit 8e9c33
    bool SpinBoxData::Data::updateState(bool value, bool pressed)
Packit 8e9c33
    {
Packit 8e9c33
        bool change = false;
Packit 8e9c33
        if( _hoverState != value ) {
Packit 8e9c33
Packit 8e9c33
            _hoverState = value;
Packit 8e9c33
            _hoverAnimation.data()->setDirection( ( _hoverState ) ? Animation::Forward : Animation::Backward );
Packit 8e9c33
            if( !_hoverAnimation.data()->isRunning() ) _hoverAnimation.data()->start();
Packit 8e9c33
            change = true;
Packit 8e9c33
Packit 8e9c33
        }
Packit 8e9c33
        if( _pressedState != pressed ) {
Packit 8e9c33
Packit 8e9c33
            _pressedState = pressed;
Packit 8e9c33
            _pressedAnimation.data()->setDirection( ( _pressedState ) ? Animation::Forward : Animation::Backward );
Packit 8e9c33
            if( !_pressedAnimation.data()->isRunning() ) _pressedAnimation.data()->start();
Packit 8e9c33
            change = true;
Packit 8e9c33
Packit 8e9c33
        }
Packit 8e9c33
        return change;
Packit 8e9c33
    }
Packit 8e9c33
Packit 8e9c33
}