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