kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
- Custom colour selection
rodzic
9082fb7482
commit
8072016817
|
@ -29,6 +29,7 @@ class Chart(QtWidgets.QWidget):
|
|||
referenceColor: QtGui.QColor = QtGui.QColor(QtCore.Qt.blue)
|
||||
referenceColor.setAlpha(64)
|
||||
backgroundColor: QtGui.QColor = QtGui.QColor(QtCore.Qt.white)
|
||||
foregroundColor: QtGui.QColor = QtGui.QColor(QtCore.Qt.lightGray)
|
||||
textColor: QtGui.QColor = QtGui.QColor(QtCore.Qt.black)
|
||||
data: List[Datapoint] = []
|
||||
reference: List[Datapoint] = []
|
||||
|
@ -52,6 +53,10 @@ class Chart(QtWidgets.QWidget):
|
|||
self.setPalette(pal)
|
||||
self.update()
|
||||
|
||||
def setForegroundColor(self, color: QtGui.QColor):
|
||||
self.foregroundColor = color
|
||||
self.update()
|
||||
|
||||
def setTextColor(self, color: QtGui.QColor):
|
||||
self.textColor = color
|
||||
self.update()
|
||||
|
@ -160,7 +165,7 @@ class PhaseChart(Chart):
|
|||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
|
||||
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
|
||||
minAngle = -180
|
||||
|
@ -173,7 +178,7 @@ class PhaseChart(Chart):
|
|||
if i != minAngle and i != maxAngle:
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, y+3, str(-i) + "°")
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
|
||||
qp.setPen(self.textColor)
|
||||
qp.drawText(3, 35, str(-minAngle) + "°")
|
||||
|
@ -204,7 +209,7 @@ class PhaseChart(Chart):
|
|||
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
|
||||
qp.setPen(self.textColor)
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
|
@ -315,7 +320,7 @@ class VSWRChart(Chart):
|
|||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
|
||||
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
|
||||
|
||||
|
@ -364,7 +369,7 @@ class VSWRChart(Chart):
|
|||
if i != minVSWR and i != maxVSWR:
|
||||
qp.setPen(self.textColor)
|
||||
qp.drawText(3, y+3, str(i))
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
|
||||
qp.drawLine(self.leftMargin - 5, 30, self.leftMargin + self.chartWidth, 30)
|
||||
qp.setPen(self.textColor)
|
||||
|
@ -375,7 +380,7 @@ class VSWRChart(Chart):
|
|||
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
|
||||
qp.setPen(self.textColor)
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
|
@ -496,7 +501,7 @@ class PolarChart(Chart):
|
|||
centerY = int(self.height()/2)
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawEllipse(QtCore.QPoint(centerX, centerY), int(self.chartWidth/2), int(self.chartHeight/2))
|
||||
qp.drawEllipse(QtCore.QPoint(centerX, centerY), int(self.chartWidth/4), int(self.chartHeight/4))
|
||||
qp.drawLine(centerX - int(self.chartWidth/2), centerY, centerX + int(self.chartWidth/2), centerY)
|
||||
|
@ -642,7 +647,7 @@ class SmithChart(Chart):
|
|||
centerY = int(self.height()/2)
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawEllipse(QtCore.QPoint(centerX, centerY), int(self.chartWidth/2), int(self.chartHeight/2))
|
||||
qp.drawLine(centerX - int(self.chartWidth/2), centerY, centerX + int(self.chartWidth/2), centerY)
|
||||
|
||||
|
@ -791,7 +796,7 @@ class LogMagChart(Chart):
|
|||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, 15, self.name + " (dB)")
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
|
||||
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
|
||||
|
||||
|
@ -838,7 +843,7 @@ class LogMagChart(Chart):
|
|||
self.span = span
|
||||
for i in range(minValue, maxValue, 10):
|
||||
y = 30 + round((i-minValue)/span*(self.chartHeight-10))
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
|
||||
if i > minValue:
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
|
@ -851,7 +856,7 @@ class LogMagChart(Chart):
|
|||
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
|
||||
qp.setPen(self.textColor)
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, LogMagChart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
|
@ -971,7 +976,7 @@ class QualityFactorChart(Chart):
|
|||
from NanoVNASaver.NanoVNASaver import NanoVNASaver
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
|
||||
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
|
||||
maxQ = 0
|
||||
|
@ -996,7 +1001,7 @@ class QualityFactorChart(Chart):
|
|||
y = 30 + round((self.maxQ - i) / self.span * (self.chartHeight-10))
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(3, y+3, str(i))
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
|
||||
qp.drawLine(self.leftMargin - 5, 30, self.leftMargin + self.chartWidth, 30)
|
||||
qp.setPen(self.textColor)
|
||||
|
@ -1027,7 +1032,7 @@ class QualityFactorChart(Chart):
|
|||
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
|
||||
qp.setPen(self.textColor)
|
||||
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
|
||||
|
@ -1129,7 +1134,7 @@ class TDRChart(Chart):
|
|||
width = self.width() - self.leftMargin - self.rightMargin
|
||||
height = self.height() - self.lowerMargin
|
||||
|
||||
qp.setPen(QtCore.Qt.lightGray)
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(self.leftMargin - 5, self.height() - self.lowerMargin, self.width() - self.rightMargin,
|
||||
self.height() - self.lowerMargin)
|
||||
qp.drawLine(self.leftMargin, 20, self.leftMargin, self.height() - self.lowerMargin + 5)
|
||||
|
@ -1142,7 +1147,7 @@ class TDRChart(Chart):
|
|||
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i + 1) * width / ticks)
|
||||
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
|
||||
qp.setPen(QtGui.QPen(self.foregroundColor))
|
||||
qp.drawLine(x, 20, x, height)
|
||||
qp.setPen(QtGui.QPen(self.textColor))
|
||||
qp.drawText(x - 20, 20 + height,
|
||||
|
|
|
@ -1030,6 +1030,33 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
|
|||
|
||||
layout.addWidget(display_options_box)
|
||||
|
||||
color_options_box = QtWidgets.QGroupBox("Colors")
|
||||
color_options_layout = QtWidgets.QFormLayout(color_options_box)
|
||||
|
||||
self.use_custom_colors = QtWidgets.QCheckBox("Use custom colors")
|
||||
self.use_custom_colors.stateChanged.connect(self.changeCustomColors)
|
||||
color_options_layout.addRow(self.use_custom_colors)
|
||||
|
||||
self.btn_background_picker = QtWidgets.QPushButton("█")
|
||||
self.btn_background_picker.setFixedWidth(20)
|
||||
self.btn_background_picker.clicked.connect(lambda: self.setColor("background", QtWidgets.QColorDialog.getColor(self.backgroundColor, options=QtWidgets.QColorDialog.ShowAlphaChannel)))
|
||||
|
||||
color_options_layout.addRow("Chart background", self.btn_background_picker)
|
||||
|
||||
self.btn_foreground_picker = QtWidgets.QPushButton("█")
|
||||
self.btn_foreground_picker.setFixedWidth(20)
|
||||
self.btn_foreground_picker.clicked.connect(lambda: self.setColor("foreground", QtWidgets.QColorDialog.getColor(self.foregroundColor, options=QtWidgets.QColorDialog.ShowAlphaChannel)))
|
||||
|
||||
color_options_layout.addRow("Chart foreground", self.btn_foreground_picker)
|
||||
|
||||
self.btn_text_picker = QtWidgets.QPushButton("█")
|
||||
self.btn_text_picker.setFixedWidth(20)
|
||||
self.btn_text_picker.clicked.connect(lambda: self.setColor("text", QtWidgets.QColorDialog.getColor(self.textColor, options=QtWidgets.QColorDialog.ShowAlphaChannel)))
|
||||
|
||||
color_options_layout.addRow("Chart text", self.btn_text_picker)
|
||||
|
||||
layout.addWidget(color_options_box)
|
||||
|
||||
charts_box = QtWidgets.QGroupBox("Displayed charts")
|
||||
charts_layout = QtWidgets.QGridLayout(charts_box)
|
||||
|
||||
|
@ -1096,6 +1123,34 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
|
|||
self.dark_mode_option.setChecked(self.app.settings.value("DarkMode", False, bool))
|
||||
self.show_lines_option.setChecked(self.app.settings.value("ShowLines", False, bool))
|
||||
|
||||
self.backgroundColor = self.app.settings.value("BackgroundColor", defaultValue=QtGui.QColor("white"),
|
||||
type=QtGui.QColor)
|
||||
self.foregroundColor = self.app.settings.value("ForegroundColor", defaultValue=QtGui.QColor("lightgray"),
|
||||
type=QtGui.QColor)
|
||||
self.textColor = self.app.settings.value("TextColor", defaultValue=QtGui.QColor("black"),
|
||||
type=QtGui.QColor)
|
||||
|
||||
if self.app.settings.value("UseCustomColors", defaultValue=False, type=bool):
|
||||
self.dark_mode_option.setDisabled(True)
|
||||
self.dark_mode_option.setChecked(False)
|
||||
self.use_custom_colors.setChecked(True)
|
||||
else:
|
||||
self.btn_background_picker.setDisabled(True)
|
||||
self.btn_foreground_picker.setDisabled(True)
|
||||
self.btn_text_picker.setDisabled(True)
|
||||
|
||||
p = self.btn_background_picker.palette()
|
||||
p.setColor(QtGui.QPalette.ButtonText, self.backgroundColor)
|
||||
self.btn_background_picker.setPalette(p)
|
||||
|
||||
p = self.btn_foreground_picker.palette()
|
||||
p.setColor(QtGui.QPalette.ButtonText, self.foregroundColor)
|
||||
self.btn_foreground_picker.setPalette(p)
|
||||
|
||||
p = self.btn_text_picker.palette()
|
||||
p.setColor(QtGui.QPalette.ButtonText, self.textColor)
|
||||
self.btn_text_picker.setPalette(p)
|
||||
|
||||
def changeChart(self, x, y, chart):
|
||||
found = None
|
||||
for c in self.app.charts:
|
||||
|
@ -1126,12 +1181,54 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
|
|||
if state:
|
||||
for c in self.app.charts:
|
||||
c.setBackgroundColor(QtGui.QColor(QtCore.Qt.black))
|
||||
c.setForegroundColor(QtGui.QColor(QtCore.Qt.lightGray))
|
||||
c.setTextColor(QtGui.QColor(QtCore.Qt.white))
|
||||
else:
|
||||
for c in self.app.charts:
|
||||
c.setBackgroundColor(QtGui.QColor(QtCore.Qt.white))
|
||||
c.setForegroundColor(QtGui.QColor(QtCore.Qt.lightGray))
|
||||
c.setTextColor(QtGui.QColor(QtCore.Qt.black))
|
||||
|
||||
def changeCustomColors(self):
|
||||
self.app.settings.setValue("UseCustomColors", self.use_custom_colors.isChecked())
|
||||
if self.use_custom_colors.isChecked():
|
||||
self.dark_mode_option.setDisabled(True)
|
||||
self.dark_mode_option.setChecked(False)
|
||||
self.btn_background_picker.setDisabled(False)
|
||||
self.btn_foreground_picker.setDisabled(False)
|
||||
self.btn_text_picker.setDisabled(False)
|
||||
for c in self.app.charts:
|
||||
c.setBackgroundColor(self.backgroundColor)
|
||||
c.setForegroundColor(self.foregroundColor)
|
||||
c.setTextColor(self.textColor)
|
||||
else:
|
||||
self.dark_mode_option.setDisabled(False)
|
||||
self.btn_background_picker.setDisabled(True)
|
||||
self.btn_foreground_picker.setDisabled(True)
|
||||
self.btn_text_picker.setDisabled(True)
|
||||
self.changeDarkMode() # Reset to the default colors depending on Dark Mode setting
|
||||
|
||||
def setColor(self, name: str, color: QtGui.QColor):
|
||||
if name == "background":
|
||||
p = self.btn_background_picker.palette()
|
||||
p.setColor(QtGui.QPalette.ButtonText, color)
|
||||
self.btn_background_picker.setPalette(p)
|
||||
self.backgroundColor = color
|
||||
self.app.settings.setValue("BackgroundColor", color)
|
||||
elif name == "foreground":
|
||||
p = self.btn_foreground_picker.palette()
|
||||
p.setColor(QtGui.QPalette.ButtonText, color)
|
||||
self.btn_foreground_picker.setPalette(p)
|
||||
self.foregroundColor = color
|
||||
self.app.settings.setValue("ForegroundColor", color)
|
||||
elif name == "text":
|
||||
p = self.btn_text_picker.palette()
|
||||
p.setColor(QtGui.QPalette.ButtonText, color)
|
||||
self.btn_text_picker.setPalette(p)
|
||||
self.textColor = color
|
||||
self.app.settings.setValue("TextColor", color)
|
||||
self.changeCustomColors()
|
||||
|
||||
|
||||
class TDRWindow(QtWidgets.QWidget):
|
||||
def __init__(self, app: NanoVNASaver):
|
||||
|
|
|
@ -14,5 +14,5 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
version = '0.0.9'
|
||||
version = '0.0.9a'
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue