#ifndef MYCALCULATOR_H
#define MYCALCULATOR_H
#include <QPushButton>
#include <QTextEdit>
#include "display.h"
class MyCalculator
: public QWidget{
Q_OBJECT
public:
//QSize sizeHint() const;
private:
Display *mydisplay;
enum{digitArrayIndex = 10};
QPushButton *addButton,
*subButton,
*mulButton,
*divButton;
//there is 6 functions for now
QPushButton *equalButton,
*pointButton,
*clearButton,
*delButton,
*ansButton;
private slots:
void digitClicked();
void operationClicked();
void functionClicked();
void equalClicked();
void pointClicked();
void clearClicked();
void delClicked();
void ansClicked();
private: //functions
};
#endif // MYCALCULATOR_H
#ifndef MYCALCULATOR_H
#define MYCALCULATOR_H
#include <QPushButton>
#include <QTextEdit>
#include "display.h"
class MyCalculator : public QWidget
{
Q_OBJECT
public:
MyCalculator(QWidget *parent = 0);
//QSize sizeHint() const;
private:
Display *mydisplay;
enum{digitArrayIndex = 10};
QPushButton *digitButtons[digitArrayIndex];
QPushButton *addButton,*subButton,*mulButton,*divButton;
//there is 6 functions for now
QPushButton *sinButton,*cosButton,*tanButton;
QPushButton *powerButton,*sqrtButton,*lnButton;
QPushButton *equalButton,*pointButton,*clearButton,*delButton,*ansButton;
private slots:
void digitClicked();
void operationClicked();
void functionClicked();
void equalClicked();
void pointClicked();
void clearClicked();
void delClicked();
void ansClicked();
private: //functions
QPushButton *createButton(const QString &text, const char *buttonSlot);
};
#endif // MYCALCULATOR_H
To copy to clipboard, switch view to plain text mode
#include <QGridLayout>
#include <QScrollArea>
#include "mycalculator.h"
#include "display.h"
MyCalculator
::MyCalculator(QWidget *parent
){
myBasicGrid
->setSizeConstraint
(QLayout::SetFixedSize);
mydisplay = new Display;
//display->setReadOnly(true);
/*QFont displayFont = display->font();
displayFont.setPointSize(displayFont.pointSize() + 4);
display->setFont(displayFont);*/
//Implement operation buttons
addButton = createButton("+",SLOT(operationClicked()));
subButton = createButton("-",SLOT(operationClicked()));
mulButton = createButton("\303\227",SLOT(operationClicked()));
divButton = createButton("\303\267",SLOT(operationClicked()));
//Implement function buttons
sinButton = createButton("sin",SLOT(functionClicked()));
cosButton = createButton("cos",SLOT(functionClicked()));
tanButton = createButton("tan",SLOT(functionClicked()));
powerButton = createButton("x\302\262",SLOT(functionClicked()));
sqrtButton = createButton("\342\210\232",SLOT(functionClicked()));
lnButton = createButton("ln",SLOT(functionClicked()));
//The rest of the buttons
equalButton = createButton("=",SLOT(equalClicked()));
pointButton = createButton(".",SLOT(pointClicked()));
ansButton = createButton("Ans",SLOT(ansClicked()));
delButton = createButton("DEL",SLOT(delClicked()));
clearButton = createButton("AC",SLOT(clearClicked()));
//The digit buttons
digitButtons[0] = createButton("0",SLOT(digitClicked()));
for(int i = 1; i<digitArrayIndex; i++){
digitButtons
[i
] = createButton
(QString::number(i
),
SLOT(digitClicked
()));
int row = ((9 - i) / 3) + 2;
int column = ((i - 1) % 3);
myBasicGrid->addWidget(digitButtons[i],row,column); //Adding the digit buttons to the grid
}
//layout the display and the rest of the buttons
//myBasicGrid->addWidget(mydisplay,0,0,1,5);
myBasicGrid->addWidget(digitButtons[0],5,0);
myBasicGrid->addWidget(sinButton,1,0);
myBasicGrid->addWidget(cosButton,1,1);
myBasicGrid->addWidget(tanButton,1,2);
myBasicGrid->addWidget(powerButton,1,3);
myBasicGrid->addWidget(sqrtButton,1,4);
myBasicGrid->addWidget(delButton,2,3);
myBasicGrid->addWidget(clearButton,2,4);
myBasicGrid->addWidget(mulButton,3,3);
myBasicGrid->addWidget(divButton,3,4);
myBasicGrid->addWidget(addButton,4,3);
myBasicGrid->addWidget(subButton,4,4);
myBasicGrid->addWidget(pointButton,5,1);
myBasicGrid->addWidget(lnButton,5,2);
myBasicGrid->addWidget(ansButton,5,3);
myBasicGrid->addWidget(equalButton,5,4);
}
//Slots implemetation
void MyCalculator::digitClicked()
{
}
void MyCalculator::operationClicked()
{
}
void MyCalculator::functionClicked()
{
}
void MyCalculator::equalClicked()
{
}
void MyCalculator::pointClicked()
{
}
void MyCalculator::clearClicked()
{
}
void MyCalculator::delClicked()
{
}
void MyCalculator::ansClicked()
{
}
//functions implimintation
connect(button, SIGNAL(clicked()), this, buttonSlot);
return button;
}
#include <QGridLayout>
#include <QScrollArea>
#include "mycalculator.h"
#include "display.h"
MyCalculator::MyCalculator(QWidget *parent)
: QWidget(parent)
{
QGridLayout *myBasicGrid = new QGridLayout(this);
myBasicGrid->setSizeConstraint(QLayout::SetFixedSize);
mydisplay = new Display;
//display->setReadOnly(true);
/*QFont displayFont = display->font();
displayFont.setPointSize(displayFont.pointSize() + 4);
display->setFont(displayFont);*/
//Implement operation buttons
addButton = createButton("+",SLOT(operationClicked()));
subButton = createButton("-",SLOT(operationClicked()));
mulButton = createButton("\303\227",SLOT(operationClicked()));
divButton = createButton("\303\267",SLOT(operationClicked()));
//Implement function buttons
sinButton = createButton("sin",SLOT(functionClicked()));
cosButton = createButton("cos",SLOT(functionClicked()));
tanButton = createButton("tan",SLOT(functionClicked()));
powerButton = createButton("x\302\262",SLOT(functionClicked()));
sqrtButton = createButton("\342\210\232",SLOT(functionClicked()));
lnButton = createButton("ln",SLOT(functionClicked()));
//The rest of the buttons
equalButton = createButton("=",SLOT(equalClicked()));
pointButton = createButton(".",SLOT(pointClicked()));
ansButton = createButton("Ans",SLOT(ansClicked()));
delButton = createButton("DEL",SLOT(delClicked()));
clearButton = createButton("AC",SLOT(clearClicked()));
//The digit buttons
digitButtons[0] = createButton("0",SLOT(digitClicked()));
for(int i = 1; i<digitArrayIndex; i++){
digitButtons[i] = createButton(QString::number(i),SLOT(digitClicked()));
int row = ((9 - i) / 3) + 2;
int column = ((i - 1) % 3);
myBasicGrid->addWidget(digitButtons[i],row,column); //Adding the digit buttons to the grid
}
//layout the display and the rest of the buttons
//myBasicGrid->addWidget(mydisplay,0,0,1,5);
myBasicGrid->addWidget(digitButtons[0],5,0);
myBasicGrid->addWidget(sinButton,1,0);
myBasicGrid->addWidget(cosButton,1,1);
myBasicGrid->addWidget(tanButton,1,2);
myBasicGrid->addWidget(powerButton,1,3);
myBasicGrid->addWidget(sqrtButton,1,4);
myBasicGrid->addWidget(delButton,2,3);
myBasicGrid->addWidget(clearButton,2,4);
myBasicGrid->addWidget(mulButton,3,3);
myBasicGrid->addWidget(divButton,3,4);
myBasicGrid->addWidget(addButton,4,3);
myBasicGrid->addWidget(subButton,4,4);
myBasicGrid->addWidget(pointButton,5,1);
myBasicGrid->addWidget(lnButton,5,2);
myBasicGrid->addWidget(ansButton,5,3);
myBasicGrid->addWidget(equalButton,5,4);
}
//Slots implemetation
void MyCalculator::digitClicked()
{
}
void MyCalculator::operationClicked()
{
}
void MyCalculator::functionClicked()
{
}
void MyCalculator::equalClicked()
{
}
void MyCalculator::pointClicked()
{
}
void MyCalculator::clearClicked()
{
}
void MyCalculator::delClicked()
{
}
void MyCalculator::ansClicked()
{
}
//functions implimintation
QPushButton *MyCalculator::createButton(const QString &text, const char *buttonSlot){
QPushButton *button = new QPushButton(text);
connect(button, SIGNAL(clicked()), this, buttonSlot);
return button;
}
To copy to clipboard, switch view to plain text mode
Bookmarks