#include "widget.h"
#define ButtonSizeH 30
#define ButtonSizeW 30
#define OutputWinH 25
#define OutputWinW 255
#define MainWindowH 175
#define MainWindowW 275
myPushButton::myPushButton(QString str)
{
strV = str;
setText(str);
connect(this, SIGNAL(clicked()), this, SLOT(sendStr()));
}
void myPushButton::sendStr(void)
{
strV = text();
emit pressed(strV);
}
Widget::Widget()
{
this->setWindowTitle(QString("p_x_l calculattor"));
this->setMaximumSize(MainWindowW,MainWindowH);
this->setMinimumSize(MainWindowW,MainWindowH);
initNumButton();
initLayout();
}
void MyLineEdit::OutputChanged(QString StrNum)
{
this->setText(StrNum);
}
void Widget::initNumButton(void)
{
/*数字按钮*/
OutPutWindow = new MyLineEdit();
OutPutWindow->setMaximumSize(OutputWinW, OutputWinH);
OutPutWindow->setMinimumSize(OutputWinW, OutputWinH);
Button_0 = new myPushButton(QString("0"));
Button_0->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_0->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_0, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_1 = new myPushButton("1");
Button_1->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_1->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_1, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_2 = new myPushButton("2");
Button_2->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_2->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_2, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_3 = new myPushButton("3");
Button_3->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_3->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_3, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_4 = new myPushButton("4");
Button_4->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_4->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_4, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_5 = new myPushButton("5");
Button_5->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_5->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_5, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_6 = new myPushButton("6");
Button_6->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_6->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_6, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_7 = new myPushButton("7");
Button_7->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_7->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_7, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_8 = new myPushButton("8");
Button_8->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_8->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_8, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_9 = new myPushButton("9");
Button_9->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_9->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_9, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_Sign = new myPushButton("+/-");
Button_Sign->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_Sign->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_Sign, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
Button_Point = new myPushButton(".");
Button_Point->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_Point->setMinimumSize(ButtonSizeW, ButtonSizeH);
connect(Button_Point, SIGNAL(pressed(const QString&)), OutPutWindow, SLOT(OutputChanged(QString)));
/*运算符按钮*/
Button_Plus = new myPushButton("+");
Button_Plus->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_Plus->setMinimumSize(ButtonSizeW, ButtonSizeH);
Button_Minus = new myPushButton("-");
Button_Minus->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_Minus->setMinimumSize(ButtonSizeW, ButtonSizeH);
Button_Mutiply = new myPushButton("*");
Button_Mutiply->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_Mutiply->setMinimumSize(ButtonSizeW, ButtonSizeH);
Button_Divide = new myPushButton("/");
Button_Divide->setMaximumSize(ButtonSizeW, ButtonSizeH);
Button_Divide->setMinimumSize(ButtonSizeW, ButtonSizeH);
}
void Widget::initLayout(void)
{
NumLayout = new QGridLayout;
NumLayout->setRowStretch(4, 1);
NumLayout->setColumnStretch(3,1);
OperatorLayout = new QGridLayout;
OperatorLayout->setRowStretch(4, 1);
OperatorLayout->setColumnStretch(3, 1);
Outlayout = new QGridLayout;
OperatorLayout->setRowStretch(2, 1);
OperatorLayout->setColumnStretch(2, 1);
MainLayout = new QGridLayout;
MainLayout->addLayout(Outlayout, 0, 0, 0);
MainLayout->addLayout(NumLayout, 1, 0, 0);
MainLayout->addLayout(OperatorLayout, 1, 1, 0);
setLayout(MainLayout);
Outlayout->addWidget(OutPutWindow, 0, 0, 0);
/*数字图层区*/
NumLayout->addWidget(Button_0, 0, 0, 0);
NumLayout->addWidget(Button_1, 0, 1, 0);
NumLayout->addWidget(Button_2, 0, 2, 0);
NumLayout->addWidget(Button_3, 1, 0, 0);
NumLayout->addWidget(Button_4, 1, 1, 0);
NumLayout->addWidget(Button_5, 1, 2, 0);
NumLayout->addWidget(Button_6, 2, 0, 0);
NumLayout->addWidget(Button_7, 2, 1, 0);
NumLayout->addWidget(Button_8, 2, 2, 0);
NumLayout->addWidget(Button_9, 3, 0, 0);
NumLayout->addWidget(Button_Sign, 3, 1, 0);
NumLayout->addWidget(Button_Point, 3, 2, 0);
/*运算符图层区*/
OperatorLayout->addWidget(Button_Plus, 0, 0, 0);
OperatorLayout->addWidget(Button_Minus, 0, 1, 0);
OperatorLayout->addWidget(Button_Mutiply, 0, 2, 0);
OperatorLayout->addWidget(Button_Divide, 0, 3, 0);
}