Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions friture/Plot.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true

scopedata: plot.scopedata

vertical_axis: scopedata.vertical_axis
horizontal_axis: scopedata.horizontal_axis

Expand Down
31 changes: 31 additions & 0 deletions friture/PlotArea.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
}
26 changes: 26 additions & 0 deletions friture/spectrogram_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,35 @@
# You should have received a copy of the GNU General Public License
# along with Friture. If not, see <http://www.gnu.org/licenses/>.

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]