-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewdesigndialog.cpp
151 lines (133 loc) · 5.17 KB
/
newdesigndialog.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
/**
* newdesigndialog.cpp
* Copyright (c) 2018 Linus Boyle <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "newdesigndialog.h"
#include "configurationentity.h"
#include <QGroupBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QIntValidator>
NewDesignDialog::NewDesignDialog(QWidget *parent):
QDialog(parent),entity(nullptr)
{
initUI();
setWindowTitle(tr("New Design Setting"));
}
NewDesignDialog::~NewDesignDialog() {
if(entity){
delete entity;
}
}
void NewDesignDialog::initUI()
{
//all the input lineedit widget
sizeEdit = new QLineEdit(this);
input1Edit = new QLineEdit(this);
input2Edit = new QLineEdit(this);
output1Edit = new QLineEdit(this);
output2Edit = new QLineEdit(this);
output3Edit = new QLineEdit(this);
//set placeholder text
sizeEdit->setPlaceholderText(tr("Equals number of rows and columns"));
input1Edit->setPlaceholderText(tr("The index starts from 0"));
input2Edit->setPlaceholderText(tr("The index starts from 0"));
output1Edit->setPlaceholderText(tr("The index starts from 0"));
output2Edit->setPlaceholderText(tr("The index starts from 0"));
output3Edit->setPlaceholderText(tr("The index starts from 0"));
//validator
QIntValidator* validator = new QIntValidator(0,PIPE_SIZE_MAX,this);
sizeEdit->setValidator(validator);
input1Edit->setValidator(validator);
input2Edit->setValidator(validator);
output1Edit->setValidator(validator);
output2Edit->setValidator(validator);
output3Edit->setValidator(validator);
//labels on side of lineedit
QLabel* sizeHint = new QLabel(tr("Size:"),this);
QLabel* input1Hint = new QLabel(tr("Input1 Pipe:"),this);
QLabel* input2Hint = new QLabel(tr("Input2 Pipe:"),this);
QLabel* output1Hint = new QLabel(tr("Output1 Pipe:"),this);
QLabel* output2Hint = new QLabel(tr("Output2 Pipe:"),this);
QLabel* output3Hint = new QLabel(tr("Output3 Pipe:"),this);
//layouts to align lineedit and label
QHBoxLayout* sizeLayout = new QHBoxLayout();
QHBoxLayout* input1Layout = new QHBoxLayout();
QHBoxLayout* input2Layout = new QHBoxLayout();
QHBoxLayout* output1Layout = new QHBoxLayout();
QHBoxLayout* output2Layout = new QHBoxLayout();
QHBoxLayout* output3Layout = new QHBoxLayout();
sizeLayout->addWidget(sizeHint);
sizeLayout->addWidget(sizeEdit);
input1Layout->addWidget(input1Hint);
input1Layout->addWidget(input1Edit);
input2Layout->addWidget(input2Hint);
input2Layout->addWidget(input2Edit);
output1Layout->addWidget(output1Hint);
output1Layout->addWidget(output1Edit);
output2Layout->addWidget(output2Hint);
output2Layout->addWidget(output2Edit);
output3Layout->addWidget(output3Hint);
output3Layout->addWidget(output3Edit);
//confirm and cancel button
QPushButton* confirm = new QPushButton(tr("OK"),this);
QPushButton* cancel = new QPushButton(tr("Cancel"),this);
connect(confirm,&QPushButton::clicked,this,&NewDesignDialog::onConfirmed);
connect(cancel,&QPushButton::clicked,this,&NewDesignDialog::reject);
QHBoxLayout* buttonLayout = new QHBoxLayout();
buttonLayout->setSpacing(10);
buttonLayout->addSpacing(100);
buttonLayout->addWidget(confirm);
buttonLayout->addWidget(cancel);
//put all into groupbox
QGroupBox* groupbox = new QGroupBox(tr("Configure New Design"),this);
QVBoxLayout* groupLayout = new QVBoxLayout();
groupLayout->addLayout(sizeLayout);
groupLayout->addLayout(input1Layout);
groupLayout->addLayout(input2Layout);
groupLayout->addLayout(output1Layout);
groupLayout->addLayout(output2Layout);
groupLayout->addLayout(output3Layout);
groupLayout->addLayout(buttonLayout);
groupbox->setLayout(groupLayout);
//set the dialog layout
QVBoxLayout* mainLayout = new QVBoxLayout();
mainLayout->addWidget(groupbox);
setLayout(mainLayout);
setFixedSize(300,400);
}
void NewDesignDialog::clearAll(){
sizeEdit->clear();
input1Edit->clear();
input2Edit->clear();
output1Edit->clear();
output2Edit->clear();
output3Edit->clear();
}
void NewDesignDialog::onConfirmed(){
if(entity){
delete entity;
}
entity = new ConfigurationEntity(sizeEdit->text().toInt(),input1Edit->text().toInt(),input2Edit->text().toInt(),
output1Edit->text().toInt(),output2Edit->text().toInt(),output3Edit->text().toInt());
this->accept();
}
ConfigurationEntity* NewDesignDialog::getEntity() const {
return entity;
}