ddWidget(button2, 2, 1, 1 ,1); gridLayout->addWidget(button3, 2, 2, 1, 1); gridLayout->addWidget(buttonadd, 2, 3, 1, 1); gridLayout->addWidget(buttonsub, 2, 4, 1, 1); gridLayout->addWidget(button4, 3, 0, 1, 1); gridLayout->addWidget(button5, 3, 1, 1, 1); gridLayout->addWidget(button6, 3, 2, 1, 1); gridLayout->addWidget(buttonx, 3, 3, 1, 1); gridLayout->addWidget(buttondivide, 3, 4, 1, 1); gridLayout->addWidget(button7, 4, 0, 1, 1); gridLayout->addWidget(button8, 4, 1, 1, 1); gridLayout->addWidget(button9, 4, 2, 1, 1); gridLayout->addWidget(buttonLArc, 4, 3, 1, 1); gridLayout->addWidget(buttonRArc, 4, 4, 1, 1); gridLayout->addWidget(button0, 5, 0, 1, 1); gridLayout->addWidget(buttondot, 5, 1, 1, 1); gridLayout->addWidget(buttonback, 5, 2, 1, 1); gridLayout->addWidget(buttonclear, 5, 3, 1, 1); gridLayout->addWidget(buttonequal, 5, 4, 1, 1);
setLayout(gridLayout); initVector(); } void Calculator::initConnect() { connect(button0, &QPushButton::clicked, this, &Calculator::getButton); connect(button1, &QPushButton::clicked, this, &Calculator::getButton); connect(button2, &QPushButton::clicked, this, &Calculator::getButton); connect(button3, &QPushButton::clicked, this, &Calculator::getButton); connect(button4, &QPushButton::clicked, this, &Calculator::getButton); connect(button5, &QPushButton::clicked, this, &Calculator::getButton); connect(button6, &QPushButton::clicked, this, &Calculator::getButton); connect(button7, &QPushButton::clicked, this, &Calculator::getButton); connect(button8, &QPushButton::clicked, this, &Calculator::getButton); connect(button9, &QPushButton::clicked, this, &Calculator::getButton); connect(buttonx, &QPushButton::clicked, this, &Calculator::getButton); connect(buttonadd, &QPushButton::clicked, this, &Calculator::getButton); connect(buttondivide, &QPushButton::clicked, this, &Calculator::getButton); connect(buttondot, &QPushButton::clicked, this, &Calculator::getButton); connect(buttonsub, &QPushButton::clicked, this, &Calculator::getButton); connect(buttonRArc, &QPushButton::clicked, this, &Calculator::getButton); connect(buttonLArc, &QPushButton::clicked, this, &Calculator::getButton);
connect(buttonback, &QPushButton::clicked, this, &Calculator::myBackSpace); connect(buttonclear, &QPushButton::clicked, this, &Calculator::clearScreen); connect(buttonequal, &QPushButton::clicked, this, &Calculator::getButton); }
bool Calculator::isTwoOptr(QPushButton *button) { if(button == buttonadd || button ==buttonsub || button == buttonx || button == buttondivide) return true; else return false; } void Calculator::myBackSpace() { QTextCursor cursor = screenTextEdit->textCursor(); cursor.deletePreviousChar(); if(!isEqualClicked) vectorExp.pop_back();
}
void Calculator::getButton() { QPushButton* button = qobject_cast(sender()); if(isTwoOptrsFlag && isTwoOptr(button)) {
} else{
vectorExp.append(button2char(button)); isEqualClicked = false; isTwoOptrsFlag = false; if(!isEnter) screenTextEdit->append(""); screenTextEdit->insertPlainText(button->text()); isEnter = true; if(button == buttonadd || button == buttonsub || button == buttonx || button == buttondivide) isTwoOptrsFlag = true; }
if(button == b |