diff --git a/plotview.cpp b/plotview.cpp index bc4d088..327342c 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -90,8 +90,12 @@ TracePlot* PlotView::createQuadratureDemodPlot(SampleSource> void PlotView::cursorsMoved() { - int selection = cursors.selection().length(); - off_t sampleCount = selection * samplesPerLine(); + selectedSamples = { + horizontalScrollBar()->value() + cursors.selection().minimum * samplesPerLine(), + horizontalScrollBar()->value() + cursors.selection().maximum * samplesPerLine() + }; + + off_t sampleCount = selectedSamples.length(); float selectionTime = sampleCount / (float)mainSampleSource->rate(); emit timeSelectionChanged(selectionTime); viewport()->update(); diff --git a/plotview.h b/plotview.h index aa1cf61..8a48be3 100644 --- a/plotview.h +++ b/plotview.h @@ -61,7 +61,7 @@ private: std::vector> plots; std::pair viewRange; bool selection = false; - range_t selectionTime; + range_t selectedSamples; std::pair selectionFreq; int fftSize; diff --git a/util.h b/util.h index 5b7a3a8..8f1129b 100644 --- a/util.h +++ b/util.h @@ -31,6 +31,19 @@ struct range_t { T minimum; T maximum; + range_t& operator=(const range_t &other) { + minimum = other.minimum; + maximum = other.maximum; + } + + range_t& operator=(const std::initializer_list &other) { + if (other.size() == 2) { + minimum = *other.begin(); + maximum = *(other.begin() + 1); + } + return *this; + } + const T length() { return maximum - minimum; }