summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-04-08 22:02:23 (UTC)
committer llornkcor <llornkcor>2004-04-08 22:02:23 (UTC)
commit3ff6546b780c2c74994e21bdd749379be064c979 (patch) (unidiff)
tree864c4ce441cf553de031da4e942247ceeaa130d1
parentc1ffd357ea7e8632f97c6974e86677946d22d816 (diff)
downloadopie-3ff6546b780c2c74994e21bdd749379be064c979.zip
opie-3ff6546b780c2c74994e21bdd749379be064c979.tar.gz
opie-3ff6546b780c2c74994e21bdd749379be064c979.tar.bz2
add kilos/pound combo
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-bartender/bac.cpp305
-rw-r--r--noncore/apps/opie-bartender/bac.h4
2 files changed, 162 insertions, 147 deletions
diff --git a/noncore/apps/opie-bartender/bac.cpp b/noncore/apps/opie-bartender/bac.cpp
index c97a253..2e74029 100644
--- a/noncore/apps/opie-bartender/bac.cpp
+++ b/noncore/apps/opie-bartender/bac.cpp
@@ -19,153 +19,166 @@
19#include <qlayout.h> 19#include <qlayout.h>
20BacDialog::BacDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) 20BacDialog::BacDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
21 : QDialog( parent, name, modal, fl ) 21 : QDialog( parent, name, modal, fl )
22{ 22{
23 if ( !name ) 23 if ( !name )
24 setName( "BacDialog" ); 24 setName( "BacDialog" );
25 setCaption( tr( "Blood Alcohol Estimator" ) ); 25 setCaption( tr( "Blood Alcohol Estimator" ) );
26 26
27 Layout7 = new QVBoxLayout( this); 27 Layout7 = new QVBoxLayout( this);
28 Layout7->setSpacing( 6 ); 28 Layout7->setSpacing( 6 );
29 Layout7->setMargin( 0 ); 29 Layout7->setMargin( 0 );
30 30
31 Layout1 = new QHBoxLayout; 31 Layout1 = new QHBoxLayout;
32 Layout1->setSpacing( 6 ); 32 Layout1->setSpacing( 6 );
33 Layout1->setMargin( 0 ); 33 Layout1->setMargin( 0 );
34 34
35 NumberSpinBox = new QSpinBox( this, "NumberSpinBox" ); 35 NumberSpinBox = new QSpinBox( this, "NumberSpinBox" );
36 Layout1->addWidget( NumberSpinBox ); 36 Layout1->addWidget( NumberSpinBox );
37 37
38 TextLabel1 = new QLabel(this, "TextLabel1" ); 38 TextLabel1 = new QLabel(this, "TextLabel1" );
39 TextLabel1->setText( tr( "Number of Drinks Consumed" ) ); 39 TextLabel1->setText( tr( "# Drinks Consumed" ) );
40 Layout1->addWidget( TextLabel1 ); 40 Layout1->addWidget( TextLabel1 );
41 Layout7->addLayout( Layout1 ); 41 Layout7->addLayout( Layout1 );
42 42
43 Layout2 = new QHBoxLayout; 43 Layout2 = new QHBoxLayout;
44 Layout2->setSpacing( 6 ); 44 Layout2->setSpacing( 6 );
45 Layout2->setMargin( 0 ); 45 Layout2->setMargin( 0 );
46 46
47 WeightSpinBox = new QSpinBox( this, "WeightSpinBox" ); 47 WeightSpinBox = new QSpinBox( this, "WeightSpinBox" );
48 Layout2->addWidget( WeightSpinBox ); 48 Layout2->addWidget( WeightSpinBox );
49 WeightSpinBox->setMaxValue(500); 49 WeightSpinBox->setMaxValue(500);
50 50
51 TextLabel2 = new QLabel( this, "TextLabel2" ); 51 TextLabel2 = new QLabel( this, "TextLabel2" );
52 TextLabel2->setText( tr( "Weight" ) ); 52 TextLabel2->setText( tr( "Weight" ) );
53 Layout2->addWidget( TextLabel2 ); 53 Layout2->addWidget( TextLabel2 );
54 Layout7->addLayout( Layout2 ); 54 Layout7->addLayout( Layout2 );
55 55
56 Layout3 = new QHBoxLayout; 56 weightUnitsCombo =new QComboBox( FALSE, this, "unitComboBox" );
57 Layout3->setSpacing( 6 ); 57 weightUnitsCombo->insertItem( tr( "Kilos" ) );
58 Layout3->setMargin( 0 ); 58 weightUnitsCombo->insertItem( tr( "Pounds" ) );
59 59 Layout2->addWidget( weightUnitsCombo );
60 TimeSpinBox = new QSpinBox( this, "TimeSpinBox" ); 60
61 Layout3->addWidget( TimeSpinBox ); 61 weightUnitsLabel = new QLabel(this, "unitsTextLabel" );
62 TimeSpinBox->setMaxValue(24); 62 weightUnitsLabel->setText( tr( "Units" ) );
63 63 Layout2->addWidget( weightUnitsLabel );
64 TextLabel3 = new QLabel( this, "TextLabel3" ); 64
65 TextLabel3->setText( tr( "Period of Time (hours)" ) ); 65 Layout3 = new QHBoxLayout;
66 Layout3->addWidget( TextLabel3 ); 66 Layout3->setSpacing( 6 );
67 Layout7->addLayout( Layout3 ); 67 Layout3->setMargin( 0 );
68 68
69 Layout4 = new QHBoxLayout; 69 TimeSpinBox = new QSpinBox( this, "TimeSpinBox" );
70 Layout4->setSpacing( 6 ); 70 Layout3->addWidget( TimeSpinBox );
71 Layout4->setMargin( 0 ); 71 TimeSpinBox->setMaxValue(24);
72 72
73 GenderComboBox = new QComboBox( FALSE, this, "GenderComboBox" ); 73 TextLabel3 = new QLabel( this, "TextLabel3" );
74 GenderComboBox->insertItem( tr( "Male" ) ); 74 TextLabel3->setText( tr( "Period of Time (hours)" ) );
75 GenderComboBox->insertItem( tr( "Female" ) ); 75 Layout3->addWidget( TextLabel3 );
76 GenderComboBox->insertItem( tr( "Unknown" ) ); 76 Layout7->addLayout( Layout3 );
77 Layout4->addWidget( GenderComboBox ); 77
78 78 Layout4 = new QHBoxLayout;
79 TextLabel4 = new QLabel( this, "TextLabel4" ); 79 Layout4->setSpacing( 6 );
80 TextLabel4->setText( tr( "Gender" ) ); 80 Layout4->setMargin( 0 );
81 Layout4->addWidget( TextLabel4 ); 81
82 Layout7->addLayout( Layout4 ); 82 GenderComboBox = new QComboBox( FALSE, this, "GenderComboBox" );
83 83 GenderComboBox->insertItem( tr( "Male" ) );
84 Layout6 = new QHBoxLayout; 84 GenderComboBox->insertItem( tr( "Female" ) );
85 Layout6->setSpacing( 6 ); 85 GenderComboBox->insertItem( tr( "Unknown" ) );
86 Layout6->setMargin( 0 ); 86 Layout4->addWidget( GenderComboBox );
87 87
88 TypeDrinkComboBox = new QComboBox( FALSE,this, "TypeDrinkComboBox" ); 88 TextLabel4 = new QLabel( this, "TextLabel4" );
89 TypeDrinkComboBox->insertItem( tr( "Beer" ) ); 89 TextLabel4->setText( tr( "Gender" ) );
90 TypeDrinkComboBox->insertItem( tr( "Wine" ) ); 90 Layout4->addWidget( TextLabel4 );
91 TypeDrinkComboBox->insertItem( tr( "Shot" ) ); 91 Layout7->addLayout( Layout4 );
92 Layout6->addWidget( TypeDrinkComboBox ); 92
93 93 Layout6 = new QHBoxLayout;
94 TextLabel1_2 = new QLabel( this, "TextLabel1_2" ); 94 Layout6->setSpacing( 6 );
95 TextLabel1_2->setText( tr( "Type of drink" ) ); 95 Layout6->setMargin( 0 );
96 Layout6->addWidget( TextLabel1_2 ); 96
97 Layout7->addLayout( Layout6 ); 97 TypeDrinkComboBox = new QComboBox( FALSE,this, "TypeDrinkComboBox" );
98 98 TypeDrinkComboBox->insertItem( tr( "Beer" ) );
99 PushButton1 = new QPushButton( this, "PushButton1" ); 99 TypeDrinkComboBox->insertItem( tr( "Wine" ) );
100 PushButton1->setText( tr( "Calculate" ) ); 100 TypeDrinkComboBox->insertItem( tr( "Shot" ) );
101 Layout7->addWidget( PushButton1 ); 101 Layout6->addWidget( TypeDrinkComboBox );
102 connect(PushButton1,SIGNAL( clicked()), this, SLOT( calculate())); 102
103 103 TextLabel1_2 = new QLabel( this, "TextLabel1_2" );
104 LCDNumber1 = new QLCDNumber( this, "LCDNumber1" ); 104 TextLabel1_2->setText( tr( "Type of drink" ) );
105 LCDNumber1->setMaximumHeight( 50); 105 Layout6->addWidget( TextLabel1_2 );
106 LCDNumber1->setNumDigits(6); 106 Layout7->addLayout( Layout6 );
107 LCDNumber1->setSmallDecimalPoint(TRUE); 107
108 LCDNumber1->setFrameStyle(QFrame::Box); 108 PushButton1 = new QPushButton( this, "PushButton1" );
109 LCDNumber1->setLineWidth(2); 109 PushButton1->setText( tr( "Calculate" ) );
110 LCDNumber1->setSegmentStyle( QLCDNumber::Filled); 110 Layout7->addWidget( PushButton1 );
111 QPalette palette = LCDNumber1->palette(); 111 connect(PushButton1,SIGNAL( clicked()), this, SLOT( calculate()));
112 palette.setColor(QPalette::Normal, QColorGroup::Foreground, Qt::red); 112
113 palette.setColor(QPalette::Normal, QColorGroup::Light, Qt::black); 113 LCDNumber1 = new QLCDNumber( this, "LCDNumber1" );
114 palette.setColor(QPalette::Normal, QColorGroup::Dark, Qt::darkGreen); 114 LCDNumber1->setMaximumHeight( 50);
115 LCDNumber1->setPalette(palette); 115 LCDNumber1->setNumDigits(6);
116 116 LCDNumber1->setSmallDecimalPoint(TRUE);
117 117 LCDNumber1->setFrameStyle(QFrame::Box);
118 Layout7->addWidget( LCDNumber1 ); 118 LCDNumber1->setLineWidth(2);
119 119 LCDNumber1->setSegmentStyle( QLCDNumber::Filled);
120 120 QPalette palette = LCDNumber1->palette();
121 palette.setColor(QPalette::Normal, QColorGroup::Foreground, Qt::red);
122 palette.setColor(QPalette::Normal, QColorGroup::Light, Qt::black);
123 palette.setColor(QPalette::Normal, QColorGroup::Dark, Qt::darkGreen);
124 LCDNumber1->setPalette(palette);
125
126 Layout7->addWidget( LCDNumber1 );
127 NumberSpinBox->setFocus();
121} 128}
122 129
123BacDialog::~BacDialog() { 130BacDialog::~BacDialog()
124} 131{}
132
133void BacDialog::calculate()
134{
125 135
126void BacDialog::calculate() { 136 float weight,genderDiff, bac, typeDrink=0, drinkOz=0, bodyWater, milliliters, oz, gram, gramsMil, alc, metab, bac1;
127 float weight,genderDiff, bac, typeDrink=0, drinkOz=0, bodyWater, milliliters, oz, gram, gramsMil, alc, metab, bac1; 137 float weightunitDifference, massunitdiff;
128 QString estBac; 138 QString estBac;
129 139
130 if( GenderComboBox->currentItem()==0) 140 if( GenderComboBox->currentItem()==0)
131 genderDiff = .58; 141 genderDiff = .58;
132 else 142 else
133 genderDiff = .49; 143 genderDiff = .49;
134 144
135 switch(TypeDrinkComboBox->currentItem()) { 145 switch(TypeDrinkComboBox->currentItem()) {
136 case 0: { //beer 146 case 0: { //beer
137 typeDrink = .045; 147 typeDrink = .045;
138 drinkOz = 12; 148 drinkOz = 12;
139 } 149 }
140 break; 150 break;
141 case 1: { 151 case 1: {
142 typeDrink = .2; 152 typeDrink = .2;
143 drinkOz = 4; 153 drinkOz = 4;
144 } 154 }
145 break; 155 break;
146 case 2: { 156 case 2: {
147 typeDrink = .5; 157 typeDrink = .5;
148 drinkOz = 1.5; 158 drinkOz = 1.5;
149 } 159 }
150 break; 160 break;
151 }; 161 };
152 weight = WeightSpinBox->value() / 2.2046; // in kilograms 162
153 bodyWater = weight * genderDiff; 163 if( weightUnitsCombo->currentItem() == 0 ) {
154 milliliters = bodyWater * 1000; 164 weight = WeightSpinBox->value(); // kilos
155 oz = 23.36/milliliters; 165 } else {
156 gram = oz * .806; 166 weight = WeightSpinBox->value() / 2.2046; // convert to kilograms
157 gramsMil = gram * 100; 167 }
158 alc = drinkOz*NumberSpinBox->value() * typeDrink; 168 bodyWater = weight * genderDiff;
159 metab = TimeSpinBox->value() * .012; 169 milliliters = bodyWater * 1000;
160 bac1 = gramsMil * alc; 170 oz = 23.36/milliliters;
161 bac = bac1 - metab; 171 gram = oz * .806;
162 172 gramsMil = gram * 100;
163 173 alc = drinkOz*NumberSpinBox->value() * typeDrink;
164 174 metab = TimeSpinBox->value() * .012;
165// weightDrink= (nDrinks * .79) / (weight * genderDiff*1000); 175 bac1 = gramsMil * alc;
166// (ounces * percent * 0.075 / weight) - (hours * 0.015); 176 bac = bac1 - metab;
167// bac = (((weightDrink * .806) * 100) * .54);// - (time * .012); // assuming beer of 4.5% 177
168 estBac.sprintf("%f",bac); 178 // weightDrink= (nDrinks * .79) / (weight * genderDiff*1000);
169 LCDNumber1->display(bac); 179 // (ounces * percent * 0.075 / weight) - (hours * 0.015);
170// BACTextLabel->setText(estBac ); 180 // bac = (((weightDrink * .806) * 100) * .54);// - (time * .012); // assuming beer of 4.5%
181 estBac.sprintf("%f",bac);
182 LCDNumber1->display(bac);
183 // BACTextLabel->setText(estBac );
171} 184}
diff --git a/noncore/apps/opie-bartender/bac.h b/noncore/apps/opie-bartender/bac.h
index 9245c96..43c7035 100644
--- a/noncore/apps/opie-bartender/bac.h
+++ b/noncore/apps/opie-bartender/bac.h
@@ -43,5 +43,6 @@ public:
43 QPushButton* PushButton1; 43 QPushButton* PushButton1;
44 QLCDNumber* LCDNumber1; 44 QLCDNumber* LCDNumber1;
45 45 QComboBox *weightUnitsCombo;
46 QLabel *weightUnitsLabel;
46protected: 47protected:
47 QVBoxLayout* Layout7; 48 QVBoxLayout* Layout7;
@@ -51,4 +52,5 @@ protected:
51 QHBoxLayout* Layout4; 52 QHBoxLayout* Layout4;
52 QHBoxLayout* Layout6; 53 QHBoxLayout* Layout6;
54
53protected slots: 55protected slots:
54 void calculate(); 56 void calculate();