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 #ifndef VIEWTOOLS_H 21*0b05c6eaSNicolas Bonnefon #define VIEWTOOLS_H 22*0b05c6eaSNicolas Bonnefon 23*0b05c6eaSNicolas Bonnefon #include <QObject> 24*0b05c6eaSNicolas Bonnefon 25*0b05c6eaSNicolas Bonnefon // This class is a controller for an elastic hook manipulated with 26*0b05c6eaSNicolas Bonnefon // the mouse wheel or touchpad. 27*0b05c6eaSNicolas Bonnefon // It is used for the "follow" line at the end of the file. 28*0b05c6eaSNicolas Bonnefon class ElasticHook : public QObject { 29*0b05c6eaSNicolas Bonnefon Q_OBJECT 30*0b05c6eaSNicolas Bonnefon 31*0b05c6eaSNicolas Bonnefon public: 32*0b05c6eaSNicolas Bonnefon ElasticHook( int hook_threshold ) { 33*0b05c6eaSNicolas Bonnefon hook_threshold_ = hook_threshold; 34*0b05c6eaSNicolas Bonnefon } 35*0b05c6eaSNicolas Bonnefon 36*0b05c6eaSNicolas Bonnefon // Instruct the elastic to move by the passed pixels 37*0b05c6eaSNicolas Bonnefon // (a positive value increase the elastic tension) 38*0b05c6eaSNicolas Bonnefon void move( int value ); 39*0b05c6eaSNicolas Bonnefon 40*0b05c6eaSNicolas Bonnefon int length() const { return position_; } 41*0b05c6eaSNicolas Bonnefon 42*0b05c6eaSNicolas Bonnefon protected: 43*0b05c6eaSNicolas Bonnefon void timerEvent( QTimerEvent *event ); 44*0b05c6eaSNicolas Bonnefon 45*0b05c6eaSNicolas Bonnefon signals: 46*0b05c6eaSNicolas Bonnefon // Sent when the length has changed 47*0b05c6eaSNicolas Bonnefon void lengthChanged(); 48*0b05c6eaSNicolas Bonnefon // Sent when the hooked status has changed 49*0b05c6eaSNicolas Bonnefon void hooked( bool is_hooked ); 50*0b05c6eaSNicolas Bonnefon 51*0b05c6eaSNicolas Bonnefon private: 52*0b05c6eaSNicolas Bonnefon static constexpr int TIMER_PERIOD_MS = 10; 53*0b05c6eaSNicolas Bonnefon static constexpr int DECREASE_RATE = 2; 54*0b05c6eaSNicolas Bonnefon int hook_threshold_; 55*0b05c6eaSNicolas Bonnefon int position_ = 0; 56*0b05c6eaSNicolas Bonnefon int timer_id_ = 0; 57*0b05c6eaSNicolas Bonnefon }; 58*0b05c6eaSNicolas Bonnefon 59*0b05c6eaSNicolas Bonnefon #endif 60