cursors: Reimplement Cursors as QObject and implement dragging

This commit is contained in:
Mike Walters
2016-03-05 15:57:11 +00:00
parent c66c708157
commit a82a1af33d
5 changed files with 86 additions and 53 deletions

View File

@@ -35,6 +35,8 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0})
mainSampleSource = input;
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
enableCursors(false);
viewport()->installEventFilter(&cursors);
connect(&cursors, SIGNAL(cursorsMoved()), this, SLOT(cursorsMoved()));
spectrogramPlot = new SpectrogramPlot(mainSampleSource);
plots.emplace_back(spectrogramPlot);
@@ -86,12 +88,15 @@ TracePlot* PlotView::createQuadratureDemodPlot(SampleSource<std::complex<float>>
);
}
void PlotView::cursorsMoved()
{
viewport()->update();
}
void PlotView::enableCursors(bool enabled)
{
if (enabled)
cursors.show();
else
cursors.hide();
cursorsEnabled = enabled;
viewport()->update();
}
void PlotView::invalidateEvent()
@@ -168,6 +173,8 @@ void PlotView::paintEvent(QPaintEvent *event)
PLOT_LAYER(paintBack);
PLOT_LAYER(paintMid);
PLOT_LAYER(paintFront);
if (cursorsEnabled)
cursors.paintFront(painter, rect, {viewRange.first, viewRange.second});
#undef PLOT_LAYER
}
@@ -179,7 +186,7 @@ void PlotView::resizeEvent(QResizeEvent * event)
// Resize cursors
// TODO: don't hardcode this
int margin = rect.width() / 3;
cursors.setGeometry(QRect(rect.left() + margin, rect.top(), rect.right() - rect.left() - 2 * margin, rect.height()));
//cursors.setGeometry(QRect(rect.left() + margin, rect.top(), rect.right() - rect.left() - 2 * margin, rect.height()));
updateView();
}