-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpageone.cpp
executable file
·398 lines (265 loc) · 9.88 KB
/
pageone.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#include "pageone.h"
#include "wizard.h"
#include "templateitem.h"
#include "customtemplate.h"
#include "constants.h"
PageOne::PageOne(QWidget *parent) : QWidget(parent)
{
//create widget to hold tabs
tabWidget = new QTabWidget(this);
//build each tab
customTab(tabWidget);
templateTab(tabWidget);
//set opening screen to templates
tabWidget->setCurrentIndex(1);
//adjust default tab styling
tabWidget->setStyleSheet("QTabWidget::pane {border: 0;}");
tabWidget->tabBar()->setStyleSheet("QTabBar::tab:selected{ color:#ffffff}");
tabWidget->setMinimumSize(400, 350);
}
void PageOne::customTab(QTabWidget *tabWidget)
{
nameEdit = new QLineEdit;
dateEdit = new QDateEdit;
heightEdit = new QSpinBox;
widthEdit = new QSpinBox;
positionEdit = new PositionEdit;
materialEdit = new QComboBox;
amountEdit = new QSpinBox;
//standard two digit width for uniformity
heightEdit->setMinimumWidth(INT_FORM_WIDTH);
heightEdit->setMaximumWidth(INT_FORM_WIDTH);
widthEdit->setMinimumWidth(INT_FORM_WIDTH);
widthEdit->setMaximumWidth(INT_FORM_WIDTH);
positionEdit->setMinimumWidth(INT_FORM_WIDTH);
//set properties for each form
heightEdit->setRange(PETRI_MIN, PETRI_MAX);
widthEdit->setRange(PETRI_MIN, PETRI_MAX);
positionEdit->setRange(POSITION_MIN, POSITION_MAX);
amountEdit->setRange(EXTRUSION_MIN, EXTRUSION_MAX);
materialEdit->addItem("Calcium Chloride");
materialEdit->addItem("Biomolecule in 1% Alginate");
materialEdit->addItem("Substrate Solution");
dateEdit->setDate(QDate::currentDate());
amountEdit->setValue(25);
amountEdit->setDisabled(true);
//to enable mouse tracking and pop up for bed pos
positionEdit->setAttribute(Qt::WA_Hover);
positionEdit->setMouseTracking(true);
//builds the print selection row (petri vs well plate)
buildPrintSelection();
//add each row of the form
QFormLayout *formLayout = new QFormLayout;
formLayout->addRow("&Name:", nameEdit);
formLayout->addRow("&Date:", dateEdit);
formLayout->addRow("&Print:", groupBox);
formLayout->addRow("&Material:", materialEdit);
formLayout->addRow("&Rows:", heightEdit);
formLayout->addRow("&Columns:", widthEdit);
formLayout->addRow("&Position:", positionEdit);
formLayout->addRow("&Extrusion Amount (μl):", amountEdit);
//build reference graphic for positions, set hidden by default
positionGraphic = new QLabel;
positionGraphic->hide();
//set frameless and non intrusive
positionGraphic->setWindowFlag(Qt::FramelessWindowHint);
positionGraphic->setAttribute(Qt::WA_ShowWithoutActivating);
//connect appropriate show/hide slots for position reference graphic
connect(positionEdit, SIGNAL(positionHoverSignal()), this, SLOT(positionHoverSlot()));
connect(positionEdit, SIGNAL(leftPositionSignal()), this, SLOT(leftPositionSlot()));
//add custom tab to the main tab widget
QWidget *customWindow = new QWidget;
customWindow->setLayout(formLayout);
tabWidget->addTab(customWindow, "Custom");
}
void PageOne::buildPrintSelection()
{
//build and group component selections
groupBox = new QGroupBox;
petriRadio = new QRadioButton(tr("Petri Dish"));
wellPlateRadio = new QRadioButton(tr("Well Plate"));
//set so that only one button may be selected
petriRadio->setAutoExclusive(true);
wellPlateRadio->setAutoExclusive(true);
//default selection
petriRadio->setChecked(true);
//add buttons to layout
QHBoxLayout *groupBoxLayout = new QHBoxLayout;
groupBoxLayout->addWidget(petriRadio);
groupBoxLayout->addWidget(wellPlateRadio);
groupBox->setLayout(groupBoxLayout);
groupBox->setStyleSheet("border: 0");
groupBoxLayout->setContentsMargins(0, 0, 0, 0);
//connect buttons to appropriate slots
connect(wellPlateRadio, SIGNAL(clicked(bool)), this, SLOT(onWellPlateRadioClicked()));
connect(petriRadio, SIGNAL(clicked(bool)), this, SLOT(onPetriRadioClicked()));
}
void PageOne::templateTab(QTabWidget *tabWidget)
{
//encapsulating widget to house the layouts
QFrame *templateWindow = new QFrame;
//encapsulating horizontal widget to house each level of templates
QHBoxLayout *firstRowLayout = new QHBoxLayout;
QHBoxLayout *secondRowLayout = new QHBoxLayout;
//paths to be changed once icons are finalized
buildCustomTemplate(firstRowLayout, "Custom" ,
"://resources/custom-template.png");
buildTemplateItem(firstRowLayout, "Row Print" ,
"://resources/template-1.png", SLOT(onRowTemplateClicked()));
buildTemplateItem(firstRowLayout, "3x3 Petri Dish" ,
"://resources/template-2.png", SLOT(gridPetriClicked()));
buildTemplateItem(secondRowLayout, "3x3 Well Plate" ,
"://resources/template-3.png", SLOT(gridPlateClicked()));
buildTemplateItem(secondRowLayout, "Well Plate Column" ,
"://resources/template-4.png", SLOT(wellPlateColumnClicked()));
buildTemplateItem(secondRowLayout, "Fill Well Plate" ,
"://resources/template5.png", SLOT(fillWellClicked()));
//put together each row
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addLayout(firstRowLayout);
vlayout->addLayout(secondRowLayout);
//ensure consistent spacing
firstRowLayout->setContentsMargins(0, 0, 0, 0);
secondRowLayout->setContentsMargins(0, 0, 0, 0);
//set layout and add template tab to main tab widget
templateWindow->setLayout(vlayout);
tabWidget->addTab(templateWindow, "Templates");
}
void PageOne::buildCustomTemplate(QHBoxLayout *hlayout, QString title, QString iconPath)
{
//builds the custom template
CustomTemplate *item = new CustomTemplate;
QVBoxLayout *vlayout = new QVBoxLayout;
//create template icon
QLabel *iconLabel = new QLabel;
QPixmap icon(iconPath);
icon.setDevicePixelRatio(devicePixelRatio());
iconLabel->setPixmap(icon);
//set title of label
QLabel *label = new QLabel(title);
label->setAlignment(Qt::AlignCenter);
//put components together
vlayout->addWidget(iconLabel);
vlayout->addWidget(label);
item->setLayout(vlayout);
//add functionality
QObject::connect(item, SIGNAL(switchTabs(int)), tabWidget, SLOT(setCurrentIndex(int)));
hlayout->addWidget(item);
}
void PageOne::buildTemplateItem(QHBoxLayout *hlayout, QString title, QString iconPath, const char *slot)
{
//builds a template item
TemplateItem *item = new TemplateItem;
QVBoxLayout *vlayout = new QVBoxLayout;
//create template icon
QLabel *iconLabel = new QLabel;
QPixmap icon(iconPath);
icon.setDevicePixelRatio(devicePixelRatio());
iconLabel->setPixmap(icon.scaled(200, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation));
//set label title
QLabel *label = new QLabel(title);
label->setAlignment(Qt::AlignCenter);
//puts components together
vlayout->addWidget(iconLabel);
vlayout->addWidget(label);
item->setLayout(vlayout);
//adds functionality, switching the tab and changing appropriate settings
QObject::connect(item, SIGNAL(activateTemplate()), this, slot);
hlayout->addWidget(item);
}
void PageOne::onWellPlateRadioClicked()
{
//shows warning message only once
if (firstMessage == true)
{
QMessageBox warningMessage;
warningMessage.setText("Note: Well plate prints currently only print "
"accurately to the Greiner 650161 well plate.");
warningMessage.exec();
firstMessage = false;
}
//new max width for well plate
widthEdit->setRange(1, 12);
widthEdit->update();
//disabling position since not needed for well plate prints
positionEdit->setDisabled(true);
positionEdit->update();
//enabling variable extrusion amount
amountEdit->setEnabled(true);
amountEdit->update();
}
void PageOne::onPetriRadioClicked()
{
//new max value for petri dish
widthEdit->setRange(1, 8);
widthEdit->update();
//enabling position for petri dish prints
positionEdit->setEnabled(true);
positionEdit->update();
//disabling extrusion variability
amountEdit->setDisabled(true);
amountEdit->update();
}
//when positionEdit widget is hovered, show the graphic
void PageOne::positionHoverSlot()
{
QPoint globalPos = positionEdit->mapToGlobal(QPoint(0,0));
int x = globalPos.x();
int y = globalPos.y();
x += OFFSET;
positionGraphic->move(x, y);
if(petriRadio->isChecked())
{
QPixmap icon("://resources/petri-template.png");
icon.setDevicePixelRatio(devicePixelRatio());
positionGraphic->setPixmap(icon.scaled(HOVER_GRAPHIC_DIMS, HOVER_GRAPHIC_DIMS,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
if(wellPlateRadio->isChecked())
{
QPixmap icon("://resources/well-plate-template.png");
icon.setDevicePixelRatio(devicePixelRatio());
positionGraphic->setPixmap(icon.scaled(HOVER_GRAPHIC_DIMS, HOVER_GRAPHIC_DIMS,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
positionGraphic->show();
positionGraphic->update();
}
//when positionEdit is no longer in focus, remove graphic
void PageOne::leftPositionSlot()
{
positionGraphic->hide();
positionGraphic->update();
}
/*
*
*
* template signals/slots
*
*
*/
void PageOne::onRowTemplateClicked()
{
emit rowTemplateSignal();
emit nextPage();
}
void PageOne::gridPetriClicked()
{
emit gridPetriSignal();
emit nextPage();
}
void PageOne::fillWellClicked()
{
emit fillWellSignal();
emit nextPage();
}
void PageOne::gridPlateClicked()
{
emit gridPlateSignal();
emit nextPage();
}
void PageOne::wellPlateColumnClicked()
{
emit wellPlateColumnSignal();
emit nextPage();
}