2
* MaltinessWidget.cpp is part of Brewtarget, and is Copyright Philip G. Lee
3
* (rocketman768@gmail.com), 2009.
5
* Brewtarget is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Brewtarget is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include <QSizePolicy>
24
#include "MaltinessWidget.h"
26
MaltinessWidget::MaltinessWidget(QWidget* parent) : QWidget(parent)
31
MaltinessWidget::MaltinessWidget(Recipe* recipe)
34
observeRecipe(recipe);
37
void MaltinessWidget::setup()
41
label = new QLabel(this);
42
// Want to specify a minimum size and have it expand if able.
43
label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
44
// Align text in center, vertically and horizontally.
45
label->setAlignment(Qt::AlignCenter);
47
label->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
49
palette = label->palette();
51
// Set size policy of the MaltinessWidget
52
//sPolicy = QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
53
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
57
void MaltinessWidget::observeRecipe(Recipe* recipe)
66
void MaltinessWidget::paintEvent(QPaintEvent*)
71
QPainter painter(this);
73
label->resize(size());
75
palette.setColor(QPalette::Active, QPalette::Window, bgColor());
76
label->setPalette(palette);
77
label->setText(fgText());
79
label->render(&painter);
82
QSize MaltinessWidget::sizeHint() const
84
return label->sizeHint();
88
QSizePolicy MaltinessWidget::sizePolicy() const
94
QColor MaltinessWidget::bgColor()
99
return QColor::fromRgb(252,91,10);
101
return QColor::fromRgb(252,134,10);
103
return QColor::fromRgb(246,195,6);
105
return QColor::fromRgb(235,248,11);
107
return QColor::fromRgb(148,251,12);
109
return QColor::fromRgb(12,248,26);
111
return QColor::fromRgb(12,178,13);
113
return QColor::fromRgb(255,255,255);
117
QString MaltinessWidget::fgText()
122
return QString("<b>Cloying</b>");
124
return QString("<b>Extra malty</b>");
126
return QString("<b>Slightly malty</b>");
128
return QString("<b>Balanced</b>");
130
return QString("<b>Slightly hoppy</b>");
132
return QString("<b>Extra hoppy</b>");
134
return QString("<b>Way hoppy</b>");
140
int MaltinessWidget::region()
148
ibu = recObs->getIBU();
149
points = (recObs->getOg() - 1)*1000;
151
if( (11./3.)*ibu-5./3. < points )
153
else if( 3*ibu-5 < points && points <= (11./3.)*ibu-5./3. )
155
else if( (7./3.)*ibu-5./3. < points && points <= 3*ibu-5 )
156
return SLIGHTLYMALTY;
157
else if( 2*ibu-5 < points && points <= (7./3.)*ibu-5./3. )
159
else if( (5./3.)*ibu-10./3. < points && points <= 2*ibu-5 )
160
return SLIGHTLYHOPPY;
161
else if( (5./4.)*ibu-3.75 < points && points <= (5./3.)*ibu-10./3. )
167
void MaltinessWidget::notify(Observable *notifier, QVariant /*info*/)
169
if( notifier != recObs )
b'\\ No newline at end of file'