diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp index 7e4099c..6c3e8d0 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp @@ -17,6 +17,7 @@ #include #include #include +#include std::set TracePlot::plots; @@ -233,13 +234,24 @@ void TracePlot::paintEvent(QPaintEvent *event) p.setBackground(QBrush(pref.Graphs.Color.background)); p.fillRect(0, 0, width(), height(), QBrush(pref.Graphs.Color.background)); + marginTop = 0; + // draw title + if(!title.isEmpty()) { + QFont font = p.font(); + font.setPixelSize(pref.Graphs.fontSizeTitle); + p.setFont(font); + p.setPen(Util::getFontColorFromBackground(pref.Graphs.Color.background)); + p.drawText(QRect(0, 0, width(), pref.Graphs.fontSizeTitle), Qt::AlignCenter, title); + marginTop += pref.Graphs.fontSizeTitle; + } + // show names of active traces and marker data (if enabled) bool hasMarkerData = false; auto marginMarkerData = pref.Graphs.fontSizeMarkerData * 12.5; - marginTop = pref.Graphs.fontSizeTraceNames + 8; + auto traceNameTop = marginTop + 5; + marginTop += pref.Graphs.fontSizeTraceNames + 8; int x = 1; // xcoordinate for the next trace name int y = marginTop; // ycoordinate for the next marker data - auto areaTextTop = 5; auto labelMarginRight = 4; auto borderRadius = 5; for(auto t : traces) { @@ -248,7 +260,7 @@ void TracePlot::paintEvent(QPaintEvent *event) } // Trace name - auto textArea = QRect(x, areaTextTop, width() - x, marginTop); + auto textArea = QRect(x, traceNameTop, width() - x, pref.Graphs.fontSizeTraceNames + 8); QFont font = p.font(); font.setPixelSize(pref.Graphs.fontSizeTraceNames); p.setFont(font); @@ -384,6 +396,13 @@ void TracePlot::paintEvent(QPaintEvent *event) void TracePlot::finishContextMenu() { contextmenu->addSeparator(); + auto setTitle = new QAction("Set Title", contextmenu); + contextmenu->addAction(setTitle); + connect(setTitle, &QAction::triggered, [=](){ + title = QInputDialog::getText(contextmenu, "Set new graph title", "Enter new title:", QLineEdit::Normal, title); + }); + contextmenu->addSeparator(); + if(parentTile) { auto add = new QMenu("Add tile...", contextmenu); auto left = new QAction("to the left", contextmenu); @@ -723,6 +742,18 @@ QRect TracePlot::getDropRect() return QRect(QPoint(w*dropBorders, h*dropBorders), QSize(w*(1.0-2*dropBorders), h*(1.0-2*dropBorders))); } +nlohmann::json TracePlot::getBaseJSON() +{ + nlohmann::json j; + j["title"] = title.toStdString(); + return j; +} + +void TracePlot::parseBaseJSON(nlohmann::json j) +{ + title = QString::fromStdString(j.value("title", "")); +} + std::set TracePlot::getPlots() { return plots; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.h b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.h index 0aca1f9..9e0257b 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.h @@ -103,6 +103,10 @@ protected: virtual QString mouseText(QPoint pos) {Q_UNUSED(pos) return QString();} QRect getDropRect(); + // save/load base class members. Should be called by derived classes in the toJSON/fromJSON functions + nlohmann::json getBaseJSON(); + void parseBaseJSON(nlohmann::json j); + protected slots: void newTraceAvailable(Trace *t); void traceDeleted(Trace *t); @@ -150,6 +154,9 @@ protected: unsigned int marginTop; bool limitPassing; + +private: + QString title; }; #endif // TRACEPLOT_H diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp index 313d69d..8de5b17 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp @@ -23,7 +23,7 @@ TracePolar::TracePolar(TraceModel &model, QWidget *parent) nlohmann::json TracePolar::toJSON() { - nlohmann::json j; + nlohmann::json j = getBaseJSON(); j["limit_to_span"] = limitToSpan; j["limit_to_edge"] = limitToEdge; j["edge_reflection"] = edgeReflection; @@ -44,6 +44,7 @@ nlohmann::json TracePolar::toJSON() void TracePolar::fromJSON(nlohmann::json j) { + parseBaseJSON(j); limitToSpan = j.value("limit_to_span", true); limitToEdge = j.value("limit_to_edge", false); edgeReflection = j.value("edge_reflection", 1.0); diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp index 04e90f0..2177cdc 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp @@ -95,6 +95,7 @@ void TraceWaterfall::replot() void TraceWaterfall::fromJSON(nlohmann::json j) { + parseBaseJSON(j); resetWaterfall(); pixelsPerLine = j.value("pixelsPerLine", pixelsPerLine); maxDataSweeps = j.value("maxLines", maxDataSweeps); @@ -127,7 +128,7 @@ void TraceWaterfall::fromJSON(nlohmann::json j) nlohmann::json TraceWaterfall::toJSON() { - nlohmann::json j; + nlohmann::json j = getBaseJSON(); j["pixelsPerLine"] = pixelsPerLine; j["direction"] = dir == Direction::TopToBottom ? "TopToBottom" : "BottomToTop"; j["keepDataBeyondPlot"] = keepDataBeyondPlotSize; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp index 7a3e7ea..0f374ae 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp @@ -157,7 +157,7 @@ void TraceXYPlot::setAuto(bool horizontally, bool vertically) nlohmann::json TraceXYPlot::toJSON() { - nlohmann::json j; + nlohmann::json j = getBaseJSON(); nlohmann::json jX; jX["type"] = xAxis.TypeToName().toStdString(); jX["mode"] = AxisModeToName(xAxisMode).toStdString(); @@ -198,6 +198,7 @@ nlohmann::json TraceXYPlot::toJSON() void TraceXYPlot::fromJSON(nlohmann::json j) { + parseBaseJSON(j); auto jX = j["XAxis"]; // old format used enum value for type and mode, new format uses string encoding (more robust when additional enum values are added). // Check which format is used and parse accordingly diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.cpp b/Software/PC_Application/LibreVNA-GUI/preferences.cpp index f6adb7f..c009d8b 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.cpp +++ b/Software/PC_Application/LibreVNA-GUI/preferences.cpp @@ -295,6 +295,7 @@ void PreferencesDialog::setInitialGUIState() ui->GraphsLimitIndication->setCurrentIndex((int) p->Graphs.limitIndication); ui->GraphsLimitNaNpasses->setCurrentIndex(p->Graphs.limitNaNpasses ? 1 : 0); ui->GraphsLineWidth->setValue(p->Graphs.lineWidth); + ui->GraphsFontSizeTitle->setValue(p->Graphs.fontSizeTitle); ui->GraphsFontSizeAxis->setValue(p->Graphs.fontSizeAxis); ui->GraphsFontSizeCursorOverlay->setValue(p->Graphs.fontSizeCursorOverlay); ui->GraphsFontSizeMarkerData->setValue(p->Graphs.fontSizeMarkerData); @@ -416,6 +417,7 @@ void PreferencesDialog::updateFromGUI() p->Graphs.limitIndication = (GraphLimitIndication) ui->GraphsLimitIndication->currentIndex(); p->Graphs.limitNaNpasses = ui->GraphsLimitNaNpasses->currentIndex() == 1; p->Graphs.lineWidth = ui->GraphsLineWidth->value(); + p->Graphs.fontSizeTitle = ui->GraphsFontSizeTitle->value(); p->Graphs.fontSizeAxis = ui->GraphsFontSizeAxis->value(); p->Graphs.fontSizeCursorOverlay = ui->GraphsFontSizeCursorOverlay->value(); p->Graphs.fontSizeMarkerData = ui->GraphsFontSizeMarkerData->value(); diff --git a/Software/PC_Application/LibreVNA-GUI/preferences.h b/Software/PC_Application/LibreVNA-GUI/preferences.h index 35096de..f3b7dfa 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferences.h +++ b/Software/PC_Application/LibreVNA-GUI/preferences.h @@ -136,6 +136,7 @@ public: bool limitNaNpasses; double lineWidth; + int fontSizeTitle; int fontSizeAxis; int fontSizeMarkerData; int fontSizeTraceNames; @@ -274,6 +275,7 @@ private: {&Graphs.limitIndication, "Graphs.limitIndication", GraphLimitIndication::PassFailText}, {&Graphs.limitNaNpasses, "Graphs.limitNaNpasses", false}, {&Graphs.lineWidth, "Graphs.lineWidth", 1.0}, + {&Graphs.fontSizeTitle, "Graphs.fontSizeTitle", 18}, {&Graphs.fontSizeAxis, "Graphs.fontSizeAxis", 10}, {&Graphs.fontSizeCursorOverlay, "Graphs.fontSizeCursorOverlay", 12}, {&Graphs.fontSizeMarkerData, "Graphs.fontSizeMarkerData", 12}, diff --git a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui index e81217e..9078999 100644 --- a/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui +++ b/Software/PC_Application/LibreVNA-GUI/preferencesdialog.ui @@ -953,9 +953,9 @@ 0 - -622 + 0 683 - 1185 + 1217 @@ -1066,62 +1066,76 @@ - + Font (axes): - + 1 - + 1 - + 1 - + 1 - + Font (trace names): - + Font (marker data): - + Font (cursor overlay): + + + + Font (title): + + + + + + + 1 + + +