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