| 1 | /* |
| 2 | * Copyright (C) 2016, Mike Walters <[email protected]> |
| 3 | * |
| 4 | * This file is part of inspectrum. |
| 5 | * |
| 6 | * This program 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 | * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include <QMouseEvent> |
| 23 | #include <QObject> |
| 24 | #include <QPainter> |
| 25 | #include <QPoint> |
| 26 | #include "cursor.h" |
| 27 | #include "util.h" |
| 28 | |
| 29 | class Cursors : public QObject |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | |
| 33 | public: |
| 34 | Cursors(QObject * parent); |
| 35 | int segments(); |
| 36 | bool mouseEvent(QEvent::Type type, QMouseEvent *event); |
| 37 | void leaveEvent(); |
| 38 | void paintFront(QPainter &painter, QRect &rect, range_t<size_t> sampleRange); |
| 39 | range_t<int> selection(); |
| 40 | void setSegments(int segments); |
| 41 | void setSelection(range_t<int> selection); |
| 42 | |
| 43 | public slots: |
| 44 | void cursorMoved(); |
| 45 | |
| 46 | signals: |
| 47 | void cursorsMoved(); |
| 48 | |
| 49 | private: |
| 50 | bool pointWithinDragRegion(QPoint point); |
| 51 | |
| 52 | Cursor *minCursor; |
| 53 | Cursor *maxCursor; |
| 54 | int segmentCount = 1; |
| 55 | |
| 56 | QPoint dragPos; // keep track of dragging distance |
| 57 | bool cursorOverride = false; // used to record if cursor is overridden |
| 58 | bool dragging = false; // record if mouse is dragging |
| 59 | }; |