| 1 | /* |
| 2 | * Copyright (C) 2015-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 <QGraphicsView> |
| 23 | #include <QPaintEvent> |
| 24 | |
| 25 | #include "cursors.h" |
| 26 | #include "inputsource.h" |
| 27 | #include "plot.h" |
| 28 | #include "samplesource.h" |
| 29 | #include "spectrogramplot.h" |
| 30 | #include "traceplot.h" |
| 31 | |
| 32 | class PlotView : public QGraphicsView, Subscriber |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | public: |
| 37 | PlotView(InputSource *input); |
| 38 | void setSampleRate(double rate); |
| 39 | |
| 40 | signals: |
| 41 | void timeSelectionChanged(float time); |
| 42 | void zoomIn(); |
| 43 | void zoomOut(); |
| 44 | |
| 45 | public slots: |
| 46 | void cursorsMoved(); |
| 47 | void enableCursors(bool enabled); |
| 48 | void enableScales(bool enabled); |
| 49 | void enableAnnotations(bool enabled); |
| 50 | void enableAnnotationCommentsTooltips(bool enabled); |
| 51 | void invalidateEvent() override; |
| 52 | void repaint(); |
| 53 | void setCursorSegments(int segments); |
| 54 | void setFFTAndZoom(int fftSize, int zoomLevel); |
| 55 | void setPowerMin(int power); |
| 56 | void setPowerMax(int power); |
| 57 | |
| 58 | protected: |
| 59 | void mouseMoveEvent(QMouseEvent *event) override; |
| 60 | void mouseReleaseEvent(QMouseEvent *event) override; |
| 61 | void contextMenuEvent(QContextMenuEvent * event) override; |
| 62 | void paintEvent(QPaintEvent *event) override; |
| 63 | void resizeEvent(QResizeEvent * event) override; |
| 64 | void scrollContentsBy(int dx, int dy) override; |
| 65 | bool viewportEvent(QEvent *event) override; |
| 66 | void showEvent(QShowEvent *event) override; |
| 67 | |
| 68 | private: |
| 69 | Cursors cursors; |
| 70 | SampleSource<std::complex<float>> *mainSampleSource = nullptr; |
| 71 | SpectrogramPlot *spectrogramPlot = nullptr; |
| 72 | std::vector<std::unique_ptr<Plot>> plots; |
| 73 | range_t<size_t> viewRange; |
| 74 | range_t<size_t> selectedSamples; |
| 75 | int zoomPos; |
| 76 | size_t zoomSample; |
| 77 | |
| 78 | int fftSize = 1024; |
| 79 | int zoomLevel = 1; |
| 80 | int powerMin; |
| 81 | int powerMax; |
| 82 | bool cursorsEnabled; |
| 83 | double sampleRate = 0.0; |
| 84 | bool timeScaleEnabled; |
| 85 | int scrollZoomStepsAccumulated = 0; |
| 86 | bool annotationCommentsEnabled; |
| 87 | |
| 88 | void addPlot(Plot *plot); |
| 89 | void emitTimeSelection(); |
| 90 | void extractSymbols(std::shared_ptr<AbstractSampleSource> src, bool toClipboard); |
| 91 | void exportSamples(std::shared_ptr<AbstractSampleSource> src); |
| 92 | template<typename SOURCETYPE> void exportSamples(std::shared_ptr<AbstractSampleSource> src); |
| 93 | int plotsHeight(); |
| 94 | size_t samplesPerColumn(); |
| 95 | void updateViewRange(bool reCenter); |
| 96 | void updateView(bool reCenter = false, bool expanding = false); |
| 97 | void paintTimeScale(QPainter &painter, QRect &rect, range_t<size_t> sampleRange); |
| 98 | void updateAnnotationTooltip(QMouseEvent *event); |
| 99 | |
| 100 | int sampleToColumn(size_t sample); |
| 101 | size_t columnToSample(int col); |
| 102 | }; |