29 #include <QApplication>
35 #include <kaboutdata.h>
36 #include <kacceleratormanager.h>
38 #include <kactioncollection.h>
39 #include <kapplication.h>
40 #include <kbuttongroup.h>
41 #include <kcmdlineargs.h>
42 #include <kcolorbutton.h>
43 #include <kcolormimedata.h>
45 #include <kconfigdialog.h>
48 #include <kglobalsettings.h>
51 #include <knumvalidator.h>
52 #include <kpushbutton.h>
53 #include <kstandardaction.h>
54 #include <kstatusbar.h>
55 #include <ktoggleaction.h>
57 #include <kxmlguifactory.h>
66 const char description[] = I18N_NOOP(
"KDE Calculator");
68 const int maxprecision = 1000;
88 setCentralWidget(central);
89 KAcceleratorManager::setNoAccel(central);
106 base_choose_group_->
addButton(hexRadio, HexMode);
107 base_choose_group_->
addButton(decRadio, DecMode);
108 base_choose_group_->
addButton(octRadio, OctMode);
109 base_choose_group_->
addButton(binRadio, BinMode);
110 connect(base_choose_group_, SIGNAL(buttonClicked(
int)),
115 angle_choose_group_->
addButton(degRadio, DegMode);
116 angle_choose_group_->
addButton(radRadio, RadMode);
117 angle_choose_group_->
addButton(gradRadio, GradMode);
118 connect(angle_choose_group_, SIGNAL(buttonClicked(
int)),
122 constants_menu_ = createConstantsMenu();
123 menuBar()->insertMenu((menuBar()->actions)()[2], constants_menu_);
131 connect(calc_display, SIGNAL(changedText(
QString)), SLOT(setCaption(
QString)));
134 calc_display->changeSettings();
139 setFixedSize(minimumSize());
146 switch (calculatorMode) {
148 action_mode_science_->setChecked(
true);
151 action_mode_statistic_->setChecked(
true);
154 action_mode_numeral_->setChecked(
true);
158 action_mode_simple_->setChecked(
true);
165 connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(
setColors()));
166 connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()), SLOT(
setFonts()));
168 calc_display->setFocus();
184 void KCalculator::setupMainActions() {
187 KStandardAction::quit(
this, SLOT(close()), actionCollection());
190 KStandardAction::undo(calc_display, SLOT(slotHistoryBack()), actionCollection());
191 KStandardAction::redo(calc_display, SLOT(slotHistoryForward()), actionCollection());
192 KStandardAction::cut(calc_display, SLOT(slotCut()), actionCollection());
193 KStandardAction::copy(calc_display, SLOT(slotCopy()), actionCollection());
194 KStandardAction::paste(calc_display, SLOT(slotPaste()), actionCollection());
199 action_mode_simple_ = actionCollection()->add<KToggleAction>(
QLatin1String(
"mode_simple"));
200 action_mode_simple_->setActionGroup(modeGroup);
201 action_mode_simple_->setText(i18n(
"Simple Mode"));
204 action_mode_science_ = actionCollection()->add<KToggleAction>(
QLatin1String(
"mode_science"));
205 action_mode_science_->setActionGroup(modeGroup);
206 action_mode_science_->setText(i18n(
"Science Mode"));
209 action_mode_statistic_ = actionCollection()->add<KToggleAction>(
QLatin1String(
"mode_statistics"));
210 action_mode_statistic_->setActionGroup(modeGroup);
211 action_mode_statistic_->setText(i18n(
"Statistic Mode"));
214 action_mode_numeral_ = actionCollection()->add<KToggleAction>(
QLatin1String(
"mode_numeral"));
215 action_mode_numeral_->setActionGroup(modeGroup);
216 action_mode_numeral_->setText(i18n(
"Numeral System Mode"));
220 action_constants_show_ = actionCollection()->add<KToggleAction>(
QLatin1String(
"show_constants"));
221 action_constants_show_->setText(i18n(
"Constants &Buttons"));
222 action_constants_show_->setChecked(
true);
223 connect(action_constants_show_, SIGNAL(toggled(
bool)), SLOT(
slotConstantsShow(
bool)));
225 action_bitset_show_ = actionCollection()->add<KToggleAction>(
QLatin1String(
"show_bitset"));
226 action_bitset_show_->setText(i18n(
"Show B&it Edit"));
227 action_bitset_show_->setChecked(
true);
228 connect(action_bitset_show_, SIGNAL(toggled(
bool)), SLOT(
slotBitsetshow(
bool)));
230 KStandardAction::preferences(
this, SLOT(
showSettings()), actionCollection());
231 KStandardAction::keyBindings(guiFactory(), SLOT(configureShortcuts()), actionCollection());
249 void KCalculator::setupStatusbar() {
252 statusBar()->insertPermanentFixedItem(
QLatin1String(
" NORM "), ShiftField);
253 statusBar()->setItemAlignment(ShiftField, Qt::AlignCenter);
255 statusBar()->insertPermanentFixedItem(
QLatin1String(
" HEX "), BaseField);
256 statusBar()->setItemAlignment(BaseField, Qt::AlignCenter);
258 statusBar()->insertPermanentFixedItem(
QLatin1String(
" DEG "), AngleField);
259 statusBar()->setItemAlignment(AngleField, Qt::AlignCenter);
261 statusBar()->insertPermanentFixedItem(
QLatin1String(
" \xa0\xa0 "), MemField);
262 statusBar()->setItemAlignment(MemField, Qt::AlignCenter);
269 void KCalculator::setupNumberKeys() {
272 connect(num_button_group_, SIGNAL(buttonClicked(
int)), SLOT(
slotNumberclicked(
int)));
290 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb0, SLOT(slotSetAccelDisplayMode(
bool)));
291 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb1, SLOT(slotSetAccelDisplayMode(
bool)));
292 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb2, SLOT(slotSetAccelDisplayMode(
bool)));
293 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb3, SLOT(slotSetAccelDisplayMode(
bool)));
294 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb4, SLOT(slotSetAccelDisplayMode(
bool)));
295 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb5, SLOT(slotSetAccelDisplayMode(
bool)));
296 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb6, SLOT(slotSetAccelDisplayMode(
bool)));
297 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb7, SLOT(slotSetAccelDisplayMode(
bool)));
298 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb8, SLOT(slotSetAccelDisplayMode(
bool)));
299 connect(
this, SIGNAL(
switchShowAccels(
bool)), pb9, SLOT(slotSetAccelDisplayMode(
bool)));
300 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbA, SLOT(slotSetAccelDisplayMode(
bool)));
301 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbB, SLOT(slotSetAccelDisplayMode(
bool)));
302 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbC, SLOT(slotSetAccelDisplayMode(
bool)));
303 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbD, SLOT(slotSetAccelDisplayMode(
bool)));
304 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbE, SLOT(slotSetAccelDisplayMode(
bool)));
305 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbF, SLOT(slotSetAccelDisplayMode(
bool)));
312 void KCalculator::setupRightKeypad() {
315 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbShift, SLOT(slotSetAccelDisplayMode(
bool)));
317 pbBackspace->setShortcut(
QKeySequence(Qt::Key_Backspace));
318 new QShortcut(Qt::Key_PageUp, pbBackspace, SLOT(animateClick()));
320 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbBackspace, SLOT(slotSetAccelDisplayMode(
bool)));
323 new QShortcut(Qt::Key_PageUp, pbClear, SLOT(animateClick()));
325 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbClear, SLOT(slotSetAccelDisplayMode(
bool)));
328 new QShortcut(Qt::Key_PageDown, pbAllClear, SLOT(animateClick()));
330 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbAllClear, SLOT(slotSetAccelDisplayMode(
bool)));
332 pbParenOpen->setShortcut(
QKeySequence(Qt::Key_ParenLeft));
334 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbParenOpen, SLOT(slotSetAccelDisplayMode(
bool)));
336 pbParenClose->setShortcut(
QKeySequence(Qt::Key_ParenRight));
338 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbParenClose, SLOT(slotSetAccelDisplayMode(
bool)));
340 pbMemRecall->setDisabled(
true);
342 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMemRecall, SLOT(slotSetAccelDisplayMode(
bool)));
345 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMemClear, SLOT(slotSetAccelDisplayMode(
bool)));
347 pbMemPlusMinus->addMode(
ModeNormal, i18nc(
"Add display to memory",
"M+"), i18n(
"Add display to memory"));
348 pbMemPlusMinus->addMode(
ModeShift, i18nc(
"Subtract from memory",
"M\xe2\x88\x92"), i18n(
"Subtract from memory"));
350 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMemPlusMinus, SLOT(slotSetAccelDisplayMode(
bool)));
354 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMemStore, SLOT(slotSetAccelDisplayMode(
bool)));
358 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbPercent, SLOT(slotSetAccelDisplayMode(
bool)));
360 pbPlusMinus->setShortcut(
QKeySequence(Qt::Key_Backslash));
362 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbPlusMinus, SLOT(slotSetAccelDisplayMode(
bool)));
369 void KCalculator::setupNumericKeypad() {
371 pbCube->addMode(
ModeNormal, i18nc(
"Third power",
"x<sup>3</sup>"), i18n(
"Third power"));
374 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbCube, SLOT(slotSetAccelDisplayMode(
bool)));
378 new QShortcut(Qt::Key_division, pbDivision, SLOT(animateClick()));
380 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbDivision, SLOT(slotSetAccelDisplayMode(
bool)));
382 pbMultiplication->setShortcut(
QKeySequence(Qt::Key_Asterisk));
383 new QShortcut(Qt::Key_X, pbMultiplication, SLOT(animateClick()));
384 new QShortcut(Qt::Key_multiply, pbMultiplication, SLOT(animateClick()));
386 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMultiplication, SLOT(slotSetAccelDisplayMode(
bool)));
390 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMinus, SLOT(slotSetAccelDisplayMode(
bool)));
394 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbPlus, SLOT(slotSetAccelDisplayMode(
bool)));
396 pbPeriod->setText(KGlobal::locale()->decimalSymbol());
397 pbPeriod->setShortcut(KGlobal::locale()->decimalSymbol());
409 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbPeriod, SLOT(slotSetAccelDisplayMode(
bool)));
412 new QShortcut(Qt::Key_Equal, pbEqual, SLOT(animateClick()));
413 new QShortcut(Qt::Key_Return, pbEqual, SLOT(animateClick()));
415 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbEqual, SLOT(slotSetAccelDisplayMode(
bool)));
422 void KCalculator::setupLogicKeys() {
424 logic_buttons_.
append(pbAND);
425 logic_buttons_.
append(pbOR);
426 logic_buttons_.
append(pbXOR);
427 logic_buttons_.
append(pbLsh);
428 logic_buttons_.
append(pbRsh);
429 logic_buttons_.
append(pbCmp);
432 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbAND, SLOT(slotSetAccelDisplayMode(
bool)));
436 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbOR, SLOT(slotSetAccelDisplayMode(
bool)));
439 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbXOR, SLOT(slotSetAccelDisplayMode(
bool)));
443 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbLsh, SLOT(slotSetAccelDisplayMode(
bool)));
447 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbRsh, SLOT(slotSetAccelDisplayMode(
bool)));
451 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbCmp, SLOT(slotSetAccelDisplayMode(
bool)));
459 void KCalculator::setupScientificKeys() {
461 scientific_buttons_.
append(pbHyp);
462 scientific_buttons_.
append(pbSin);
463 scientific_buttons_.
append(pbCos);
464 scientific_buttons_.
append(pbTan);
465 scientific_buttons_.
append(pbLog);
466 scientific_buttons_.
append(pbLn);
468 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbHyp, SLOT(slotSetAccelDisplayMode(
bool)));
469 connect(pbHyp, SIGNAL(toggled(
bool)), SLOT(
slotHyptoggled(
bool)));
471 pbSin->addMode(
ModeNormal, i18nc(
"Sine",
"Sin"), i18n(
"Sine"));
472 pbSin->addMode(
ModeShift, i18nc(
"Arc sine",
"Asin"), i18n(
"Arc sine"));
473 pbSin->addMode(
ModeHyperbolic, i18nc(
"Hyperbolic sine",
"Sinh"), i18n(
"Hyperbolic sine"));
475 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbSin, SLOT(slotSetAccelDisplayMode(
bool)));
479 pbCos->addMode(
ModeNormal, i18nc(
"Cosine",
"Cos"), i18n(
"Cosine"));
480 pbCos->addMode(
ModeShift, i18nc(
"Arc cosine",
"Acos"), i18n(
"Arc cosine"));
481 pbCos->addMode(
ModeHyperbolic, i18nc(
"Hyperbolic cosine",
"Cosh"), i18n(
"Hyperbolic cosine"));
483 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbCos, SLOT(slotSetAccelDisplayMode(
bool)));
487 pbTan->addMode(
ModeNormal, i18nc(
"Tangent",
"Tan"), i18n(
"Tangent"));
488 pbTan->addMode(
ModeShift, i18nc(
"Arc tangent",
"Atan"), i18n(
"Arc tangent"));
489 pbTan->addMode(
ModeHyperbolic, i18nc(
"Hyperbolic tangent",
"Tanh"), i18n(
"Hyperbolic tangent"));
491 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbTan, SLOT(slotSetAccelDisplayMode(
bool)));
495 pbLog->addMode(
ModeNormal, i18nc(
"Logarithm to base 10",
"Log"), i18n(
"Logarithm to base 10"));
496 pbLog->addMode(
ModeShift, i18nc(
"10 to the power of x",
"10<sup>x</sup>"), i18n(
"10 to the power of x"));
497 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbLog, SLOT(slotSetAccelDisplayMode(
bool)));
500 pbLn->addMode(
ModeNormal, i18nc(
"Natural log",
"Ln"), i18n(
"Natural log"));
501 pbLn->addMode(
ModeShift, i18nc(
"Exponential function",
"e<sup>x</sup>"), i18n(
"Exponential function"));
502 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbLn, SLOT(slotSetAccelDisplayMode(
bool)));
511 void KCalculator::setupStatisticKeys() {
513 stat_buttons_.
append(pbNData);
514 stat_buttons_.
append(pbMean);
515 stat_buttons_.
append(pbSd);
516 stat_buttons_.
append(pbMed);
517 stat_buttons_.
append(pbDat);
518 stat_buttons_.
append(pbCSt);
520 pbNData->addMode(
ModeNormal, i18nc(
"Number of data entered",
"N"), i18n(
"Number of data entered"));
522 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbNData, SLOT(slotSetAccelDisplayMode(
bool)));
526 pbMean->addMode(
ModeNormal, i18nc(
"Mean",
"Mea"), i18n(
"Mean"));
528 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMean, SLOT(slotSetAccelDisplayMode(
bool)));
534 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbSd, SLOT(slotSetAccelDisplayMode(
bool)));
538 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMed, SLOT(slotSetAccelDisplayMode(
bool)));
541 pbDat->addMode(
ModeNormal, i18nc(
"Enter data",
"Dat"), i18n(
"Enter data"));
542 pbDat->addMode(
ModeShift, i18nc(
"Delete last data item",
"CDat"), i18n(
"Delete last data item"));
543 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbDat, SLOT(slotSetAccelDisplayMode(
bool)));
547 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbCSt, SLOT(slotSetAccelDisplayMode(
bool)));
555 void KCalculator::setupConstantsKeys() {
557 const_buttons_.
append(pbC1);
558 const_buttons_.
append(pbC2);
559 const_buttons_.
append(pbC3);
560 const_buttons_.
append(pbC4);
561 const_buttons_.
append(pbC5);
562 const_buttons_.
append(pbC6);
564 pbC1->setButtonNumber(0);
565 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbC1, SLOT(slotSetAccelDisplayMode(
bool)));
569 pbC2->setButtonNumber(1);
570 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbC2, SLOT(slotSetAccelDisplayMode(
bool)));
574 pbC3->setButtonNumber(2);
575 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbC3, SLOT(slotSetAccelDisplayMode(
bool)));
579 pbC4->setButtonNumber(3);
580 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbC4, SLOT(slotSetAccelDisplayMode(
bool)));
584 pbC5->setButtonNumber(4);
585 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbC5, SLOT(slotSetAccelDisplayMode(
bool)));
589 pbC6->setButtonNumber(5);
590 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbC6, SLOT(slotSetAccelDisplayMode(
bool)));
601 void KCalculator::setupMiscKeys() {
603 pbMod->addMode(
ModeNormal, i18nc(
"Modulo",
"Mod"), i18n(
"Modulo"));
604 pbMod->addMode(
ModeShift, i18nc(
"Integer division",
"IntDiv"), i18n(
"Integer division"));
606 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbMod, SLOT(slotSetAccelDisplayMode(
bool)));
610 pbReci->addMode(
ModeNormal, i18nc(
"Reciprocal",
"1/x"), i18n(
"Reciprocal"));
611 pbReci->addMode(
ModeShift, i18nc(
"n Choose m",
"nCm"), i18n(
"n Choose m"));
613 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbReci, SLOT(slotSetAccelDisplayMode(
bool)));
616 pbFactorial->addMode(
ModeNormal, i18nc(
"Factorial",
"x!"), i18n(
"Factorial"));
619 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbFactorial, SLOT(slotSetAccelDisplayMode(
bool)));
623 pbSquare->addMode(
ModeNormal, i18nc(
"Square",
"x<sup>2</sup>"), i18n(
"Square"));
625 pbSquare->setShortcut(
QKeySequence(Qt::Key_BracketLeft));
626 new QShortcut(Qt::Key_twosuperior, pbSquare, SLOT(animateClick()));
627 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbSquare, SLOT(slotSetAccelDisplayMode(
bool)));
631 pbPower->addMode(
ModeNormal, i18nc(
"x to the power of y",
"x<sup>y</sup>"), i18n(
"x to the power of y"));
632 pbPower->addMode(
ModeShift, i18nc(
"x to the power of 1/y",
"x<sup>1/y</sup>"), i18n(
"x to the power of 1/y"));
633 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbPower, SLOT(slotSetAccelDisplayMode(
bool)));
635 pbPower->setShortcut(
QKeySequence(Qt::Key_AsciiCircum));
639 connect(
this, SIGNAL(
switchShowAccels(
bool)), pbEE, SLOT(slotSetAccelDisplayMode(
bool)));
648 void KCalculator::setupKeys() {
652 setupNumericKeypad();
654 setupScientificKeys();
655 setupStatisticKeys();
656 setupConstantsKeys();
661 function_button_list_.
append(pbHyp);
662 function_button_list_.
append(pbShift);
663 function_button_list_.
append(pbEE);
664 function_button_list_.
append(pbSin);
665 function_button_list_.
append(pbPlusMinus);
666 function_button_list_.
append(pbCos);
667 function_button_list_.
append(pbReci);
668 function_button_list_.
append(pbTan);
669 function_button_list_.
append(pbFactorial);
670 function_button_list_.
append(pbLog);
671 function_button_list_.
append(pbSquare);
672 function_button_list_.
append(pbLn);
673 function_button_list_.
append(pbPower);
674 function_button_list_.
append(pbCube);
676 mem_button_list_.
append(pbMemRecall);
677 mem_button_list_.
append(pbMemPlusMinus);
678 mem_button_list_.
append(pbMemStore);
679 mem_button_list_.
append(pbMemClear);
680 mem_button_list_.
append(pbClear);
681 mem_button_list_.
append(pbAllClear);
683 operation_button_list_.
append(pbMultiplication);
684 operation_button_list_.
append(pbParenOpen);
685 operation_button_list_.
append(pbParenClose);
686 operation_button_list_.
append(pbAND);
687 operation_button_list_.
append(pbDivision);
688 operation_button_list_.
append(pbOR);
689 operation_button_list_.
append(pbXOR);
690 operation_button_list_.
append(pbPlus);
691 operation_button_list_.
append(pbMinus);
692 operation_button_list_.
append(pbLsh);
693 operation_button_list_.
append(pbRsh);
694 operation_button_list_.
append(pbPeriod);
695 operation_button_list_.
append(pbEqual);
696 operation_button_list_.
append(pbPercent);
697 operation_button_list_.
append(pbCmp);
698 operation_button_list_.
append(pbMod);
705 void KCalculator::updateGeometry() {
709 margin = qMax(qMin(margin / 2, 3), 3);
713 if (
KCalcButton *
const button = qobject_cast<KCalcButton *>(obj)) {
714 button->setFixedWidth(em.
width() * 4 + margin * 2);
715 button->installEventFilter(
this);
723 if (button && button != pbShift) {
724 button->setFixedWidth(em.
width() * 3 + margin * 2);
725 button->installEventFilter(
this);
731 if (
KCalcButton *
const button = qobject_cast<KCalcButton *>(obj)) {
734 button->setFixedWidth(em.
width() * 3 + margin * 2);
736 button->installEventFilter(
this);
749 calc_display->setAmount(
KNumber(val));
764 current_base = calc_display->setBase(
NumBase(2));
766 calc_display->setStatusText(BaseField,
QLatin1String(
"Bin"));
769 current_base = calc_display->setBase(
NumBase(8));
771 calc_display->setStatusText(BaseField,
QLatin1String(
"Oct"));
774 current_base = calc_display->setBase(
NumBase(10));
776 calc_display->setStatusText(BaseField,
QLatin1String(
"Dec"));
779 current_base = calc_display->setBase(
NumBase(16));
781 calc_display->setStatusText(BaseField,
QLatin1String(
"Hex"));
785 calc_display->setStatusText(BaseField,
QLatin1String(
"Error"));
790 for (
int i = 0; i < current_base; ++i) {
791 (num_button_group_->
buttons()[i])->setEnabled(
true);
795 for (
int i = current_base; i < 16; ++i) {
796 (num_button_group_->
buttons()[i])->setEnabled(
false);
800 pbPeriod->setEnabled(current_base ==
NB_DECIMAL);
823 void KCalculator::keyPressEvent(
QKeyEvent *e) {
830 if(e->
key() == Qt::Key_Period && e->
modifiers() & Qt::KeypadModifier) {
831 pbPeriod->animateClick();
836 if (((e->
modifiers() & Qt::NoModifier) == 0) || (e->
modifiers() & Qt::ShiftModifier)) {
838 case Qt::Key_Backspace:
839 calc_display->deleteLastDigit();
844 if (e->
key() == Qt::Key_Control) {
853 void KCalculator::keyReleaseEvent(
QKeyEvent *e) {
855 if (e->
key() == Qt::Key_Control) {
871 calc_display->setStatusText(AngleField,
QLatin1String(
"Deg"));
875 calc_display->setStatusText(AngleField,
QLatin1String(
"Rad"));
879 calc_display->setStatusText(AngleField,
QLatin1String(
"Gra"));
882 angle_mode_ = RadMode;
907 statusBar()->changeItem(i18nc(
"Second button functions are active",
"SHIFT"), ShiftField);
908 calc_display->setStatusText(ShiftField, i18n(
"Shift"));
910 statusBar()->changeItem(i18nc(
"Normal button functions are active",
"NORM"), ShiftField);
911 calc_display->setStatusText(ShiftField,
QString());
936 calc_display->setAmount(memory_num_);
948 memory_num_ = calc_display->getAmount();
951 pbMemRecall->setEnabled(
true);
960 calc_display->enterDigit(number_clicked);
972 core.
SinHyp(calc_display->getAmount());
979 switch (angle_mode_) {
981 core.
SinDeg(calc_display->getAmount());
984 core.
SinRad(calc_display->getAmount());
987 core.
SinGrad(calc_display->getAmount());
991 switch (angle_mode_) {
993 core.
ArcSinDeg(calc_display->getAmount());
996 core.
ArcSinRad(calc_display->getAmount());
1028 bool tmp_shift_mode = shift_mode_;
1031 if (!tmp_shift_mode) {
1032 memory_num_ += calc_display->getAmount();
1034 memory_num_ -= calc_display->getAmount();
1037 pbShift->setChecked(
false);
1038 statusBar()->changeItem(i18n(
"M"), MemField);
1039 calc_display->setStatusText(MemField, i18n(
"M"));
1040 pbMemRecall->setEnabled(
true);
1052 core.
CosHyp(calc_display->getAmount());
1059 switch (angle_mode_) {
1061 core.
CosDeg(calc_display->getAmount());
1064 core.
CosRad(calc_display->getAmount());
1067 core.
CosGrad(calc_display->getAmount());
1071 switch (angle_mode_) {
1073 core.
ArcCosDeg(calc_display->getAmount());
1076 core.
ArcCosRad(calc_display->getAmount());
1103 KNumber tmp_num = calc_display->getAmount();
1105 calc_display->setAmount(tmp_num);
1125 switch (angle_mode_) {
1137 switch (angle_mode_) {
1165 core.
Factorial(calc_display->getAmount());
1167 core.
Gamma(calc_display->getAmount());
1180 core.
Log10(calc_display->getAmount());
1182 core.
Exp10(calc_display->getAmount());
1195 core.
Square(calc_display->getAmount());
1210 core.
Cube(calc_display->getAmount());
1212 core.
CubeRoot(calc_display->getAmount());
1225 core.
Ln(calc_display->getAmount());
1227 core.
Exp(calc_display->getAmount());
1241 pbShift->setChecked(
false);
1247 KNumber tmp_num = calc_display->getAmount();
1249 calc_display->setAmount(tmp_num);
1260 statusBar()->changeItem(
QLatin1String(
" \xa0\xa0 "), MemField);
1261 calc_display->setStatusText(MemField,
QString());
1262 pbMemRecall->setDisabled(
true);
1271 calc_display->deleteLastDigit();
1300 core.
ParenOpen(calc_display->getAmount());
1411 calc_display->newCharacter(KGlobal::locale()->decimalSymbol()[0]);
1478 pbShift->setChecked(
false);
1494 pbShift->setChecked(
false);
1510 pbShift->setChecked(
false);
1531 pbShift->setChecked(
false);
1547 pbShift->setChecked(
false);
1549 statusBar()->showMessage(i18n(
"Last stat item erased"), 3000);
1563 statusBar()->showMessage(i18n(
"Stat mem cleared"), 3000);
1565 pbShift->setChecked(
false);
1576 if(
KCalcConstButton *btn = qobject_cast<KCalcConstButton*>(const_buttons_[button])) {
1580 QString val = btn->constant();
1582 calc_display->setAmount(
KNumber(val));
1585 pbShift->setChecked(
false);
1588 QString val = calc_display->text();
1593 btn->setLabelAndTooltip();
1597 calc_display->setAmount(calc_display->getAmount());
1618 dialog->showButtonSeparator(
true);
1622 general->kcfg_Precision->setMaximum(maxprecision);
1623 dialog->addPage(general, i18n(
"General"),
QLatin1String(
"accessories-calculator"), i18n(
"General Settings"));
1627 dialog->addPage(fonts, i18n(
"Font"),
QLatin1String(
"preferences-desktop-font"), i18n(
"Select Display Font"));
1631 dialog->addPage(color, i18n(
"Colors"),
QLatin1String(
"format-fill-color"), i18n(
"Button & Display Colors"));
1641 constants_->pushButton0->setMenu(tmp_menu);
1645 constants_->pushButton1->setMenu(tmp_menu);
1649 constants_->pushButton2->setMenu(tmp_menu);
1653 constants_->pushButton3->setMenu(tmp_menu);
1657 constants_->pushButton4->setMenu(tmp_menu);
1661 constants_->pushButton5->setMenu(tmp_menu);
1663 dialog->addPage(constants_, i18n(
"Constants"),
QLatin1String(
"preferences-kcalc-constants"), i18n(
"Define Constants"));
1682 constants_->kcfg_valueConstant0->setText(chosen_const.
value);
1683 constants_->kcfg_nameConstant0->setText(chosen_const.
label);
1691 constants_->kcfg_valueConstant1->setText(chosen_const.
value);
1692 constants_->kcfg_nameConstant1->setText(chosen_const.
label);
1700 constants_->kcfg_valueConstant2->setText(chosen_const.
value);
1701 constants_->kcfg_nameConstant2->setText(chosen_const.
label);
1709 constants_->kcfg_valueConstant3->setText(chosen_const.
value);
1710 constants_->kcfg_nameConstant3->setText(chosen_const.
label);
1718 constants_->kcfg_valueConstant4->setText(chosen_const.
value);
1719 constants_->kcfg_nameConstant4->setText(chosen_const.
label);
1727 constants_->kcfg_valueConstant5->setText(chosen_const.
value);
1728 constants_->kcfg_nameConstant5->setText(chosen_const.
label);
1737 action_constants_show_->setChecked(
false);
1738 action_constants_show_->setEnabled(
false);
1739 action_bitset_show_->setChecked(
false);
1740 action_bitset_show_->setEnabled(
false);
1741 showMemButtons(
false);
1742 showScienceButtons(
false);
1743 showStatButtons(
false);
1744 showLogicButtons(
false);
1750 pbFactorial->hide();
1754 pbBackspace->hide();
1758 delete constants_menu_;
1759 constants_menu_ = 0;
1770 action_constants_show_->setEnabled(
true);
1772 action_bitset_show_->setChecked(
false);
1773 action_bitset_show_->setEnabled(
false);
1779 pbFactorial->show();
1783 pbBackspace->show();
1787 showMemButtons(
true);
1788 showScienceButtons(
true);
1789 showStatButtons(
false);
1790 showLogicButtons(
false);
1792 if(!constants_menu_) {
1793 constants_menu_ = createConstantsMenu();
1794 menuBar()->insertMenu((menuBar()->actions)()[2], constants_menu_);
1806 action_constants_show_->setEnabled(
true);
1808 action_bitset_show_->setChecked(
false);
1809 action_bitset_show_->setEnabled(
false);
1815 pbFactorial->show();
1819 pbBackspace->show();
1823 showMemButtons(
true);
1824 showScienceButtons(
true);
1825 showStatButtons(
true);
1826 showLogicButtons(
false);
1828 if(!constants_menu_) {
1829 constants_menu_ = createConstantsMenu();
1830 menuBar()->insertMenu((menuBar()->actions)()[2], constants_menu_);
1842 action_constants_show_->setChecked(
false);
1843 action_constants_show_->setEnabled(
false);
1844 action_bitset_show_->setEnabled(
true);
1851 pbFactorial->show();
1855 pbBackspace->show();
1859 showMemButtons(
true);
1860 showScienceButtons(
false);
1861 showStatButtons(
false);
1862 showLogicButtons(
true);
1864 if(!constants_menu_) {
1865 constants_menu_ = createConstantsMenu();
1866 menuBar()->insertMenu((menuBar()->actions)()[2], constants_menu_);
1876 void KCalculator::showMemButtons(
bool toggled) {
1897 void KCalculator::showStatButtons(
bool toggled) {
1914 void KCalculator::showScienceButtons(
bool toggled) {
1926 statusBar()->setItemFixed(AngleField, -1);
1936 statusBar()->changeItem(
QString(), AngleField);
1937 statusBar()->setItemFixed(AngleField, 0);
1938 calc_display->setStatusText(AngleField,
QString());
1946 void KCalculator::showLogicButtons(
bool toggled) {
1949 mBitset->setEnabled(
true);
1950 connect(mBitset, SIGNAL(valueChanged(quint64)),
this, SLOT(
slotBitsetChanged(quint64)));
1958 statusBar()->setItemFixed(BaseField, -1);
1964 for (
int i = 10; i < 16; ++i) {
1965 (num_button_group_->
button(i))->show();
1968 mBitset->setEnabled(
false);
1969 disconnect(mBitset, SIGNAL(valueChanged(quint64)),
this, SLOT(
slotBitsetChanged(quint64)));
1977 decRadio->animateClick(0);
1983 statusBar()->changeItem(
QString(), BaseField);
1984 statusBar()->setItemFixed(BaseField, 0);
1985 calc_display->setStatusText(BaseField,
QString());
1986 for (
int i = 10; i < 16; ++i) {
1987 (num_button_group_->
button(i))->hide();
2017 mBitset->setVisible(toggled);
2030 if (
KCalcConstButton *
const constbtn = qobject_cast<KCalcConstButton*>(btn)) {
2031 constbtn->setLabelAndTooltip();
2043 calc_display->setAmount(
KNumber(value));
2068 disconnect(calc_display, SIGNAL(changedText(
QString)),
this, 0);
2071 connect(calc_display, SIGNAL(changedText(
QString)), SLOT(setCaption(
QString)));
2076 calc_display->changeSettings();
2084 void KCalculator::updateDisplay(UpdateFlags flags) {
2089 calc_display->update();
2092 pbShift->setChecked(
false);
2102 calc_display->changeSettings();
2104 KColorScheme schemeButtons(QPalette::Active, KColorScheme::Button);
2105 const QColor defaultColor = schemeButtons.background().color();
2119 for (
int i = 0; i < 10; ++i) {
2120 (num_button_group_->
button(i))->setStyleSheet(sheet.
arg(numPal.
name()));
2134 for (
int i = 10; i < 16; ++i) {
2135 (num_button_group_->
button(i))->setStyleSheet(sheet.
arg(hexPal.
name()));
2156 if (
KCalcButton *
const button = qobject_cast<KCalcButton*>(obj)) {
2162 if (
KCalcButton *
const button = qobject_cast<KCalcButton*>(obj)) {
2168 if (
KCalcButton *
const button = qobject_cast<KCalcButton*>(obj)) {
2180 void KCalculator::setPrecision() {
2190 void KCalculator::setAngle() {
2201 void KCalculator::setBase() {
2213 switch (e->
type()) {
2214 case QEvent::DragEnter: {
2219 case QEvent::DragLeave: {
2222 case QEvent::Drop: {
2236 const int num_but = num_button_group_->
buttons().
indexOf(calcButton);
2237 if (num_but != -1) {
2240 for (
int i = 0; i < 10; ++i) {
2241 (num_button_group_->
buttons()[i])->setStyleSheet(sheet.
arg(cn));
2244 for (
int i = 10; i < 16; ++i) {
2245 (num_button_group_->
buttons()[i])->setStyleSheet(sheet.
arg(cn));
2249 }
else if (function_button_list_.
contains(calcButton)) {
2250 list = &function_button_list_;
2251 }
else if (stat_button_list_.
contains(calcButton)) {
2252 list = &stat_button_list_;
2253 }
else if (mem_button_list_.
contains(calcButton)) {
2254 list = &mem_button_list_;
2255 }
else if (operation_button_list_.
contains(calcButton)) {
2256 list = &operation_button_list_;
2261 for (
int i = 0; i < list->
size(); ++i) {
2262 list->
at(i)->setStyleSheet(sheet.
arg(cn));
2269 return KXmlGuiWindow::eventFilter(o, e);
2276 #include "kcalc.moc"
2282 extern "C" KDE_EXPORT
int kdemain(
int argc,
char *argv[]) {
2284 KAboutData aboutData(
"kcalc",
2289 KAboutData::License_GPL,
2291 "© 2008-2013, Evan Teran\n"
2292 "© 2000-2008, The KDE Team\n"
2293 "© 2003-2005, Klaus Niederkr" "\xc3\xbc" "ger\n"
2294 "© 1996-2000, Bernd Johannes Wuebben"),
2296 "http://utils.kde.org/projects/kcalc");
2299 aboutData.addAuthor(ki18n(
"Klaus Niederkr" "\xc3\xbc" "ger"), KLocalizedString(),
"kniederk@math.uni-koeln.de");
2300 aboutData.addAuthor(ki18n(
"Bernd Johannes Wuebben"), KLocalizedString(),
"wuebben@kde.org");
2301 aboutData.addAuthor(ki18n(
"Evan Teran"), ki18n(
"Maintainer"),
"eteran@alum.rit.edu");
2302 aboutData.addAuthor(ki18n(
"Espen Sand"), KLocalizedString(),
"espen@kde.org");
2303 aboutData.addAuthor(ki18n(
"Chris Howells"), KLocalizedString(),
"howells@kde.org");
2304 aboutData.addAuthor(ki18n(
"Aaron J. Seigo"), KLocalizedString(),
"aseigo@olympusproject.org");
2305 aboutData.addAuthor(ki18n(
"Charles Samuels"), KLocalizedString(),
"charles@altair.dhs.org");
2307 aboutData.addAuthor(ki18n(
"Ren" "\xc3\xa9" " M" "\xc3\xa9" "rou"), KLocalizedString(),
"ochominutosdearco@yahoo.es");
2308 aboutData.addAuthor(ki18n(
"Michel Marti"), KLocalizedString(),
"mma@objectxp.com");
2309 aboutData.addAuthor(ki18n(
"David Johnson"), KLocalizedString(),
"david@usermode.org");
2311 aboutData.setProgramIconName(
QLatin1String(
"accessories-calculator"));
2313 KCmdLineArgs::init(argc, argv, &aboutData);
2318 setlocale(LC_NUMERIC,
"C");
2324 app.setTopWidget(calc);
void CosGrad(const KNumber &input)
void Square(const KNumber &input)
void Complement(const KNumber &input)
static QColor operationButtonsColor()
Get The color of operation buttons.
void slotSetStatisticMode()
static QColor statButtonsColor()
Get The color of statistical buttons.
Qt::KeyboardModifiers modifiers() const
static void setBaseMode(uint v)
Set Numeric base.
void SquareRoot(const KNumber &input)
void slotChooseScientificConst4(const science_constant &)
void AreaSinHyp(const KNumber &input)
static void setShowConstants(bool v)
Set Whether to show constant buttons.
void CosDeg(const KNumber &input)
static QColor memoryButtonsColor()
Get The color of memory buttons.
void enterOperation(const KNumber &num, Operation func)
const QMimeData * mimeData() const
void StatSumSquares(const KNumber &input)
void slotBitsetChanged(quint64)
void slotRightShiftclicked()
static bool showBitset()
Get Whether to show the bit edit widget.
void TangensDeg(const KNumber &input)
static QString decimalSeparator()
void slotStatStdDevclicked()
static void setGroupSeparator(const QString &ch)
static const KNumber Zero
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
void slotConstantsShow(bool toggled)
void Reciprocal(const KNumber &input)
void TangensHyp(const KNumber &input)
const T & at(int i) const
const QObjectList & children() const
void CubeRoot(const KNumber &input)
void slotPercentclicked()
static QColor hexButtonsColor()
Get The color of hex buttons.
void ParenOpen(const KNumber &input)
void Exp(const KNumber &input)
void slotConstantToDisplay(const science_constant &const_chosen)
static QColor functionButtonsColor()
Get The color of function buttons.
void slotBackspaceclicked()
void SinRad(const KNumber &input)
void StatMedian(const KNumber &input)
void slotStatClearDataclicked()
void slotStatDataInputclicked()
void TangensRad(const KNumber &input)
void slotStatNumclicked()
void slotFactorialclicked()
void slotDivisionclicked()
void StatMean(const KNumber &input)
void slotMultiplicationclicked()
int indexOf(const T &value, int from) const
void slotStatMedianclicked()
static void setDefaultFloatPrecision(int precision)
void Cube(const KNumber &input)
void SinHyp(const KNumber &input)
void StatStdSample(const KNumber &input)
void SinDeg(const KNumber &input)
void ArcCosGrad(const KNumber &input)
void ArcSinDeg(const KNumber &input)
void append(const T &value)
QString fromUtf8(const char *str, int size)
void setAccepted(bool accepted)
void ArcTangensDeg(const KNumber &input)
static void setAngleMode(uint v)
Set Degrees, radians or grads.
void ArcCosDeg(const KNumber &input)
void SinGrad(const KNumber &input)
void slotChooseScientificConst5(const science_constant &)
static void setShowBitset(bool v)
Set Whether to show the bit edit widget.
void CosHyp(const KNumber &input)
void slotMemStoreclicked()
void switchShowAccels(bool)
void slotParenCloseclicked()
void slotConstclicked(int)
void setOverrideCursor(const QCursor &cursor)
void slotLeftShiftclicked()
void slotSetNumeralMode()
void restoreOverrideCursor()
void slotAngleSelected(int mode)
void AreaTangensHyp(const KNumber &input)
static QColor numberButtonsColor()
Get The color of number buttons.
void CosRad(const KNumber &input)
void Log10(const KNumber &input)
void StatSum(const KNumber &input)
void Factorial(const KNumber &input)
void slotChooseScientificConst0(const science_constant &)
void ArcSinGrad(const KNumber &input)
void ArcSinRad(const KNumber &input)
void StatClearAll(const KNumber &input)
static QFont buttonFont()
Get The font to use for the buttons.
void AreaCosHyp(const KNumber &input)
KCalculator(QWidget *parent=0)
bool contains(const T &value) const
void TangensGrad(const KNumber &input)
void slotAllClearclicked()
void slotMemClearclicked()
static void setCalculatorMode(EnumCalculatorMode::type v)
Set CalculatorMode.
QString & replace(int position, int n, QChar after)
KDE_EXPORT int kdemain(int argc, char *argv[])
static void setDecimalSeparator(const QString &ch)
static EnumCalculatorMode::type calculatorMode()
Get CalculatorMode.
static void setValueConstant(int i, const QString &v)
Set List of user programmable constants.
static bool showConstants()
Get Whether to show constant buttons.
void StatDataDel(const KNumber &input)
void ParenClose(KNumber input)
void Gamma(const KNumber &input)
void slotBaseSelected(int base)
void slotSetScienceMode()
void slotStatMeanclicked()
static uint precision()
Get Maximum number of digits displayed.
void ArcCosRad(const KNumber &input)
void slotChooseScientificConst1(const science_constant &)
void ArcTangensRad(const KNumber &input)
void switchMode(ButtonModeFlags, bool)
static uint baseMode()
Get Numeric base.
void slotParenOpenclicked()
static uint angleMode()
Get Degrees, radians or grads.
void slotChooseScientificConst2(const science_constant &)
void slotChooseScientificConst3(const science_constant &)
void slotBitsetshow(bool toggled)
void slotPlusMinusclicked()
void slotUpdateBitset(const KNumber &)
void InvertSign(const KNumber &input)
void StatStdDeviation(const KNumber &input)
void StatDataNew(const KNumber &input)
void slotMemRecallclicked()
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void slotMemPlusMinusclicked()
static bool captionResult()
Get Whether to show the result in the window title.
void slotHyptoggled(bool flag)
static KCalcSettings * self()
void slotNumberclicked(int number_clicked)
void Exp10(const KNumber &input)
void StatCount(const KNumber &input)
void slotShifttoggled(bool myboolean)
void ArcTangensGrad(const KNumber &input)
void Ln(const KNumber &input)