src/RangedSlider.cpp

changeset 96
c36fef8bb088
parent 92
fb0bb9a2a7e1
child 97
8283bbf95806
--- a/src/RangedSlider.cpp	Thu Mar 31 16:24:03 2022 +0200
+++ b/src/RangedSlider.cpp	Thu Mar 31 17:16:44 2022 +0200
@@ -22,7 +22,6 @@
  */
 
 #include "RangedSlider.h"
-//#include "brewtarget.h"
 #include <QPaintEvent>
 #include <QPainter>
 #include <QColor>
@@ -46,7 +45,6 @@
      _prefMin(0.25),
      _prefMax(0.75),
      _val(0.5),
-     _valText("0.500"),
      _prec(3),
      _tickInterval(0),
      _secondaryTicks(1),
@@ -56,9 +54,6 @@
      _prefRangePen(Qt::NoPen),
      _markerBrush(QColor(255,255,255)),
      _markerTextIsValue(false),
-     valueTextFont("Arial",
-                   14,             // QFonts are specified in point size, so the hard-coded number is fine here.
-                   QFont::Black),  // Note that QFont::Black is a weight (more bold than ExtraBold), not a colour.
      indicatorTextFont("Arial",
                        10,
                        QFont::Normal) // Previously we just did the indicator text in 'default' font
@@ -112,7 +107,7 @@
 void RangedSlider::setValue(double value)
 {
    _val = value;
-   _valText = QString("%1").arg(_val, 0, 'f', _prec);
+//   _valText = QString("%1").arg(_val, 0, 'f', _prec);
    update();
 
    // See comment in constructor for why we call this here
@@ -215,8 +210,8 @@
    // could end up painting us into a corner.
    //
    QFontMetrics indicatorTextFontMetrics(this->indicatorTextFont);
-   QFontMetrics valueTextFontMetrics(this->valueTextFont);
-   this->heightInPixels = indicatorTextFontMetrics.lineSpacing() + valueTextFontMetrics.lineSpacing();
+//   QFontMetrics valueTextFontMetrics(this->valueTextFont);
+   this->heightInPixels = indicatorTextFontMetrics.lineSpacing()/* + valueTextFontMetrics.lineSpacing()*/;
    return;
 }
 
@@ -256,8 +251,8 @@
    //    |-------------------------------------------------------------|
    //    |                   Indicator text               | B L A N K  |
    //    |------------------------------------------------+------------|
-   //    | <--------------- Graphical Area -------------> | Value text |
-   //    |-------------------------------------------------------------|
+   //    | <--------------- Graphical Area -------------> |
+   //    |------------------------------------------------|
    //
    // The graphical area has:
    //  - a background rectangle of the full width of the area, representing the range from this->_min to this->_max
@@ -276,12 +271,6 @@
 
    QFontMetrics indicatorTextFontMetrics(this->indicatorTextFont);
    int indicatorTextHeight = indicatorTextFontMetrics.lineSpacing();
-
-   // The heights of the slider graphic and the value text are usually the same, but we calculate them differently in
-   // case, in future, we want to squeeze things up a bit.
-   QFontMetrics valueTextFontMetrics(this->valueTextFont);
-   int valueTextHeight = valueTextFontMetrics.lineSpacing();
-
    int graphicalAreaHeight = this->height() - indicatorTextHeight;
 
    // Although the Qt calls take an x- and a y- radius, we want the radius on the rectangle corners to be the same
@@ -294,21 +283,6 @@
    static const QColor indicatorTextColor(0,0,0);
    static const QColor valueTextColor(0,127,0);
 
-   // We need to allow for the width of the text that displays to the right of the slider showing the current value.
-   // If there were just one slider, we might ask Qt for the width of this text with one of the following calls:
-   //    const int valueTextWidth = valueTextFontMetrics.width(_valText);              // Pre Qt 5.13
-   //    const int valueTextWidth = valueTextFontMetrics.horizontalAdvance(_valText);  // Since Qt 5.13
-   // However, we want all the sliders to have exact same width, so we choose some representative text to measure the
-   // width of.  We assume that all sliders show no more than 4 digits and a decimal point, and then add a space to
-   // ensure a gap between the value text and the graphical area.  (Note that digits are all the same width in the font
-   // we are using.
-   int valueTextWidth =
-#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
-      valueTextFontMetrics.width(" 1.000");
-#else
-      valueTextFontMetrics.horizontalAdvance(" 1.000");
-#endif
-
    QLinearGradient glassGrad( QPointF(0,0), QPointF(0,graphicalAreaHeight) );
    glassGrad.setColorAt( 0, QColor(255,255,255,127) );
    glassGrad.setColorAt( 1, QColor(255,255,255,0) );
@@ -321,7 +295,7 @@
    QPainter painter(this);
 
    // Work out the left-to-right (ie x-coordinate) positions of things in the graphical area
-   double graphicalAreaWidth  = this->width() - valueTextWidth;
+   double graphicalAreaWidth  = this->width()/* - valueTextWidth*/;
    double range               = this->_max - this->_min;
    double fgRectLeft          = graphicalAreaWidth * ((this->_prefMin - this->_min    )/range);
    double fgRectWidth         = graphicalAreaWidth * ((this->_prefMax - this->_prefMin)/range);
@@ -338,9 +312,7 @@
    // First we ask the painter what size rectangle it will need to display this text
    painter.setPen(indicatorTextColor);
    painter.setFont(this->indicatorTextFont);
-   QRectF indicatorTextRect = painter.boundingRect(QRectF(),
-                                                   Qt::AlignCenter | Qt::AlignBottom,
-                                                   this->_markerTextIsValue ? this->_valText : this->_markerText);
+   QRectF indicatorTextRect = painter.boundingRect(QRectF(), Qt::AlignCenter | Qt::AlignBottom, this->_markerText);
 
    // Then we use the size of this rectangle to try to make the middle of the text sit over the indicator marker on
    // the slider - but bounding things so that the text doesn't go off the edge of the slider.
@@ -352,20 +324,9 @@
    painter.drawText(
       indicatorTextLeft, 0,
       indicatorTextRect.width(), indicatorTextRect.height(),
-      Qt::AlignCenter | Qt::AlignBottom,
-      this->_markerTextIsValue ? this->_valText : this->_markerText
+      Qt::AlignCenter | Qt::AlignBottom, this->_markerText
    );
 
-   // Next draw the value text
-   // We work out its vertical position relative to the bottom of the graphical area in case (in future) we want to be
-   // able to use some of the blank space above it (to the right of the indicator text).
-   painter.setPen(valueTextColor);
-   painter.setFont(this->valueTextFont);
-   painter.drawText(graphicalAreaWidth, this->height() - valueTextHeight,
-                    valueTextWidth, valueTextHeight,
-                    Qt::AlignRight | Qt::AlignVCenter,
-                    this->_valText );
-
    // All the rest of what we need to do is inside the graphical area, so move the origin to the top-left corner of it
    painter.translate(0, indicatorTextRect.height());
    painter.setPen(Qt::NoPen);

mercurial