#include <QtGui>
#include "Calc++.h"
QObject::connect(cls,
SIGNAL(clicked
()),lineEdit,
SLOT(clear
()));
QObject::connect(_1,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_1
->text
())));
QObject::connect(_2,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_2
->text
())));
QObject::connect(_3,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_3
->text
())));
QObject::connect(_4,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_4
->text
())));
QObject::connect(_5,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_5
->text
())));
QObject::connect(_6,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_6
->text
())));
QObject::connect(_7,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_7
->text
())));
QObject::connect(_8,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_8
->text
())));
QObject::connect(_9,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_9
->text
())));
QObject::connect(_10,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(_10
->text
())));
QObject::connect(point,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
(point
->text
())));
QObject::connect(unmin,
SIGNAL(clicked
()),lineEdit,
SLOT(edig
('u')));
QObject::connect(plus,
SIGNAL(clicked
()),lineEdit,
SLOT(set_op_op1
('+')));
QObject::connect(minus,
SIGNAL(clicked
()),lineEdit,
SLOT(set_op_op1
('-')));
QObject::connect(multiply,
SIGNAL(clicked
()),lineEdit,
SLOT(set_op_op1
('*')));
QObject::connect(division,
SIGNAL(clicked
()),lineEdit,
SLOT(set_op_op1
('/')));
QObject::connect(equal,
SIGNAL(clicked
()),lineEdit,
SLOT(compute_result
()));
} void calc::edig(const char &num){
if(num
=='u') lineEdit
->setText
(QString((char)((lineEdit
->text
().
toDouble())*(-1))));
else lineEdit->setText(lineEdit->text()+num);}
void calc::set_op_op1(const char &op){
op1=(lineEdit->text()).toDouble();
ope=op;
lineEdit->clear();}
void calc::compute_result(){
op2=(lineEdit->text()).toDouble();
switch(ope){
case '+':
lineEdit
->setText
(QString((char)(op1
+op2
)));
break;
case '-':
lineEdit
->setText
(QString((char)(op1
-op2
)));
break;
case '*':
lineEdit
->setText
(QString((char)(op1
*op2
)));
break;
case '/':
lineEdit
->setText
(QString((char)(op1
/op2
)));
break;}}
#include <QtGui>
#include "Calc++.h"
calc::calc(QWidget *parent):QDialog(parent){
lineEdit->setValidator(new QRegexpValidator(QDoubleValidator,this));
QObject::connect(cls,SIGNAL(clicked()),lineEdit,SLOT(clear()));
QObject::connect(_1,SIGNAL(clicked()),lineEdit,SLOT(edig(_1->text())));
QObject::connect(_2,SIGNAL(clicked()),lineEdit,SLOT(edig(_2->text())));
QObject::connect(_3,SIGNAL(clicked()),lineEdit,SLOT(edig(_3->text())));
QObject::connect(_4,SIGNAL(clicked()),lineEdit,SLOT(edig(_4->text())));
QObject::connect(_5,SIGNAL(clicked()),lineEdit,SLOT(edig(_5->text())));
QObject::connect(_6,SIGNAL(clicked()),lineEdit,SLOT(edig(_6->text())));
QObject::connect(_7,SIGNAL(clicked()),lineEdit,SLOT(edig(_7->text())));
QObject::connect(_8,SIGNAL(clicked()),lineEdit,SLOT(edig(_8->text())));
QObject::connect(_9,SIGNAL(clicked()),lineEdit,SLOT(edig(_9->text())));
QObject::connect(_10,SIGNAL(clicked()),lineEdit,SLOT(edig(_10->text())));
QObject::connect(point,SIGNAL(clicked()),lineEdit,SLOT(edig(point->text())));
QObject::connect(unmin,SIGNAL(clicked()),lineEdit,SLOT(edig('u')));
QObject::connect(plus,SIGNAL(clicked()),lineEdit,SLOT(set_op_op1('+')));
QObject::connect(minus,SIGNAL(clicked()),lineEdit,SLOT(set_op_op1('-')));
QObject::connect(multiply,SIGNAL(clicked()),lineEdit,SLOT(set_op_op1('*')));
QObject::connect(division,SIGNAL(clicked()),lineEdit,SLOT(set_op_op1('/')));
QObject::connect(equal,SIGNAL(clicked()),lineEdit,SLOT(compute_result()));}
void calc::edig(const char &num){
if(num=='u') lineEdit->setText(QString((char)((lineEdit->text().toDouble())*(-1))));
else lineEdit->setText(lineEdit->text()+num);}
void calc::set_op_op1(const char &op){
op1=(lineEdit->text()).toDouble();
ope=op;
lineEdit->clear();}
void calc::compute_result(){
op2=(lineEdit->text()).toDouble();
switch(ope){
case '+':
lineEdit->setText(QString((char)(op1+op2)));
break;
case '-':
lineEdit->setText(QString((char)(op1-op2)));
break;
case '*':
lineEdit->setText(QString((char)(op1*op2)));
break;
case '/':
lineEdit->setText(QString((char)(op1/op2)));
break;}}
To copy to clipboard, switch view to plain text mode
/********************************************************************************
** Form generated from reading ui file 'Calc++.ui'
**
** Created: Wed Mar 4 15:07:20 2009
** by: Qt User Interface Compiler version 4.5.0
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_CALC_2B__2B__H
#define UI_CALC_2B__2B__H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
QT_BEGIN_NAMESPACE
class Ui_Calc
{
public:
{
if (Calc->objectName().isEmpty())
Calc
->setObjectName
(QString::fromUtf8("Calc"));
Calc->resize(245, 163);
point
->setObjectName
(QString::fromUtf8("point"));
point
->setGeometry
(QRect(100,
130,
31,
23));
cls
->setObjectName
(QString::fromUtf8("cls"));
cls
->setGeometry
(QRect(200,
40,
31,
41));
_3
->setObjectName
(QString::fromUtf8("_3"));
_3
->setGeometry
(QRect(100,
40,
31,
23));
plus
->setObjectName
(QString::fromUtf8("plus"));
plus
->setGeometry
(QRect(150,
40,
31,
23));
_7
->setObjectName
(QString::fromUtf8("_7"));
_7
->setGeometry
(QRect(20,
100,
31,
23));
division
->setObjectName
(QString::fromUtf8("division"));
division
->setGeometry
(QRect(150,
130,
31,
21));
_6
->setObjectName
(QString::fromUtf8("_6"));
_6
->setGeometry
(QRect(100,
70,
31,
23));
_5
->setObjectName
(QString::fromUtf8("_5"));
_5
->setGeometry
(QRect(60,
70,
31,
23));
_1
->setObjectName
(QString::fromUtf8("_1"));
_1
->setGeometry
(QRect(20,
40,
31,
23));
unmin
->setObjectName
(QString::fromUtf8("unmin"));
unmin
->setGeometry
(QRect(20,
130,
31,
23));
_4
->setObjectName
(QString::fromUtf8("_4"));
_4
->setGeometry
(QRect(20,
70,
31,
23));
_8
->setObjectName
(QString::fromUtf8("_8"));
_8
->setGeometry
(QRect(60,
100,
31,
23));
_9
->setObjectName
(QString::fromUtf8("_9"));
_9
->setGeometry
(QRect(100,
100,
31,
23));
_2
->setObjectName
(QString::fromUtf8("_2"));
_2
->setGeometry
(QRect(60,
40,
31,
23));
_10
->setObjectName
(QString::fromUtf8("_10"));
_10
->setGeometry
(QRect(60,
130,
31,
23));
lineEdit
->setObjectName
(QString::fromUtf8("lineEdit"));
lineEdit
->setGeometry
(QRect(10,
10,
231,
21));
equal
->setObjectName
(QString::fromUtf8("equal"));
equal
->setGeometry
(QRect(200,
90,
31,
61));
minus
->setObjectName
(QString::fromUtf8("minus"));
minus
->setGeometry
(QRect(150,
70,
31,
23));
multiply
->setObjectName
(QString::fromUtf8("multiply"));
multiply
->setGeometry
(QRect(150,
100,
31,
23));
retranslateUi(Calc);
} // setupUi
{
Q_UNUSED(Calc);
} // retranslateUi
};
namespace Ui {
class Calc: public Ui_Calc {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_CALC_2B__2B__H
/********************************************************************************
** Form generated from reading ui file 'Calc++.ui'
**
** Created: Wed Mar 4 15:07:20 2009
** by: Qt User Interface Compiler version 4.5.0
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_CALC_2B__2B__H
#define UI_CALC_2B__2B__H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
QT_BEGIN_NAMESPACE
class Ui_Calc
{
public:
QPushButton *point;
QPushButton *cls;
QPushButton *_3;
QPushButton *plus;
QPushButton *_7;
QPushButton *division;
QPushButton *_6;
QPushButton *_5;
QPushButton *_1;
QPushButton *unmin;
QPushButton *_4;
QPushButton *_8;
QPushButton *_9;
QPushButton *_2;
QPushButton *_10;
QLineEdit *lineEdit;
QPushButton *equal;
QPushButton *minus;
QPushButton *multiply;
void setupUi(QDialog *Calc)
{
if (Calc->objectName().isEmpty())
Calc->setObjectName(QString::fromUtf8("Calc"));
Calc->resize(245, 163);
point = new QPushButton(Calc);
point->setObjectName(QString::fromUtf8("point"));
point->setGeometry(QRect(100, 130, 31, 23));
cls = new QPushButton(Calc);
cls->setObjectName(QString::fromUtf8("cls"));
cls->setGeometry(QRect(200, 40, 31, 41));
_3 = new QPushButton(Calc);
_3->setObjectName(QString::fromUtf8("_3"));
_3->setGeometry(QRect(100, 40, 31, 23));
plus = new QPushButton(Calc);
plus->setObjectName(QString::fromUtf8("plus"));
plus->setGeometry(QRect(150, 40, 31, 23));
_7 = new QPushButton(Calc);
_7->setObjectName(QString::fromUtf8("_7"));
_7->setGeometry(QRect(20, 100, 31, 23));
division = new QPushButton(Calc);
division->setObjectName(QString::fromUtf8("division"));
division->setGeometry(QRect(150, 130, 31, 21));
_6 = new QPushButton(Calc);
_6->setObjectName(QString::fromUtf8("_6"));
_6->setGeometry(QRect(100, 70, 31, 23));
_5 = new QPushButton(Calc);
_5->setObjectName(QString::fromUtf8("_5"));
_5->setGeometry(QRect(60, 70, 31, 23));
_1 = new QPushButton(Calc);
_1->setObjectName(QString::fromUtf8("_1"));
_1->setGeometry(QRect(20, 40, 31, 23));
unmin = new QPushButton(Calc);
unmin->setObjectName(QString::fromUtf8("unmin"));
unmin->setGeometry(QRect(20, 130, 31, 23));
_4 = new QPushButton(Calc);
_4->setObjectName(QString::fromUtf8("_4"));
_4->setGeometry(QRect(20, 70, 31, 23));
_8 = new QPushButton(Calc);
_8->setObjectName(QString::fromUtf8("_8"));
_8->setGeometry(QRect(60, 100, 31, 23));
_9 = new QPushButton(Calc);
_9->setObjectName(QString::fromUtf8("_9"));
_9->setGeometry(QRect(100, 100, 31, 23));
_2 = new QPushButton(Calc);
_2->setObjectName(QString::fromUtf8("_2"));
_2->setGeometry(QRect(60, 40, 31, 23));
_10 = new QPushButton(Calc);
_10->setObjectName(QString::fromUtf8("_10"));
_10->setGeometry(QRect(60, 130, 31, 23));
lineEdit = new QLineEdit(Calc);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(10, 10, 231, 21));
equal = new QPushButton(Calc);
equal->setObjectName(QString::fromUtf8("equal"));
equal->setGeometry(QRect(200, 90, 31, 61));
minus = new QPushButton(Calc);
minus->setObjectName(QString::fromUtf8("minus"));
minus->setGeometry(QRect(150, 70, 31, 23));
multiply = new QPushButton(Calc);
multiply->setObjectName(QString::fromUtf8("multiply"));
multiply->setGeometry(QRect(150, 100, 31, 23));
retranslateUi(Calc);
QMetaObject::connectSlotsByName(Calc);
} // setupUi
void retranslateUi(QDialog *Calc)
{
Calc->setWindowTitle(QApplication::translate("Calc", "Dialog", 0, QApplication::UnicodeUTF8));
point->setText(QApplication::translate("Calc", ".", 0, QApplication::UnicodeUTF8));
cls->setText(QApplication::translate("Calc", "&CLS", 0, QApplication::UnicodeUTF8));
_3->setText(QApplication::translate("Calc", "3", 0, QApplication::UnicodeUTF8));
plus->setText(QApplication::translate("Calc", "+", 0, QApplication::UnicodeUTF8));
_7->setText(QApplication::translate("Calc", "7", 0, QApplication::UnicodeUTF8));
division->setText(QApplication::translate("Calc", "/", 0, QApplication::UnicodeUTF8));
_6->setText(QApplication::translate("Calc", "6", 0, QApplication::UnicodeUTF8));
_5->setText(QApplication::translate("Calc", "5", 0, QApplication::UnicodeUTF8));
_1->setText(QApplication::translate("Calc", "1", 0, QApplication::UnicodeUTF8));
unmin->setText(QApplication::translate("Calc", "+/-", 0, QApplication::UnicodeUTF8));
_4->setText(QApplication::translate("Calc", "4", 0, QApplication::UnicodeUTF8));
_8->setText(QApplication::translate("Calc", "8", 0, QApplication::UnicodeUTF8));
_9->setText(QApplication::translate("Calc", "9", 0, QApplication::UnicodeUTF8));
_2->setText(QApplication::translate("Calc", "2", 0, QApplication::UnicodeUTF8));
_10->setText(QApplication::translate("Calc", "0", 0, QApplication::UnicodeUTF8));
lineEdit->setText(QString());
equal->setText(QApplication::translate("Calc", "=", 0, QApplication::UnicodeUTF8));
minus->setText(QApplication::translate("Calc", "-", 0, QApplication::UnicodeUTF8));
multiply->setText(QApplication::translate("Calc", "*", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Calc);
} // retranslateUi
};
namespace Ui {
class Calc: public Ui_Calc {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_CALC_2B__2B__H
To copy to clipboard, switch view to plain text mode
Bookmarks