Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

calcdisplay.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  *
00003  * File:        calcdisplay.cpp
00004  *
00005  * Description:
00006  *
00007  *
00008  * Authors:     Eric Santonacci <Eric.Santonacci@talc.fr>
00009  *
00010  * Requirements:    Qt
00011  *
00012  * $Id: calcdisplay.cpp,v 1.5 2004/09/10 11:18:05 zecke Exp $
00013  *
00014  ***************************************************************************/
00015 
00016 #include <stdio.h>
00017 #include <qvbox.h>
00018 #include <qpixmap.h>
00019 
00020 #include "currency.h"
00021 #include "calcdisplay.h"
00022 
00023 /* XPM */
00024 static char *swap_xpm[] = {
00025 /* width height num_colors chars_per_pixel */
00026 "    13    18        2            1",
00027 /* colors */
00028 ". c None",
00029 "# c #000000",
00030 /* pixels */
00031 "..#######....",
00032 "..#####......",
00033 "..######.....",
00034 "..#...###....",
00035 "........##...",
00036 ".........##..",
00037 "..........##.",
00038 "...........##",
00039 "...........##",
00040 "...........##",
00041 "...........##",
00042 "..........##.",
00043 ".........##..",
00044 "........##...",
00045 "..#...###....",
00046 "..######.....",
00047 "..#####......",
00048 "..#######....",
00049 };
00050 
00051 
00052 LCDDisplay::LCDDisplay( QWidget *parent, const char *name )
00053         : QHBox( parent, name ){
00054 
00055 
00056 
00057 this->setMargin(5);
00058 this->setSpacing(5);
00059 
00060 // Create display
00061 QVBox *vbxlayout    = new QVBox (this);
00062 
00063 /***************    Top LCD   ***********************/
00064 grpbxTop    = new QHGroupBox(vbxlayout, "grpbxTop");
00065 grpbxStyle  = grpbxTop->frameStyle();
00066 grpbxTop->setMaximumHeight(48);
00067 
00068 cbbxTop     = new QComboBox(grpbxTop, "cbbxTop");
00069 cbbxTop->setMaximumWidth(50);
00070 cbbxTop->insertStrList(aCurrency);
00071 
00072 lcdTop      = new QLCDNumber(10, grpbxTop, "lcdTop");
00073 lcdTop->setMode( QLCDNumber::DEC );
00074 lcdTop->setSmallDecimalPoint(false);
00075 lcdTop->setSegmentStyle(QLCDNumber::Flat);
00076 
00077 /**************   Bottom LCD  ************************/
00078 grpbxBottom = new QHGroupBox(vbxlayout, "grpbxBottom");
00079 grpbxBottom->setMaximumHeight(46);
00080 grpbxBottom->setFrameStyle(0);
00081 grpbxBottom->setFrameShadow(QFrame::MShadow);
00082 
00083 cbbxBottom  = new QComboBox(grpbxBottom, "cbbxBottom");
00084 cbbxBottom->setMaximumWidth(50);
00085 cbbxBottom->insertStrList(aCurrency);
00086 
00087 lcdBottom   = new QLCDNumber(10, grpbxBottom, "lcdBottom");
00088 lcdBottom->setMode( QLCDNumber::DEC );
00089 lcdBottom->setSmallDecimalPoint(false);
00090 lcdBottom->setSegmentStyle(QLCDNumber::Flat);
00091 
00092 // set combo box signals
00093 connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange()));
00094 connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange()));
00095 
00096 btnSwap     = new QPushButton(this, "swap");
00097 QPixmap imgSwap((const char**) swap_xpm);
00098 btnSwap->setPixmap(imgSwap);
00099 btnSwap->setFixedSize(20,40);
00100 // set signal
00101 connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD()));
00102 
00103 // set default LCD to top
00104 iCurrentLCD = 0;
00105 
00106 }
00107 
00108 /***********************************************************************
00109  * SLOT: Display value in the correct LCD
00110  **********************************************************************/
00111 void LCDDisplay::setValue(double dSrcValue){
00112 
00113 double  dDstValue=0;
00114 
00115 int     iSrcIndex;
00116 int     iDstIndex;
00117 
00118 
00119 // get item index of the focused
00120 if(!iCurrentLCD){
00121     iSrcIndex = cbbxTop->currentItem();
00122     iDstIndex = cbbxBottom->currentItem();
00123 }else{
00124     iSrcIndex = cbbxBottom->currentItem();
00125     iDstIndex = cbbxTop->currentItem();
00126 }
00127 
00128 if(iSrcIndex == iDstIndex)
00129     dDstValue = dSrcValue;
00130 else{
00131     if(iSrcIndex){
00132         // we are NOT in Euro as iDstIndex <> 0
00133         // Convert to Euro
00134         dDstValue = x2Euro(iSrcIndex, dSrcValue);
00135         dDstValue = Euro2x(iDstIndex, dDstValue);
00136     }else
00137         // We are in Euro
00138         dDstValue = Euro2x(iDstIndex, dSrcValue);
00139 }
00140 
00141 
00142 if(!iCurrentLCD){
00143     lcdTop->display(dSrcValue);
00144     lcdBottom->display(dDstValue);
00145 }else{
00146     lcdBottom->display(dSrcValue);
00147     lcdTop->display(dDstValue);
00148 }
00149 
00150 }
00151 
00152 /***********************************************************************
00153  * SLOT: Swap output keypad between LCD displays
00154  **********************************************************************/
00155 void LCDDisplay::swapLCD(void){
00156 
00157 double dCurrentValue;
00158 
00159 // get current value
00160 if(!iCurrentLCD){
00161     // iCurrentLCD = 0, lcdTop has current focus and is going to loose
00162     // it
00163     dCurrentValue = lcdTop->value();
00164     iCurrentLCD = 1;
00165     grpbxTop->setFrameStyle(0);
00166     grpbxBottom->setFrameStyle(grpbxStyle);
00167 }else{
00168     dCurrentValue = lcdBottom->value();
00169     iCurrentLCD = 0;
00170     grpbxTop->setFrameStyle(grpbxStyle);
00171     grpbxBottom->setFrameStyle(0);
00172 }
00173 
00174 setValue(dCurrentValue);
00175 }
00176 
00177 /***********************************************************************
00178  * SLOT: Currency change
00179  **********************************************************************/
00180 void LCDDisplay::cbbxChange(void){
00181 
00182 double dCurrentValue;
00183 
00184 // get current value
00185 if(!iCurrentLCD){
00186     dCurrentValue = lcdTop->value();
00187 }else{
00188     dCurrentValue = lcdBottom->value();
00189 }
00190 
00191 setValue(dCurrentValue);
00192 }
00193 
00194 
00195 /***********************************************************************
00196  * Euro2x converts dValue from Euro to the currency which combo box
00197  * index is provided in iIndex.
00198  **********************************************************************/
00199 double LCDDisplay::Euro2x(int iIndex, double dValue){
00200 
00201 switch (iIndex){
00202     case 0: // Euro
00203         return(dValue);
00204         break;
00205 
00206     case 1: // FF: French Francs
00207         return(dValue*FRF);
00208         break;
00209 
00210     case 2: // DM: Deutch Mark
00211         return(dValue*DEM);
00212         break;
00213 
00214     case 3: // BEL Belgium Francs
00215         return(dValue*BEF);
00216         break;
00217 
00218     case 4: // ITL Itialian Lire
00219         return(dValue*ITL);
00220         break;
00221 
00222     case 5: // LUF Luxemburg
00223         return(dValue*LUF);
00224         break;
00225 
00226     case 6: // IEP Irish Pound
00227         return(dValue*IEP);
00228         break;
00229 
00230     default:
00231         return 0;
00232 }//switch (iIndex)
00233 }// fct Eur2x
00234 
00235 
00236 
00237 /***********************************************************************
00238  * x2Euro converts dValue to Euro from the currency which combo box
00239  * index is provided in iIndex.
00240  **********************************************************************/
00241 double LCDDisplay::x2Euro(int iIndex, double dValue){
00242 
00243 switch (iIndex){
00244     case 0: // Euro
00245         return(dValue);
00246         break;
00247 
00248     case 1: // FF: French Francs
00249         return(dValue/FRF);
00250         break;
00251 
00252     case 2: // DM: Deutch Mark
00253         return(dValue/DEM);
00254         break;
00255 
00256     case 3: // BEL Belgium Francs
00257         return(dValue/BEF);
00258         break;
00259 
00260     case 4: // ITL Itialian Lire
00261         return(dValue/ITL);
00262         break;
00263 
00264     case 5: // LUF Luxemburg
00265         return(dValue/LUF);
00266         break;
00267 
00268     case 6: // IEP Irish Pound
00269         return(dValue/IEP);
00270         break;
00271 }//switch (iIndex)
00272 
00273 // we shouldn't come here
00274 return 0;
00275 
00276 }// fct x2Euro

Generated on Sat Nov 5 16:18:01 2005 for OPIE by  doxygen 1.4.2