From d22bdb3e5e18b8d77fedf2d3bfcd5ecac73ea632 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 17 Feb 2021 07:27:10 +0100 Subject: [PATCH] Spectrum frequency zoom: implemented panning. Implements #773 --- sdrgui/gui/glspectrum.cpp | 22 ++++++++++++++++++++++ sdrgui/gui/glspectrum.h | 1 + 2 files changed, 23 insertions(+) diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index b513c27bd..a1838762e 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -2211,6 +2211,10 @@ void GLSpectrum::mousePressEvent(QMouseEvent* event) update(); } } + else if (event->modifiers() & Qt::AltModifier) + { + frequencyPan(event); + } if (m_cursorState == CSSplitter) { @@ -2303,6 +2307,24 @@ void GLSpectrum::frequencyZoom(QWheelEvent *event) qDebug("GLSpectrum::spectrumZoom: pw: %f p: %f z: %f", pw, m_frequencyZoomPos, m_frequencyZoomFactor); } +void GLSpectrum::frequencyPan(QMouseEvent *event) +{ + if (m_frequencyZoomFactor == 1.0f) { + return; + } + + const QPointF& p = event->pos(); + float pw = (p.x() - m_leftMargin) / (width() - m_leftMargin - m_rightMargin); // position in window + pw = pw < 0.0f ? 0.0f : pw > 1.0f ? 1.0 : pw; + float dw = pw - 0.5f; + m_frequencyZoomPos += dw * (1.0f / m_frequencyZoomFactor); + float lim = 0.5f / m_frequencyZoomFactor; + m_frequencyZoomPos = m_frequencyZoomPos < lim ? lim : m_frequencyZoomPos > 1 - lim ? 1 - lim : m_frequencyZoomPos; + + updateFFTLimits(); + qDebug("GLSpectrum::frequencyPan: pw: %f p: %f", pw, m_frequencyZoomPos); +} + void GLSpectrum::resetFrequencyZoom() { m_frequencyZoomFactor = 1.0f; diff --git a/sdrgui/gui/glspectrum.h b/sdrgui/gui/glspectrum.h index cf73ca682..43f7c33f1 100644 --- a/sdrgui/gui/glspectrum.h +++ b/sdrgui/gui/glspectrum.h @@ -350,6 +350,7 @@ private: void wheelEvent(QWheelEvent*); void channelMarkerMove(QWheelEvent*, int mul); void frequencyZoom(QWheelEvent*); + void frequencyPan(QMouseEvent*); void resetFrequencyZoom(); void updateFFTLimits(); void setFrequencyScale();