-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
emaildialog.cpp
186 lines (156 loc) · 4.85 KB
/
emaildialog.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <vector>
#include <string>
#include <QLabel>
#include <QSignalMapper>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QToolButton>
#include <QPushButton>
#include "emaildialog.h"
using std::vector;
using std::string;
EmailDialog :: EmailDialog(QDialog* parent) : QDialog(parent)
{
setModal(true);
setupLayout();
setWindowTitle("Email your design");
lineEdit->setText("");
}
void EmailDialog :: setupLayout()
{
layout = new QVBoxLayout(this);
this->setLayout(layout);
addressLayout = new QHBoxLayout(this);
addressLayout->addStretch(1);
addressLayout->addWidget(new QLabel("Email address:", this));
lineEdit = new QLineEdit(this);
lineEdit->setFixedWidth(200);
addressLayout->addWidget(lineEdit);
QPushButton* sendButton = new QPushButton("Send", this);
addressLayout->addWidget(sendButton);
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendClicked()));
addressLayout->addStretch(1);
layout->addLayout(addressLayout);
const QString kRow0Keys[] = {"!", "@", "#", "$", "%", "^", QString("&&"), "*", "_", "-", "."};
const QString kRow1Keys[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
const QString kRow2Keys[] = {"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"};
const QString kRow3Keys[] = {"A", "S", "D", "F", "G", "H", "J", "K", "L"};
const QString kRow4Keys[] = {"Z", "X", "C", "V", "B", "N", "M"};
int keySize = 50;
QToolButton* keyButton;
mapper = new QSignalMapper(this);
connect(mapper, SIGNAL(mapped(QString)), this, SLOT(keyClicked(QString)));
kRow0Layout = new QHBoxLayout(this);
layout->addLayout(kRow0Layout);
kRow0Layout->addStretch(1);
for (int i = 0; i < 11; ++i)
{
keyButton = new QToolButton(this);
keyButton->setText(kRow0Keys[i]);
keyButton->setFixedSize(keySize, keySize);
kRow0Layout->addWidget(keyButton);
mapper->setMapping(keyButton, kRow0Keys[i]);
connect(keyButton, SIGNAL(clicked()), mapper, SLOT(map()));
}
kRow0Layout->addStretch(1);
kRow1Layout = new QHBoxLayout(this);
layout->addLayout(kRow1Layout);
kRow1Layout->addStretch(1);
for (int i = 0; i < 10; ++i)
{
keyButton = new QToolButton(this);
keyButton->setText(kRow1Keys[i]);
keyButton->setFixedSize(keySize, keySize);
kRow1Layout->addWidget(keyButton);
mapper->setMapping(keyButton, kRow1Keys[i]);
connect(keyButton, SIGNAL(clicked()), mapper, SLOT(map()));
}
kRow1Layout->addStretch(1);
kRow2Layout = new QHBoxLayout(this);
layout->addLayout(kRow2Layout);
kRow2Layout->addStretch(1);
for (int i = 0; i < 10; ++i)
{
keyButton = new QToolButton(this);
keyButton->setText(kRow2Keys[i]);
keyButton->setFixedSize(keySize, keySize);
kRow2Layout->addWidget(keyButton);
mapper->setMapping(keyButton, kRow2Keys[i]);
connect(keyButton, SIGNAL(clicked()), mapper, SLOT(map()));
}
kRow2Layout->addStretch(1);
kRow3Layout = new QHBoxLayout(this);
layout->addLayout(kRow3Layout);
kRow3Layout->addStretch(1);
for (int i = 0; i < 9; ++i)
{
keyButton = new QToolButton(this);
keyButton->setText(kRow3Keys[i]);
keyButton->setFixedSize(keySize, keySize);
kRow3Layout->addWidget(keyButton);
mapper->setMapping(keyButton, kRow3Keys[i]);
connect(keyButton, SIGNAL(clicked()), mapper, SLOT(map()));
}
kRow3Layout->addStretch(1);
kRow4Layout = new QHBoxLayout(this);
layout->addLayout(kRow4Layout);
kRow4Layout->addStretch(1);
for (int i = 0; i < 7; ++i)
{
keyButton = new QToolButton(this);
keyButton->setText(kRow4Keys[i]);
keyButton->setFixedSize(keySize, keySize);
kRow4Layout->addWidget(keyButton);
mapper->setMapping(keyButton, kRow4Keys[i]);
connect(keyButton, SIGNAL(clicked()), mapper, SLOT(map()));
}
QToolButton* backspaceButton = new QToolButton(this);
backspaceButton->setFixedSize(2 * keySize, keySize);
backspaceButton->setText("Backspace");
kRow4Layout->addWidget(backspaceButton);
connect(backspaceButton, SIGNAL(clicked()), this, SLOT(backspaceClicked()));
kRow4Layout->addStretch(1);
}
EmailDialog :: ~EmailDialog()
{
delete addressLayout->itemAt(0)->widget(); // label
delete lineEdit;
delete addressLayout;
while (kRow0Layout->count())
delete kRow0Layout->takeAt(0)->widget();
delete kRow0Layout;
while (kRow1Layout->count())
delete kRow1Layout->takeAt(0)->widget();
delete kRow1Layout;
while (kRow2Layout->count())
delete kRow2Layout->takeAt(0)->widget();
delete kRow2Layout;
while (kRow3Layout->count())
delete kRow3Layout->takeAt(0)->widget();
delete kRow3Layout;
while (kRow4Layout->count())
delete kRow4Layout->takeAt(0)->widget();
delete kRow4Layout;
delete mapper;
delete layout;
}
void EmailDialog :: sendClicked()
{
accept();
}
void EmailDialog :: keyClicked(QString s)
{
lineEdit->setText(lineEdit->text() + s);
}
void EmailDialog :: backspaceClicked()
{
QString text = lineEdit->text();
if (text.size() == 0)
return;
text = text.remove(text.size()-1, 1);
lineEdit->setText(text);
}
QString EmailDialog :: address()
{
return lineEdit->text();
}