10b05c6eaSNicolas Bonnefon /* 20b05c6eaSNicolas Bonnefon * Copyright (C) 2015 Nicolas Bonnefon and other contributors 30b05c6eaSNicolas Bonnefon * 40b05c6eaSNicolas Bonnefon * This file is part of glogg. 50b05c6eaSNicolas Bonnefon * 60b05c6eaSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 70b05c6eaSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 80b05c6eaSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 90b05c6eaSNicolas Bonnefon * (at your option) any later version. 100b05c6eaSNicolas Bonnefon * 110b05c6eaSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 120b05c6eaSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 130b05c6eaSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 140b05c6eaSNicolas Bonnefon * GNU General Public License for more details. 150b05c6eaSNicolas Bonnefon * 160b05c6eaSNicolas Bonnefon * You should have received a copy of the GNU General Public License 170b05c6eaSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 180b05c6eaSNicolas Bonnefon */ 190b05c6eaSNicolas Bonnefon 200b05c6eaSNicolas Bonnefon #ifndef VIEWTOOLS_H 210b05c6eaSNicolas Bonnefon #define VIEWTOOLS_H 220b05c6eaSNicolas Bonnefon 23a9448ba0SNicolas Bonnefon #include <chrono> 24a9448ba0SNicolas Bonnefon 250b05c6eaSNicolas Bonnefon #include <QObject> 260b05c6eaSNicolas Bonnefon 270b05c6eaSNicolas Bonnefon // This class is a controller for an elastic hook manipulated with 280b05c6eaSNicolas Bonnefon // the mouse wheel or touchpad. 290b05c6eaSNicolas Bonnefon // It is used for the "follow" line at the end of the file. 300b05c6eaSNicolas Bonnefon class ElasticHook : public QObject { 310b05c6eaSNicolas Bonnefon Q_OBJECT 320b05c6eaSNicolas Bonnefon 330b05c6eaSNicolas Bonnefon public: 34*ac6602a5SNicolas Bonnefon ElasticHook( int hook_threshold ) : hook_threshold_( hook_threshold ) {} 350b05c6eaSNicolas Bonnefon 360b05c6eaSNicolas Bonnefon // Instruct the elastic to move by the passed pixels 370b05c6eaSNicolas Bonnefon // (a positive value increase the elastic tension) 380b05c6eaSNicolas Bonnefon void move( int value ); 390b05c6eaSNicolas Bonnefon 400b05c6eaSNicolas Bonnefon int length() const { return position_; } 41*ac6602a5SNicolas Bonnefon bool isHooked() const { return hooked_; } 420b05c6eaSNicolas Bonnefon 430b05c6eaSNicolas Bonnefon protected: 440b05c6eaSNicolas Bonnefon void timerEvent( QTimerEvent *event ); 450b05c6eaSNicolas Bonnefon 460b05c6eaSNicolas Bonnefon signals: 470b05c6eaSNicolas Bonnefon // Sent when the length has changed 480b05c6eaSNicolas Bonnefon void lengthChanged(); 490b05c6eaSNicolas Bonnefon // Sent when the hooked status has changed 500b05c6eaSNicolas Bonnefon void hooked( bool is_hooked ); 510b05c6eaSNicolas Bonnefon 520b05c6eaSNicolas Bonnefon private: 53a9448ba0SNicolas Bonnefon void decreasePosition(); 54a9448ba0SNicolas Bonnefon 550b05c6eaSNicolas Bonnefon static constexpr int TIMER_PERIOD_MS = 10; 56a9448ba0SNicolas Bonnefon static constexpr int DECREASE_RATE = 4; 57*ac6602a5SNicolas Bonnefon const int hook_threshold_; 58*ac6602a5SNicolas Bonnefon bool hooked_ = false; 590b05c6eaSNicolas Bonnefon int position_ = 0; 600b05c6eaSNicolas Bonnefon int timer_id_ = 0; 61a9448ba0SNicolas Bonnefon std::chrono::time_point<std::chrono::steady_clock> last_update_; 620b05c6eaSNicolas Bonnefon }; 630b05c6eaSNicolas Bonnefon 640b05c6eaSNicolas Bonnefon #endif 65