1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#include <QMainWindow>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QLabel *label;
QLabel *label_2;
QLabel *label_3;
QLabel *label_4;
QLineEdit *subtotal;
QLineEdit *tippercent;
QLineEdit *tipamount;
QLineEdit *total;
QPushButton *pushButton;
QHBoxLayout *horizontalLayout;
QHBoxLayout *horizontalLayout_2;
QHBoxLayout *horizontalLayout_3;
QHBoxLayout *horizontalLayout_4;
QVBoxLayout *verticalLayout;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(273, 177);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
label = new QLabel(centralWidget);
label_2 = new QLabel(centralWidget);
label_3 = new QLabel(centralWidget);
label_4 = new QLabel(centralWidget);
label->setObjectName( QString::fromUtf8("label" ));
label_2->setObjectName(QString::fromUtf8("label_2"));
label_3->setObjectName(QString::fromUtf8("label_3"));
label_4->setObjectName(QString::fromUtf8("label_4"));
subtotal = new QLineEdit(centralWidget);
tippercent = new QLineEdit(centralWidget);
tipamount = new QLineEdit(centralWidget);
total = new QLineEdit(centralWidget);
subtotal->setObjectName( QString::fromUtf8("subtotal" ));
tippercent->setObjectName(QString::fromUtf8("tippercent"));
tipamount->setObjectName( QString::fromUtf8("tipamount" ));
total->setObjectName( QString::fromUtf8("total" ));
tipamount->setReadOnly(true);
total->setReadOnly(true);
pushButton = new QPushButton(centralWidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
horizontalLayout = new QHBoxLayout();
horizontalLayout->setSpacing(6);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
horizontalLayout->addWidget(label);
horizontalLayout->addWidget(subtotal);
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setSpacing(6);
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
horizontalLayout_2->addWidget(label_2);
horizontalLayout_2->addWidget(tippercent);
horizontalLayout_3 = new QHBoxLayout();
horizontalLayout_3->setSpacing(6);
horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
horizontalLayout_3->addWidget(label_3);
horizontalLayout_3->addWidget(tipamount);
horizontalLayout_4 = new QHBoxLayout();
horizontalLayout_4->setSpacing(6);
horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4"));
horizontalLayout_4->addWidget(label_4);
horizontalLayout_4->addWidget(total);
verticalLayout = new QVBoxLayout(centralWidget);
verticalLayout->setSpacing(6);
verticalLayout->setContentsMargins(11, 11, 11, 11);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
verticalLayout->addLayout(horizontalLayout);
verticalLayout->addLayout(horizontalLayout_2);
verticalLayout->addWidget(pushButton);
verticalLayout->addLayout(horizontalLayout_3);
verticalLayout->addLayout(horizontalLayout_4);
MainWindow->setCentralWidget(centralWidget);
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow" , 0, QApplication::UnicodeUTF8));
label->setText( QApplication::translate("MainWindow", "Subtotal $:", 0, QApplication::UnicodeUTF8));
label_2->setText( QApplication::translate("MainWindow", "Tip %:" , 0, QApplication::UnicodeUTF8));
label_3->setText( QApplication::translate("MainWindow", "Tip Amount:", 0, QApplication::UnicodeUTF8));
label_4->setText( QApplication::translate("MainWindow", "Total:" , 0, QApplication::UnicodeUTF8));
subtotal->setText( QApplication::translate("MainWindow", "10.00" , 0, QApplication::UnicodeUTF8));
tippercent->setText( QApplication::translate("MainWindow", "15.0" , 0, QApplication::UnicodeUTF8));
pushButton->setText( QApplication::translate("MainWindow", "Calculate" , 0, QApplication::UnicodeUTF8));
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui_MainWindow) { ui->setupUi(this); }
~MainWindow() { delete ui; }
private slots:
void on_pushButton_released()
{
double subtotal = ui->subtotal->text().toDouble();
double tippercent = ui->tippercent->text().toDouble();
double tipamount = subtotal * (tippercent/100.);
double total = subtotal + tipamount;
ui->tipamount->setText(QString("%1").arg(tipamount));
ui->total->setText(QString("%1").arg(total));
}
private:
Ui_MainWindow *ui;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
|