-rw-r--r-- | noncore/apps/opie-bartender/bac.cpp | 33 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/bac.h | 4 |
2 files changed, 26 insertions, 11 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 | |||
@@ -27,41 +27,50 @@ BacDialog::BacDialog( QWidget* parent, const char* name, bool modal, WFlags fl | |||
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 | weightUnitsCombo =new QComboBox( FALSE, this, "unitComboBox" ); | ||
57 | weightUnitsCombo->insertItem( tr( "Kilos" ) ); | ||
58 | weightUnitsCombo->insertItem( tr( "Pounds" ) ); | ||
59 | Layout2->addWidget( weightUnitsCombo ); | ||
60 | |||
61 | weightUnitsLabel = new QLabel(this, "unitsTextLabel" ); | ||
62 | weightUnitsLabel->setText( tr( "Units" ) ); | ||
63 | Layout2->addWidget( weightUnitsLabel ); | ||
64 | |||
56 | Layout3 = new QHBoxLayout; | 65 | Layout3 = new QHBoxLayout; |
57 | Layout3->setSpacing( 6 ); | 66 | Layout3->setSpacing( 6 ); |
58 | Layout3->setMargin( 0 ); | 67 | Layout3->setMargin( 0 ); |
59 | 68 | ||
60 | TimeSpinBox = new QSpinBox( this, "TimeSpinBox" ); | 69 | TimeSpinBox = new QSpinBox( this, "TimeSpinBox" ); |
61 | Layout3->addWidget( TimeSpinBox ); | 70 | Layout3->addWidget( TimeSpinBox ); |
62 | TimeSpinBox->setMaxValue(24); | 71 | TimeSpinBox->setMaxValue(24); |
63 | 72 | ||
64 | TextLabel3 = new QLabel( this, "TextLabel3" ); | 73 | TextLabel3 = new QLabel( this, "TextLabel3" ); |
65 | TextLabel3->setText( tr( "Period of Time (hours)" ) ); | 74 | TextLabel3->setText( tr( "Period of Time (hours)" ) ); |
66 | Layout3->addWidget( TextLabel3 ); | 75 | Layout3->addWidget( TextLabel3 ); |
67 | Layout7->addLayout( Layout3 ); | 76 | Layout7->addLayout( Layout3 ); |
@@ -105,67 +114,71 @@ BacDialog::BacDialog( QWidget* parent, const char* name, bool modal, WFlags fl | |||
105 | LCDNumber1->setMaximumHeight( 50); | 114 | LCDNumber1->setMaximumHeight( 50); |
106 | LCDNumber1->setNumDigits(6); | 115 | LCDNumber1->setNumDigits(6); |
107 | LCDNumber1->setSmallDecimalPoint(TRUE); | 116 | LCDNumber1->setSmallDecimalPoint(TRUE); |
108 | LCDNumber1->setFrameStyle(QFrame::Box); | 117 | LCDNumber1->setFrameStyle(QFrame::Box); |
109 | LCDNumber1->setLineWidth(2); | 118 | LCDNumber1->setLineWidth(2); |
110 | LCDNumber1->setSegmentStyle( QLCDNumber::Filled); | 119 | LCDNumber1->setSegmentStyle( QLCDNumber::Filled); |
111 | QPalette palette = LCDNumber1->palette(); | 120 | QPalette palette = LCDNumber1->palette(); |
112 | palette.setColor(QPalette::Normal, QColorGroup::Foreground, Qt::red); | 121 | palette.setColor(QPalette::Normal, QColorGroup::Foreground, Qt::red); |
113 | palette.setColor(QPalette::Normal, QColorGroup::Light, Qt::black); | 122 | palette.setColor(QPalette::Normal, QColorGroup::Light, Qt::black); |
114 | palette.setColor(QPalette::Normal, QColorGroup::Dark, Qt::darkGreen); | 123 | palette.setColor(QPalette::Normal, QColorGroup::Dark, Qt::darkGreen); |
115 | LCDNumber1->setPalette(palette); | 124 | LCDNumber1->setPalette(palette); |
116 | 125 | ||
117 | |||
118 | Layout7->addWidget( LCDNumber1 ); | 126 | Layout7->addWidget( LCDNumber1 ); |
119 | 127 | NumberSpinBox->setFocus(); | |
120 | |||
121 | } | 128 | } |
122 | 129 | ||
123 | BacDialog::~BacDialog() { | 130 | BacDialog::~BacDialog() |
124 | } | 131 | {} |
132 | |||
133 | void BacDialog::calculate() | ||
134 | { | ||
125 | 135 | ||
126 | void BacDialog::calculate() { | ||
127 | float weight,genderDiff, bac, typeDrink=0, drinkOz=0, bodyWater, milliliters, oz, gram, gramsMil, alc, metab, bac1; | 136 | 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 | |
163 | if( weightUnitsCombo->currentItem() == 0 ) { | ||
164 | weight = WeightSpinBox->value(); // kilos | ||
165 | } else { | ||
166 | weight = WeightSpinBox->value() / 2.2046; // convert to kilograms | ||
167 | } | ||
153 | bodyWater = weight * genderDiff; | 168 | bodyWater = weight * genderDiff; |
154 | milliliters = bodyWater * 1000; | 169 | milliliters = bodyWater * 1000; |
155 | oz = 23.36/milliliters; | 170 | oz = 23.36/milliliters; |
156 | gram = oz * .806; | 171 | gram = oz * .806; |
157 | gramsMil = gram * 100; | 172 | gramsMil = gram * 100; |
158 | alc = drinkOz*NumberSpinBox->value() * typeDrink; | 173 | alc = drinkOz*NumberSpinBox->value() * typeDrink; |
159 | metab = TimeSpinBox->value() * .012; | 174 | metab = TimeSpinBox->value() * .012; |
160 | bac1 = gramsMil * alc; | 175 | bac1 = gramsMil * alc; |
161 | bac = bac1 - metab; | 176 | bac = bac1 - metab; |
162 | 177 | ||
163 | |||
164 | |||
165 | // weightDrink= (nDrinks * .79) / (weight * genderDiff*1000); | 178 | // weightDrink= (nDrinks * .79) / (weight * genderDiff*1000); |
166 | // (ounces * percent * 0.075 / weight) - (hours * 0.015); | 179 | // (ounces * percent * 0.075 / weight) - (hours * 0.015); |
167 | // bac = (((weightDrink * .806) * 100) * .54);// - (time * .012); // assuming beer of 4.5% | 180 | // bac = (((weightDrink * .806) * 100) * .54);// - (time * .012); // assuming beer of 4.5% |
168 | estBac.sprintf("%f",bac); | 181 | estBac.sprintf("%f",bac); |
169 | LCDNumber1->display(bac); | 182 | LCDNumber1->display(bac); |
170 | // BACTextLabel->setText(estBac ); | 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 | |||
@@ -33,26 +33,28 @@ public: | |||
33 | QSpinBox* NumberSpinBox; | 33 | QSpinBox* NumberSpinBox; |
34 | QLabel* TextLabel1; | 34 | QLabel* TextLabel1; |
35 | QSpinBox* WeightSpinBox; | 35 | QSpinBox* WeightSpinBox; |
36 | QLabel* TextLabel2; | 36 | QLabel* TextLabel2; |
37 | QSpinBox* TimeSpinBox; | 37 | QSpinBox* TimeSpinBox; |
38 | QLabel* TextLabel3; | 38 | QLabel* TextLabel3; |
39 | QComboBox* GenderComboBox; | 39 | QComboBox* GenderComboBox; |
40 | QLabel* TextLabel4; | 40 | QLabel* TextLabel4; |
41 | QComboBox* TypeDrinkComboBox; | 41 | QComboBox* TypeDrinkComboBox; |
42 | QLabel* TextLabel1_2; | 42 | QLabel* TextLabel1_2; |
43 | QPushButton* PushButton1; | 43 | QPushButton* PushButton1; |
44 | QLCDNumber* LCDNumber1; | 44 | QLCDNumber* LCDNumber1; |
45 | 45 | QComboBox *weightUnitsCombo; | |
46 | QLabel *weightUnitsLabel; | ||
46 | protected: | 47 | protected: |
47 | QVBoxLayout* Layout7; | 48 | QVBoxLayout* Layout7; |
48 | QHBoxLayout* Layout1; | 49 | QHBoxLayout* Layout1; |
49 | QHBoxLayout* Layout2; | 50 | QHBoxLayout* Layout2; |
50 | QHBoxLayout* Layout3; | 51 | QHBoxLayout* Layout3; |
51 | QHBoxLayout* Layout4; | 52 | QHBoxLayout* Layout4; |
52 | QHBoxLayout* Layout6; | 53 | QHBoxLayout* Layout6; |
54 | |||
53 | protected slots: | 55 | protected slots: |
54 | void calculate(); | 56 | void calculate(); |
55 | 57 | ||
56 | }; | 58 | }; |
57 | 59 | ||
58 | #endif // BACDIALOG_H | 60 | #endif // BACDIALOG_H |