src/RangedSlider.h

Fri, 29 Jul 2022 13:12:26 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 29 Jul 2022 13:12:26 +0200
changeset 373
b02aca4e926c
parent 107
bb4607e23065
permissions
-rw-r--r--

First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.

/*
 * RangedSlider.h is part bmsapp.
 *
 * Original written for Brewtarget, and is Copyright the following
 * authors 2009-2020
 * - Matt Young <mfsy@yahoo.com>
 * - Mik Firestone <mikfire@gmail.com>
 * - Philip G. Lee <rocketman768@gmail.com>
 *
 * bmsapp is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * bmsapp is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef RANGEDSLIDER_H
#define RANGEDSLIDER_H

#include <QWidget>
#include <QSize>
#include <QString>
#include <QBrush>
#include <QPen>
class QPaintEvent;
class QMouseEvent;

/**
 * @brief Widget to display a number with an optional range on a type of read-only slider.
 * @author Philip G. Lee
 */
class RangedSlider : public QWidget
{
   Q_OBJECT

public:
   RangedSlider(QWidget* parent=0);

   Q_PROPERTY( double value READ value WRITE setValue )

   double value() const { return _val; }
   double minval() const { return _prefMin; }
   double maxval() const { return _prefMax; }

   //! \brief Set the background brush for the widget.
   void setBackgroundBrush( QBrush const& brush );
   //! \brief Set the brush for the marker.
   void setMarkerBrush( QBrush const& brush );
   //! \brief Set the text displayed above the marker.
   void setMarkerText( QString const& text );
   //! \brief If true, the marker text will always be updated to the value given by \c setValue().
   void setMarkerTextIsValue(bool val);

   //! \brief Set the \c precision for displaying values.
   void setPrecision(int precision);

public slots:
   /**
    * @brief Set the value for the indicator.
    */
   void setValue(double value);

   /**
    * @brief Set the range of values considered to be *best* and calculate
    *        the real widget display.
    *
    * @param range range.first and range.second are the min and max
    *        values for the preferred range resp.
    */
   void setRange(QPair<double,double> range);

   /**
    * @brief Convenience method for setting the widget range
    */
   void setRange( double min, double max );

protected:
   //! \brief Reimplemented from QWidget.
   virtual void paintEvent(QPaintEvent* event);
   //! \brief Reimplemented from QWidget for popup on mouseover.
   virtual void mouseMoveEvent(QMouseEvent* event);
   //! \brief Reimplemented from QWidget.
   virtual void moveEvent(QMoveEvent *event);

private:
   /**
    * Minimum value the widget displays
    */
   double _min;
   /**
    * Maximum value the widget displays
    */
   double _max;

   /**
    * Minimum value for the "best" sub-range
    */
   double _prefMin;
   /**
    * Maximum value for the "best" sub-range
    */
   double _prefMax;

   double _val;
   QString _markerText;
   int _prec;
   QString _tooltipText;
   QBrush _bgBrush;
   QBrush _prefRangeBrush;
   QPen _prefRangePen;
   QBrush _markerBrush;
   bool _markerTextIsValue;

   /**
    * 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.
    */
   QFont const indicatorTextFont;
};

#endif

mercurial