mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-04 22:17:31 +00:00
Customizable graph colors
This commit is contained in:
parent
978ac89aa9
commit
74e068d8d1
22 changed files with 266 additions and 97 deletions
|
|
@ -1,6 +1,5 @@
|
|||
#include "tracebodeplot.h"
|
||||
#include <QGridLayout>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include "qwtplotpiecewisecurve.h"
|
||||
#include "qwt_series_data.h"
|
||||
#include "trace.h"
|
||||
|
|
@ -13,9 +12,12 @@
|
|||
#include <qwt_symbol.h>
|
||||
#include <qwt_picker_machine.h>
|
||||
#include "bodeplotaxisdialog.h"
|
||||
#include <preferences.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
set<TraceBodePlot*> TraceBodePlot::allPlots;
|
||||
|
||||
static double AxisTransformation(TraceBodePlot::YAxisType type, complex<double> data) {
|
||||
switch(type) {
|
||||
case TraceBodePlot::YAxisType::Magnitude: return 20*log10(abs(data)); break;
|
||||
|
|
@ -58,16 +60,14 @@ TraceBodePlot::TraceBodePlot(TraceModel &model, QWidget *parent)
|
|||
selectedMarker(nullptr)
|
||||
{
|
||||
plot = new QwtPlot(this);
|
||||
plot->setCanvasBackground(Background);
|
||||
auto pal = plot->palette();
|
||||
pal.setColor(QPalette::Window, Background);
|
||||
pal.setColor(QPalette::WindowText, Border);
|
||||
pal.setColor(QPalette::Text, Border);
|
||||
|
||||
auto canvas = new QwtPlotCanvas(plot);
|
||||
canvas->setFrameStyle(QFrame::Plain);
|
||||
plot->setCanvas(canvas);
|
||||
plot->setPalette(pal);
|
||||
plot->setAutoFillBackground(true);
|
||||
grid = new QwtPlotGrid();
|
||||
grid->attach(plot);
|
||||
setColorFromPreferences();
|
||||
|
||||
auto selectPicker = new BodeplotPicker(plot->xBottom, plot->yLeft, QwtPicker::NoRubberBand, QwtPicker::ActiveOnly, plot->canvas());
|
||||
selectPicker->setStateMachine(new QwtPickerClickPointMachine);
|
||||
|
|
@ -81,15 +81,11 @@ TraceBodePlot::TraceBodePlot(TraceModel &model, QWidget *parent)
|
|||
// Marker movement
|
||||
connect(drawPicker, SIGNAL(moved(QPointF)), this, SLOT(moved(QPointF)));
|
||||
|
||||
QwtPlotGrid *grid = new QwtPlotGrid();
|
||||
grid->setMajorPen(QPen(Divisions, 1.0, Qt::DotLine));
|
||||
grid->attach(plot);
|
||||
auto layout = new QGridLayout;
|
||||
layout->addWidget(plot);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(layout);
|
||||
plot->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
// plot->plotLayout()->setAlignCanvasToScales(true);
|
||||
initializeTraceInfo(model);
|
||||
setAutoFillBackground(true);
|
||||
|
||||
|
|
@ -101,6 +97,8 @@ TraceBodePlot::TraceBodePlot(TraceModel &model, QWidget *parent)
|
|||
setXAxis(true, 0, 6000000000, 600000000);
|
||||
// get notified when the span changes
|
||||
connect(&model, &TraceModel::SpanChanged, this, qOverload<double, double>(&TraceBodePlot::setXAxis));
|
||||
|
||||
allPlots.insert(this);
|
||||
}
|
||||
|
||||
TraceBodePlot::~TraceBodePlot()
|
||||
|
|
@ -111,6 +109,7 @@ TraceBodePlot::~TraceBodePlot()
|
|||
}
|
||||
}
|
||||
delete drawPicker;
|
||||
allPlots.erase(this);
|
||||
}
|
||||
|
||||
void TraceBodePlot::setXAxis(double min, double max)
|
||||
|
|
@ -187,32 +186,16 @@ void TraceBodePlot::enableTrace(Trace *t, bool enabled)
|
|||
}
|
||||
}
|
||||
|
||||
void TraceBodePlot::updateGraphColors()
|
||||
{
|
||||
for(auto p : allPlots) {
|
||||
p->setColorFromPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
void TraceBodePlot::updateContextMenu()
|
||||
{
|
||||
contextmenu->clear();
|
||||
// for(int axis = 0;axis < 2;axis++) {
|
||||
// QMenu *axisMenu;
|
||||
// if(axis == 0) {
|
||||
// axisMenu = contextmenu->addMenu("Primary Axis");
|
||||
// } else {
|
||||
// axisMenu = contextmenu->addMenu("Secondary Axis");
|
||||
// }
|
||||
// auto group = new QActionGroup(this);
|
||||
// for(int i=0;i<(int) YAxisType::Last;i++) {
|
||||
// auto action = new QAction(AxisTypeToName((YAxisType) i));
|
||||
// action->setCheckable(true);
|
||||
// group->addAction(action);
|
||||
// if(YAxis[axis].type == (YAxisType) i) {
|
||||
// action->setChecked(true);
|
||||
// }
|
||||
// connect(action, &QAction::triggered, [=](bool active) {
|
||||
// if(active) {
|
||||
// setYAxisType(axis, (YAxisType) i);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// axisMenu->addActions(group->actions());
|
||||
// }
|
||||
auto setup = new QAction("Axis setup...");
|
||||
connect(setup, &QAction::triggered, [this]() {
|
||||
auto setup = new BodeplotAxisDialog(this);
|
||||
|
|
@ -483,13 +466,18 @@ void TraceBodePlot::moved(const QPointF pos)
|
|||
if(!selectedMarker || !selectedCurve) {
|
||||
return;
|
||||
}
|
||||
// int index = selectedCurve->closestPoint(pos.toPoint());
|
||||
// qDebug() << index;
|
||||
// if(index < 0) {
|
||||
// // unable to find closest point
|
||||
// return;
|
||||
// }
|
||||
// selectedMarker->setFrequency(selectedCurve->sample(index).x());
|
||||
selectedMarker->setFrequency(pos.x());
|
||||
}
|
||||
|
||||
void TraceBodePlot::setColorFromPreferences()
|
||||
{
|
||||
auto pref = Preferences::getInstance();
|
||||
plot->setCanvasBackground(pref.General.graphColors.background);
|
||||
auto pal = plot->palette();
|
||||
pal.setColor(QPalette::Window, pref.General.graphColors.background);
|
||||
pal.setColor(QPalette::WindowText, pref.General.graphColors.axis);
|
||||
pal.setColor(QPalette::Text, pref.General.graphColors.axis);
|
||||
plot->setPalette(pal);
|
||||
grid->setPen(pref.General.graphColors.divisions);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_series_data.h>
|
||||
#include <qwt_plot_marker.h>
|
||||
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_plot_picker.h>
|
||||
|
||||
// Derived plotpicker, exposing transformation functions
|
||||
|
|
@ -45,6 +45,9 @@ public:
|
|||
void setXAxis(bool autorange, double min, double max, double div);
|
||||
void enableTrace(Trace *t, bool enabled) override;
|
||||
|
||||
// Applies potentially changed colors to all bodeplots
|
||||
static void updateGraphColors();
|
||||
|
||||
protected:
|
||||
virtual void updateContextMenu();
|
||||
virtual bool supported(Trace *t);
|
||||
|
|
@ -60,6 +63,7 @@ private slots:
|
|||
void clicked(const QPointF pos);
|
||||
void moved(const QPointF pos);
|
||||
private:
|
||||
void setColorFromPreferences();
|
||||
QString AxisTypeToName(YAxisType type);
|
||||
void enableTraceAxis(Trace *t, int axis, bool enabled);
|
||||
bool supported(Trace *t, YAxisType type);
|
||||
|
|
@ -89,10 +93,14 @@ private:
|
|||
std::map<Trace*, CurveData> curves[2];
|
||||
std::map<TraceMarker*, QwtPlotMarker*> markers;
|
||||
QwtPlot *plot;
|
||||
QwtPlotGrid *grid;
|
||||
TraceMarker *selectedMarker;
|
||||
QwtPlotCurve *selectedCurve;
|
||||
|
||||
BodeplotPicker *drawPicker;
|
||||
|
||||
// keep track of all created plots for changing colors
|
||||
static std::set<TraceBodePlot*> allPlots;
|
||||
};
|
||||
|
||||
#endif // TRACEBODEPLOT_H
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) :
|
|||
{
|
||||
ui->setupUi(this);
|
||||
ui->name->setText(t.name());
|
||||
setColor(trace.color());
|
||||
ui->color->setColor(trace.color());
|
||||
connect(ui->color, &ColorPickerButton::colorChanged, [=](const QColor& color){
|
||||
trace.setColor(color);
|
||||
});
|
||||
|
||||
ui->GSource->setId(ui->bLive, 0);
|
||||
ui->GSource->setId(ui->bFile, 1);
|
||||
|
|
@ -98,13 +101,6 @@ TraceEditDialog::~TraceEditDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void TraceEditDialog::on_color_clicked()
|
||||
{
|
||||
auto color = QColorDialog::getColor(trace.color(), this, "Select color", QColorDialog::DontUseNativeDialog);
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
|
||||
void TraceEditDialog::on_buttonBox_accepted()
|
||||
{
|
||||
trace.setName(ui->name->text());
|
||||
|
|
@ -139,13 +135,3 @@ void TraceEditDialog::on_buttonBox_accepted()
|
|||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void TraceEditDialog::setColor(QColor c)
|
||||
{
|
||||
QPalette pal = ui->color->palette();
|
||||
pal.setColor(QPalette::Button, c);
|
||||
ui->color->setAutoFillBackground(true);
|
||||
ui->color->setPalette(pal);
|
||||
ui->color->update();
|
||||
trace.setColor(c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,9 @@ public:
|
|||
~TraceEditDialog();
|
||||
|
||||
private slots:
|
||||
void on_color_clicked();
|
||||
void on_buttonBox_accepted();
|
||||
|
||||
private:
|
||||
void setColor(QColor c);
|
||||
Ui::TraceEditDialog *ui;
|
||||
Trace &trace;
|
||||
bool VNAtrace;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="color">
|
||||
<widget class="ColorPickerButton" name="color">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
@ -162,6 +162,11 @@
|
|||
<header>CustomWidgets/touchstoneimport.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ColorPickerButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>CustomWidgets/colorpickerbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
|
|
|||
|
|
@ -117,6 +117,8 @@ QString TraceMarker::readableData()
|
|||
return ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return "Unknown marker type";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -378,6 +380,7 @@ void TraceMarker::adjustSettings(double value)
|
|||
case Type::Delta:
|
||||
default:
|
||||
setFrequency(value);
|
||||
/* no break */
|
||||
case Type::Lowpass:
|
||||
case Type::Highpass:
|
||||
case Type::Bandpass:
|
||||
|
|
@ -396,6 +399,7 @@ void TraceMarker::update()
|
|||
}
|
||||
switch(type) {
|
||||
case Type::Manual:
|
||||
case Type::Delta:
|
||||
// nothing to do
|
||||
break;
|
||||
case Type::Maximum:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "traceplot.h"
|
||||
|
||||
const QColor TracePlot::Background = QColor(0,0,0);
|
||||
const QColor TracePlot::Border = QColor(255,255,255);
|
||||
const QColor TracePlot::Divisions = QColor(255,255,255);
|
||||
//const QColor TracePlot::Background = QColor(0,0,0);
|
||||
//const QColor TracePlot::Border = QColor(255,255,255);
|
||||
//const QColor TracePlot::Divisions = QColor(255,255,255);
|
||||
#include "tracemarker.h"
|
||||
|
||||
std::set<TracePlot*> TracePlot::plots;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ signals:
|
|||
void deleted(TracePlot*);
|
||||
|
||||
protected:
|
||||
static const QColor Background;// = QColor(0,0,0);
|
||||
static const QColor Border;// = QColor(255,255,255);
|
||||
static const QColor Divisions;// = QColor(255,255,255);
|
||||
// static const QColor Background;// = QColor(0,0,0);
|
||||
// static const QColor Border;// = QColor(255,255,255);
|
||||
// static const QColor Divisions;// = QColor(255,255,255);
|
||||
static constexpr int MinUpdateInterval = 100;
|
||||
// need to be called in derived class constructor
|
||||
void initializeTraceInfo(TraceModel &model);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <math.h>
|
||||
#include "tracemarker.h"
|
||||
#include <QDebug>
|
||||
#include "preferences.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -92,13 +93,15 @@ void TraceSmithChart::draw(QPainter * painter, double width_factor) {
|
|||
// painter->setFont(font);
|
||||
// painter->drawText(-512, -512, title);
|
||||
|
||||
auto pref = Preferences::getInstance();
|
||||
|
||||
// Outer circle
|
||||
painter->setPen(QPen(Border, 1.5 * width_factor));
|
||||
painter->setPen(QPen(pref.General.graphColors.axis, 1.5 * width_factor));
|
||||
QRectF rectangle(-smithCoordMax, -smithCoordMax, 2*smithCoordMax, 2*smithCoordMax);
|
||||
painter->drawArc(rectangle, 0, 5760);
|
||||
|
||||
constexpr int Circles = 6;
|
||||
painter->setPen(QPen(Divisions, 0.5 * width_factor, Qt::DashLine));
|
||||
painter->setPen(QPen(pref.General.graphColors.divisions, 0.5 * width_factor, Qt::DashLine));
|
||||
for(int i=1;i<Circles;i++) {
|
||||
rectangle.adjust(2*smithCoordMax/Circles, smithCoordMax/Circles, 0, -smithCoordMax/Circles);
|
||||
painter->drawArc(rectangle, 0, 5760);
|
||||
|
|
@ -162,10 +165,11 @@ void TraceSmithChart::replot()
|
|||
|
||||
void TraceSmithChart::paintEvent(QPaintEvent * /* the event */)
|
||||
{
|
||||
auto pref = Preferences::getInstance();
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setBackground(QBrush(Background));
|
||||
painter.fillRect(0, 0, width(), height(), QBrush(Background));
|
||||
painter.setBackground(QBrush(pref.General.graphColors.background));
|
||||
painter.fillRect(0, 0, width(), height(), QBrush(pref.General.graphColors.background));
|
||||
|
||||
double side = qMin(width(), height()) * screenUsage;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue