00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "bac.h"
00013
00014 #include <qcombobox.h>
00015 #include <qlabel.h>
00016 #include <qlcdnumber.h>
00017 #include <qpushbutton.h>
00018 #include <qspinbox.h>
00019 #include <qlayout.h>
00020 BacDialog::BacDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
00021 : QDialog( parent, name, modal, fl )
00022 {
00023 if ( !name )
00024 setName( "BacDialog" );
00025 setCaption( tr( "Blood Alcohol Estimator" ) );
00026
00027 Layout7 = new QVBoxLayout( this);
00028 Layout7->setSpacing( 6 );
00029 Layout7->setMargin( 0 );
00030
00031 Layout1 = new QHBoxLayout;
00032 Layout1->setSpacing( 6 );
00033 Layout1->setMargin( 0 );
00034
00035 NumberSpinBox = new QSpinBox( this, "NumberSpinBox" );
00036 Layout1->addWidget( NumberSpinBox );
00037
00038 TextLabel1 = new QLabel(this, "TextLabel1" );
00039 TextLabel1->setText( tr( "# Drinks Consumed" ) );
00040 Layout1->addWidget( TextLabel1 );
00041 Layout7->addLayout( Layout1 );
00042
00043 Layout2 = new QHBoxLayout;
00044 Layout2->setSpacing( 6 );
00045 Layout2->setMargin( 0 );
00046
00047 WeightSpinBox = new QSpinBox( this, "WeightSpinBox" );
00048 Layout2->addWidget( WeightSpinBox );
00049 WeightSpinBox->setMaxValue(500);
00050
00051 TextLabel2 = new QLabel( this, "TextLabel2" );
00052 TextLabel2->setText( tr( "Weight" ) );
00053 Layout2->addWidget( TextLabel2 );
00054 Layout7->addLayout( Layout2 );
00055
00056 weightUnitsCombo =new QComboBox( FALSE, this, "unitComboBox" );
00057 weightUnitsCombo->insertItem( tr( "Kilos" ) );
00058 weightUnitsCombo->insertItem( tr( "Pounds" ) );
00059 Layout2->addWidget( weightUnitsCombo );
00060
00061 weightUnitsLabel = new QLabel(this, "unitsTextLabel" );
00062 weightUnitsLabel->setText( tr( "Units" ) );
00063 Layout2->addWidget( weightUnitsLabel );
00064
00065 Layout3 = new QHBoxLayout;
00066 Layout3->setSpacing( 6 );
00067 Layout3->setMargin( 0 );
00068
00069 TimeSpinBox = new QSpinBox( this, "TimeSpinBox" );
00070 Layout3->addWidget( TimeSpinBox );
00071 TimeSpinBox->setMaxValue(24);
00072
00073 TextLabel3 = new QLabel( this, "TextLabel3" );
00074 TextLabel3->setText( tr( "Period of Time (hours)" ) );
00075 Layout3->addWidget( TextLabel3 );
00076 Layout7->addLayout( Layout3 );
00077
00078 Layout4 = new QHBoxLayout;
00079 Layout4->setSpacing( 6 );
00080 Layout4->setMargin( 0 );
00081
00082 GenderComboBox = new QComboBox( FALSE, this, "GenderComboBox" );
00083 GenderComboBox->insertItem( tr( "Male" ) );
00084 GenderComboBox->insertItem( tr( "Female" ) );
00085 GenderComboBox->insertItem( tr( "Unknown" ) );
00086 Layout4->addWidget( GenderComboBox );
00087
00088 TextLabel4 = new QLabel( this, "TextLabel4" );
00089 TextLabel4->setText( tr( "Gender" ) );
00090 Layout4->addWidget( TextLabel4 );
00091 Layout7->addLayout( Layout4 );
00092
00093 Layout6 = new QHBoxLayout;
00094 Layout6->setSpacing( 6 );
00095 Layout6->setMargin( 0 );
00096
00097 TypeDrinkComboBox = new QComboBox( FALSE,this, "TypeDrinkComboBox" );
00098 TypeDrinkComboBox->insertItem( tr( "Beer" ) );
00099 TypeDrinkComboBox->insertItem( tr( "Wine" ) );
00100 TypeDrinkComboBox->insertItem( tr( "Shot" ) );
00101 Layout6->addWidget( TypeDrinkComboBox );
00102
00103 TextLabel1_2 = new QLabel( this, "TextLabel1_2" );
00104 TextLabel1_2->setText( tr( "Type of drink" ) );
00105 Layout6->addWidget( TextLabel1_2 );
00106 Layout7->addLayout( Layout6 );
00107
00108 PushButton1 = new QPushButton( this, "PushButton1" );
00109 PushButton1->setText( tr( "Calculate" ) );
00110 Layout7->addWidget( PushButton1 );
00111 connect(PushButton1,SIGNAL( clicked()), this, SLOT( calculate()));
00112
00113 LCDNumber1 = new QLCDNumber( this, "LCDNumber1" );
00114 LCDNumber1->setMaximumHeight( 50);
00115 LCDNumber1->setNumDigits(6);
00116 LCDNumber1->setSmallDecimalPoint(TRUE);
00117 LCDNumber1->setFrameStyle(QFrame::Box);
00118 LCDNumber1->setLineWidth(2);
00119 LCDNumber1->setSegmentStyle( QLCDNumber::Filled);
00120 QPalette palette = LCDNumber1->palette();
00121 palette.setColor(QPalette::Normal, QColorGroup::Foreground, Qt::red);
00122 palette.setColor(QPalette::Normal, QColorGroup::Light, Qt::black);
00123 palette.setColor(QPalette::Normal, QColorGroup::Dark, Qt::darkGreen);
00124 LCDNumber1->setPalette(palette);
00125
00126 Layout7->addWidget( LCDNumber1 );
00127 NumberSpinBox->setFocus();
00128 }
00129
00130 BacDialog::~BacDialog()
00131 {}
00132
00133 void BacDialog::calculate()
00134 {
00135
00136 float weight,genderDiff, bac, typeDrink=0, drinkOz=0, bodyWater, milliliters, oz, gram, gramsMil, alc, metab, bac1;
00137 QString estBac;
00138
00139 if( GenderComboBox->currentItem()==0)
00140 genderDiff = .58;
00141 else
00142 genderDiff = .49;
00143
00144 switch(TypeDrinkComboBox->currentItem()) {
00145 case 0: {
00146 typeDrink = .045;
00147 drinkOz = 12;
00148 }
00149 break;
00150 case 1: {
00151 typeDrink = .2;
00152 drinkOz = 4;
00153 }
00154 break;
00155 case 2: {
00156 typeDrink = .5;
00157 drinkOz = 1.5;
00158 }
00159 break;
00160 };
00161
00162 if( weightUnitsCombo->currentItem() == 0 ) {
00163 weight = WeightSpinBox->value();
00164 } else {
00165 weight = WeightSpinBox->value() / 2.2046;
00166 }
00167 bodyWater = weight * genderDiff;
00168 milliliters = bodyWater * 1000;
00169 oz = 23.36/milliliters;
00170 gram = oz * .806;
00171 gramsMil = gram * 100;
00172 alc = drinkOz*NumberSpinBox->value() * typeDrink;
00173 metab = TimeSpinBox->value() * .012;
00174 bac1 = gramsMil * alc;
00175 bac = bac1 - metab;
00176
00177
00178
00179
00180 estBac.sprintf("%f",bac);
00181 LCDNumber1->display(bac);
00182
00183 }