kspread Library API Documentation

kcalc.cpp

00001 /*
00002     $Id: kcalc.cpp 273394 2003-12-16 19:28:32Z binner $
00003 
00004     kCalculator, a simple scientific calculator for KDE
00005 
00006     Copyright (C) 1996 Bernd Johannes Wuebben wuebben@math.cornell.edu
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022 */
00023 
00024 #include "configdlg.h"
00025 #include "version.h"
00026 #include <klocale.h>
00027 #include <knotifyclient.h>
00028 #include <qlayout.h>
00029 #include <qobjectlist.h>
00030 #include <qpushbutton.h>
00031 #include <kapplication.h>
00032 #include <kglobalsettings.h>
00033 #include <qstyle.h>
00034 #include <kdialog.h>
00035 #include <kconfig.h>
00036 #include <kglobal.h>
00037 #include "kcalc.h"
00038 
00039 extern last_input_type last_input;
00040 extern item_contents   display_data;
00041 extern num_base        current_base;
00042 
00043 QPtrList<CALCAMNT>       temp_stack;
00044 
00045 QtCalculator :: QtCalculator( Calculator *_corba, QWidget *parent, const char *name )
00046   : QDialog( parent, name )
00047 {
00048 
00049     corba = _corba;
00050     mInternalSpacing=4;
00051     key_pressed = false;
00052     selection_timer = new QTimer;
00053     status_timer = new QTimer;
00054 
00055     connect(status_timer,SIGNAL(timeout()),this,SLOT(clear_status_label()));
00056     connect(selection_timer,SIGNAL(timeout()),this,SLOT(selection_timed_out()));
00057 
00058     readSettings();
00059 
00060     QFont buttonfont( KGlobalSettings::generalFont() );
00061     buttonfont.setStyleStrategy( QFont::PreferAntialias );
00062 
00063     // Set the window caption/title
00064 
00065     // connect(kapp,SIGNAL(kdisplayPaletteChanged()),this,SLOT(set_colors()));
00066     // setCaption( kapp->caption() );
00067 
00068     // create help button
00069 
00070     QPushButton *pb;
00071 
00072     pb = new QPushButton( this, "helpbutton" );
00073     pb->setText( "kCalc" );
00074     pb->setFont( QFont("times",12,QFont::Bold,FALSE) );
00075     QToolTip::add( pb, i18n("KCalc Setup/Help") );
00076 
00077     connect( pb, SIGNAL(clicked()), SLOT(configclicked()) );
00078 
00079     // Create the display
00080     calc_display = new DLabel( this, "display" );
00081     calc_display->setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
00082     calc_display->setAlignment( AlignRight|AlignVCenter );
00083     calc_display->setFocus();
00084     calc_display->setFocusPolicy( QWidget::StrongFocus );
00085 
00086     connect(calc_display,SIGNAL(clicked()),this,SLOT(display_selected()));
00087 
00088     statusINVLabel = new QLabel( this, "INV" );
00089     Q_CHECK_PTR( statusINVLabel );
00090     statusINVLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00091     statusINVLabel->setAlignment( AlignCenter );
00092     statusINVLabel->setText("NORM");
00093 
00094     statusHYPLabel = new QLabel( this, "HYP" );
00095     Q_CHECK_PTR( statusHYPLabel );
00096     statusHYPLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00097     statusHYPLabel->setAlignment( AlignCenter );
00098 
00099     statusERRORLabel = new QLabel( this, "ERROR" );
00100     Q_CHECK_PTR( statusERRORLabel );
00101     statusERRORLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00102     statusERRORLabel->setAlignment( AlignLeft|AlignVCenter );
00103 
00104     // create angle button group
00105 
00106     QAccel *accel = new QAccel( this );
00107 
00108     QButtonGroup *angle_group = new QButtonGroup( 3, Horizontal,this, "AngleButtons" );
00109     angle_group->setTitle(i18n( "Angle") );
00110 
00111     anglebutton[0] = new QRadioButton( angle_group );
00112     anglebutton[0]->setText( "&Deg" )   ;
00113     anglebutton[0]->setChecked(   TRUE);
00114     accel->connectItem( accel->insertItem(Key_D + ALT), this ,
00115                         SLOT(Deg_Selected()) );
00116 
00117     anglebutton[1] = new QRadioButton( angle_group );
00118     anglebutton[1]->setText( "&Rad" );
00119     accel->connectItem( accel->insertItem(Key_R + ALT), this ,
00120                         SLOT(Rad_Selected()) );
00121 
00122     anglebutton[2] = new QRadioButton( angle_group );
00123     anglebutton[2]->setText( "&Gra" );
00124     accel->connectItem( accel->insertItem(Key_G + ALT), this ,
00125                         SLOT(Gra_Selected()) );
00126 
00127     connect( angle_group, SIGNAL(clicked(int)), SLOT(angle_selected(int)) );
00128 
00129 
00131 //
00132 // Create Number Base Button Group
00133 //
00134 
00135 
00136 
00137     QButtonGroup *base_group = new QButtonGroup( 4, Horizontal,this, "BaseButtons" );
00138     base_group->setTitle( i18n("Base") );
00139 
00140     basebutton[0] = new QRadioButton( base_group );
00141     basebutton[0]->setText( "&Hex" );
00142     accel->connectItem( accel->insertItem(Key_H + ALT), this ,
00143                         SLOT(Hex_Selected()) );
00144 
00145     basebutton[1] = new QRadioButton( base_group );
00146     basebutton[1]->setText( "D&ec" );
00147     basebutton[1]->setChecked(TRUE);
00148     accel->connectItem( accel->insertItem(Key_E + ALT), this ,
00149                         SLOT(Dec_Selected()) );
00150 
00151     basebutton[2] = new QRadioButton( base_group );
00152     basebutton[2]->setText( "&Oct" );
00153     accel->connectItem( accel->insertItem(Key_O + ALT), this ,
00154                         SLOT(Oct_Selected()) );
00155 
00156     basebutton[3] = new QRadioButton( base_group);
00157     basebutton[3]->setText( "&Bin" );
00158     accel->connectItem( accel->insertItem(Key_B + ALT), this ,
00159                         SLOT(Bin_Selected()) );
00160 
00161     connect( base_group, SIGNAL(clicked(int)), SLOT(base_selected(int)) );
00162 
00164 //
00165 //  Create Calculator Buttons
00166 //
00167 
00168 
00169     // First the widgets that are the parents of the buttons
00170     mSmallPage = new QWidget(this);
00171     mLargePage = new QWidget(this);
00172 
00173     pbhyp = new QPushButton("Hyp", mSmallPage, "hypbutton" );
00174     connect( pbhyp, SIGNAL(toggled(bool)), SLOT(pbhyptoggled(bool)));
00175     pbhyp->setToggleButton(TRUE);
00176 
00177     pbinv = new QPushButton( "Inv", mSmallPage, "InverseButton" );
00178     connect( pbinv, SIGNAL(toggled(bool)), SLOT(pbinvtoggled(bool)));
00179     pbinv->setToggleButton(TRUE);
00180 
00181     pbA = new QPushButton("A",mSmallPage, "Abutton" );
00182     connect( pbA, SIGNAL(toggled(bool)), SLOT(pbAtoggled(bool)));
00183     pbA->setToggleButton(TRUE);
00184 
00185     pbSin = new QPushButton("Sin",mSmallPage, "Sinbutton" );
00186     connect( pbSin, SIGNAL(toggled(bool)), SLOT(pbSintoggled(bool)));
00187     pbSin->setToggleButton(TRUE);
00188 
00189     pbplusminus = new QPushButton( "+/-", mSmallPage, "plusminusbutton" );
00190     connect( pbplusminus, SIGNAL(toggled(bool)), SLOT(pbplusminustoggled(bool)));
00191     pbplusminus->setToggleButton(TRUE);
00192     pbplusminus->setFont(buttonfont);
00193 
00194     pbB = new QPushButton("B", mSmallPage, "Bbutton" );
00195     connect( pbB, SIGNAL(toggled(bool)), SLOT(pbBtoggled(bool)));
00196     pbB->setToggleButton(TRUE);
00197 
00198     pbCos = new QPushButton("Cos",mSmallPage, "Cosbutton" );
00199     pbCos->setText( "Cos" );
00200     connect( pbCos, SIGNAL(toggled(bool)), SLOT(pbCostoggled(bool)));
00201     pbCos->setToggleButton(TRUE);
00202 
00203 
00204     pbreci = new QPushButton("1/x",mSmallPage, "recibutton" );
00205     connect( pbreci, SIGNAL(toggled(bool)), SLOT(pbrecitoggled(bool)));
00206     pbreci->setToggleButton(TRUE);
00207 
00208     pbC = new QPushButton( "C", mSmallPage, "Cbutton" );
00209     connect( pbC, SIGNAL(toggled(bool)), SLOT(pbCtoggled(bool)));
00210     pbC->setToggleButton(TRUE);
00211 
00212     pbTan = new QPushButton("Tan" ,mSmallPage,  "Tanbutton" );
00213     connect( pbTan, SIGNAL(toggled(bool)), SLOT(pbTantoggled(bool)));
00214     pbTan->setToggleButton(TRUE);
00215 
00216     pbfactorial = new QPushButton("x!",mSmallPage, "factorialbutton" );
00217     connect( pbfactorial, SIGNAL(toggled(bool)), SLOT(pbfactorialtoggled(bool)));
00218     pbfactorial->setToggleButton(TRUE);
00219 
00220     pbD = new QPushButton("D",mSmallPage,  "Dbutton" );
00221     connect( pbD, SIGNAL(toggled(bool)), SLOT(pbDtoggled(bool)));
00222     pbD->setToggleButton(TRUE);
00223 
00224     pblog = new QPushButton("Log",mSmallPage, "logbutton" );
00225     connect( pblog, SIGNAL(toggled(bool)), SLOT(pblogtoggled(bool)));
00226     pblog->setToggleButton(TRUE);
00227 
00228     pbsquare = new QPushButton( "x^2", mSmallPage,  "squarebutton" );
00229     connect( pbsquare, SIGNAL(toggled(bool)), SLOT(pbsquaretoggled(bool)));
00230     pbsquare->setToggleButton(TRUE);
00231 
00232     pbE = new QPushButton("E",mSmallPage, "Ebutton" );
00233     connect( pbE, SIGNAL(toggled(bool)), SLOT(pbEtoggled(bool)));
00234     pbE->setToggleButton(TRUE);
00235 
00236 
00237     pbln = new QPushButton( "Ln", mSmallPage, "lnbutton" );
00238     connect( pbln, SIGNAL(toggled(bool)), SLOT(pblntoggled(bool)));
00239     pbln->setToggleButton(TRUE);
00240 
00241     pbpower = new QPushButton("x^y",mSmallPage,  "powerbutton" );
00242     connect( pbpower, SIGNAL(toggled(bool)), SLOT(pbpowertoggled(bool)));
00243     pbpower->setToggleButton(TRUE);
00244 
00245     pbF = new QPushButton("F",mSmallPage, "Fbutton" );
00246     connect( pbF, SIGNAL(toggled(bool)), SLOT(pbFtoggled(bool)));
00247     pbF->setToggleButton(TRUE);
00248 
00249     pbEE = new QPushButton("EE",mLargePage,  "EEbutton" );
00250     pbEE->setToggleButton(TRUE);
00251     connect( pbEE, SIGNAL(toggled(bool)), SLOT(EEtoggled(bool)));
00252 
00253     pbMR = new QPushButton("MR",mLargePage,  "MRbutton" );
00254     connect( pbMR, SIGNAL(toggled(bool)), SLOT(pbMRtoggled(bool)));
00255     pbMR->setToggleButton(TRUE);
00256     pbMR->setFont(buttonfont);
00257 
00258     pbMplusminus = new QPushButton("M+-",mLargePage,  "Mplusminusbutton" );
00259     connect( pbMplusminus, SIGNAL(toggled(bool)), SLOT(pbMplusminustoggled(bool)));
00260     pbMplusminus->setToggleButton(TRUE);
00261 
00262     pbMC = new QPushButton("MC",mLargePage,  "MCbutton" );
00263     connect( pbMC, SIGNAL(toggled(bool)), SLOT(pbMCtoggled(bool)));
00264     pbMC->setToggleButton(TRUE);
00265 
00266     pbClear = new QPushButton("C",mLargePage,  "Clearbutton" );
00267     connect( pbClear, SIGNAL(toggled(bool)), SLOT(pbCleartoggled(bool)));
00268     pbClear->setToggleButton(TRUE);
00269 
00270     pbAC = new QPushButton("AC", mLargePage,  "ACbutton" );
00271     connect( pbAC, SIGNAL(toggled(bool)), SLOT(pbACtoggled(bool)));
00272     pbAC->setToggleButton(TRUE);
00273 
00274     pb7 = new QPushButton("7",mLargePage, "7button" );
00275     connect( pb7, SIGNAL(toggled(bool)), SLOT(pb7toggled(bool)));
00276     pb7->setToggleButton(TRUE);
00277 
00278     pb8 = new QPushButton("8",mLargePage, "8button" );
00279     connect( pb8, SIGNAL(toggled(bool)), SLOT(pb8toggled(bool)));
00280     pb8->setToggleButton(TRUE);
00281 
00282     pb9 = new QPushButton("9",mLargePage,"9button" );
00283     connect( pb9, SIGNAL(toggled(bool)), SLOT(pb9toggled(bool)));
00284     pb9->setToggleButton(TRUE);
00285 
00286     pbparenopen = new QPushButton("(",mLargePage,  "parenopenbutton" );
00287     connect( pbparenopen, SIGNAL(toggled(bool)), SLOT(pbparenopentoggled(bool)));
00288     pbparenopen->setToggleButton(TRUE);
00289 
00290     pbparenclose = new QPushButton(")",mLargePage, "parenclosebutton" );
00291     connect( pbparenclose, SIGNAL(toggled(bool)), SLOT(pbparenclosetoggled(bool)));
00292     pbparenclose->setToggleButton(TRUE);
00293 
00294     pband = new QPushButton("And",mLargePage, "andbutton" );
00295     connect( pband, SIGNAL(toggled(bool)), SLOT(pbandtoggled(bool)));
00296     pband->setToggleButton(TRUE);
00297     pband->setFont(buttonfont);
00298 
00299     pb4 = new QPushButton("4",mLargePage,  "4button" );
00300     connect( pb4, SIGNAL(toggled(bool)), SLOT(pb4toggled(bool)));
00301     pb4->setToggleButton(TRUE);
00302 
00303     pb5 = new QPushButton("5",mLargePage,  "5button" );
00304     connect( pb5, SIGNAL(toggled(bool)), SLOT(pb5toggled(bool)));
00305     pb5->setToggleButton(TRUE);
00306 
00307     pb6 = new QPushButton("6",mLargePage,  "6button" );
00308     connect( pb6, SIGNAL(toggled(bool)), SLOT(pb6toggled(bool)));
00309     pb6->setToggleButton(TRUE);
00310 
00311     pbX = new QPushButton("X",mLargePage, "Multiplybutton" );
00312     connect( pbX, SIGNAL(toggled(bool)), SLOT(pbXtoggled(bool)));
00313     pbX->setToggleButton(TRUE);
00314 
00315     pbdivision = new QPushButton("/",mLargePage,  "divisionbutton" );
00316     connect( pbdivision, SIGNAL(toggled(bool)), SLOT(pbdivisiontoggled(bool)));
00317     pbdivision->setToggleButton(TRUE);
00318 
00319     pbor = new QPushButton("Or",mLargePage,  "orbutton" );
00320     connect( pbor, SIGNAL(toggled(bool)), SLOT(pbortoggled(bool)));
00321     pbor->setToggleButton(TRUE);
00322 
00323     pb1 = new QPushButton("1",mLargePage,  "1button" );
00324     connect( pb1, SIGNAL(toggled(bool)), SLOT(pb1toggled(bool)));
00325     pb1->setToggleButton(TRUE);
00326 
00327     pb2 = new QPushButton("2",mLargePage,  "2button" );
00328 
00329     connect( pb2, SIGNAL(toggled(bool)), SLOT(pb2toggled(bool)));
00330     pb2->setToggleButton(TRUE);
00331 
00332     pb3 = new QPushButton("3",mLargePage,  "3button" );
00333     connect( pb3, SIGNAL(toggled(bool)), SLOT(pb3toggled(bool)));
00334     pb3->setToggleButton(TRUE);
00335 
00336     pbplus = new QPushButton("+",mLargePage, "plusbutton" );
00337     connect( pbplus, SIGNAL(toggled(bool)), SLOT(pbplustoggled(bool)));
00338     pbplus->setToggleButton(TRUE);
00339 
00340 
00341     pbminus = new QPushButton("-",mLargePage,  "minusbutton" );
00342     connect( pbminus, SIGNAL(toggled(bool)), SLOT(pbminustoggled(bool)));
00343     pbminus->setToggleButton(TRUE);
00344 
00345     pbshift = new QPushButton("Lsh",mLargePage, "shiftbutton" );
00346     connect( pbshift, SIGNAL(toggled(bool)), SLOT(pbshifttoggled(bool)));
00347     pbshift->setToggleButton(TRUE);
00348 
00349     pbperiod = new QPushButton(".",mLargePage,  "periodbutton" );
00350     connect( pbperiod, SIGNAL(toggled(bool)), SLOT(pbperiodtoggled(bool)));
00351     pbperiod->setToggleButton(TRUE);
00352 
00353     pb0 = new QPushButton("0",mLargePage,  "0button" );
00354     connect( pb0, SIGNAL(toggled(bool)), SLOT(pb0toggled(bool)));
00355     pb0->setToggleButton(TRUE);
00356 
00357     pbequal = new QPushButton("=",mLargePage,  "equalbutton" );
00358     connect( pbequal, SIGNAL(toggled(bool)), SLOT(pbequaltoggled(bool)));
00359     pbequal->setToggleButton(TRUE);
00360 
00361     pbpercent = new QPushButton("%",mLargePage, "percentbutton" );
00362     connect( pbpercent, SIGNAL(toggled(bool)), SLOT(pbpercenttoggled(bool)));
00363     pbpercent->setToggleButton(TRUE);
00364 
00365     pbnegate = new QPushButton("Cmp",mLargePage,  "OneComplementbutton" );
00366     connect( pbnegate, SIGNAL(toggled(bool)), SLOT(pbnegatetoggled(bool)));
00367     pbnegate->setToggleButton(TRUE);
00368 
00369     pbmod = new QPushButton("Mod",mLargePage,  "modbutton" );
00370     connect( pbmod, SIGNAL(toggled(bool)), SLOT(pbmodtoggled(bool)));
00371     pbmod->setToggleButton(TRUE);
00372 
00373     QGridLayout *smallBtnLayout = new QGridLayout(mSmallPage, 6, 3, 0,
00374                                                   mInternalSpacing);
00375     QGridLayout *largeBtnLayout = new QGridLayout(mLargePage, 5, 6, 0,
00376                                                   mInternalSpacing);
00377 
00378     QHBoxLayout *topLayout      = new QHBoxLayout();
00379     QHBoxLayout *radioLayout    = new QHBoxLayout();
00380     QHBoxLayout *btnLayout      = new QHBoxLayout();
00381     QHBoxLayout *statusLayout   = new QHBoxLayout();
00382 
00383     // bring them all together
00384     QVBoxLayout *mainLayout = new QVBoxLayout(this, mInternalSpacing,
00385                                               mInternalSpacing );
00386 
00387     mainLayout->addLayout(topLayout );
00388     mainLayout->addLayout(radioLayout, 1);
00389     mainLayout->addLayout(btnLayout);
00390     mainLayout->addLayout(statusLayout);
00391 
00392     // button layout
00393     btnLayout->addWidget(mSmallPage,0,AlignTop);
00394     btnLayout->addSpacing(mInternalSpacing);
00395     btnLayout->addWidget(mLargePage,0,AlignTop);
00396 
00397     // small button layout
00398     smallBtnLayout->addWidget(pbhyp, 0, 0);
00399     smallBtnLayout->addWidget(pbinv, 0, 1);
00400     smallBtnLayout->addWidget(pbA, 0, 2);
00401 
00402     smallBtnLayout->addWidget(pbSin, 1, 0);
00403     smallBtnLayout->addWidget(pbplusminus, 1, 1);
00404     smallBtnLayout->addWidget(pbB, 1, 2);
00405 
00406     smallBtnLayout->addWidget(pbCos, 2, 0);
00407     smallBtnLayout->addWidget(pbreci, 2, 1);
00408     smallBtnLayout->addWidget(pbC, 2, 2);
00409 
00410     smallBtnLayout->addWidget(pbTan, 3, 0);
00411     smallBtnLayout->addWidget(pbfactorial, 3, 1);
00412     smallBtnLayout->addWidget(pbD, 3, 2);
00413 
00414     smallBtnLayout->addWidget(pblog, 4, 0);
00415     smallBtnLayout->addWidget(pbsquare, 4, 1);
00416     smallBtnLayout->addWidget(pbE, 4, 2);
00417 
00418     smallBtnLayout->addWidget(pbln, 5, 0);
00419     smallBtnLayout->addWidget(pbpower, 5, 1);
00420     smallBtnLayout->addWidget(pbF, 5, 2);
00421 
00422     smallBtnLayout->setRowStretch(0, 0);
00423     smallBtnLayout->setRowStretch(1, 0);
00424     smallBtnLayout->setRowStretch(2, 0);
00425     smallBtnLayout->setRowStretch(3, 0);
00426     smallBtnLayout->setRowStretch(4, 0);
00427     smallBtnLayout->setRowStretch(5, 0);
00428 
00429     // large button layout
00430     largeBtnLayout->addWidget(pbEE, 0, 0);
00431     largeBtnLayout->addWidget(pbMR, 0, 1);
00432     largeBtnLayout->addWidget(pbMplusminus, 0, 2);
00433     largeBtnLayout->addWidget(pbMC, 0, 3);
00434     largeBtnLayout->addWidget(pbClear, 0, 4);
00435     largeBtnLayout->addWidget(pbAC, 0, 5);
00436 
00437     largeBtnLayout->addWidget(pb7, 1, 0);
00438     largeBtnLayout->addWidget(pb8, 1, 1);
00439     largeBtnLayout->addWidget(pb9, 1, 2);
00440     largeBtnLayout->addWidget(pbparenopen, 1, 3);
00441     largeBtnLayout->addWidget(pbparenclose, 1, 4);
00442     largeBtnLayout->addWidget(pband, 1, 5);
00443 
00444     largeBtnLayout->addWidget(pb4, 2, 0);
00445     largeBtnLayout->addWidget(pb5, 2, 1);
00446     largeBtnLayout->addWidget(pb6, 2, 2);
00447     largeBtnLayout->addWidget(pbX, 2, 3);
00448     largeBtnLayout->addWidget(pbdivision, 2, 4);
00449     largeBtnLayout->addWidget(pbor, 2, 5);
00450 
00451     largeBtnLayout->addWidget(pb1, 3, 0);
00452     largeBtnLayout->addWidget(pb2, 3, 1);
00453     largeBtnLayout->addWidget(pb3, 3, 2);
00454     largeBtnLayout->addWidget(pbplus, 3, 3);
00455     largeBtnLayout->addWidget(pbminus, 3, 4);
00456     largeBtnLayout->addWidget(pbshift, 3, 5);
00457 
00458     largeBtnLayout->addWidget(pbperiod, 4, 0);
00459     largeBtnLayout->addWidget(pb0, 4, 1);
00460     largeBtnLayout->addWidget(pbequal, 4, 2);
00461     largeBtnLayout->addWidget(pbpercent, 4, 3);
00462     largeBtnLayout->addWidget(pbnegate, 4, 4);
00463     largeBtnLayout->addWidget(pbmod, 4, 5);
00464 
00465     largeBtnLayout->addColSpacing(0,10);
00466     largeBtnLayout->addColSpacing(1,10);
00467     largeBtnLayout->addColSpacing(2,10);
00468     largeBtnLayout->addColSpacing(3,10);
00469     largeBtnLayout->addColSpacing(4,10);
00470     topLayout->addWidget(pb);
00471     topLayout->addWidget(calc_display, 10);
00472 
00473 
00474     // radiobutton layout
00475     radioLayout->addWidget(base_group);
00476     radioLayout->addWidget(angle_group);
00477 
00478     // status layout
00479     statusLayout->addWidget(statusINVLabel);
00480     statusLayout->addWidget(statusHYPLabel);
00481     statusLayout->addWidget(statusERRORLabel, 10);
00482 
00483     mNumButtonList.append(pb0);
00484     mNumButtonList.append(pb1);
00485     mNumButtonList.append(pb2);
00486     mNumButtonList.append(pb3);
00487     mNumButtonList.append(pb4);
00488     mNumButtonList.append(pb5);
00489     mNumButtonList.append(pb6);
00490     mNumButtonList.append(pb7);
00491     mNumButtonList.append(pb8);
00492     mNumButtonList.append(pb9);
00493 
00494     mFunctionButtonList.append(pbhyp);
00495     mFunctionButtonList.append(pbinv);
00496     mFunctionButtonList.append(pbSin);
00497     mFunctionButtonList.append(pbplusminus);
00498     mFunctionButtonList.append(pbCos);
00499     mFunctionButtonList.append(pbreci);
00500     mFunctionButtonList.append(pbTan);
00501     mFunctionButtonList.append(pbfactorial);
00502     mFunctionButtonList.append(pblog);
00503     mFunctionButtonList.append(pbsquare);
00504     mFunctionButtonList.append(pbln);
00505     mFunctionButtonList.append(pbpower);
00506 
00507     mHexButtonList.append(pbA);
00508     mHexButtonList.append(pbB);
00509     mHexButtonList.append(pbC);
00510     mHexButtonList.append(pbD);
00511     mHexButtonList.append(pbE);
00512     mHexButtonList.append(pbF);
00513 
00514     mMemButtonList.append(pbEE);
00515     mMemButtonList.append(pbMR);
00516     mMemButtonList.append(pbMplusminus);
00517     mMemButtonList.append(pbMC);
00518     mMemButtonList.append(pbClear);
00519     mMemButtonList.append(pbAC);
00520 
00521     mOperationButtonList.append(pbX);
00522     mOperationButtonList.append(pbparenopen);
00523     mOperationButtonList.append(pbparenclose);
00524     mOperationButtonList.append(pband);
00525     mOperationButtonList.append(pbdivision);
00526     mOperationButtonList.append(pbor);
00527     mOperationButtonList.append(pbplus);
00528     mOperationButtonList.append(pbminus);
00529     mOperationButtonList.append(pbshift);
00530     mOperationButtonList.append(pbperiod);
00531     mOperationButtonList.append(pbequal);
00532     mOperationButtonList.append(pbpercent);
00533     mOperationButtonList.append(pbnegate);
00534     mOperationButtonList.append(pbmod);
00535 
00536     set_colors();
00537     set_precision();
00538     set_style();
00539     updateGeometry();
00540     setFixedHeight(minimumHeight());
00541     InitializeCalculator();
00542 }
00543 
00544 QtCalculator::~QtCalculator()
00545 {
00546     delete selection_timer;
00547     delete status_timer;
00548 
00549 }
00550 
00551 void QtCalculator::set_display_font()
00552 {
00553     calc_display->setFont(kcalcdefaults.font);
00554 }
00555 
00556 void QtCalculator::updateGeometry()
00557 {
00558     QObjectList *l;
00559     QSize s;
00560     int margin;
00561 
00562     //
00563     // Uppermost bar
00564     //
00565     calc_display->setMinimumWidth(calc_display->fontMetrics().maxWidth() * 15);
00566 
00567     //
00568     // Button groups (base and angle)
00569     //
00570     //QButtonGroup *g;
00571     //g = (QButtonGroup*)(anglebutton[0]->parentWidget());
00572     //g = (QButtonGroup*)(basebutton[0]->parentWidget());
00573 
00574     //
00575     // Calculator buttons
00576     //
00577     s.setWidth(mSmallPage->fontMetrics().width("MMM"));
00578     s.setHeight(mSmallPage->fontMetrics().lineSpacing());
00579 
00580     l = (QObjectList*)mSmallPage->children(); // silence please
00581 
00582     for(uint i=0; i < l->count(); i++)
00583     {
00584         QObject *o = l->at(i);
00585         if( o->isWidgetType() )
00586         {
00587             margin = QApplication::style().
00588                 pixelMetric(QStyle::PM_ButtonMargin, ((QWidget *)o))*2;
00589             ((QWidget*)o)->setMinimumSize(s.width()+margin, s.height()+margin);
00590             ((QWidget*)o)->installEventFilter( this );
00591             ((QWidget*)o)->setAcceptDrops(true);
00592         }
00593     }
00594 
00595     l = (QObjectList*)mLargePage->children(); // silence please
00596 
00597     int h1 = pbF->minimumSize().height();
00598     int h2 = (int)((((float)h1 + 4.0) / 5.0));
00599     s.setWidth(mLargePage->fontMetrics().width("MMM") +
00600                QApplication::style().
00601                pixelMetric(QStyle::PM_ButtonMargin, pbF)*2);
00602     s.setHeight(h1 + h2);
00603 
00604     for(uint i = 0; i < l->count(); i++)
00605     {
00606         QObject *o = l->at(i);
00607         if(o->isWidgetType())
00608         {
00609             ((QWidget*)o)->setFixedSize(s);
00610             ((QWidget*)o)->installEventFilter(this);
00611             ((QWidget*)o)->setAcceptDrops(true);
00612         }
00613     }
00614 
00615     //
00616     // The status bar
00617     //
00618     s.setWidth( statusINVLabel->fontMetrics().width("NORM") +
00619                 statusINVLabel->frameWidth() * 2 + 10);
00620     statusINVLabel->setMinimumWidth(s.width());
00621     statusHYPLabel->setMinimumWidth(s.width());
00622 
00623     //setFixedSize(minimumSize());
00624 }
00625 
00626 void QtCalculator::exit()
00627 {
00628     // QApplication::exit();
00629 }
00630 
00631 void QtCalculator::Hex_Selected()
00632 {
00633   basebutton[0]->setChecked(TRUE);
00634   basebutton[1]->setChecked(FALSE);
00635   basebutton[2]->setChecked(FALSE);
00636   basebutton[3]->setChecked(FALSE);
00637   SetHex();
00638 }
00639 
00640 
00641 void QtCalculator::Dec_Selected()
00642 {
00643   basebutton[0]->setChecked(FALSE);
00644   basebutton[1]->setChecked(TRUE);
00645   basebutton[2]->setChecked(FALSE);
00646   basebutton[3]->setChecked(FALSE);
00647   SetDec();
00648 }
00649 
00650 
00651 void QtCalculator::Oct_Selected()
00652 {
00653   basebutton[0]->setChecked(FALSE);
00654   basebutton[1]->setChecked(FALSE);
00655   basebutton[2]->setChecked(TRUE);
00656   basebutton[3]->setChecked(FALSE);
00657   SetOct();
00658 }
00659 
00660 
00661 
00662 void QtCalculator::Bin_Selected()
00663 {
00664   basebutton[0]->setChecked(FALSE);
00665   basebutton[1]->setChecked(FALSE);
00666   basebutton[2]->setChecked(FALSE);
00667   basebutton[3]->setChecked(TRUE);
00668   SetBin();
00669 }
00670 
00671 void QtCalculator::Deg_Selected()
00672 {
00673   anglebutton[0]->setChecked(TRUE);
00674   anglebutton[1]->setChecked(FALSE);
00675   anglebutton[2]->setChecked(FALSE);
00676   SetDeg();
00677 }
00678 
00679 
00680 void QtCalculator::Rad_Selected()
00681 {
00682   anglebutton[0]->setChecked(FALSE);
00683   anglebutton[1]->setChecked(TRUE);
00684   anglebutton[2]->setChecked(FALSE);
00685   SetRad();
00686 
00687 }
00688 
00689 
00690 void QtCalculator::Gra_Selected()
00691 {
00692   anglebutton[0]->setChecked(FALSE);
00693   anglebutton[1]->setChecked(FALSE);
00694   anglebutton[2]->setChecked(TRUE);
00695   SetGra();
00696 }
00697 
00698 
00699 void QtCalculator::helpclicked(){
00700 }
00701 
00702 void QtCalculator::keyPressEvent( QKeyEvent *e ){
00703 
00704   switch (e->key() ){
00705 
00706   case Key_F1:
00707      helpclicked();
00708      break;
00709   case Key_F2:
00710      configclicked();
00711      break;
00712   case Key_F3:
00713     if(kcalcdefaults.style == 0)
00714       kcalcdefaults.style = 1;
00715     else if(kcalcdefaults.style == 1)
00716       kcalcdefaults.style = 2;
00717     else
00718       kcalcdefaults.style = 0;
00719      set_style();
00720      break;
00721   case Key_Up:
00722      temp_stack_prev();
00723      break;
00724   case Key_Down:
00725      temp_stack_next();
00726      break;
00727 
00728   case Key_Next:
00729      key_pressed = TRUE;
00730      pbAC->setOn(TRUE);
00731      break;
00732   case Key_Prior:
00733      key_pressed = TRUE;
00734      pbClear->setOn(TRUE);
00735      break;
00736 
00737   case Key_H:
00738      key_pressed = TRUE;
00739      pbhyp->setOn(TRUE);
00740      break;
00741   case Key_I:
00742      key_pressed = TRUE;
00743      pbinv->setOn(TRUE);
00744      break;
00745   case Key_A:
00746      key_pressed = TRUE;
00747      pbA->setOn(TRUE);
00748 
00749      break;
00750   case Key_E:
00751      key_pressed = TRUE;
00752     if (current_base == NB_HEX)
00753      pbE->setOn(TRUE);
00754     else
00755      pbEE->setOn(TRUE);
00756      break;
00757   case Key_Escape:
00758      key_pressed = TRUE;
00759      pbClear->setOn(TRUE);
00760      break;
00761   case Key_Delete:
00762      key_pressed = TRUE;
00763      pbAC->setOn(TRUE);
00764      break;
00765   case Key_S:
00766      key_pressed = TRUE;
00767      pbSin->setOn(TRUE);
00768      break;
00769   case Key_Backslash:
00770      key_pressed = TRUE;
00771      pbplusminus->setOn(TRUE);
00772      break;
00773   case Key_B:
00774      key_pressed = TRUE;
00775      pbB->setOn(TRUE);
00776      break;
00777   case Key_7:
00778      key_pressed = TRUE;
00779      pb7->setOn(TRUE);
00780      break;
00781   case Key_8:
00782      key_pressed = TRUE;
00783      pb8->setOn(TRUE);
00784      break;
00785   case Key_9:
00786      key_pressed = TRUE;
00787      pb9->setOn(TRUE);
00788      break;
00789   case Key_ParenLeft:
00790      key_pressed = TRUE;
00791      pbparenopen->setOn(TRUE);
00792      break;
00793   case Key_ParenRight:
00794      key_pressed = TRUE;
00795      pbparenclose->setOn(TRUE);
00796      break;
00797   case Key_Ampersand:
00798      key_pressed = TRUE;
00799      pband->setOn(TRUE);
00800      break;
00801   case Key_C:
00802      key_pressed = TRUE;
00803     if (current_base == NB_HEX)
00804      pbC->setOn(TRUE);
00805     else
00806      pbCos->setOn(TRUE);
00807      break;
00808   case Key_4:
00809      key_pressed = TRUE;
00810      pb4->setOn(TRUE);
00811      break;
00812   case Key_5:
00813      key_pressed = TRUE;
00814      pb5->setOn(TRUE);
00815      break;
00816   case Key_6:
00817      key_pressed = TRUE;
00818      pb6->setOn(TRUE);
00819      break;
00820   case Key_Asterisk:
00821      key_pressed = TRUE;
00822      pbX->setOn(TRUE);
00823      break;
00824   case Key_Slash:
00825      key_pressed = TRUE;
00826      pbdivision->setOn(TRUE);
00827      break;
00828   case Key_O:
00829      key_pressed = TRUE;
00830      pbor->setOn(TRUE);
00831      break;
00832   case Key_T:
00833      key_pressed = TRUE;
00834      pbTan->setOn(TRUE);
00835      break;
00836   case Key_Exclam:
00837      key_pressed = TRUE;
00838      pbfactorial->setOn(TRUE);
00839      break;
00840   case Key_D:
00841      key_pressed = TRUE;
00842      if(kcalcdefaults.style == 0)
00843        pbD->setOn(TRUE); // trig mode
00844      else
00845        pblog->setOn(TRUE); // stat mode
00846     break;
00847   case Key_1:
00848      key_pressed = TRUE;
00849      pb1->setOn(TRUE);
00850      break;
00851   case Key_2:
00852      key_pressed = TRUE;
00853      pb2->setOn(TRUE);
00854      break;
00855   case Key_3:
00856      key_pressed = TRUE;
00857      pb3->setOn(TRUE);
00858      break;
00859   case Key_Plus:
00860      key_pressed = TRUE;
00861      pbplus->setOn(TRUE);
00862      break;
00863   case Key_Minus:
00864      key_pressed = TRUE;
00865      pbminus->setOn(TRUE);
00866      break;
00867   case Key_Less:
00868      key_pressed = TRUE;
00869      pbshift->setOn(TRUE);
00870      break;
00871   case Key_N:
00872      key_pressed = TRUE;
00873      pbln->setOn(TRUE);
00874      break;
00875   case Key_L:
00876      key_pressed = TRUE;
00877      pblog->setOn(TRUE);
00878      break;
00879   case Key_AsciiCircum:
00880      key_pressed = TRUE;
00881      pbpower->setOn(TRUE);
00882      break;
00883   case Key_F:
00884      key_pressed = TRUE;
00885      pbF->setOn(TRUE);
00886      break;
00887   case Key_Period:
00888      key_pressed = TRUE;
00889      pbperiod->setOn(TRUE);
00890      break;
00891   case Key_Comma:
00892      key_pressed = TRUE;
00893      pbperiod->setOn(TRUE);
00894      break;
00895   case Key_0:
00896      key_pressed = TRUE;
00897      pb0->setOn(TRUE);
00898      break;
00899      case Key_Equal:
00900      key_pressed = TRUE;
00901      pbequal->setOn(TRUE);
00902      break;
00903   case Key_Return:
00904      key_pressed = TRUE;
00905      pbequal->setOn(TRUE);
00906      break;
00907   case Key_Enter:
00908      key_pressed = TRUE;
00909      pbequal->setOn(TRUE);
00910      break;
00911   case Key_Percent:
00912      key_pressed = TRUE;
00913      pbpercent->setOn(TRUE);
00914      break;
00915   case Key_AsciiTilde:
00916      key_pressed = TRUE;
00917      pbnegate->setOn(TRUE);
00918      break;
00919   case Key_Colon:
00920      key_pressed = TRUE;
00921      pbmod->setOn(TRUE);
00922      break;
00923   case Key_BracketLeft:
00924      key_pressed = TRUE;
00925      pbsquare->setOn(TRUE);
00926      break;
00927  case Key_Backspace:
00928      key_pressed = TRUE;
00929      pbAC->setOn(TRUE);
00930      break;
00931   case Key_R:
00932      key_pressed = TRUE;
00933      pbreci->setOn(TRUE);
00934      break;
00935   }
00936 }
00937 
00938 void QtCalculator::keyReleaseEvent( QKeyEvent *e ){
00939   switch (e->key() ){
00940 
00941   case Key_Next:
00942      key_pressed = FALSE;
00943      pbAC->setOn(FALSE);
00944      break;
00945   case Key_Prior:
00946      key_pressed = FALSE;
00947      pbClear->setOn(FALSE);
00948      break;
00949 
00950   case Key_H:
00951     key_pressed = FALSE;
00952      pbhyp->setOn(FALSE);
00953      break;
00954   case Key_I:
00955     key_pressed = FALSE;
00956      pbinv->setOn(FALSE);
00957      break;
00958   case Key_A:
00959     key_pressed = FALSE;
00960      pbA->setOn(FALSE);
00961      break;
00962   case Key_E:
00963     key_pressed = FALSE;
00964     if (current_base == NB_HEX)
00965      pbE->setOn(FALSE);
00966     else
00967      pbEE->setOn(FALSE);
00968      break;
00969   case Key_Escape:
00970     key_pressed = FALSE;
00971      pbClear->setOn(FALSE);
00972      break;
00973   case Key_Delete:
00974     key_pressed = FALSE;
00975      pbAC->setOn(FALSE);
00976      break;
00977   case Key_S:
00978     key_pressed = FALSE;
00979      pbSin->setOn(FALSE);
00980      break;
00981   case Key_Backslash:
00982     key_pressed = FALSE;
00983      pbplusminus->setOn(FALSE);
00984      break;
00985   case Key_B:
00986     key_pressed = FALSE;
00987      pbB->setOn(FALSE);
00988      break;
00989   case Key_7:
00990     key_pressed = FALSE;
00991      pb7->setOn(FALSE);
00992      break;
00993   case Key_8:
00994     key_pressed = FALSE;
00995      pb8->setOn(FALSE);
00996      break;
00997   case Key_9:
00998     key_pressed = FALSE;
00999      pb9->setOn(FALSE);
01000      break;
01001   case Key_ParenLeft:
01002     key_pressed = FALSE;
01003      pbparenopen->setOn(FALSE);
01004      break;
01005   case Key_ParenRight:
01006     key_pressed = FALSE;
01007      pbparenclose->setOn(FALSE);
01008      break;
01009   case Key_Ampersand:
01010     key_pressed = FALSE;
01011      pband->setOn(FALSE);
01012      break;
01013   case Key_C:
01014     key_pressed = FALSE;
01015     if (current_base == NB_HEX)
01016      pbC->setOn(FALSE);
01017     else
01018      pbCos->setOn(FALSE);
01019      break;
01020   case Key_4:
01021     key_pressed = FALSE;
01022      pb4->setOn(FALSE);
01023      break;
01024   case Key_5:
01025     key_pressed = FALSE;
01026      pb5->setOn(FALSE);
01027      break;
01028   case Key_6:
01029     key_pressed = FALSE;
01030      pb6->setOn(FALSE);
01031      break;
01032   case Key_Asterisk:
01033     key_pressed = FALSE;
01034      pbX->setOn(FALSE);
01035      break;
01036   case Key_Slash:
01037     key_pressed = FALSE;
01038      pbdivision->setOn(FALSE);
01039      break;
01040   case Key_O:
01041     key_pressed = FALSE;
01042      pbor->setOn(FALSE);
01043      break;
01044   case Key_T:
01045     key_pressed = FALSE;
01046      pbTan->setOn(FALSE);
01047      break;
01048   case Key_Exclam:
01049     key_pressed = FALSE;
01050      pbfactorial->setOn(FALSE);
01051      break;
01052   case Key_D:
01053     key_pressed = FALSE;
01054     if(kcalcdefaults.style == 0)
01055       pbD->setOn(FALSE); // trig mode
01056     else
01057       pblog->setOn(FALSE);// stat mode
01058      break;
01059   case Key_1:
01060     key_pressed = FALSE;
01061      pb1->setOn(FALSE);
01062      break;
01063   case Key_2:
01064     key_pressed = FALSE;
01065      pb2->setOn(FALSE);
01066      break;
01067   case Key_3:
01068     key_pressed = FALSE;
01069      pb3->setOn(FALSE);
01070      break;
01071   case Key_Plus:
01072     key_pressed = FALSE;
01073      pbplus->setOn(FALSE);
01074      break;
01075   case Key_Minus:
01076     key_pressed = FALSE;
01077      pbminus->setOn(FALSE);
01078      break;
01079   case Key_Less:
01080     key_pressed = FALSE;
01081      pbshift->setOn(FALSE);
01082      break;
01083   case Key_N:
01084     key_pressed = FALSE;
01085      pbln->setOn(FALSE);
01086      break;
01087   case Key_L:
01088     key_pressed = FALSE;
01089      pblog->setOn(FALSE);
01090      break;
01091   case Key_AsciiCircum:
01092     key_pressed = FALSE;
01093      pbpower->setOn(FALSE);
01094      break;
01095   case Key_F:
01096     key_pressed = FALSE;
01097      pbF->setOn(FALSE);
01098      break;
01099   case Key_Period:
01100     key_pressed = FALSE;
01101      pbperiod->setOn(FALSE);
01102      break;
01103   case Key_Comma:
01104     key_pressed = FALSE;
01105      pbperiod->setOn(FALSE);
01106      break;
01107   case Key_0:
01108     key_pressed = FALSE;
01109      pb0->setOn(FALSE);
01110      break;
01111   case Key_Equal:
01112     key_pressed = FALSE;
01113      pbequal->setOn(FALSE);
01114      break;
01115   case Key_Return:
01116     key_pressed = FALSE;
01117      pbequal->setOn(FALSE);
01118      break;
01119   case Key_Enter:
01120      key_pressed = FALSE;
01121      pbequal->setOn(FALSE);
01122      break;
01123   case Key_Percent:
01124     key_pressed = FALSE;
01125      pbpercent->setOn(FALSE);
01126      break;
01127   case Key_AsciiTilde:
01128     key_pressed = FALSE;
01129      pbnegate->setOn(FALSE);
01130      break;
01131   case Key_Colon:
01132     key_pressed = FALSE;
01133      pbmod->setOn(FALSE);
01134      break;
01135   case Key_BracketLeft:
01136      key_pressed = FALSE;
01137      pbsquare->setOn(FALSE);
01138      break;
01139   case Key_Backspace:
01140      key_pressed = FALSE;
01141      pbAC->setOn(FALSE);
01142      break;
01143   case Key_R:
01144      key_pressed = FALSE;
01145      pbreci->setOn(FALSE);
01146      break;
01147   }
01148 
01149   clear_buttons();
01150 }
01151 
01152 void QtCalculator::clear_buttons(){
01153 
01154 }
01155 
01156 void QtCalculator::EEtoggled(bool myboolean){
01157 
01158   if(myboolean)
01159     EE();
01160   if(pbEE->isOn() && (!key_pressed))
01161     pbEE->setOn(FALSE);
01162 }
01163 
01164 void QtCalculator::pbinvtoggled(bool myboolean){
01165   if(myboolean)
01166     SetInverse();
01167   if(pbinv->isOn() && (!key_pressed))
01168     pbinv->setOn(FALSE);
01169 }
01170 
01171 void QtCalculator::pbhyptoggled(bool myboolean){
01172   if(myboolean)
01173     EnterHyp();
01174   if(pbhyp->isOn() && (!key_pressed))
01175     pbhyp->setOn(FALSE);
01176 }
01177 void QtCalculator::pbMRtoggled(bool myboolean){
01178   if(myboolean)
01179     MR();
01180   if(pbMR->isOn() && (!key_pressed))
01181     pbMR->setOn(FALSE);
01182 }
01183 
01184 void QtCalculator::pbAtoggled(bool myboolean){
01185   if(myboolean)
01186     buttonA();
01187     if(pbA->isOn() && (!key_pressed))
01188    pbA->setOn(FALSE);
01189 }
01190 
01191 void QtCalculator::pbSintoggled(bool myboolean){
01192   if(myboolean)
01193     ExecSin();
01194   if(pbSin->isOn() && (!key_pressed))
01195     pbSin->setOn(FALSE);
01196 }
01197 void QtCalculator::pbplusminustoggled(bool myboolean){
01198   if(myboolean)
01199     EnterNegate();
01200   if(pbplusminus->isOn() && (!key_pressed))
01201     pbplusminus->setOn(FALSE);
01202 }
01203 void QtCalculator::pbMplusminustoggled(bool myboolean){
01204   if(myboolean)
01205     Mplusminus();
01206   if(pbMplusminus->isOn() && (!key_pressed))
01207     pbMplusminus->setOn(FALSE);
01208 }
01209 void QtCalculator::pbBtoggled(bool myboolean){
01210   if(myboolean)
01211     buttonB();
01212   if(pbB->isOn() && (!key_pressed))
01213     pbB->setOn(FALSE);
01214 }
01215 void QtCalculator::pbCostoggled(bool myboolean){
01216   if(myboolean)
01217     ExecCos();
01218   if(pbCos->isOn() && (!key_pressed))
01219     pbCos->setOn(FALSE);
01220 }
01221 void QtCalculator::pbrecitoggled(bool myboolean){
01222   if(myboolean)
01223     EnterRecip();
01224   if(pbreci->isOn() && (!key_pressed))
01225     pbreci->setOn(FALSE);
01226 }
01227 void QtCalculator::pbCtoggled(bool myboolean){
01228   if(myboolean)
01229     buttonC();
01230   if(pbC->isOn() && (!key_pressed))
01231     pbC->setOn(FALSE);
01232 }
01233 void QtCalculator::pbTantoggled(bool myboolean){
01234   if(myboolean)
01235     ExecTan();
01236   if(pbTan->isOn() && (!key_pressed))
01237     pbTan->setOn(FALSE);
01238 }
01239 void QtCalculator::pbfactorialtoggled(bool myboolean){
01240   if(myboolean)
01241     EnterFactorial();
01242   if(pbfactorial->isOn() && (!key_pressed))
01243     pbfactorial->setOn(FALSE);
01244 }
01245 void QtCalculator::pbDtoggled(bool myboolean){
01246   if(myboolean)
01247     buttonD();
01248   if(pbD->isOn() && (!key_pressed))
01249     pbD->setOn(FALSE);
01250 }
01251 void QtCalculator::pblogtoggled(bool myboolean){
01252   if(myboolean)
01253    EnterLogr();
01254   if(pblog->isOn() && (!key_pressed))
01255     pblog->setOn(FALSE);
01256 }
01257 void QtCalculator::pbsquaretoggled(bool myboolean){
01258   if(myboolean)
01259     EnterSquare();
01260   if(pbsquare->isOn() && (!key_pressed))
01261     pbsquare->setOn(FALSE);
01262 }
01263 void QtCalculator::pbEtoggled(bool myboolean){
01264   if(myboolean)
01265     buttonE();
01266   if(pbE->isOn() && (!key_pressed))
01267     pbE->setOn(FALSE);
01268 }
01269 void QtCalculator::pblntoggled(bool myboolean){
01270   if(myboolean)
01271     EnterLogn();
01272   if(pbln->isOn() && (!key_pressed))
01273     pbln->setOn(FALSE);
01274 }
01275 void QtCalculator::pbpowertoggled(bool myboolean){
01276   if(myboolean)
01277     Power();
01278   if(pbpower->isOn() && (!key_pressed))
01279     pbpower->setOn(FALSE);
01280 }
01281 void QtCalculator::pbFtoggled(bool myboolean){
01282   if(myboolean)
01283     buttonF();
01284   if(pbF->isOn() && (!key_pressed))
01285     pbF->setOn(FALSE);
01286 }
01287 void QtCalculator::pbMCtoggled(bool myboolean){
01288   if(myboolean)
01289     MC();
01290   if(pbMC->isOn() && (!key_pressed))
01291     pbMC->setOn(FALSE);
01292 }
01293 void QtCalculator::pbCleartoggled(bool myboolean){
01294   if(myboolean)
01295     Clear();
01296   if(pbClear->isOn() && (!key_pressed))
01297     pbClear->setOn(FALSE);
01298 }
01299 void QtCalculator::pbACtoggled(bool myboolean){
01300   if(myboolean)
01301     ClearAll();
01302   if(pbAC->isOn() && (!key_pressed))
01303     pbAC->setOn(FALSE);
01304 }
01305 void QtCalculator::pb7toggled(bool myboolean){
01306   if(myboolean)
01307     button7();
01308   if(pb7->isOn() && (!key_pressed))
01309     pb7->setOn(FALSE);
01310 }
01311 void QtCalculator::pb8toggled(bool myboolean){
01312   if(myboolean)
01313     button8();
01314   if(pb8->isOn() && (!key_pressed))
01315     pb8->setOn(FALSE);
01316 }
01317 void QtCalculator::pb9toggled(bool myboolean){
01318   if(myboolean)
01319     button9();
01320   if(pb9->isOn() && (!key_pressed))
01321     pb9->setOn(FALSE);
01322 }
01323 void QtCalculator::pbparenopentoggled(bool myboolean){
01324   if(myboolean)
01325     EnterOpenParen();
01326   if(pbparenopen->isOn() && (!key_pressed))
01327     pbparenopen->setOn(FALSE);
01328 }
01329 void QtCalculator::pbparenclosetoggled(bool myboolean){
01330   if(myboolean)
01331     EnterCloseParen();
01332   if(pbparenclose->isOn() && (!key_pressed))
01333     pbparenclose->setOn(FALSE);
01334 }
01335 void QtCalculator::pbandtoggled(bool myboolean){
01336   if(myboolean)
01337     And();
01338   if(pband->isOn() && (!key_pressed))
01339     pband->setOn(FALSE);
01340 }
01341 void QtCalculator::pb4toggled(bool myboolean){
01342   if(myboolean)
01343     button4();
01344   if(pb4->isOn() && (!key_pressed))
01345     pb4->setOn(FALSE);
01346 }
01347 void QtCalculator::pb5toggled(bool myboolean){
01348   if(myboolean)
01349     button5();
01350   if(pb5->isOn() && (!key_pressed))
01351     pb5->setOn(FALSE);
01352 }
01353 void QtCalculator::pb6toggled(bool myboolean){
01354   if(myboolean)
01355     button6();
01356   if(pb6->isOn() && (!key_pressed))
01357     pb6->setOn(FALSE);
01358 }
01359 void QtCalculator::pbXtoggled(bool myboolean){
01360   if(myboolean)
01361     Multiply();
01362   if(pbX->isOn() && (!key_pressed))
01363     pbX->setOn(FALSE);
01364 }
01365 void QtCalculator::pbdivisiontoggled(bool myboolean){
01366   if(myboolean)
01367     Divide();
01368   if(pbdivision->isOn() && (!key_pressed))
01369     pbdivision->setOn(FALSE);
01370 }
01371 void QtCalculator::pbortoggled(bool myboolean){
01372   if(myboolean)
01373     Or();
01374   if(pbor->isOn() && (!key_pressed))
01375     pbor->setOn(FALSE);
01376 }
01377 void QtCalculator::pb1toggled(bool myboolean){
01378   if(myboolean)
01379     button1();
01380   if(pb1->isOn() && (!key_pressed))
01381     pb1->setOn(FALSE);
01382 }
01383 void QtCalculator::pb2toggled(bool myboolean){
01384   if(myboolean)
01385     button2();
01386   if(pb2->isOn() && (!key_pressed))
01387     pb2->setOn(FALSE);
01388 }
01389 void QtCalculator::pb3toggled(bool myboolean){
01390   if(myboolean)
01391     button3();
01392   if(pb3->isOn() && (!key_pressed))
01393     pb3->setOn(FALSE);
01394 }
01395 void QtCalculator::pbplustoggled(bool myboolean){
01396   if(myboolean)
01397     Plus();
01398   if(pbplus->isOn() && (!key_pressed))
01399     pbplus->setOn(FALSE);
01400 }
01401 void QtCalculator::pbminustoggled(bool myboolean){
01402   if(myboolean)
01403     Minus();
01404   if(pbminus->isOn() && (!key_pressed))
01405     pbminus->setOn(FALSE);
01406 }
01407 void QtCalculator::pbshifttoggled(bool myboolean){
01408   if(myboolean)
01409     Shift();
01410   if(pbshift->isOn() && (!key_pressed))
01411     pbshift->setOn(FALSE);
01412 }
01413 void QtCalculator::pbperiodtoggled(bool myboolean){
01414   if(myboolean)
01415     EnterDecimal();
01416   if(pbperiod->isOn() && (!key_pressed))
01417     pbperiod->setOn(FALSE);
01418 }
01419 void QtCalculator::pb0toggled(bool myboolean){
01420   if(myboolean)
01421     button0();
01422   if(pb0->isOn() && (!key_pressed))
01423     pb0->setOn(FALSE);
01424 }
01425 void QtCalculator::pbequaltoggled(bool myboolean){
01426   if(myboolean)
01427     EnterEqual();
01428   if(pbequal->isOn() && (!key_pressed))
01429     pbequal->setOn(FALSE);
01430 }
01431 void QtCalculator::pbpercenttoggled(bool myboolean){
01432   if(myboolean)
01433     EnterPercent();
01434   if(pbpercent->isOn() && (!key_pressed))
01435     pbpercent->setOn(FALSE);
01436 }
01437 void QtCalculator::pbnegatetoggled(bool myboolean){
01438   if(myboolean)
01439     EnterNotCmp();
01440   if(pbnegate->isOn() && (!key_pressed))
01441     pbnegate->setOn(FALSE);
01442 }
01443 void QtCalculator::pbmodtoggled(bool myboolean)  {
01444   if(myboolean)
01445     Mod();
01446   if(pbmod->isOn() && (!key_pressed))
01447     pbmod->setOn(FALSE);
01448 }
01449 
01450 void QtCalculator::configclicked(){
01451 
01452 
01453   QTabDialog * tabdialog;
01454   tabdialog = new QTabDialog(0,"tabdialog",TRUE);
01455 
01456   tabdialog->setCaption( i18n("KCalc Configuration") );
01457   tabdialog->resize( 360, 390 );
01458   tabdialog->setCancelButton( i18n("&Cancel") );
01459   tabdialog->setOKButton(i18n("&OK"));
01460 
01461   QWidget *about = new QWidget(tabdialog,"about");
01462   QVBoxLayout *lay1 = new QVBoxLayout( about );
01463   lay1->setMargin( KDialog::marginHint() );
01464   lay1->setSpacing( KDialog::spacingHint() );
01465 
01466   QGroupBox *box = new QGroupBox(0,Qt::Vertical,about,"box");
01467   box->layout()->setSpacing(KDialog::spacingHint());
01468   box->layout()->setMargin(KDialog::marginHint());
01469   QGridLayout *grid1 = new QGridLayout(box->layout(),2,2);
01470   QLabel  *label = new QLabel(box,"label");
01471   QLabel  *label2 = new QLabel(box,"label2");
01472 
01473   box->setTitle(i18n("About"));
01474   grid1->addWidget(label,0,1);
01475   grid1->addMultiCellWidget(label2,2,2,0,1);
01476 
01477   QString labelstring = "KCalc "KCALCVERSION"\n"\
01478     "Bernd Johannes Wuebben\n"\
01479     "wuebben@math.cornell.edu\n"\
01480     "wuebben@kde.org\n"\
01481     "Copyright (C) 1996-98\n"\
01482     "\n\n";
01483 
01484   QString labelstring2 =
01485 #ifdef HAVE_LONG_DOUBLE
01486                 i18n( "Base type: long double\n");
01487 #else
01488                 i18n( "Due to broken glibc's everywhere, "\
01489                       "I had to reduce KCalc's precision from 'long double' "\
01490                       "to 'double'. "\
01491                       "Owners of systems with a working libc "\
01492                       "should recompile KCalc with 'long double' precision "\
01493                       "enabled. See the README for details.");
01494 #endif
01495 
01496   label->setAlignment(AlignLeft|WordBreak|ExpandTabs);
01497   label->setText(labelstring);
01498 
01499   label2->setAlignment(AlignLeft|WordBreak|ExpandTabs);
01500   label2->setText(labelstring2);
01501 
01502   // HACK
01503   // QPixmap pm( BarIcon( "kcalclogo" ) );
01504   QPixmap pm;
01505   QLabel *logo = new QLabel(box);
01506   logo->setPixmap(pm);
01507   grid1->addWidget(logo,0,0);
01508   lay1->addWidget(box);
01509 
01510 
01511   DefStruct newdefstruct;
01512   newdefstruct.forecolor  = kcalcdefaults.forecolor;
01513   newdefstruct.backcolor  = kcalcdefaults.backcolor;
01514   newdefstruct.precision  = kcalcdefaults.precision;
01515   newdefstruct.fixedprecision  = kcalcdefaults.fixedprecision;
01516   newdefstruct.fixed  = kcalcdefaults.fixed;
01517   newdefstruct.style  = kcalcdefaults.style;
01518   newdefstruct.beep  = kcalcdefaults.beep;
01519 
01520   ConfigDlg *configdlg;
01521   configdlg = new ConfigDlg(tabdialog,"configdlg",&newdefstruct);
01522 
01523   tabdialog->addTab(configdlg,i18n("Defaults"));
01524   tabdialog->addTab(about,i18n("About"));
01525 
01526 
01527   if(tabdialog->exec() == QDialog::Accepted){
01528 
01529 
01530     kcalcdefaults.forecolor  = newdefstruct.forecolor;
01531     kcalcdefaults.backcolor  = newdefstruct.backcolor;
01532     kcalcdefaults.precision  = newdefstruct.precision;
01533     kcalcdefaults.fixedprecision  = newdefstruct.fixedprecision;
01534     kcalcdefaults.fixed  = newdefstruct.fixed;
01535     kcalcdefaults.style  = newdefstruct.style;
01536     kcalcdefaults.beep  = newdefstruct.beep;
01537 
01538     set_colors();
01539     set_precision();
01540     set_style();
01541     updateGeometry();
01542     resize(minimumSize());
01543   }
01544   delete configdlg;
01545 }
01546 
01547 
01548 void QtCalculator::set_style(){
01549 
01550   switch(kcalcdefaults.style){
01551   case  0:{
01552     pbhyp->setText( "Hyp" );
01553     pbSin->setText( "Sin" );
01554     pbCos->setText( "Cos" );
01555     pbTan->setText( "Tan" );
01556     pblog->setText( "Log" );
01557     pbln ->setText( "Ln"  );
01558     break;
01559   }
01560   case 1:{
01561     pbhyp->setText( "N" );
01562     pbSin->setText( "Mea" );
01563     pbCos->setText( "Std" );
01564     pbTan->setText( "Med" );
01565     pblog->setText( "Dat" );
01566     pbln ->setText( "CSt"  );
01567     break;
01568   }
01569   case 2:{
01570     pbhyp->setText( "N" );
01571     pbSin->setText( "Min" );
01572     pbCos->setText( "Max" );
01573     pbTan->setText( "Med" );
01574     pblog->setText( "Sum" );
01575     pbln ->setText( "Mul"  );
01576     break;
01577   }
01578 
01579   default:
01580     break;
01581   }
01582 }
01583 
01584 void QtCalculator::readSettings()
01585 {
01586     QColor tmpC(189, 255, 180);
01587     QColor blackC(0,0,0);
01588 
01589     KConfig *config = KGlobal::config();
01590     config->setGroup("CalcPlugin");
01591     kcalcdefaults.forecolor = config->readColorEntry("ForeColor", &blackC);
01592     kcalcdefaults.backcolor = config->readColorEntry("BackColor", &tmpC);
01593 
01594 #ifdef HAVE_LONG_DOUBLE
01595     kcalcdefaults.precision = config->readNumEntry("precision", (int)14);
01596 #else
01597     kcalcdefaults.precision = config->readNumEntry("precision", (int)10);
01598 #endif
01599     kcalcdefaults.fixedprecision = config->readNumEntry("fixedprecision", (int)2);
01600     kcalcdefaults.fixed = config->readBoolEntry("fixed", false);
01601 
01602     kcalcdefaults.style = config->readNumEntry("style", (int)0);
01603     kcalcdefaults.beep  = config->readBoolEntry("beep", true);
01604 }
01605 
01606 void QtCalculator::writeSettings()
01607 {
01608     KConfig *config = KGlobal::config();
01609 
01610     config->setGroup("CalcPlugin");
01611     config->writeEntry("ForeColor",kcalcdefaults.forecolor);
01612     config->writeEntry("BackColor",kcalcdefaults.backcolor);
01613 
01614     config->writeEntry("precision",  kcalcdefaults.precision);
01615     config->writeEntry("fixedprecision",  kcalcdefaults.fixedprecision);
01616     config->writeEntry("fixed",  kcalcdefaults.fixed);
01617 
01618     config->writeEntry("style",(int)kcalcdefaults.style);
01619     config->writeEntry("beep", kcalcdefaults.beep);
01620 
01621     config->sync();
01622 }
01623 
01624 void QtCalculator::display_selected(){
01625 
01626   if(calc_display->Button() == LeftButton){
01627 
01628     if(calc_display->isLit()){
01629 
01630       QClipboard *cb = QApplication::clipboard();
01631       cb->setText(calc_display->text());
01632       selection_timer->start(100);
01633 
01634     }
01635     else{
01636 
01637       selection_timer->stop();
01638 
01639     }
01640 
01641     invertColors();
01642   }
01643   else{
01644 
01645     QClipboard *cb = QApplication::clipboard();
01646 
01647     CALCAMNT result;
01648     result = (CALCAMNT) cb->text().toDouble();
01649     //    printf("%Lg\n",result);
01650     last_input = PASTE;
01651     DISPLAY_AMOUNT = result;
01652     UpdateDisplay();
01653   }
01654 
01655 }
01656 
01657 void QtCalculator::selection_timed_out(){
01658 
01659   //  printf("selection timed out\n");
01660   selection_timer->stop();
01661   calc_display->setLit(FALSE);
01662   invertColors();
01663 
01664 
01665 }
01666 
01667 
01668 void QtCalculator::clear_status_label(){
01669 
01670   statusERRORLabel->setText("");
01671   status_timer->stop();
01672 }
01673 
01674 void QtCalculator::setStatusLabel(const QString& string){
01675 
01676   statusERRORLabel->setText(string);
01677   status_timer->start(3000,TRUE);
01678 
01679 }
01680 
01681 
01682 void QtCalculator::invertColors(){
01683 
01684   QColor tmpcolor;
01685 
01686   if(calc_display->isLit()){
01687     tmpcolor = kcalcdefaults.backcolor;
01688     kcalcdefaults.backcolor = kcalcdefaults.forecolor;
01689     kcalcdefaults.forecolor = tmpcolor;
01690     set_colors();
01691     tmpcolor = kcalcdefaults.backcolor;
01692     kcalcdefaults.backcolor = kcalcdefaults.forecolor;
01693     kcalcdefaults.forecolor = tmpcolor;
01694   }
01695   else{
01696     set_colors();
01697     //printf("normal Colors\n");
01698   }
01699 }
01700 
01701 void QtCalculator::closeEvent( QCloseEvent*e )
01702 {
01703     writeSettings();
01704     e->accept();
01705 }
01706 
01707 void QtCalculator::set_colors(){
01708 
01709 
01710   QPalette mypalette = (calc_display->palette()).copy();
01711 
01712   QColorGroup cgrp = mypalette.active();
01713   QColorGroup ncgrp(kcalcdefaults.forecolor,
01714                     cgrp.background(),
01715                     cgrp.light(),
01716                     cgrp.dark(),
01717                     cgrp.mid(),
01718                     kcalcdefaults.forecolor,
01719                     kcalcdefaults.backcolor);
01720 
01721   mypalette.setActive(ncgrp);
01722   mypalette.setDisabled(ncgrp);
01723   mypalette.setActive(ncgrp);
01724 
01725   calc_display->setPalette(mypalette);
01726   calc_display->setBackgroundColor(kcalcdefaults.backcolor);
01727 
01728 }
01729 
01730 void QtCalculator::set_precision(){
01731 
01732   UpdateDisplay();
01733 }
01734 
01735 void QtCalculator::temp_stack_next(){
01736 
01737   CALCAMNT *number;
01738 
01739   if( temp_stack.current() == temp_stack.getLast()){
01740         KNotifyClient::beep();
01741         return;
01742   }
01743 
01744   number = temp_stack.next();
01745 
01746   if(number == NULL){
01747        KNotifyClient::beep();
01748     return;
01749   }
01750   else{
01751     //    printf("Number: %Lg\n",*number);
01752     last_input = RECALL;
01753     DISPLAY_AMOUNT = *number;
01754     UpdateDisplay();
01755 
01756   }
01757 
01758 
01759 }
01760 
01761 void QtCalculator::temp_stack_prev(){
01762 
01763   CALCAMNT *number;
01764 
01765   if( temp_stack.current() == temp_stack.getFirst()){
01766         KNotifyClient::beep();
01767         return;
01768   }
01769 
01770   number = temp_stack.prev();
01771 
01772   if(number == NULL){
01773     KNotifyClient::beep();
01774     return;
01775   }
01776   else{
01777     //    printf("Number: %Lg\n",*number);
01778     last_input = RECALL;
01779     DISPLAY_AMOUNT = *number;
01780     UpdateDisplay();
01781 
01782   }
01783 
01784 }
01785 
01786 #include "kcalc.moc"
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:42:45 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003