customizable font sizes on graphs

This commit is contained in:
Jan Käberich 2022-04-20 15:19:58 +02:00
parent 2cf4c5a311
commit d7830de8d1
9 changed files with 133 additions and 55 deletions

View File

@ -21,7 +21,8 @@ TracePlot::TracePlot(TraceModel &model, QWidget *parent)
selectedMarker(nullptr),
traceRemovalPending(false),
dropPending(false),
dropTrace(nullptr)
dropTrace(nullptr),
marginTop(20)
{
contextmenu = new QMenu();
markedForDeletion = false;
@ -37,9 +38,6 @@ TracePlot::TracePlot(TraceModel &model, QWidget *parent)
cursorLabel = new QLabel("Test", this);
cursorLabel->setStyleSheet("color: white;");
auto font = cursorLabel->font();
font.setPixelSize(12);
cursorLabel->setFont(font);
cursorLabel->hide();
setMouseTracking(true);
setAcceptDrops(true);
@ -155,6 +153,8 @@ void TracePlot::paintEvent(QPaintEvent *event)
// 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;
int x = 1; // xcoordinate for the next trace name
int y = marginTop; // ycoordinate for the next marker data
auto areaTextTop = 5;
@ -168,7 +168,7 @@ void TracePlot::paintEvent(QPaintEvent *event)
// Trace name
auto textArea = QRect(x, areaTextTop, width() - x, marginTop);
QFont font = p.font();
font.setPixelSize(12);
font.setPixelSize(pref.Graphs.fontSizeTraceNames);
p.setFont(font);
p.setPen(t.first->color());
auto space = " ";
@ -194,6 +194,9 @@ void TracePlot::paintEvent(QPaintEvent *event)
continue;
}
hasMarkerData = true;
QFont font = p.font();
font.setPixelSize(pref.Graphs.fontSizeMarkerData);
p.setFont(font);
// Rounded box
auto space = " ";
@ -269,6 +272,9 @@ void TracePlot::mouseMoveEvent(QMouseEvent *event)
cursorLabel->setText(text);
cursorLabel->adjustSize();
cursorLabel->move(event->pos() + QPoint(15, 0));
auto font = cursorLabel->font();
font.setPixelSize(Preferences::getInstance().Graphs.fontSizeCursorOverlay);
cursorLabel->setFont(font);
cursorLabel->show();
} else {
cursorLabel->hide();

View File

@ -88,13 +88,10 @@ protected slots:
virtual void markerRemoved(Marker *m);
virtual bool markerVisible(double x) = 0;
protected:
static constexpr unsigned int marginTop = 20;
static constexpr unsigned int marginBottom = 0;
static constexpr unsigned int marginLeft = 0;
static constexpr unsigned int marginRight = 0;
static constexpr unsigned int marginMarkerData = 150;
double sweep_fmin, sweep_fmax;
TraceModel &model;
Marker *selectedMarker;
@ -108,6 +105,7 @@ protected:
QLabel *cursorLabel;
unsigned int marginTop;
};
#endif // TRACEPLOT_H

View File

@ -214,16 +214,12 @@ void TraceWaterfall::draw(QPainter &p)
{
auto pref = Preferences::getInstance();
// constexpr int yAxisLegendSpace = 25;
// constexpr int yAxisDisabledSpace = 10;
constexpr int xAxisSpace = 30;
int xAxisSpace = pref.Graphs.fontSizeAxis * 3;
constexpr int topMargin = 10;
auto w = p.window();
auto pen = QPen(pref.Graphs.Color.axis, 0);
pen.setCosmetic(true);
p.setPen(pen);
// plotAreaLeft = yAxisDisabledSpace;
// plotAreaWidth = w.width() - 3 * yAxisDisabledSpace - yAxisLegendSpace;
auto leftMargin = TraceXYPlot::sideMargin(align == Alignment::PrimaryOnly || align == Alignment::BothAxes);
auto rightMargin = TraceXYPlot::sideMargin(align == Alignment::SecondaryOnly || align == Alignment::BothAxes);
@ -235,6 +231,9 @@ void TraceWaterfall::draw(QPainter &p)
plotAreaBottom = plotRect.y()+plotRect.height();
// draw Y legend
auto font = p.font();
font.setPixelSize(pref.Graphs.fontSizeAxis);
p.setFont(font);
QRect legendRect;
constexpr int legendMargin = 10;
if(leftMargin < rightMargin) {
@ -271,10 +270,7 @@ void TraceWaterfall::draw(QPainter &p)
p.drawRect(plotRect);
// draw axis types
auto font = p.font();
font.setPixelSize(AxisLabelSize);
p.setFont(font);
p.drawText(QRect(0, w.height()-AxisLabelSize*1.5, w.width(), AxisLabelSize*1.5), Qt::AlignHCenter, xAxis.TypeToName());
p.drawText(QRect(0, w.height()-pref.Graphs.fontSizeAxis*1.5, w.width(), pref.Graphs.fontSizeAxis*1.5), Qt::AlignHCenter, xAxis.TypeToName());
if(xAxis.getTicks().size() >= 1) {
// draw X ticks
@ -313,9 +309,9 @@ void TraceWaterfall::draw(QPainter &p)
back.append("..");
p.setPen(QPen(QColor("orange")));
QRect bounding;
p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding);
p.drawText(QRect(2, plotAreaBottom + pref.Graphs.fontSizeAxis + 5, w.width(), pref.Graphs.fontSizeAxis), 0, front, &bounding);
p.setPen(pref.Graphs.Color.axis);
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back);
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + pref.Graphs.fontSizeAxis + 5, w.width(), pref.Graphs.fontSizeAxis), 0, back);
}
int lastTickLabelEnd = 0;
@ -335,7 +331,7 @@ void TraceWaterfall::draw(QPainter &p)
p.setPen(QPen(pref.Graphs.Color.axis, 1));
if(displayFullFreq) {
QRect bounding;
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, pref.Graphs.fontSizeAxis), Qt::AlignHCenter, tickValue, &bounding);
lastTickLabelEnd = bounding.x() + bounding.width();
} else {
// check if the same prefix was used as in the fullFreq string
@ -346,10 +342,10 @@ void TraceWaterfall::draw(QPainter &p)
tickValue.remove(0, tickValue.size() - displayLastDigits - unit.length());
QRect bounding;
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, pref.Graphs.fontSizeAxis), Qt::AlignHCenter, tickValue, &bounding);
lastTickLabelEnd = bounding.x() + bounding.width();
p.setPen(QPen(QColor("orange")));
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, "..", &bounding);
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, pref.Graphs.fontSizeAxis), Qt::AlignRight, "..", &bounding);
}
}
}

View File

@ -44,8 +44,6 @@ protected slots:
private slots:
void updateYAxis();
private:
static constexpr int AxisLabelSize = 10;
// color scale, input value from 0.0 to 1.0
QColor getColor(double scale);

View File

@ -192,7 +192,7 @@ bool TraceXYPlot::isTDRtype(YAxis::Type type)
int TraceXYPlot::sideMargin(bool YAxisEnabled)
{
if(YAxisEnabled) {
return yAxisSpace;
return Preferences::getInstance().Graphs.fontSizeAxis * 5.5;
} else {
return yAxisDisabledSpace;
}
@ -334,6 +334,8 @@ void TraceXYPlot::draw(QPainter &p)
auto pen = QPen(pref.Graphs.Color.axis, 0);
pen.setCosmetic(true);
p.setPen(pen);
auto yAxisSpace = pref.Graphs.fontSizeAxis * 5.5;
auto xAxisSpace = pref.Graphs.fontSizeAxis * 3;
plotAreaLeft = yAxis[0].getType() == YAxis::Type::Disabled ? yAxisDisabledSpace : yAxisSpace;
plotAreaWidth = w.width();
plotAreaTop = 10;
@ -354,20 +356,20 @@ void TraceXYPlot::draw(QPainter &p)
// draw axis types
auto font = p.font();
font.setPixelSize(AxisLabelSize);
font.setPixelSize(pref.Graphs.fontSizeAxis);
p.setFont(font);
p.drawText(QRect(0, w.height()-AxisLabelSize*1.5, w.width(), AxisLabelSize*1.5), Qt::AlignHCenter, xAxis.TypeToName());
p.drawText(QRect(0, w.height()-pref.Graphs.fontSizeAxis*1.5, w.width(), pref.Graphs.fontSizeAxis*1.5), Qt::AlignHCenter, xAxis.TypeToName());
for(int i=0;i<2;i++) {
if(yAxis[i].getType() == YAxis::Type::Disabled) {
continue;
}
QString labelY = yAxis[i].TypeToName();
p.setPen(QPen(pref.Graphs.Color.axis, 1));
auto xStart = i == 0 ? 0 : w.width() - AxisLabelSize * 1.5;
auto xStart = i == 0 ? 0 : w.width() - pref.Graphs.fontSizeAxis * 1.5;
p.save();
p.translate(xStart, w.height()-xAxisSpace);
p.rotate(-90);
p.drawText(QRect(0, 0, w.height()-xAxisSpace, AxisLabelSize*1.5), Qt::AlignHCenter, labelY);
p.drawText(QRect(0, 0, w.height()-xAxisSpace, pref.Graphs.fontSizeAxis*1.5), Qt::AlignHCenter, labelY);
p.restore();
// draw ticks
if(yAxis[i].getType() != YAxis::Type::Disabled && yAxis[i].getTicks().size() > 0) {
@ -397,9 +399,9 @@ void TraceXYPlot::draw(QPainter &p)
}
auto tickValue = Unit::ToString(yAxis[i].getTicks()[j], unit, prefix, significantDigits);
if(i == 0) {
p.drawText(QRectF(0, yCoord - AxisLabelSize/2 - 2, tickStart + 2 * tickLen, AxisLabelSize), Qt::AlignRight, tickValue);
p.drawText(QRectF(0, yCoord - pref.Graphs.fontSizeAxis/2 - 2, tickStart + 2 * tickLen, pref.Graphs.fontSizeAxis), Qt::AlignRight, tickValue);
} else {
p.drawText(QRectF(tickStart + 2 * tickLen + 2, yCoord - AxisLabelSize/2 - 2, yAxisSpace, AxisLabelSize), Qt::AlignLeft, tickValue);
p.drawText(QRectF(tickStart + 2 * tickLen + 2, yCoord - pref.Graphs.fontSizeAxis/2 - 2, yAxisSpace, pref.Graphs.fontSizeAxis), Qt::AlignLeft, tickValue);
}
// tick lines
@ -540,9 +542,9 @@ void TraceXYPlot::draw(QPainter &p)
back.append("..");
p.setPen(QPen(QColor("orange")));
QRect bounding;
p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding);
p.drawText(QRect(2, plotAreaBottom + pref.Graphs.fontSizeAxis + 5, w.width(), pref.Graphs.fontSizeAxis), 0, front, &bounding);
p.setPen(pref.Graphs.Color.axis);
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back);
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + pref.Graphs.fontSizeAxis + 5, w.width(), pref.Graphs.fontSizeAxis), 0, back);
}
int lastTickLabelEnd = 0;
@ -562,7 +564,7 @@ void TraceXYPlot::draw(QPainter &p)
p.setPen(QPen(pref.Graphs.Color.axis, 1));
if(displayFullFreq) {
QRect bounding;
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, pref.Graphs.fontSizeAxis), Qt::AlignHCenter, tickValue, &bounding);
lastTickLabelEnd = bounding.x() + bounding.width();
} else {
// check if the same prefix was used as in the fullFreq string
@ -573,10 +575,10 @@ void TraceXYPlot::draw(QPainter &p)
tickValue.remove(0, tickValue.size() - displayLastDigits - unit.length());
QRect bounding;
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, pref.Graphs.fontSizeAxis), Qt::AlignHCenter, tickValue, &bounding);
lastTickLabelEnd = bounding.x() + bounding.width();
p.setPen(QPen(QColor("orange")));
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, "..", &bounding);
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, pref.Graphs.fontSizeAxis), Qt::AlignRight, "..", &bounding);
}
}
}

View File

@ -46,10 +46,7 @@ protected:
private slots:
void updateAxisTicks();
private:
static constexpr int AxisLabelSize = 10;
static constexpr int yAxisSpace = 55;
static constexpr int yAxisDisabledSpace = 10;
static constexpr int xAxisSpace = 30;
static QString AxisModeToName(XAxisMode mode);
static XAxisMode AxisModeFromName(QString name);
void enableTraceAxis(Trace *t, int axis, bool enabled);

View File

@ -249,6 +249,10 @@ void PreferencesDialog::setInitialGUIState()
ui->GraphsColorTicksBackground->setColor(p->Graphs.Color.Ticks.Background.background);
ui->GraphsDomainChangeBehavior->setCurrentIndex((int) p->Graphs.domainChangeBehavior);
ui->GraphsLineWidth->setValue(p->Graphs.lineWidth);
ui->GraphsFontSizeAxis->setValue(p->Graphs.fontSizeAxis);
ui->GraphsFontSizeCursorOverlay->setValue(p->Graphs.fontSizeCursorOverlay);
ui->GraphsFontSizeMarkerData->setValue(p->Graphs.fontSizeMarkerData);
ui->GraphsFontSizeTraceNames->setValue(p->Graphs.fontSizeTraceNames);
ui->MarkerShowMarkerData->setChecked(p->Marker.defaultBehavior.showDataOnGraphs);
ui->MarkerShowAllMarkerData->setChecked(p->Marker.defaultBehavior.showAllData);
@ -309,6 +313,10 @@ void PreferencesDialog::updateFromGUI()
p->Graphs.Color.Ticks.divisions = ui->GraphsColorTicksDivisions->getColor();
p->Graphs.domainChangeBehavior = (GraphDomainChangeBehavior) ui->GraphsDomainChangeBehavior->currentIndex();
p->Graphs.lineWidth = ui->GraphsLineWidth->value();
p->Graphs.fontSizeAxis = ui->GraphsFontSizeAxis->value();
p->Graphs.fontSizeCursorOverlay = ui->GraphsFontSizeCursorOverlay->value();
p->Graphs.fontSizeMarkerData = ui->GraphsFontSizeMarkerData->value();
p->Graphs.fontSizeTraceNames = ui->GraphsFontSizeTraceNames->value();
p->Marker.defaultBehavior.showDataOnGraphs = ui->MarkerShowMarkerData->isChecked();
p->Marker.defaultBehavior.showAllData = ui->MarkerShowAllMarkerData->isChecked();

View File

@ -95,6 +95,10 @@ public:
GraphDomainChangeBehavior domainChangeBehavior;
double lineWidth;
int fontSizeAxis;
int fontSizeMarkerData;
int fontSizeTraceNames;
int fontSizeCursorOverlay;
} Graphs;
struct {
struct {
@ -163,6 +167,10 @@ private:
{&Graphs.Color.Ticks.divisions, "Graphs.Color.Ticks.divisions", QColor(Qt::gray)},
{&Graphs.domainChangeBehavior, "Graphs.domainChangeBehavior", GraphDomainChangeBehavior::AdjustGraphs},
{&Graphs.lineWidth, "Graphs.lineWidth", 1.0},
{&Graphs.fontSizeAxis, "Graphs.fontSizeAxis", 10},
{&Graphs.fontSizeCursorOverlay, "Graphs.fontSizeCursorOverlay", 12},
{&Graphs.fontSizeMarkerData, "Graphs.fontSizeMarkerData", 12},
{&Graphs.fontSizeTraceNames, "Graphs.fontSizeTraceNames", 12},
{&Marker.defaultBehavior.showDataOnGraphs, "Marker.defaultBehavior.ShowDataOnGraphs", true},
{&Marker.defaultBehavior.showAllData, "Marker.defaultBehavior.ShowAllData", false},
{&Marker.interpolatePoints, "Marker.interpolatePoints", false},

View File

@ -83,7 +83,7 @@
</size>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -945,6 +945,85 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_16">
<property name="title">
<string>Size</string>
</property>
<layout class="QFormLayout" name="formLayout_11">
<item row="0" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>Line Width:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="GraphsLineWidth">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_39">
<property name="text">
<string>Font (axes):</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="GraphsFontSizeAxis">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="GraphsFontSizeTraceNames">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="GraphsFontSizeMarkerData">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="GraphsFontSizeCursorOverlay">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_40">
<property name="text">
<string>Font (trace names):</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_41">
<property name="text">
<string>Font (marker data):</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_42">
<property name="text">
<string>Font (cursor overlay):</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
@ -979,7 +1058,7 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_13">
<property name="title">
<string>Ticks</string>
@ -1028,20 +1107,6 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>Line Width:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="GraphsLineWidth">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>