-
Notifications
You must be signed in to change notification settings - Fork 5
/
pagetwo.cpp
executable file
·114 lines (69 loc) · 2.38 KB
/
pagetwo.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
#include "pagetwo.h"
#include "wizard.h"
PageTwo::PageTwo(QWidget *parent) : QWidget(parent)
{
//encapuslating layout widget
layout = new QVBoxLayout( this );
//title label
QLabel *label = new QLabel;
label->setText("G-Code Output");
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
}
void PageTwo::updateOutput(const QString output)
{
this->output = output;
//firstOutput check to ensure new output text box is not created every time
if (firstOutput == true)
{
//sets firstOutput to false so onNewOutput is called
firstOutput = false;
//creates text box and sets to read only so it is not editable but selectable
textEdit = new QTextEdit;
textEdit->setReadOnly(true);
//placeholder just in case
textEdit->setPlaceholderText("Output code should go here");
//set text to calculated output
textEdit->setText(output);
layout->addWidget(textEdit);
//creates buttons for file export (only one for now, text export removed)
QWidget *buttonEncapsulator = new QWidget;
QHBoxLayout *hlayout = new QHBoxLayout;
QPushButton *exportGC = new QPushButton(tr("Export as G-Code File"));
exportGC->setMaximumWidth(200);
hlayout->addWidget(exportGC);
buttonEncapsulator->setLayout(hlayout);
layout->addWidget(buttonEncapsulator);
//connect button to appropriate slot for functionality
QObject::connect(exportGC, SIGNAL(clicked(bool)), this, SLOT(onExportGCClicked()));
} else
onNewOutput(output);
}
void PageTwo::onExportGCClicked()
{
//obtains directory and passes it to GCOutput()
QString saveDirectory;
saveDirectory = QFileDialog::getSaveFileName(this, tr("Export G-Code File"), title);
GCOutput(saveDirectory);
}
void PageTwo::GCOutput(QString directory)
{
//creates file, writes data, and outputs to appropriate directory
directory += ".gcode";
QFile file(directory);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out << this->output;
file.close();
}
void PageTwo::onNewOutput(QString output)
{
//sets the new output
textEdit->setText(output);
//refreshes the text box to show new output
textEdit->update();
}
void PageTwo::updateTitle(QString title)
{
this->title = title;
}