-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdialog.cpp
103 lines (86 loc) · 3.01 KB
/
dialog.cpp
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
#include "dialog.h"
#include "ui_dialog.h"
#include "calculator.h"
#include "asciitable.h"
#include<QDebug>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
this->setWindowTitle("Number Converter");
this->setWindowFlags(this->windowFlags() | Qt::WindowMinimizeButtonHint);
}
Dialog::~Dialog()
{
delete ui;
}
//for decimal conversion
void Dialog::on_pushButton_clicked()
{
QString text=ui->lineEdit->text();
bool ok;
long long num=text.toLongLong(&ok,10);
QString hex = QString::number(num, 16).toUpper(); //convert to hexadecimal
QString octal=QString::number(num,8); //convert to octal
QString bin=QString::number(num,2);
ui->textBrowser->setText("Decimal[10] : "+text);
ui->textBrowser->append("\nHexadecimal[16] : "+hex);
ui->textBrowser->append("\nOctal[8] : " +octal);
ui->textBrowser->append("\nBinary[2] : " +bin);
//converting to ascii value
}
//for hexadecimal conversion
void Dialog::on_pushButton_2_clicked()
{
QString text=ui->lineEdit_2->text();
bool ok;
long long num=text.toLongLong(&ok,16);
QString dec = QString::number(num,10); //convert to decimal
QString octal=QString::number(num,8); //convert to octal
QString bin=QString::number(num,2);
ui->textBrowser->setText("Decimal[10] : "+dec);
ui->textBrowser->append("\nHexadecimal[16] : "+text.toUpper());
ui->textBrowser->append("\nOctal[8] : " +octal);
ui->textBrowser->append("\nBinary[2] : " +bin);
}
//for octal conversion
void Dialog::on_pushButton_3_clicked()
{
QString text=ui->lineEdit_3->text();
bool ok;
long long num=text.toLongLong(&ok,8);
QString dec = QString::number(num,10); //convert to decimal
QString hex=QString::number(num,16).toUpper(); //convert to octal
QString bin=QString::number(num,2);
ui->textBrowser->setText("Decimal[10] : "+dec);
ui->textBrowser->append("\nHexadecimal[16] : "+hex);
ui->textBrowser->append("\nOctal[8] : " +text);
ui->textBrowser->append("\nBinary[2] : " +bin);
}
void Dialog::on_pushButton_4_clicked()
{
QString text=ui->lineEdit_4->text();
bool ok;
long long num=text.toLongLong(&ok,2);
QString dec = QString::number(num,10); //convert to decimal
QString hex=QString::number(num,16).toUpper(); //convert to octal
QString octal=QString::number(num,8);
ui->textBrowser->setText("Decimal[10] : "+dec);
ui->textBrowser->append("\nHexadecimal[16] : "+hex);
ui->textBrowser->append("\nOctal[8] : " +octal);
ui->textBrowser->append("\nBinary[2] : " +text);
}
void Dialog::on_pushButton_5_clicked()
{
calculator* cal=new calculator(this);
cal->setWindowFlags(cal->windowFlags() | Qt::WindowMinimizeButtonHint);
cal->show();
}
/*
void Dialog::on_pushButton_6_clicked()
{
asciiTable* ascii=new asciiTable(this);
ascii->show();
}
*/