# HG changeset patch # User Michiel Broek # Date 1648739804 -7200 # Node ID c36fef8bb0886758b4bc8fd4cc9ab755cb7a43ed # Parent ef6048186cb32248b84482fa550880cca0a05c6b Removed the ugly green value text from the ranged slider. diff -r ef6048186cb3 -r c36fef8bb088 designer/RangedSliderPlugin.cpp --- 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 "\n" " \n" - " \n" - " The ranged slider\n" - " \n" - " \n" - " Slider that shows if a value is in range.\n" - " \n" " \n" "\n"; } diff -r ef6048186cb3 -r c36fef8bb088 src/EditRecipe.cpp --- 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 diff -r ef6048186cb3 -r c36fef8bb088 src/RangedSlider.cpp --- 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 #include #include @@ -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); diff -r ef6048186cb3 -r c36fef8bb088 src/RangedSlider.h --- 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. diff -r ef6048186cb3 -r c36fef8bb088 ui/EditRecipe.ui --- 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 @@ 220 200 148 - 37 + 41 - - The ranged slider - - - Slider that shows if a value is in range. - @@ -536,12 +530,6 @@ 37 - - The ranged slider - - - Slider that shows if a value is in range. - @@ -611,14 +599,8 @@ 37 - - The ranged slider - - - Slider that shows if a value is in range. - - + 590 @@ -628,6 +610,26 @@ + + + + 140 + 420 + 201 + 23 + + + + + + + 220 + 380 + 151 + 31 + + +