| orig/kalkulacka2/ckalkulacka.cpp | kalkulacka2/ckalkulacka.cpp |
| l_first = 0; | | l_first = 0; |
| l_second = 0; | | l_second = 0; |
| l_finish = 0; | | l_finish = 0; |
| n | l_operator = -1;
| n | l_operator = OperatorNone;
|
| | | |
| ui->VYSLEDEK->setText("0"); | | ui->VYSLEDEK->setText("0"); |
| SetDisableAll(false); | | SetDisableAll(false); |
| } | | } |
| | | |
| n | | n | void CKalkulacka::handleNumericalButton(int aNumber)
|
| | | {
|
| | | //QString a_str = ui->VYSLEDEK->text();
|
| | | QString a_str(ui->VYSLEDEK->text()); // usetri jeden tmp objekt
|
| | | QString input;
|
| | | input.setNum(aNumber, 10); // pouze dekadicky
|
| | |
|
| | | if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
|
| | | a_str = "0";
|
| | |
|
| | | if (a_str == "0" && a_str != "-0")
|
| | | a_str = input;
|
| | | else if (a_str == "-0")
|
| | | a_str = "-" + input;
|
| | | else
|
| | | a_str += input;
|
| | |
|
| | | if (l_operator == -1)
|
| | | {
|
| | | l_first = a_str.toDouble();
|
| | | }
|
| | | else
|
| | | l_second = a_str.toDouble();
|
| | |
|
| | | ui->pushButton_3->setDisabled(false);
|
| | | ui->VYSLEDEK->setText(a_str);
|
| | | }
|
| | |
|
| void CKalkulacka::on_JEDNA_released() | | void CKalkulacka::on_JEDNA_released() |
| { | | { |
| n | QString a_str = ui->VYSLEDEK->text();
| n | handleNumericalButton(1);
|
|
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str == "0" && a_str != "-0")
| | |
| a_str = "1";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-1";
| | |
| else
| | |
| a_str += "1";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| } | | } |
| | | |
| void CKalkulacka::on_NULA_released() | | void CKalkulacka::on_NULA_released() |
| { | | { |
| n | QString a_str = ui->VYSLEDEK->text();
| n | handleNumericalButton(0);
|
|
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str.length() > 1 && a_str != "-0" || a_str != "0" && a_str != "-0")
| | |
| a_str += "0";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| } | | } |
| | | |
| void CKalkulacka::on_DVA_released() | | void CKalkulacka::on_DVA_released() |
| n | | n | {
|
| | | handleNumericalButton(2);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_TRI_released()
|
| | | {
|
| | | handleNumericalButton(3);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_CTYRI_released()
|
| | | {
|
| | | handleNumericalButton(4);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_PET_released()
|
| | | {
|
| | | handleNumericalButton(5);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_SEST_released()
|
| | | {
|
| | | handleNumericalButton(6);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_SEDM_released()
|
| | | {
|
| | | handleNumericalButton(7);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_OSM_released()
|
| | | {
|
| | | handleNumericalButton(8);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_DEVET_released()
|
| | | {
|
| | | handleNumericalButton(9);
|
| | | }
|
| | |
|
| | | void CKalkulacka::on_pushButton_6_released()
|
| { | | { |
| QString a_str = ui->VYSLEDEK->text(); | | QString a_str = ui->VYSLEDEK->text(); |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*") | | if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*") |
| a_str = "0"; | | a_str = "0"; |
| | | |
| n | if (a_str == "0" && a_str != "-0")
| n | if (a_str.indexOf(".") == -1 && a_str.indexOf(",") == -1)
|
| a_str = "2";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-2";
| | |
| else
| | |
| a_str += "2"; | | a_str += "."; |
| | | else
|
| | | return;
|
| | | |
| n | if (l_operator == -1) | n | if (l_operator == OperatorNone) |
| { | | { |
| l_first = a_str.toDouble(); | | l_first = a_str.toDouble(); |
| } | | } |
| orig/kalkulacka2/ckalkulacka.cpp | kalkulacka2/ckalkulacka.cpp |
| ui->VYSLEDEK->setText(a_str); | | ui->VYSLEDEK->setText(a_str); |
| } | | } |
| | | |
| n | void CKalkulacka::on_TRI_released() | n | void CKalkulacka::on_pushButton_5_released() |
| { | | { |
| QString a_str = ui->VYSLEDEK->text(); | | QString a_str = ui->VYSLEDEK->text(); |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*") | | if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*") |
| a_str = "0"; | | a_str = "0"; |
| | | |
| n | if (a_str == "0" && a_str != "-0")
| n | |
| a_str = "3";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-3";
| | |
| else
| | |
| a_str += "3";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_CTYRI_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str == "0" && a_str != "-0")
| | |
| a_str = "4";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-4";
| | |
| else
| | |
| a_str += "4";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_PET_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str == "0" && a_str != "-0")
| | |
| a_str = "5";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-5";
| | |
| else
| | |
| a_str += "5";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_SEST_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str == "0" && a_str != "-0")
| | |
| a_str = "6";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-6";
| | |
| else
| | |
| a_str += "6";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_SEDM_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str == "0" && a_str != "-0")
| | |
| a_str = "7";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-7";
| | |
| else
| | |
| a_str += "7";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_OSM_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str == "0" && a_str != "-0")
| | |
| a_str = "8";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-8";
| | |
| else
| | |
| a_str += "8";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_DEVET_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str == "0" && a_str != "-0")
| | |
| a_str = "9";
| | |
| else if (a_str == "-0")
| | |
| a_str = "-9";
| | |
| else
| | |
| a_str += "9";
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_pushButton_6_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str.indexOf(".") == -1 && a_str.indexOf(",") == -1)
| | |
| a_str += ".";
| | |
| else
| | |
| return;
| | |
|
| | |
| if (l_operator == -1)
| | |
| {
| | |
| l_first = a_str.toDouble();
| | |
| }
| | |
| else
| | |
| l_second = a_str.toDouble();
| | |
|
| | |
| ui->pushButton_3->setDisabled(false);
| | |
| ui->VYSLEDEK->setText(a_str);
| | |
| }
| | |
|
| | |
| void CKalkulacka::on_pushButton_5_released()
| | |
| {
| | |
| QString a_str = ui->VYSLEDEK->text();
| | |
| if (a_str == "+" || a_str == "-" || a_str == "/" || a_str == "*")
| | |
| a_str = "0";
| | |
|
| | |
| if (a_str.indexOf("-") != -1) | | if (a_str.indexOf("-") != -1) |
| a_str.remove(0, 1); | | a_str.remove(0, 1); |
| else | | else |
| a_str = "-"+a_str; | | a_str = "-"+a_str; |
| | | |
| n | if (l_operator == -1) | n | if (l_operator == OperatorNone) |
| { | | { |
| l_first = a_str.toDouble(); | | l_first = a_str.toDouble(); |
| } | | } |
| orig/kalkulacka2/ckalkulacka.cpp | kalkulacka2/ckalkulacka.cpp |
| ui->VYSLEDEK->setText(a_str); | | ui->VYSLEDEK->setText(a_str); |
| } | | } |
| | | |
| n | | n | void CKalkulacka::handleOperators(Operators o)
|
| | | {
|
| | | QString a_str(ui->VYSLEDEK->text());
|
| | | QList<QString> l;
|
| | | l << "none" << "+" << "-" << "*" << "/";
|
| | |
|
| | | l_first = a_str.toDouble();
|
| | | l_operator = o;
|
| | | ui->pushButton_3->setDisabled(true);
|
| | |
|
| | | ui->VYSLEDEK->setText(l.at(o));
|
| | | }
|
| | |
|
| void CKalkulacka::on_pushButton_7_released() | | void CKalkulacka::on_pushButton_7_released() |
| { | | { |
| n | QString a_str = ui->VYSLEDEK->text();
| n | handleOperators(CKalkulacka::OperatorPlus);
|
|
| | |
| l_first = a_str.toDouble();
| | |
| l_operator = 1;
| | |
| ui->pushButton_3->setDisabled(true);
| | |
|
| | |
| ui->VYSLEDEK->setText("+");
| | |
| } | | } |
| | | |
| void CKalkulacka::on_pushButton_8_released() | | void CKalkulacka::on_pushButton_8_released() |
| { | | { |
| n | QString a_str = ui->VYSLEDEK->text();
| n | handleOperators(CKalkulacka::OperatorMinus);
|
|
| | |
| l_first = a_str.toDouble();
| | |
| l_operator = 2;
| | |
| ui->pushButton_3->setDisabled(true);
| | |
|
| | |
| ui->VYSLEDEK->setText("-");
| | |
| } | | } |
| | | |
| void CKalkulacka::on_pushButton_9_released() | | void CKalkulacka::on_pushButton_9_released() |
| { | | { |
| n | QString a_str = ui->VYSLEDEK->text();
| n | handleOperators(CKalkulacka::OperatorMultiply);
|
|
| | |
| l_first = a_str.toDouble();
| | |
| l_operator = 3;
| | |
| ui->pushButton_3->setDisabled(true);
| | |
|
| | |
| ui->VYSLEDEK->setText("*");
| | |
| } | | } |
| | | |
| void CKalkulacka::on_pushButton_10_released() | | void CKalkulacka::on_pushButton_10_released() |
| { | | { |
| n | QString a_str = ui->VYSLEDEK->text();
| n | handleOperators(CKalkulacka::OperatorDivide);
|
|
| | |
| l_first = a_str.toDouble();
| | |
| l_operator = 4;
| | |
| ui->pushButton_3->setDisabled(true);
| | |
|
| | |
| ui->VYSLEDEK->setText("/");
| | |
| } | | } |
| | | |
| void CKalkulacka::on_ROVNASE_released() | | void CKalkulacka::on_ROVNASE_released() |
| { | | { |
| n | char a_buffer[255];
| n | char a_buffer[255]; // WTF? Proc 255? Proc to vubec omezovat?
|
| | | |
| switch(l_operator) | | switch(l_operator) |
| { | | { |
| n | case 1:
| n | case OperatorPlus:
|
| l_finish = l_first + l_second; | | l_finish = l_first + l_second; |
| n | sprintf(a_buffer, "%g", (double)l_finish);
| n | |
| ui->VYSLEDEK->setText(a_buffer);
| | |
| ui->pushButton_3->setDisabled(true);
| | |
| break; | | break; |
| n | case 2:
| n | case OperatorMinus:
|
| l_finish = l_first - l_second; | | l_finish = l_first - l_second; |
| n | sprintf(a_buffer, "%g", (double)l_finish);
| n | |
| ui->VYSLEDEK->setText(a_buffer);
| | |
| ui->pushButton_3->setDisabled(true);
| | |
| break; | | break; |
| n | case 3:
| n | case OperatorMultiply:
|
| l_finish = l_first * l_second; | | l_finish = l_first * l_second; |
| n | sprintf(a_buffer, "%g", (double)l_finish);
| n | |
| ui->VYSLEDEK->setText(a_buffer);
| | |
| ui->pushButton_3->setDisabled(true);
| | |
| break; | | break; |
| n | case 4:
| n | case OperatorDivide:
|
| if (l_second != 0) | | if (l_second != 0) |
| n | {
| n | |
| l_finish = l_first / l_second; | | l_finish = l_first / l_second; |
| n | sprintf(a_buffer, "%g", (double)l_finish);
| n | |
| ui->VYSLEDEK->setText(a_buffer);
| | |
| ui->pushButton_3->setDisabled(true);
| | |
| }
| | |
| else | | else |
| { | | { |
| ui->VYSLEDEK->setText("error"); | | ui->VYSLEDEK->setText("error"); |
| ui->pushButton_3->setDisabled(true); | | ui->pushButton_3->setDisabled(true); |
| SetDisableAll(true); | | SetDisableAll(true); |
| n | | n | return;
|
| } | | } |
| n |
| n | |
| break; | | break; |
| n | | n | default:
|
| | | qDebug("None operator in ROVNASE slot...");
|
| } | | } |
| n | | n | sprintf(a_buffer, "%g", (double)l_finish);
|
| | | ui->VYSLEDEK->setText(a_buffer);
|
| | | ui->pushButton_3->setDisabled(true);
|
| } | | } |
| | | |
| void CKalkulacka::on_pushButton_3_released() | | void CKalkulacka::on_pushButton_3_released() |
| orig/kalkulacka2/ckalkulacka.cpp | kalkulacka2/ckalkulacka.cpp |
| | | |
| void CKalkulacka::SetDisableAll(bool a_enabled) | | void CKalkulacka::SetDisableAll(bool a_enabled) |
| { | | { |
| n | ui->JEDNA->setDisabled(a_enabled);
| n | // To asi bude lepsi nez rucne vypsany seznam tlacitek.
|
| ui->DVA->setDisabled(a_enabled);
| | // Zvlaste, kdyz se kdykoli muze pridat dalsi...
|
| ui->TRI->setDisabled(a_enabled);
| | QList<QPushButton *> buttons = this->findChildren<QPushButton *>();
|
| ui->CTYRI->setDisabled(a_enabled);
| | foreach(QPushButton * o, buttons)
|
| ui->PET->setDisabled(a_enabled);
| | o->setDisabled(a_enabled);
|
| ui->SEST->setDisabled(a_enabled);
| | |
| ui->SEDM->setDisabled(a_enabled);
| | |
| ui->OSM->setDisabled(a_enabled);
| | |
| ui->DEVET->setDisabled(a_enabled);
| | |
| ui->NULA->setDisabled(a_enabled);
| | |
| ui->pushButton_10->setDisabled(a_enabled);
| | |
| ui->pushButton_2->setDisabled(a_enabled);
| | |
| ui->pushButton_3->setDisabled(a_enabled);
| | |
| ui->pushButton_5->setDisabled(a_enabled);
| | |
| ui->pushButton_6->setDisabled(a_enabled);
| | |
| ui->pushButton_9->setDisabled(a_enabled);
| | |
| ui->pushButton_8->setDisabled(a_enabled);
| | |
| ui->pushButton_7->setDisabled(a_enabled);
| | |
| ui->ROVNASE->setDisabled(a_enabled);
| | |
| } | | } |
| | | |
| void CKalkulacka::keyPressEvent ( QKeyEvent * event ) | | void CKalkulacka::keyPressEvent ( QKeyEvent * event ) |
| { | | { |
| t | | t | // jen finta na umlceni prekladace
|
| | | Q_UNUSED(event);
|
| } | | } |