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