17 m_plcd =
new QLCDNumber(12);
18 m_plcd->setSegmentStyle(QLCDNumber::Flat);
19 m_plcd->setMinimumSize(150, 50);
21 QChar aButtons[4][4] = {{
'7',
'8',
'9',
'/'},
28 QGridLayout* ptopLayout =
new QGridLayout;
29 ptopLayout->addWidget(m_plcd, 0, 0, 1, 4);
32 for (
int i = 0; i < 4; ++i) {
33 for (
int j = 0; j < 4; ++j) {
34 ptopLayout->addWidget(
createButton(aButtons[i][j]), i + 2, j);
37 setLayout(ptopLayout);
43 QPushButton* pcmd =
new QPushButton(str);
44 pcmd->setMinimumSize(40, 40);
53 qreal fOperand2 = m_stk.pop().toFloat();
54 QString strOperation = m_stk.pop();
55 qreal fOperand1 = m_stk.pop().toFloat();
58 if (strOperation ==
"+") {
59 fResult = fOperand1 + fOperand2;
61 if (strOperation ==
"-") {
62 fResult = fOperand1 - fOperand2;
64 if (strOperation ==
"/") {
65 fResult = fOperand1 / fOperand2;
67 if (strOperation ==
"*") {
68 fResult = fOperand1 * fOperand2;
70 m_plcd->display(fResult);
76 QString str = ((QPushButton*)sender())->text();
84 if (str.contains(QRegExp(
"[0-9]"))) {
86 m_plcd->display(m_strDisplay.toDouble());
88 else if (str ==
".") {
90 m_plcd->display(m_strDisplay);
93 if (m_stk.count() >= 2) {
94 m_stk.push(QString().setNum(m_plcd->value()));
97 m_stk.push(QString().setNum(m_plcd->value()));
103 m_stk.push(QString().setNum(m_plcd->value()));
QPushButton * createButton(const QString &str)
Calculator(QWidget *pwgt=0)