diff --git a/friture/Plot.qml b/friture/Plot.qml index ac4ef74e..88e39daa 100644 --- a/friture/Plot.qml +++ b/friture/Plot.qml @@ -62,6 +62,8 @@ Rectangle { Layout.fillHeight: true Layout.fillWidth: true + scopedata: plot.scopedata + vertical_axis: scopedata.vertical_axis horizontal_axis: scopedata.horizontal_axis diff --git a/friture/PlotArea.qml b/friture/PlotArea.qml index f49e6870..5ed1831f 100644 --- a/friture/PlotArea.qml +++ b/friture/PlotArea.qml @@ -8,6 +8,7 @@ Item { SystemPalette { id: systemPalette; colorGroup: SystemPalette.Active } + required property var scopedata required property Axis vertical_axis required property Axis horizontal_axis @@ -31,6 +32,22 @@ Item { anchors.fill: parent } + Repeater { + id: annotationRepeater + anchors.fill: parent + + model: scopePlotArea.scopedata.target_frequencies + + Rectangle { + x: 0 + y: parent.height * (1. - scopePlotArea.vertical_axis.coordinate_transform.toScreen(modelData) ) + width: parent.width + height: 1 + color: "lime" + } + + } + Rectangle { id: plotBorder anchors.fill: parent @@ -87,5 +104,19 @@ Item { id: plotMouseArea anchors.fill: parent cursorShape: Qt.CrossCursor + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onClicked: { + if (mouse.button !== Qt.RightButton) { return; } + var freq = vertical_axis.coordinate_transform.toPlot((parent.height - mouse.y) / parent.height); + for (var existingFreq of scopedata.target_frequencies) { + var existingCoord = parent.height * (1 - scopePlotArea.vertical_axis.coordinate_transform.toScreen(existingFreq)); + if (Math.abs(existingCoord - mouse.y) < 5) { + scopedata.remove_target_frequency(existingFreq); + return; + } + } + scopedata.add_target_frequency(freq); + } } } diff --git a/friture/spectrogram_data.py b/friture/spectrogram_data.py index eaa83917..994f7e52 100644 --- a/friture/spectrogram_data.py +++ b/friture/spectrogram_data.py @@ -17,9 +17,35 @@ # You should have received a copy of the GNU General Public License # along with Friture. If not, see . +from PyQt5 import QtCore +from PyQt5.QtCore import pyqtProperty, pyqtSlot + from friture.scope_data import Scope_Data class Spectrogram_Data(Scope_Data): + target_frequencies_changed = QtCore.pyqtSignal() def __init__(self, parent=None): super().__init__(parent) + self._target_frequencies = [] + + + @pyqtProperty('QVariantList', notify=target_frequencies_changed) # type: ignore + def target_frequencies(self): + return self._target_frequencies + + @target_frequencies.setter + def target_frequencies(self, freqs): + if self._target_frequencies != freqs: + self._target_frequencies = freqs + self.target_frequencies_changed.emit() + + @pyqtSlot(float) + def add_target_frequency(self, frequency): + if frequency not in self._target_frequencies: + self._target_frequencies.append(frequency) + self.target_frequencies_changed.emit() + + @pyqtSlot(float) + def remove_target_frequency(self, frequency): + self.target_frequencies = [f for f in self._target_frequencies if f != frequency]