From d7957363ffe86cb3fa2d01112a158b45b8692d12 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Fri, 1 Oct 2021 12:47:53 +0100 Subject: [PATCH] Fix Legend Proportions (and spacing bug) .. legend item spacing and linewidth is now proportional to the text height, which resolves the jarring sizes when not scaled. .. there was a bug related to the height calculation that did not take into account the space left below the colored line which made it overlap the text. --- src/Charts/GenericLegend.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Charts/GenericLegend.cpp b/src/Charts/GenericLegend.cpp index d1700ccd5..5a7658206 100644 --- a/src/Charts/GenericLegend.cpp +++ b/src/Charts/GenericLegend.cpp @@ -52,11 +52,6 @@ GenericLegendItem::GenericLegendItem(Context *context, GenericLegend *parent, QS void GenericLegendItem::configChanged(qint32) { - static const double gl_margin = 5 * dpiXFactor*legend->plot()->scale(); - static const double gl_spacer = 2 * dpiXFactor*legend->plot()->scale(); - static const double gl_block = 7 * dpiXFactor*legend->plot()->scale(); - static const double gl_linewidth = 1 * dpiXFactor*legend->plot()->scale(); - // we just set geometry for now. QFont f; // based on what just got set in prefs // we need to scale... @@ -65,13 +60,21 @@ GenericLegendItem::configChanged(qint32) // so now the string we would display QString valuelabel = QString ("%1").arg("9999999.999"); // xxx later we might have scale/dp + double textheight = fm.boundingRect(valuelabel).height(); + + double gl_linefactor = 0.1; // width is proportional to text height + double gl_spacefactor = 0.05; // spacing is proportional to text height + double gl_margin = 4 * dpiXFactor*legend->plot()->scale(); + double gl_block = 4 * dpiXFactor*legend->plot()->scale(); + double gl_spacer = gl_spacefactor * textheight; + double gl_linewidth = gl_linefactor * textheight; // maximum width of widget = margin + block + space + name + space + value + margin double width = gl_margin + gl_block + gl_spacer + fm.boundingRect(name).width() + gl_spacer + fm.boundingRect(valuelabel).width() + gl_margin; // maximum height of widget = margin + textheight + spacer + line - double height = (gl_margin*2) + fm.boundingRect(valuelabel).height() + gl_spacer + gl_linewidth; + double height = (gl_margin*3) + fm.boundingRect(valuelabel).height() + gl_spacer + gl_linewidth; // now set geometry of widget setFixedWidth(width);