summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-bartender/bac.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-bartender/bac.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-bartender/bac.cpp174
1 files changed, 174 insertions, 0 deletions
diff --git a/noncore/apps/opie-bartender/bac.cpp b/noncore/apps/opie-bartender/bac.cpp
new file mode 100644
index 0000000..ac8a83e
--- a/dev/null
+++ b/noncore/apps/opie-bartender/bac.cpp
@@ -0,0 +1,174 @@
1/****************************************************************************
2**
3** Created: Sun Jul 21 19:00:14 2002
4** by: L.J. Potter <ljp@llornkcor.com>
5** copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 ***************************************************************************/
12#include "bac.h"
13
14#include <qcombobox.h>
15#include <qlabel.h>
16#include <qlcdnumber.h>
17#include <qpushbutton.h>
18#include <qspinbox.h>
19#include <qlayout.h>
20#include <qvariant.h>
21#include <qtooltip.h>
22#include <qwhatsthis.h>
23BacDialog::BacDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
24 : QDialog( parent, name, modal, fl )
25{
26 if ( !name )
27 setName( "BacDialog" );
28 setCaption( tr( "Blood Alcohol Estimator" ) );
29
30 Layout7 = new QVBoxLayout( this);
31 Layout7->setSpacing( 6 );
32 Layout7->setMargin( 0 );
33
34 Layout1 = new QHBoxLayout;
35 Layout1->setSpacing( 6 );
36 Layout1->setMargin( 0 );
37
38 NumberSpinBox = new QSpinBox( this, "NumberSpinBox" );
39 Layout1->addWidget( NumberSpinBox );
40
41 TextLabel1 = new QLabel(this, "TextLabel1" );
42 TextLabel1->setText( tr( "Number of Drinks Consumed" ) );
43 Layout1->addWidget( TextLabel1 );
44 Layout7->addLayout( Layout1 );
45
46 Layout2 = new QHBoxLayout;
47 Layout2->setSpacing( 6 );
48 Layout2->setMargin( 0 );
49
50 WeightSpinBox = new QSpinBox( this, "WeightSpinBox" );
51 Layout2->addWidget( WeightSpinBox );
52 WeightSpinBox->setMaxValue(500);
53
54 TextLabel2 = new QLabel( this, "TextLabel2" );
55 TextLabel2->setText( tr( "Weight" ) );
56 Layout2->addWidget( TextLabel2 );
57 Layout7->addLayout( Layout2 );
58
59 Layout3 = new QHBoxLayout;
60 Layout3->setSpacing( 6 );
61 Layout3->setMargin( 0 );
62
63 TimeSpinBox = new QSpinBox( this, "TimeSpinBox" );
64 Layout3->addWidget( TimeSpinBox );
65 TimeSpinBox->setMaxValue(24);
66
67 TextLabel3 = new QLabel( this, "TextLabel3" );
68 TextLabel3->setText( tr( "Period of Time (hours)" ) );
69 Layout3->addWidget( TextLabel3 );
70 Layout7->addLayout( Layout3 );
71
72 Layout4 = new QHBoxLayout;
73 Layout4->setSpacing( 6 );
74 Layout4->setMargin( 0 );
75
76 GenderComboBox = new QComboBox( FALSE, this, "GenderComboBox" );
77 GenderComboBox->insertItem( tr( "Male" ) );
78 GenderComboBox->insertItem( tr( "Female" ) );
79 GenderComboBox->insertItem( tr( "Unknown" ) );
80 Layout4->addWidget( GenderComboBox );
81
82 TextLabel4 = new QLabel( this, "TextLabel4" );
83 TextLabel4->setText( tr( "Gender" ) );
84 Layout4->addWidget( TextLabel4 );
85 Layout7->addLayout( Layout4 );
86
87 Layout6 = new QHBoxLayout;
88 Layout6->setSpacing( 6 );
89 Layout6->setMargin( 0 );
90
91 TypeDrinkComboBox = new QComboBox( FALSE,this, "TypeDrinkComboBox" );
92 TypeDrinkComboBox->insertItem( tr( "Beer" ) );
93 TypeDrinkComboBox->insertItem( tr( "Wine" ) );
94 TypeDrinkComboBox->insertItem( tr( "Shot" ) );
95 Layout6->addWidget( TypeDrinkComboBox );
96
97 TextLabel1_2 = new QLabel( this, "TextLabel1_2" );
98 TextLabel1_2->setText( tr( "Type of drink" ) );
99 Layout6->addWidget( TextLabel1_2 );
100 Layout7->addLayout( Layout6 );
101
102 PushButton1 = new QPushButton( this, "PushButton1" );
103 PushButton1->setText( tr( "Calculate" ) );
104 Layout7->addWidget( PushButton1 );
105 connect(PushButton1,SIGNAL( clicked()), this, SLOT( calculate()));
106
107 LCDNumber1 = new QLCDNumber( this, "LCDNumber1" );
108 LCDNumber1->setMaximumHeight( 50);
109 LCDNumber1->setNumDigits(6);
110 LCDNumber1->setSmallDecimalPoint(TRUE);
111 LCDNumber1->setFrameStyle(QFrame::Box);
112 LCDNumber1->setLineWidth(2);
113 LCDNumber1->setSegmentStyle( QLCDNumber::Filled);
114 QPalette palette = LCDNumber1->palette();
115 palette.setColor(QPalette::Normal, QColorGroup::Foreground, Qt::red);
116 palette.setColor(QPalette::Normal, QColorGroup::Light, Qt::black);
117 palette.setColor(QPalette::Normal, QColorGroup::Dark, Qt::darkGreen);
118 LCDNumber1->setPalette(palette);
119
120
121 Layout7->addWidget( LCDNumber1 );
122
123
124}
125
126BacDialog::~BacDialog() {
127}
128
129void BacDialog::calculate() {
130 float weight,genderDiff, bac, typeDrink=0, drinkOz=0, bodyWater, milliliters, oz, gram, gramsMil, alc, metab, bac1;
131 QString estBac;
132
133 if( GenderComboBox->currentItem()==0)
134 genderDiff = .58;
135 else
136 genderDiff = .49;
137
138 switch(TypeDrinkComboBox->currentItem()) {
139 case 0: { //beer
140 typeDrink = .045;
141 drinkOz = 12;
142 }
143 break;
144 case 1: {
145 typeDrink = .2;
146 drinkOz = 4;
147 }
148 break;
149 case 2: {
150 typeDrink = .5;
151 drinkOz = 1.5;
152 }
153 break;
154 };
155 weight = WeightSpinBox->value() / 2.2046; // in kilograms
156 bodyWater = weight * genderDiff;
157 milliliters = bodyWater * 1000;
158 oz = 23.36/milliliters;
159 gram = oz * .806;
160 gramsMil = gram * 100;
161 alc = drinkOz*NumberSpinBox->value() * typeDrink;
162 metab = TimeSpinBox->value() * .012;
163 bac1 = gramsMil * alc;
164 bac = bac1 - metab;
165
166
167
168// weightDrink= (nDrinks * .79) / (weight * genderDiff*1000);
169// (ounces * percent * 0.075 / weight) - (hours * 0.015);
170// bac = (((weightDrink * .806) * 100) * .54);// - (time * .012); // assuming beer of 4.5%
171 estBac.sprintf("%f",bac);
172 LCDNumber1->display(bac);
173// BACTextLabel->setText(estBac );
174}