1*0b05c6eaSNicolas Bonnefon /* 2*0b05c6eaSNicolas Bonnefon * Copyright (C) 2015 Nicolas Bonnefon and other contributors 3*0b05c6eaSNicolas Bonnefon * 4*0b05c6eaSNicolas Bonnefon * This file is part of glogg. 5*0b05c6eaSNicolas Bonnefon * 6*0b05c6eaSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7*0b05c6eaSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8*0b05c6eaSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9*0b05c6eaSNicolas Bonnefon * (at your option) any later version. 10*0b05c6eaSNicolas Bonnefon * 11*0b05c6eaSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12*0b05c6eaSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*0b05c6eaSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*0b05c6eaSNicolas Bonnefon * GNU General Public License for more details. 15*0b05c6eaSNicolas Bonnefon * 16*0b05c6eaSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17*0b05c6eaSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18*0b05c6eaSNicolas Bonnefon */ 19*0b05c6eaSNicolas Bonnefon 20*0b05c6eaSNicolas Bonnefon #include "viewtools.h" 21*0b05c6eaSNicolas Bonnefon 22*0b05c6eaSNicolas Bonnefon #include "log.h" 23*0b05c6eaSNicolas Bonnefon 24*0b05c6eaSNicolas Bonnefon /* ElasticHook */ 25*0b05c6eaSNicolas Bonnefon 26*0b05c6eaSNicolas Bonnefon void ElasticHook::move( int value ) 27*0b05c6eaSNicolas Bonnefon { 28*0b05c6eaSNicolas Bonnefon if ( timer_id_ == 0 ) 29*0b05c6eaSNicolas Bonnefon timer_id_ = startTimer( TIMER_PERIOD_MS ); 30*0b05c6eaSNicolas Bonnefon 31*0b05c6eaSNicolas Bonnefon position_ += value; 32*0b05c6eaSNicolas Bonnefon if ( position_ <= 0 ) 33*0b05c6eaSNicolas Bonnefon position_ = 0; 34*0b05c6eaSNicolas Bonnefon 35*0b05c6eaSNicolas Bonnefon LOG( logDEBUG ) << "ElasticHook::move: new value " << position_; 36*0b05c6eaSNicolas Bonnefon 37*0b05c6eaSNicolas Bonnefon emit lengthChanged(); 38*0b05c6eaSNicolas Bonnefon } 39*0b05c6eaSNicolas Bonnefon 40*0b05c6eaSNicolas Bonnefon void ElasticHook::timerEvent( QTimerEvent* event ) 41*0b05c6eaSNicolas Bonnefon { 42*0b05c6eaSNicolas Bonnefon static constexpr int SQUARE_RATIO = 80; 43*0b05c6eaSNicolas Bonnefon 44*0b05c6eaSNicolas Bonnefon position_ -= DECREASE_RATE + ( ( position_/SQUARE_RATIO ) * ( position_/SQUARE_RATIO ) ); 45*0b05c6eaSNicolas Bonnefon 46*0b05c6eaSNicolas Bonnefon if ( position_ <= 0 ) { 47*0b05c6eaSNicolas Bonnefon position_ = 0; 48*0b05c6eaSNicolas Bonnefon killTimer( timer_id_ ); 49*0b05c6eaSNicolas Bonnefon timer_id_ = 0; 50*0b05c6eaSNicolas Bonnefon } 51*0b05c6eaSNicolas Bonnefon LOG( logDEBUG ) << "ElasticHook::timerEvent: new value " << position_; 52*0b05c6eaSNicolas Bonnefon 53*0b05c6eaSNicolas Bonnefon emit lengthChanged(); 54*0b05c6eaSNicolas Bonnefon } 55