-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberSystem.cpp
More file actions
122 lines (97 loc) · 3.71 KB
/
Copy pathNumberSystem.cpp
File metadata and controls
122 lines (97 loc) · 3.71 KB
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
#include <QLabel>
#include <QLineEdit>
#include <QGridLayout>
#include "NumberSystem.h"
#include "CoreManager.h"
#define LABEL_HEIGHT 30
NumberSystem::NumberSystem(QWidget* parent)
:QWidget(parent)
{
setFixedSize(700, 300);
setWindowTitle("NumberSystems");
setStyleSheet("background: #c6c9f0;");
createMembers();
makeConnections();
setupLayout();
installStyleSheets();
}
void NumberSystem::createMembers()
{
m_decimalLabel = new QLabel("Decimal", this);
m_hexLabel = new QLabel("Hex", this);
m_binaryLabel = new QLabel("Binary", this);
m_decimalLineEdit = new QLineEdit(this);
m_hexLineEdit = new QLineEdit(this);
m_binaryLineEdit = new QLineEdit(this);
m_core = new CoreManager(this);
}
void NumberSystem::makeConnections()
{
connect(m_decimalLineEdit, &QLineEdit::textChanged, m_core, &CoreManager::onDecimalChangedSlot);
connect(m_hexLineEdit, &QLineEdit::textChanged, m_core, &CoreManager::onHexChangedSlot);
connect(m_binaryLineEdit, &QLineEdit::textChanged, m_core, &CoreManager::onBinaryChangedSlot);
// core
connect(m_core, &CoreManager::decimalProcessed, this, &NumberSystem::onDecimialProcessedSlot);
connect(m_core, &CoreManager::hexProcessed, this, &NumberSystem::onHexProcessedSlot);
connect(m_core, &CoreManager::binaryProcessed, this, &NumberSystem::onBinaryProcessedSlot);
connect(m_core, &CoreManager::processFailed, this, &NumberSystem::clearData);
}
void NumberSystem::setupLayout()
{
QGridLayout* gridLayout = new QGridLayout(this);
gridLayout->addWidget(m_decimalLabel);
gridLayout->addWidget(m_hexLabel);
gridLayout->addWidget(m_binaryLabel);
gridLayout->addWidget(m_decimalLineEdit, 0, 2, 1, 5);
gridLayout->addWidget(m_hexLineEdit, 1, 2, 1, 5);
gridLayout->addWidget(m_binaryLineEdit, 2, 2, 1, 5);
setLayout(gridLayout);
}
void NumberSystem::installStyleSheets()
{
const QString labelsStyleSheet = "QLabel{font: 18px}";
m_decimalLabel->setStyleSheet(labelsStyleSheet);
m_hexLabel->setStyleSheet(labelsStyleSheet);
m_binaryLabel->setStyleSheet(labelsStyleSheet);
m_decimalLineEdit->setFixedHeight(LABEL_HEIGHT);
m_hexLineEdit->setFixedHeight(LABEL_HEIGHT);
m_binaryLineEdit->setFixedHeight(LABEL_HEIGHT);
const QString lineEditsStyleSheet = "QLineEdit{background: #ffffff; border: 2px solid black; font-size: 18px;\
border-radius: 2px; padding-left: 5px; }";
m_decimalLineEdit->setStyleSheet(lineEditsStyleSheet);
m_hexLineEdit->setStyleSheet(lineEditsStyleSheet);
m_binaryLineEdit->setStyleSheet(lineEditsStyleSheet);
}
void NumberSystem::onDecimialProcessedSlot(const QString &binary, const QString &hex)
{
m_binaryLineEdit->blockSignals(true);
m_hexLineEdit->blockSignals(true);
m_binaryLineEdit->setText(binary);
m_hexLineEdit->setText(hex);
m_binaryLineEdit->blockSignals(false);
m_hexLineEdit->blockSignals(false);
}
void NumberSystem::onHexProcessedSlot(const QString &decimal, const QString &binary)
{
m_decimalLineEdit->blockSignals(true);
m_binaryLineEdit->blockSignals(true);
m_decimalLineEdit->setText(decimal);
m_binaryLineEdit->setText(binary);
m_decimalLineEdit->blockSignals(false);
m_binaryLineEdit->blockSignals(false);
}
void NumberSystem::onBinaryProcessedSlot(const QString &decimal, const QString &hex)
{
m_decimalLineEdit->blockSignals(true);
m_hexLineEdit->blockSignals(true);
m_decimalLineEdit->setText(decimal);
m_hexLineEdit->setText(hex);
m_decimalLineEdit->blockSignals(false);
m_hexLineEdit->blockSignals(false);
}
void NumberSystem::clearData()
{
m_decimalLineEdit->clear();
m_hexLineEdit->clear();
m_binaryLineEdit->clear();
}