Resizable markers (Fixes half of #53)

pull/71/head^2
Rune Broberg 2019-10-29 12:47:30 +01:00
rodzic f4c88e2ee3
commit d5042a8191
2 zmienionych plików z 60 dodań i 18 usunięć

Wyświetl plik

@ -51,7 +51,7 @@ class Chart(QtWidgets.QWidget):
minChartWidth = 200
lineThickness = 1
pointSize = 2
markerSize = 3
isPopout = False
popoutRequested = pyqtSignal(object)
@ -127,6 +127,10 @@ class Chart(QtWidgets.QWidget):
self.pointSize = size
self.update()
def setMarkerSize(self, size):
self.markerSize = size
self.update()
def getActiveMarker(self, event: QtGui.QMouseEvent) -> Marker:
if self.draggedMarker is not None:
return self.draggedMarker
@ -553,9 +557,12 @@ class FrequencyChart(Chart):
x = self.getXPosition(data[m.location])
y = y_function(data[m.location])
if self.isPlotable(x, y):
qp.drawLine(int(x), int(y) + 3, int(x) - 3, int(y) - 3)
qp.drawLine(int(x), int(y) + 3, int(x) + 3, int(y) - 3)
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)
qp.drawLine(int(x), int(y) + self.markerSize,
int(x) - self.markerSize, int(y) - self.markerSize)
qp.drawLine(int(x), int(y) + self.markerSize,
int(x) + self.markerSize, int(y) - self.markerSize)
qp.drawLine(int(x) - self.markerSize, int(y) - self.markerSize,
int(x) + self.markerSize, int(y) - self.markerSize)
def isPlotable(self, x, y):
return self.leftMargin <= x <= self.leftMargin + self.chartWidth and \
@ -983,9 +990,12 @@ class PolarChart(SquareChart):
qp.setPen(highlighter)
x = self.getXPosition(self.data[m.location])
y = self.height() / 2 + self.data[m.location].im * -1 * self.chartHeight / 2
qp.drawLine(int(x), int(y) + 3, int(x) - 3, int(y) - 3)
qp.drawLine(int(x), int(y) + 3, int(x) + 3, int(y) - 3)
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)
qp.drawLine(int(x), int(y) + self.markerSize,
int(x) - self.markerSize, int(y) - self.markerSize)
qp.drawLine(int(x), int(y) + self.markerSize,
int(x) + self.markerSize, int(y) - self.markerSize)
qp.drawLine(int(x) - self.markerSize, int(y) - self.markerSize,
int(x) + self.markerSize, int(y) - self.markerSize)
def getXPosition(self, d: Datapoint) -> int:
return self.width()/2 + d.re * self.chartWidth/2
@ -1129,9 +1139,12 @@ class SmithChart(SquareChart):
qp.setPen(highlighter)
x = self.getXPosition(self.data[m.location])
y = self.height() / 2 + self.data[m.location].im * -1 * self.chartHeight / 2
qp.drawLine(int(x), int(y) + 3, int(x) - 3, int(y) - 3)
qp.drawLine(int(x), int(y) + 3, int(x) + 3, int(y) - 3)
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)
qp.drawLine(int(x), int(y) + self.markerSize,
int(x) - self.markerSize, int(y) - self.markerSize)
qp.drawLine(int(x), int(y) + self.markerSize,
int(x) + self.markerSize, int(y) - self.markerSize)
qp.drawLine(int(x) - self.markerSize, int(y) - self.markerSize,
int(x) + self.markerSize, int(y) - self.markerSize)
def getXPosition(self, d: Datapoint) -> int:
return self.width()/2 + d.re * self.chartWidth/2
@ -2396,13 +2409,19 @@ class RealImaginaryChart(FrequencyChart):
y_re = self.getReYPosition(self.data[m.location])
y_im = self.getImYPosition(self.data[m.location])
qp.drawLine(int(x), int(y_re) + 3, int(x) - 3, int(y_re) - 3)
qp.drawLine(int(x), int(y_re) + 3, int(x) + 3, int(y_re) - 3)
qp.drawLine(int(x) - 3, int(y_re) - 3, int(x) + 3, int(y_re) - 3)
qp.drawLine(int(x), int(y_re) + self.markerSize,
int(x) - self.markerSize, int(y_re) - self.markerSize)
qp.drawLine(int(x), int(y_re) + self.markerSize,
int(x) + self.markerSize, int(y_re) - self.markerSize)
qp.drawLine(int(x) - self.markerSize, int(y_re) - self.markerSize,
int(x) + self.markerSize, int(y_re) - self.markerSize)
qp.drawLine(int(x), int(y_im) + 3, int(x) - 3, int(y_im) - 3)
qp.drawLine(int(x), int(y_im) + 3, int(x) + 3, int(y_im) - 3)
qp.drawLine(int(x) - 3, int(y_im) - 3, int(x) + 3, int(y_im) - 3)
qp.drawLine(int(x), int(y_im) + self.markerSize,
int(x) - self.markerSize, int(y_im) - self.markerSize)
qp.drawLine(int(x), int(y_im) + self.markerSize,
int(x) + self.markerSize, int(y_im) - self.markerSize)
qp.drawLine(int(x) - self.markerSize, int(y_im) - self.markerSize,
int(x) + self.markerSize, int(y_im) - self.markerSize)
def getImYPosition(self, d: Datapoint) -> int:
_, im = RFTools.normalize50(d)

Wyświetl plik

@ -1044,7 +1044,7 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
display_options_layout.addRow("Point size", self.pointSizeInput)
self.lineThicknessInput = QtWidgets.QSpinBox()
linethickness = self.app.settings.value("LineThickness", 2, int)
linethickness = self.app.settings.value("LineThickness", 1, int)
self.lineThicknessInput.setValue(linethickness)
self.changeLineThickness(linethickness)
self.lineThicknessInput.setMinimum(1)
@ -1054,6 +1054,19 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
self.lineThicknessInput.valueChanged.connect(self.changeLineThickness)
display_options_layout.addRow("Line thickness", self.lineThicknessInput)
self.markerSizeInput = QtWidgets.QSpinBox()
markersize = self.app.settings.value("MarkerSize", 6, int)
self.markerSizeInput.setValue(markersize)
self.changeMarkerSize(markersize)
self.markerSizeInput.setMinimum(4)
self.markerSizeInput.setMaximum(20)
self.markerSizeInput.setSingleStep(2)
self.markerSizeInput.setSuffix(" px")
self.markerSizeInput.setAlignment(QtCore.Qt.AlignRight)
self.markerSizeInput.valueChanged.connect(self.changeMarkerSize)
self.markerSizeInput.editingFinished.connect(self.validateMarkerSize)
display_options_layout.addRow("Marker size", self.markerSizeInput)
color_options_box = QtWidgets.QGroupBox("Chart colors")
color_options_layout = QtWidgets.QFormLayout(color_options_box)
@ -1193,7 +1206,6 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
selections.append(c.name)
selections.append("None")
# TODO: Make this tolerant of non-existant charts
chart00_selection = QtWidgets.QComboBox()
chart00_selection.addItems(selections)
chart00 = self.app.settings.value("Chart00", "S11 Smith Chart")
@ -1366,6 +1378,17 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
for c in self.app.subscribing_charts:
c.setLineThickness(size)
def changeMarkerSize(self, size: int):
if size % 2 == 0:
self.app.settings.setValue("MarkerSize", size)
for c in self.app.subscribing_charts:
c.setMarkerSize(int(size / 2))
def validateMarkerSize(self):
size = self.markerSizeInput.value()
if size % 2 != 0:
self.markerSizeInput.setValue(size + 1)
def changeDarkMode(self):
state = self.dark_mode_option.isChecked()
self.app.settings.setValue("DarkMode", state)