Removed the ugly green value text from the ranged slider.

Thu, 31 Mar 2022 17:16:44 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 31 Mar 2022 17:16:44 +0200
changeset 96
c36fef8bb088
parent 95
ef6048186cb3
child 97
8283bbf95806

Removed the ugly green value text from the ranged slider.

designer/RangedSliderPlugin.cpp file | annotate | diff | comparison | revisions
src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/RangedSlider.cpp file | annotate | diff | comparison | revisions
src/RangedSlider.h file | annotate | diff | comparison | revisions
ui/EditRecipe.ui file | annotate | diff | comparison | revisions
--- a/designer/RangedSliderPlugin.cpp	Thu Mar 31 16:24:03 2022 +0200
+++ b/designer/RangedSliderPlugin.cpp	Thu Mar 31 17:16:44 2022 +0200
@@ -83,12 +83,6 @@
 {
    return "<ui language=\"c++\">\n"
 	  " <widget class=\"RangedSlider\" name=\"rangedSliderWidget\">\n"
-          "  <property name=\"toolTip\" >\n"
-          "   <string>The ranged slider</string>\n"
-          "  </property>\n"
-          "  <property name=\"whatsThis\" >\n"
-          "   <string>Slider that shows if a value is in range.</string>\n"
-          "  </property>\n"
           " </widget>\n"
           "</ui>\n";
 }
--- a/src/EditRecipe.cpp	Thu Mar 31 16:24:03 2022 +0200
+++ b/src/EditRecipe.cpp	Thu Mar 31 17:16:44 2022 +0200
@@ -96,14 +96,21 @@
 
 	ui->est_colorEdit->setValue(query.value(31).toDouble());
 	QColor color = Utils::ebc_to_color(query.value(31).toInt());
-	ui->est_colorShow->setColor(color);
+	ui->est_colorGlass->setColor(color);
+	ui->est_colorShow->setRange(query.value(15).toDouble(), query.value(16).toDouble());
+        ui->est_colorShow->setPrecision(0);
+        ui->est_colorShow->setTickMarks(1.0, 2);
+        ui->est_colorShow->setBackgroundBrush(QColor(121,201,121));
+        ui->est_colorShow->setPreferredRangeBrush(QColor(0,127,0));
+        ui->est_colorShow->setMarkerTextIsValue(true);
+        ui->est_colorShow->setValue(query.value(31).toDouble());
 
-	color_methodEdit->addItem("Morey");
-    	color_methodEdit->addItem("Mosher");
-    	color_methodEdit->addItem("Daniels");
-    	color_methodEdit->addItem("Halberstadt");
-    	color_methodEdit->addItem("Naudts");
-	color_methodEdit->setCurrentIndex(query.value(32).toInt());
+	ui->color_methodEdit->addItem("Morey");
+    	ui->color_methodEdit->addItem("Mosher");
+    	ui->color_methodEdit->addItem("Daniels");
+    	ui->color_methodEdit->addItem("Halberstadt");
+    	ui->color_methodEdit->addItem("Naudts");
+	ui->color_methodEdit->setCurrentIndex(query.value(32).toInt());
 
 	// 33 est_ibu
 	// 34 ibu_method
--- 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);
--- a/src/RangedSlider.h	Thu Mar 31 16:24:03 2022 +0200
+++ b/src/RangedSlider.h	Thu Mar 31 17:16:44 2022 +0200
@@ -136,7 +136,6 @@
     */
    double _prefMax;
    double _val;
-   QString _valText;
    QString _markerText;
    int _prec;
    double _tickInterval;
@@ -149,11 +148,6 @@
    bool _markerTextIsValue;
 
    /**
-    * The font used for showing the value at the right-hand side of the slider
-    */
-   QFont const valueTextFont;
-
-   /**
     * The font used for showing the indicator above the "needle" on the slider.  Often this is just showing the same as
     * the value - eg OG, FG, ABV - but sometimes it's something else - eg descriptive text such as "slightly hoppy" for
     * the IBU/GU reading.
--- a/ui/EditRecipe.ui	Thu Mar 31 16:24:03 2022 +0200
+++ b/ui/EditRecipe.ui	Thu Mar 31 17:16:44 2022 +0200
@@ -397,15 +397,9 @@
           <x>220</x>
           <y>200</y>
           <width>148</width>
-          <height>37</height>
+          <height>41</height>
          </rect>
         </property>
-        <property name="toolTip">
-         <string>The ranged slider</string>
-        </property>
-        <property name="whatsThis">
-         <string>Slider that shows if a value is in range.</string>
-        </property>
        </widget>
        <widget class="QLabel" name="est_ogLabel">
         <property name="geometry">
@@ -536,12 +530,6 @@
           <height>37</height>
          </rect>
         </property>
-        <property name="toolTip">
-         <string>The ranged slider</string>
-        </property>
-        <property name="whatsThis">
-         <string>Slider that shows if a value is in range.</string>
-        </property>
        </widget>
        <widget class="QDoubleSpinBox" name="est_abvEdit">
         <property name="geometry">
@@ -611,14 +599,8 @@
           <height>37</height>
          </rect>
         </property>
-        <property name="toolTip">
-         <string>The ranged slider</string>
-        </property>
-        <property name="whatsThis">
-         <string>Slider that shows if a value is in range.</string>
-        </property>
        </widget>
-       <widget class="BeerColor" name="est_colorShow">
+       <widget class="BeerColor" name="est_colorGlass">
         <property name="geometry">
          <rect>
           <x>590</x>
@@ -628,6 +610,26 @@
          </rect>
         </property>
        </widget>
+       <widget class="QComboBox" name="color_methodEdit">
+        <property name="geometry">
+         <rect>
+          <x>140</x>
+          <y>420</y>
+          <width>201</width>
+          <height>23</height>
+         </rect>
+        </property>
+       </widget>
+       <widget class="RangedSlider" name="est_colorShow">
+        <property name="geometry">
+         <rect>
+          <x>220</x>
+          <y>380</y>
+          <width>151</width>
+          <height>31</height>
+         </rect>
+        </property>
+       </widget>
       </widget>
       <widget class="QWidget" name="fermentables">
        <attribute name="icon">

mercurial