Calculator::Calculator(QWidget *parent) : QDialog(parent), ui(new Ui::Calculator) { clear = false; ui->setupUi(this); connect(ui->num_0, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_1, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_2, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_3, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_4, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_5, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_6, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_7, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_8, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->num_9, SIGNAL(clicked()), this, SLOT(numberButtonClicked())); connect(ui->expr_add, SIGNAL(clicked()), this, SLOT(operationButtonClicked())); connect(ui->expr_sub, SIGNAL(clicked()), this, SLOT(operationButtonClicked())); connect(ui->expr_mul, SIGNAL(clicked()), this, SLOT(operationButtonClicked())); connect(ui->expr_div, SIGNAL(clicked()), this, SLOT(operationButtonClicked())); connect(ui->paren_begin, SIGNAL(clicked()), this, SLOT(parenthesisButtonClicked())); connect(ui->paren_end, SIGNAL(clicked()), this, SLOT(parenthesisButtonClicked())); connect(ui->func_sin, SIGNAL(clicked()), this, SLOT(functionButtonClicked())); connect(ui->func_cos, SIGNAL(clicked()), this, SLOT(functionButtonClicked())); connect(ui->func_tan, SIGNAL(clicked()), this, SLOT(functionButtonClicked())); connect(ui->func_sinh, SIGNAL(clicked()), this, SLOT(functionButtonClicked())); connect(ui->func_cosh, SIGNAL(clicked()), this, SLOT(functionButtonClicked())); connect(ui->func_tanh, SIGNAL(clicked()), this, SLOT(functionButtonClicked())); connect(ui->pow_2, SIGNAL(clicked()), this, SLOT(powerButtonClicked())); connect(ui->pow_3, SIGNAL(clicked()), this, SLOT(powerButtonClicked())); connect(ui->pow_n, SIGNAL(clicked()), this, SLOT(powerButtonClicked())); connect(ui->pow_half, SIGNAL(clicked()), this, SLOT(powerButtonClicked())); connect(ui->pow_minus_one, SIGNAL(clicked()), this, SLOT(powerButtonClicked())); connect(ui->memory_clear, SIGNAL(clicked()), this, SLOT(memoryButtonClicked())); connect(ui->memory_save, SIGNAL(clicked()), this, SLOT(memoryButtonClicked())); connect(ui->memory_recall, SIGNAL(clicked()), this, SLOT(memoryButtonClicked())); connect(ui->backspace, SIGNAL(clicked()), this, SLOT(removeLastChar())); connect(ui->num_dot, SIGNAL(clicked()), this, SLOT(dotButtonClicked())); connect(ui->eval, SIGNAL(clicked()), this, SLOT(evaluate())); connect(ui->factorial, SIGNAL(clicked()), this, SLOT(factButtonClicked())); connect(ui->all_clear, SIGNAL(clicked()), this, SLOT(acButtonClicked())); // reset for the first time acButtonClicked(); setWindowTitle("Minhaz Calc"); }
QLayout *Calculator::setupNumberButtons() { QGridLayout *gridNumber = new QGridLayout; for( int i = 0; i <= 9; i++ ){ QPushButton *button = new QPushButton(QString::number(i),this); button->setObjectName(QString("button%1").arg(i)); int row = 0, col = 0, rowspan = 1, colspan = 1; if( i == 0 ){ row = 3; col = 0; colspan = 3; } else{ row = 2 - (i - 1) / 3; col = (i - 1) % 3; } gridNumber->addWidget(button,row,col,rowspan,colspan); connect(button,SIGNAL(clicked()),this,SLOT(numberButtonClicked())); m_numberMap[button] = i; } return gridNumber; }