Changeset View
Changeset View
Standalone View
Standalone View
testclient/mainwindow.cpp
Show All 33 Lines | |||||
34 | #include "widgets/about.h" | 34 | #include "widgets/about.h" | ||
35 | 35 | | |||
36 | Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core") | 36 | Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core") | ||
37 | 37 | | |||
38 | int MainWindow::fanCount = 4; | 38 | int MainWindow::fanCount = 4; | ||
39 | 39 | | |||
40 | MainWindow::MainWindow(QWidget *parent) : | 40 | MainWindow::MainWindow(QWidget *parent) : | ||
41 | QMainWindow(parent), | 41 | QMainWindow(parent), | ||
42 | ui(new Ui::MainWindow), | | |||
43 | core(new AtCore(this)), | 42 | core(new AtCore(this)), | ||
44 | logFile(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))) | 43 | logFile(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))) | ||
45 | { | 44 | { | ||
46 | ui->setupUi(this); | 45 | setWindowTitle(QStringLiteral("AtCore - Test Client")); | ||
laysrodrigues: use tr so we can have translation. | |||||
We currenly do not translate the test gui at all rizzitello: We currenly do not translate the test gui at all
These can be added in another path, this patch… | |||||
rizzitello: Adding tr calls to this patch | |||||
47 | setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); | 46 | setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); | ||
48 | QCoreApplication::setApplicationVersion(core->version()); | 47 | QCoreApplication::setApplicationVersion(core->version()); | ||
49 | ui->serialPortCB->setEditable(true); | 48 | initMenu(); | ||
50 | QValidator *validator = new QIntValidator(); | 49 | initStatusBar(); | ||
51 | ui->baudRateLE->setValidator(validator); | 50 | initWidgets(); | ||
52 | ui->baudRateLE->addItems(core->portSpeeds()); | | |||
53 | ui->baudRateLE->setCurrentIndex(9); | | |||
54 | | ||||
55 | ui->pluginCB->addItem(tr("Autodetect")); | | |||
56 | ui->pluginCB->addItems(core->availableFirmwarePlugins()); | | |||
57 | | ||||
58 | AxisControl *axisControl = new AxisControl; | | |||
59 | ui->moveDockContents->layout()->addWidget(axisControl); | | |||
60 | 51 | | |||
61 | addLog(tr("Attempting to locate Serial Ports")); | 52 | addLog(tr("Attempting to locate Serial Ports")); | ||
62 | core->setSerialTimerInterval(1000); | 53 | core->setSerialTimerInterval(1000); | ||
63 | populateCBs(); | 54 | populateCBs(); | ||
64 | 55 | | |||
65 | //Icon for actionQuit | | |||
66 | #ifndef Q_OS_MAC | | |||
67 | ui->actionQuit->setIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); | | |||
68 | #endif | | |||
69 | | ||||
70 | //hide the printing progress bar. | 56 | //hide the printing progress bar. | ||
71 | ui->printLayout->setVisible(false); | 57 | printProgressWidget->setVisible(false); | ||
72 | 58 | | |||
73 | ui->statusBar->addWidget(ui->statusBarWidget); | | |||
74 | printTime = new QTime(); | 59 | printTime = new QTime(); | ||
75 | printTimer = new QTimer(); | 60 | printTimer = new QTimer(); | ||
76 | printTimer->setInterval(1000); | 61 | printTimer->setInterval(1000); | ||
77 | printTimer->setSingleShot(false); | 62 | printTimer->setSingleShot(false); | ||
78 | connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); | 63 | connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); | ||
79 | 64 | | |||
80 | connect(ui->connectPB, &QPushButton::clicked, this, &MainWindow::connectPBClicked); | | |||
81 | connect(ui->saveLogPB, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); | | |||
82 | connect(ui->sendPB, &QPushButton::clicked, this, &MainWindow::sendPBClicked); | | |||
83 | connect(ui->commandLE, &QLineEdit::returnPressed, this, &MainWindow::sendPBClicked); | | |||
84 | connect(ui->homeAllPB, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); | | |||
85 | connect(ui->homeXPB, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); | | |||
86 | connect(ui->homeYPB, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); | | |||
87 | connect(ui->homeZPB, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); | | |||
88 | connect(ui->bedTempPB, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); | | |||
89 | connect(ui->extTempPB, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); | | |||
90 | connect(ui->mvAxisPB, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); | | |||
91 | connect(ui->fanSpeedPB, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); | | |||
92 | connect(ui->printPB, &QPushButton::clicked, this, &MainWindow::printPBClicked); | | |||
93 | connect(ui->sdPrintPB, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); | | |||
94 | connect(ui->sdDelPB, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); | | |||
95 | connect(ui->printerSpeedPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); | | |||
96 | connect(ui->flowRatePB, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked); | | |||
97 | connect(ui->showMessagePB, &QPushButton::clicked, this, &MainWindow::showMessage); | | |||
98 | connect(ui->pluginCB, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); | | |||
99 | connect(ui->disableMotorsPB, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); | | |||
100 | connect(ui->sdListPB, &QPushButton::clicked, this, &MainWindow::getSdList); | | |||
101 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | 65 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | ||
102 | connect(ui->stopPB, &QPushButton::clicked, core, &AtCore::stop); | | |||
103 | connect(ui->emergencyStopPB, &QPushButton::clicked, core, &AtCore::emergencyStop); | | |||
104 | connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); | | |||
105 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | 66 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | ||
106 | connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); | 67 | connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); | ||
107 | connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); | 68 | connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); | ||
108 | 69 | | |||
109 | connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { | 70 | connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { | ||
110 | ui->sdFileListView->clear(); | 71 | listSdFiles->clear(); | ||
111 | ui->sdFileListView->addItems(fileList); | 72 | listSdFiles->addItems(fileList); | ||
112 | }); | 73 | }); | ||
113 | 74 | | |||
114 | connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { | 75 | connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { | ||
115 | checkTemperature(0x00, 0, temp); | 76 | checkTemperature(0x00, 0, temp); | ||
116 | ui->plotWidget->appendPoint(tr("Actual Bed"), temp); | 77 | plotWidget->appendPoint(tr("Actual Bed"), temp); | ||
117 | ui->plotWidget->update(); | 78 | plotWidget->update(); | ||
118 | }); | 79 | }); | ||
119 | connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { | 80 | connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { | ||
120 | checkTemperature(0x01, 0, temp); | 81 | checkTemperature(0x01, 0, temp); | ||
121 | ui->plotWidget->appendPoint(tr("Target Bed"), temp); | 82 | plotWidget->appendPoint(tr("Target Bed"), temp); | ||
122 | ui->plotWidget->update(); | 83 | plotWidget->update(); | ||
123 | }); | 84 | }); | ||
124 | connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { | 85 | connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { | ||
125 | checkTemperature(0x02, 0, temp); | 86 | checkTemperature(0x02, 0, temp); | ||
126 | ui->plotWidget->appendPoint(tr("Actual Ext.1"), temp); | 87 | plotWidget->appendPoint(tr("Actual Ext.1"), temp); | ||
127 | ui->plotWidget->update(); | 88 | plotWidget->update(); | ||
128 | }); | 89 | }); | ||
129 | connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { | 90 | connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { | ||
130 | checkTemperature(0x03, 0, temp); | 91 | checkTemperature(0x03, 0, temp); | ||
131 | ui->plotWidget->appendPoint(tr("Target Ext.1"), temp); | 92 | plotWidget->appendPoint(tr("Target Ext.1"), temp); | ||
132 | ui->plotWidget->update(); | 93 | plotWidget->update(); | ||
133 | }); | 94 | }); | ||
134 | 95 | | |||
135 | connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::close); | | |||
136 | connect(ui->actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); | | |||
137 | connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::about); | | |||
138 | | ||||
139 | ui->menuView->insertAction(nullptr, ui->connectDock->toggleViewAction()); | | |||
140 | ui->menuView->insertAction(nullptr, ui->tempControlsDock->toggleViewAction()); | | |||
141 | ui->menuView->insertAction(nullptr, ui->commandDock->toggleViewAction()); | | |||
142 | ui->menuView->insertAction(nullptr, ui->printDock->toggleViewAction()); | | |||
143 | ui->menuView->insertAction(nullptr, ui->moveDock->toggleViewAction()); | | |||
144 | ui->menuView->insertAction(nullptr, ui->tempTimelineDock->toggleViewAction()); | | |||
145 | ui->menuView->insertAction(nullptr, ui->logDock->toggleViewAction()); | | |||
146 | ui->menuView->insertAction(nullptr, ui->sdDock->toggleViewAction()); | | |||
147 | | ||||
148 | //more dock stuff. | 96 | //more dock stuff. | ||
149 | setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); | 97 | setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); | ||
150 | setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); | 98 | setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); | ||
151 | tabifyDockWidget(ui->moveDock, ui->tempControlsDock); | 99 | tabifyDockWidget(moveDock, tempControlsDock); | ||
152 | tabifyDockWidget(ui->moveDock, ui->sdDock); | 100 | tabifyDockWidget(moveDock, sdDock); | ||
153 | ui->moveDock->raise(); | 101 | moveDock->raise(); | ||
154 | 102 | | |||
155 | tabifyDockWidget(ui->connectDock, ui->printDock); | 103 | tabifyDockWidget(connectDock, printDock); | ||
156 | tabifyDockWidget(ui->connectDock, ui->commandDock); | 104 | tabifyDockWidget(connectDock, commandDock); | ||
157 | ui->connectDock->raise(); | 105 | connectDock->raise(); | ||
158 | setCentralWidget(nullptr); | 106 | setCentralWidget(nullptr); | ||
159 | } | 107 | } | ||
160 | 108 | | |||
109 | void MainWindow::initMenu() | ||||
110 | { | ||||
111 | QMenu *menuFile = new QMenu(QStringLiteral("&File")); | ||||
112 | QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), QStringLiteral("Quit")); | ||||
113 | connect(actionQuit, &QAction::triggered, this, &MainWindow::close); | ||||
114 | menuFile->addAction(actionQuit); | ||||
115 | | ||||
116 | menuView = new QMenu(QStringLiteral("&View")); | ||||
117 | QAction *actionShowDockTitles = new QAction(QStringLiteral("Show Dock Titles")); | ||||
118 | actionShowDockTitles->setCheckable(true); | ||||
119 | actionShowDockTitles->setChecked(true); | ||||
120 | connect(actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); | ||||
121 | menuView->addAction(actionShowDockTitles); | ||||
122 | | ||||
123 | QMenu *menuHelp = new QMenu(QStringLiteral("&Help")); | ||||
124 | QAction *actionAbout = new QAction(QStringLiteral("About")); | ||||
125 | actionAbout->setShortcut(QKeySequence(Qt::Key_F1)); | ||||
126 | connect(actionAbout, &QAction::triggered, [] { | ||||
127 | auto *dialog = new About; | ||||
128 | dialog->exec(); | ||||
129 | }); | ||||
130 | menuHelp->addAction(actionAbout); | ||||
131 | | ||||
132 | menuBar()->addMenu(menuFile); | ||||
133 | menuBar()->addMenu(menuView); | ||||
134 | menuBar()->addMenu(menuHelp); | ||||
135 | } | ||||
136 | | ||||
137 | void MainWindow::initStatusBar() | ||||
138 | { | ||||
139 | auto *labelStatus = new QLabel(QStringLiteral("AtCore State:")); | ||||
140 | lblState = new QLabel(QStringLiteral("Not Connected")); | ||||
141 | lblSd = new QLabel(); | ||||
142 | printingProgress = new QProgressBar; | ||||
143 | auto *stopPB = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); | ||||
144 | connect(stopPB, &QPushButton::clicked, core, &AtCore::stop); | ||||
145 | lblTime = new QLabel(QStringLiteral("00:00:00")); | ||||
146 | lblTime->setAlignment(Qt::AlignHCenter); | ||||
147 | auto *labelSlash = new QLabel(QStringLiteral(" / ")); | ||||
148 | lblTimeLeft = new QLabel(QStringLiteral("00:00:00")); | ||||
149 | lblTimeLeft->setAlignment(Qt::AlignHCenter); | ||||
150 | | ||||
151 | auto *printLayout = new QHBoxLayout; | ||||
152 | printLayout->addWidget(printingProgress); | ||||
153 | printLayout->addWidget(stopPB); | ||||
154 | printLayout->addWidget(lblTime); | ||||
155 | printLayout->addWidget(labelSlash); | ||||
156 | printLayout->addWidget(lblTimeLeft); | ||||
157 | printProgressWidget = new QWidget(); | ||||
158 | printProgressWidget->setLayout(printLayout); | ||||
159 | | ||||
160 | auto *statusLayout = new QHBoxLayout; | ||||
161 | statusLayout->addWidget(labelStatus); | ||||
162 | statusLayout->addWidget(lblState); | ||||
163 | statusLayout->addSpacerItem(new QSpacerItem(10, 20, QSizePolicy::Fixed)); | ||||
164 | statusLayout->addWidget(lblSd); | ||||
165 | statusLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); | ||||
166 | statusLayout->addWidget(printProgressWidget); | ||||
167 | QWidget *sBar = new QWidget(); | ||||
168 | sBar->setLayout(statusLayout); | ||||
169 | statusBar()->addPermanentWidget(sBar, width()); | ||||
170 | } | ||||
171 | | ||||
172 | void MainWindow::initWidgets() | ||||
173 | { | ||||
174 | makeCommandDock(); | ||||
175 | commandDock->setEnabled(false); | ||||
176 | makePrintDock(); | ||||
177 | printDock->setEnabled(false); | ||||
178 | makeTempTimelineDock(); | ||||
179 | tempTimelineDock->setEnabled(false); | ||||
180 | makeLogDock(); | ||||
181 | makeConnectDock(); | ||||
182 | makeMoveDock(); | ||||
183 | moveDock->setEnabled(false); | ||||
184 | makeTempControlsDock(); | ||||
185 | tempControlsDock->setEnabled(false); | ||||
186 | makeSdDock(); | ||||
187 | sdDock->setEnabled(false); | ||||
188 | } | ||||
189 | | ||||
190 | void MainWindow::makeCommandDock() | ||||
191 | { | ||||
192 | lineCommand = new QLineEdit; | ||||
193 | lineCommand->setPlaceholderText(QStringLiteral("Send Command")); | ||||
194 | auto *newPB = new QPushButton(QStringLiteral("Send")); | ||||
195 | connect(newPB, &QPushButton::clicked, this, &MainWindow::sendPBClicked); | ||||
196 | | ||||
197 | auto *hBoxLayout1 = new QHBoxLayout; | ||||
198 | hBoxLayout1->addWidget(lineCommand); | ||||
199 | hBoxLayout1->addWidget(newPB); | ||||
200 | | ||||
201 | lineMessage = new QLineEdit; | ||||
202 | lineMessage->setPlaceholderText(QStringLiteral("Show Message")); | ||||
203 | newPB = new QPushButton(QStringLiteral("Send")); | ||||
204 | connect(newPB, &QPushButton::clicked, this, &MainWindow::showMessage); | ||||
205 | auto *hBoxLayout2 = new QHBoxLayout; | ||||
206 | hBoxLayout2->addWidget(lineMessage); | ||||
207 | hBoxLayout2->addWidget(newPB); | ||||
208 | | ||||
209 | auto *vBoxLayout1 = new QVBoxLayout; | ||||
210 | vBoxLayout1->addItem(hBoxLayout1); | ||||
211 | vBoxLayout1->addItem(hBoxLayout2); | ||||
212 | | ||||
213 | auto *dockContents = new QWidget; | ||||
214 | dockContents->setLayout(vBoxLayout1); | ||||
215 | | ||||
216 | commandDock = new QDockWidget(QStringLiteral("Commands"), this); | ||||
217 | menuView->insertAction(nullptr, commandDock->toggleViewAction()); | ||||
218 | commandDock->setWidget(dockContents); | ||||
219 | addDockWidget(Qt::LeftDockWidgetArea, commandDock); | ||||
220 | } | ||||
221 | | ||||
222 | void MainWindow::makePrintDock() | ||||
223 | { | ||||
224 | buttonPrint = new QPushButton(QStringLiteral("Print File")); | ||||
225 | connect(buttonPrint, &QPushButton::clicked, this, &MainWindow::printPBClicked); | ||||
226 | | ||||
227 | auto *newPB = new QPushButton(QStringLiteral("Emergency Stop")); | ||||
228 | connect(newPB, &QPushButton::clicked, core, &AtCore::emergencyStop); | ||||
229 | auto *hBoxLayout1 = new QHBoxLayout; | ||||
230 | hBoxLayout1->addWidget(buttonPrint); | ||||
231 | hBoxLayout1->addWidget(newPB); | ||||
232 | | ||||
233 | auto *newLabel = new QLabel(QStringLiteral("On Pause:")); | ||||
234 | linePostPause = new QLineEdit; | ||||
235 | linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); | ||||
236 | auto *hBoxLayout2 = new QHBoxLayout; | ||||
237 | hBoxLayout2->addWidget(newLabel); | ||||
238 | hBoxLayout2->addWidget(linePostPause); | ||||
239 | | ||||
240 | newLabel = new QLabel(QStringLiteral("Printer Speed")); | ||||
241 | sbPrintSpeed = new QSpinBox; | ||||
242 | sbPrintSpeed->setRange(1, 300); | ||||
243 | sbPrintSpeed->setValue(100); | ||||
244 | sbPrintSpeed->setSuffix(QStringLiteral("%")); | ||||
245 | | ||||
246 | newPB = new QPushButton(QStringLiteral("Set")); | ||||
247 | connect(newPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); | ||||
248 | | ||||
249 | auto *hBoxLayout3 = new QHBoxLayout; | ||||
250 | hBoxLayout3->addWidget(newLabel, 35); | ||||
251 | hBoxLayout3->addWidget(sbPrintSpeed, 10); | ||||
252 | hBoxLayout3->addWidget(newPB, 20); | ||||
253 | | ||||
254 | newLabel = new QLabel(QStringLiteral("Flow Rate")); | ||||
255 | sbFlowRate = new QSpinBox; | ||||
256 | sbFlowRate->setRange(1, 300); | ||||
257 | sbFlowRate->setValue(100); | ||||
258 | sbFlowRate->setSuffix(QStringLiteral("%")); | ||||
259 | | ||||
260 | newPB = new QPushButton(QStringLiteral("Set")); | ||||
261 | connect(newPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); | ||||
262 | | ||||
263 | auto *hBoxLayout4 = new QHBoxLayout; | ||||
264 | hBoxLayout4->addWidget(newLabel, 35); | ||||
265 | hBoxLayout4->addWidget(sbFlowRate, 10); | ||||
266 | hBoxLayout4->addWidget(newPB, 20); | ||||
267 | | ||||
268 | auto *vBoxLayout1 = new QVBoxLayout; | ||||
269 | vBoxLayout1->addItem(hBoxLayout1); | ||||
270 | vBoxLayout1->addItem(hBoxLayout2); | ||||
271 | vBoxLayout1->addItem(hBoxLayout3); | ||||
272 | vBoxLayout1->addItem(hBoxLayout4); | ||||
273 | | ||||
274 | auto *dockContents = new QWidget; | ||||
275 | dockContents->setLayout(vBoxLayout1); | ||||
276 | | ||||
277 | printDock = new QDockWidget(QStringLiteral("Print"), this); | ||||
278 | menuView->insertAction(nullptr, printDock->toggleViewAction()); | ||||
279 | printDock->setWidget(dockContents); | ||||
280 | addDockWidget(Qt::LeftDockWidgetArea, printDock); | ||||
281 | } | ||||
282 | | ||||
283 | void MainWindow::makeTempTimelineDock() | ||||
284 | { | ||||
285 | plotWidget = new PlotWidget; | ||||
286 | tempTimelineDock = new QDockWidget(QStringLiteral("Temperature Timeline"), this); | ||||
287 | menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); | ||||
288 | tempTimelineDock->setWidget(plotWidget); | ||||
289 | addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); | ||||
290 | } | ||||
291 | | ||||
292 | void MainWindow::makeLogDock() | ||||
293 | { | ||||
294 | textLog = new QPlainTextEdit; | ||||
295 | textLog->setReadOnly(true); | ||||
296 | textLog->setMaximumBlockCount(1000); | ||||
297 | | ||||
298 | auto *buttonSave = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton), QStringLiteral("Save Session Log")); | ||||
299 | connect(buttonSave, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); | ||||
300 | | ||||
301 | auto *vBoxLayout1 = new QVBoxLayout; | ||||
302 | vBoxLayout1->addWidget(textLog); | ||||
303 | vBoxLayout1->addWidget(buttonSave); | ||||
304 | | ||||
305 | auto *dockContents = new QWidget(); | ||||
306 | dockContents->setLayout(vBoxLayout1); | ||||
307 | | ||||
308 | logDock = new QDockWidget(QStringLiteral("Session Log"), this); | ||||
309 | menuView->insertAction(nullptr, logDock->toggleViewAction()); | ||||
310 | logDock->setWidget(dockContents); | ||||
311 | addDockWidget(Qt::RightDockWidgetArea, logDock); | ||||
312 | } | ||||
313 | | ||||
314 | void MainWindow::makeConnectDock() | ||||
315 | { | ||||
316 | auto *newLabel = new QLabel(QStringLiteral("Port:")); | ||||
317 | comboPort = new QComboBox; | ||||
318 | comboPort->setEditable(true); | ||||
319 | auto *hBoxLayout1 = new QHBoxLayout; | ||||
320 | hBoxLayout1->addWidget(newLabel); | ||||
321 | hBoxLayout1->addWidget(comboPort, 75); | ||||
322 | | ||||
323 | newLabel = new QLabel(QStringLiteral("Baud Rate:")); | ||||
324 | comboBAUD = new QComboBox; | ||||
325 | comboBAUD->addItems(core->portSpeeds()); | ||||
326 | comboBAUD->setCurrentIndex(9); | ||||
327 | | ||||
328 | auto *hBoxLayout2 = new QHBoxLayout; | ||||
329 | hBoxLayout2->addWidget(newLabel); | ||||
330 | hBoxLayout2->addWidget(comboBAUD, 75); | ||||
331 | | ||||
332 | newLabel = new QLabel(QStringLiteral("Use Plugin:")); | ||||
333 | comboPlugin = new QComboBox; | ||||
334 | comboPlugin->addItem(tr("Autodetect")); | ||||
335 | comboPlugin->addItems(core->availableFirmwarePlugins()); | ||||
336 | connect(comboPlugin, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); | ||||
337 | | ||||
338 | auto *hBoxLayout3 = new QHBoxLayout; | ||||
339 | hBoxLayout3->addWidget(newLabel); | ||||
340 | hBoxLayout3->addWidget(comboPlugin, 75); | ||||
341 | | ||||
342 | buttonConnect = new QPushButton(QStringLiteral("Connect")); | ||||
343 | auto *vBoxLayout = new QVBoxLayout; | ||||
344 | vBoxLayout->addItem(hBoxLayout1); | ||||
345 | vBoxLayout->addItem(hBoxLayout2); | ||||
346 | vBoxLayout->addItem(hBoxLayout3); | ||||
347 | vBoxLayout->addWidget(buttonConnect); | ||||
348 | | ||||
349 | auto *dockContents = new QWidget; | ||||
350 | dockContents->setLayout(vBoxLayout); | ||||
351 | | ||||
352 | connectDock = new QDockWidget(QStringLiteral("Connect"), this); | ||||
353 | menuView->insertAction(nullptr, connectDock->toggleViewAction()); | ||||
354 | connectDock->setWidget(dockContents); | ||||
355 | addDockWidget(Qt::LeftDockWidgetArea, connectDock); | ||||
356 | } | ||||
357 | | ||||
358 | void MainWindow::makeMoveDock() | ||||
359 | { | ||||
360 | auto *buttonHomeA = new QPushButton(QStringLiteral("Home All")); | ||||
361 | connect(buttonHomeA, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); | ||||
362 | | ||||
363 | auto *buttonHomeX = new QPushButton(QStringLiteral("Home X")); | ||||
364 | connect(buttonHomeX, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); | ||||
365 | | ||||
366 | auto *buttonHomeY = new QPushButton(QStringLiteral("Home Y")); | ||||
367 | connect(buttonHomeY, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); | ||||
368 | | ||||
369 | auto *buttonHomeZ = new QPushButton(QStringLiteral("Home Z")); | ||||
370 | connect(buttonHomeZ, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); | ||||
371 | | ||||
372 | auto *hBoxLayout1 = new QHBoxLayout; | ||||
373 | hBoxLayout1->addWidget(buttonHomeA); | ||||
374 | hBoxLayout1->addWidget(buttonHomeX); | ||||
375 | hBoxLayout1->addWidget(buttonHomeY); | ||||
376 | hBoxLayout1->addWidget(buttonHomeZ); | ||||
377 | | ||||
378 | comboMoveAxis = new QComboBox; | ||||
379 | comboMoveAxis->addItem(QStringLiteral("Move X Axis to")); | ||||
380 | comboMoveAxis->addItem(QStringLiteral("Move Y Axis to")); | ||||
381 | comboMoveAxis->addItem(QStringLiteral("Move Z Axis to")); | ||||
382 | | ||||
383 | sbMoveAxis = new QDoubleSpinBox; | ||||
384 | sbMoveAxis->setRange(0, 200); | ||||
385 | | ||||
386 | auto *newPB = new QPushButton(QStringLiteral("Go")); | ||||
387 | connect(newPB, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); | ||||
388 | | ||||
389 | auto *hBoxLayout2 = new QHBoxLayout; | ||||
390 | hBoxLayout2->addWidget(comboMoveAxis); | ||||
391 | hBoxLayout2->addWidget(sbMoveAxis); | ||||
392 | hBoxLayout2->addWidget(newPB); | ||||
393 | | ||||
394 | newPB = new QPushButton(QStringLiteral("Disable Motors")); | ||||
395 | connect(newPB, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); | ||||
396 | | ||||
397 | auto *axisControl = new AxisControl; | ||||
398 | connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); | ||||
399 | | ||||
400 | auto *vBoxLayout = new QVBoxLayout; | ||||
401 | vBoxLayout->addItem(hBoxLayout1); | ||||
402 | vBoxLayout->addItem(hBoxLayout2); | ||||
403 | vBoxLayout->addWidget(newPB); | ||||
404 | vBoxLayout->addWidget(axisControl); | ||||
405 | | ||||
406 | auto *dockContents = new QWidget; | ||||
407 | dockContents->setLayout(vBoxLayout); | ||||
408 | | ||||
409 | moveDock = new QDockWidget(QStringLiteral("Movement"), this); | ||||
410 | menuView->insertAction(nullptr, moveDock->toggleViewAction()); | ||||
411 | moveDock->setWidget(dockContents); | ||||
412 | addDockWidget(Qt::LeftDockWidgetArea, moveDock); | ||||
413 | } | ||||
414 | | ||||
415 | void MainWindow::makeTempControlsDock() | ||||
416 | { | ||||
417 | auto *mainLayout = new QVBoxLayout; | ||||
418 | checkAndWait = new QCheckBox(QStringLiteral("Wait Untill Temperature Stablizes")); | ||||
419 | mainLayout->addWidget(checkAndWait); | ||||
420 | | ||||
421 | auto label = new QLabel(QStringLiteral("Bed Temp")); | ||||
422 | | ||||
423 | sbBedTemp = new QSpinBox; | ||||
424 | sbBedTemp->setRange(0, 120); | ||||
425 | sbBedTemp->setSuffix(QStringLiteral("°C")); | ||||
426 | | ||||
427 | auto *newPB = new QPushButton(QStringLiteral("Set")); | ||||
428 | connect(newPB, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); | ||||
429 | | ||||
430 | auto *hboxLayout = new QHBoxLayout; | ||||
431 | hboxLayout->addWidget(label, 80); | ||||
432 | hboxLayout->addWidget(sbBedTemp); | ||||
433 | hboxLayout->addWidget(newPB); | ||||
434 | mainLayout->addItem(hboxLayout); | ||||
435 | | ||||
436 | comboExtruderSelect = new QComboBox; | ||||
437 | sbExtruderTemp = new QSpinBox; | ||||
438 | sbExtruderTemp->setRange(0, 275); | ||||
439 | sbExtruderTemp->setSuffix(QStringLiteral("°C")); | ||||
440 | | ||||
441 | newPB = new QPushButton(QStringLiteral("Set")); | ||||
442 | connect(newPB, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); | ||||
443 | hboxLayout = new QHBoxLayout; | ||||
444 | hboxLayout->addWidget(comboExtruderSelect, 80); | ||||
445 | hboxLayout->addWidget(sbExtruderTemp); | ||||
446 | hboxLayout->addWidget(newPB); | ||||
447 | mainLayout->addItem(hboxLayout); | ||||
448 | | ||||
449 | comboFanSelect = new QComboBox; | ||||
450 | sbFanSpeed = new QSpinBox; | ||||
451 | sbFanSpeed->setRange(0, 100); | ||||
452 | sbFanSpeed->setSuffix(QStringLiteral("%")); | ||||
453 | | ||||
454 | newPB = new QPushButton(QStringLiteral("Set")); | ||||
455 | connect(newPB, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); | ||||
456 | hboxLayout = new QHBoxLayout; | ||||
457 | hboxLayout->addWidget(comboFanSelect, 80); | ||||
458 | hboxLayout->addWidget(sbFanSpeed); | ||||
459 | hboxLayout->addWidget(newPB); | ||||
460 | mainLayout->addItem(hboxLayout); | ||||
461 | | ||||
462 | auto *dockContents = new QWidget; | ||||
463 | dockContents->setLayout(mainLayout); | ||||
464 | | ||||
465 | tempControlsDock = new QDockWidget(QStringLiteral("Temperatures"), this); | ||||
466 | menuView->insertAction(nullptr, tempControlsDock->toggleViewAction()); | ||||
467 | tempControlsDock->setWidget(dockContents); | ||||
468 | addDockWidget(Qt::LeftDockWidgetArea, tempControlsDock); | ||||
469 | } | ||||
470 | | ||||
471 | void MainWindow::makeSdDock() | ||||
472 | { | ||||
473 | auto *hBoxLayout = new QHBoxLayout; | ||||
474 | auto *newPB = new QPushButton(QStringLiteral("Get List")); | ||||
475 | connect(newPB, &QPushButton::clicked, this, &MainWindow::getSdList); | ||||
476 | hBoxLayout->addWidget(newPB); | ||||
477 | | ||||
478 | newPB = new QPushButton(QStringLiteral("Print Selected")); | ||||
479 | connect(newPB, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); | ||||
480 | hBoxLayout->addWidget(newPB); | ||||
481 | | ||||
482 | newPB = new QPushButton(QStringLiteral("Delete Selected")); | ||||
483 | connect(newPB, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); | ||||
484 | hBoxLayout->addWidget(newPB); | ||||
485 | | ||||
486 | auto *groupFiles = new QGroupBox(QStringLiteral("Files On Sd Card")); | ||||
487 | listSdFiles = new QListWidget; | ||||
488 | auto *groupLayout = new QVBoxLayout; | ||||
489 | groupLayout->addWidget(listSdFiles); | ||||
490 | groupFiles->setLayout(groupLayout); | ||||
491 | | ||||
492 | auto *finalLayout = new QVBoxLayout; | ||||
493 | finalLayout->addItem(hBoxLayout); | ||||
494 | finalLayout->addWidget(groupFiles); | ||||
495 | | ||||
496 | auto *dockContents = new QWidget; | ||||
497 | dockContents->setLayout(finalLayout); | ||||
498 | | ||||
499 | sdDock = new QDockWidget(QStringLiteral("Sd Card"), this); | ||||
500 | menuView->insertAction(nullptr, sdDock->toggleViewAction()); | ||||
501 | sdDock->setWidget(dockContents); | ||||
502 | addDockWidget(Qt::LeftDockWidgetArea, sdDock); | ||||
503 | } | ||||
I don't see this as a good thing. Ui files help to improve the interface without changing the code base. Any GOOD motive to remove it ? patrickelectric: I don't see this as a good thing. Ui files help to improve the interface without changing the… | |||||
Some reasons:
This Diff Is Only the first part of the plan to simplify the atcore-gui
rizzitello: Some reasons:
- Removes code spaghettification by making the docks in one place instead of… | |||||
504 | | ||||
161 | void MainWindow::closeEvent(QCloseEvent *event) | 505 | void MainWindow::closeEvent(QCloseEvent *event) | ||
162 | { | 506 | { | ||
163 | core->close(); | 507 | core->close(); | ||
164 | event->accept(); | 508 | event->accept(); | ||
165 | } | 509 | } | ||
166 | 510 | | |||
167 | MainWindow::~MainWindow() | 511 | MainWindow::~MainWindow() | ||
168 | { | 512 | { | ||
169 | delete logFile; | 513 | delete logFile; | ||
170 | delete ui; | | |||
171 | } | 514 | } | ||
172 | 515 | | |||
173 | QString MainWindow::getTime() | 516 | QString MainWindow::getTime() | ||
174 | { | 517 | { | ||
175 | return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); | 518 | return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); | ||
176 | } | 519 | } | ||
177 | 520 | | |||
178 | QString MainWindow::logHeader() | 521 | QString MainWindow::logHeader() | ||
Show All 24 Lines | 537 | { | |||
203 | logFile->write(text.toLatin1()); | 546 | logFile->write(text.toLatin1()); | ||
204 | logFile->putChar('\n'); | 547 | logFile->putChar('\n'); | ||
205 | logFile->close(); | 548 | logFile->close(); | ||
206 | } | 549 | } | ||
207 | 550 | | |||
208 | void MainWindow::addLog(QString msg) | 551 | void MainWindow::addLog(QString msg) | ||
209 | { | 552 | { | ||
210 | QString message(logHeader() + msg); | 553 | QString message(logHeader() + msg); | ||
211 | ui->logTE->appendPlainText(message); | 554 | textLog->appendPlainText(message); | ||
212 | writeTempFile(message); | 555 | writeTempFile(message); | ||
213 | } | 556 | } | ||
214 | 557 | | |||
215 | void MainWindow::addRLog(QString msg) | 558 | void MainWindow::addRLog(QString msg) | ||
216 | { | 559 | { | ||
217 | QString message(rLogHeader() + msg); | 560 | QString message(rLogHeader() + msg); | ||
218 | ui->logTE->appendPlainText(message); | 561 | textLog->appendPlainText(message); | ||
219 | writeTempFile(message); | 562 | writeTempFile(message); | ||
220 | } | 563 | } | ||
221 | 564 | | |||
222 | void MainWindow::addSLog(QString msg) | 565 | void MainWindow::addSLog(QString msg) | ||
223 | { | 566 | { | ||
224 | QString message(sLogHeader() + msg); | 567 | QString message(sLogHeader() + msg); | ||
225 | ui->logTE->appendPlainText(message); | 568 | textLog->appendPlainText(message); | ||
226 | writeTempFile(message); | 569 | writeTempFile(message); | ||
227 | } | 570 | } | ||
228 | 571 | | |||
229 | void MainWindow::checkReceivedCommand(const QByteArray &message) | 572 | void MainWindow::checkReceivedCommand(const QByteArray &message) | ||
230 | { | 573 | { | ||
231 | addRLog(QString::fromUtf8(message)); | 574 | addRLog(QString::fromUtf8(message)); | ||
232 | } | 575 | } | ||
233 | 576 | | |||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
278 | } | 621 | } | ||
279 | /** | 622 | /** | ||
280 | * @brief MainWindow::locateSerialPort | 623 | * @brief MainWindow::locateSerialPort | ||
281 | * Locate all active serial ports on the computer and add to the list | 624 | * Locate all active serial ports on the computer and add to the list | ||
282 | * of serial ports | 625 | * of serial ports | ||
283 | */ | 626 | */ | ||
284 | void MainWindow::locateSerialPort(const QStringList &ports) | 627 | void MainWindow::locateSerialPort(const QStringList &ports) | ||
285 | { | 628 | { | ||
286 | ui->serialPortCB->clear(); | 629 | comboPort->clear(); | ||
287 | if (!ports.isEmpty()) { | 630 | if (!ports.isEmpty()) { | ||
288 | ui->serialPortCB->addItems(ports); | 631 | comboPort->addItems(ports); | ||
289 | addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); | 632 | addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); | ||
290 | } else { | 633 | } else { | ||
291 | QString portError(tr("No available ports! Please connect a serial device to continue!")); | 634 | QString portError(tr("No available ports! Please connect a serial device to continue!")); | ||
292 | if (! ui->logTE->toPlainText().endsWith(portError)) { | 635 | if (! textLog->toPlainText().endsWith(portError)) { | ||
293 | addLog(portError); | 636 | addLog(portError); | ||
294 | } | 637 | } | ||
295 | } | 638 | } | ||
296 | } | 639 | } | ||
297 | 640 | | |||
298 | void MainWindow::connectPBClicked() | 641 | void MainWindow::connectPBClicked() | ||
299 | { | 642 | { | ||
300 | if (core->state() == AtCore::DISCONNECTED) { | 643 | if (core->state() == AtCore::DISCONNECTED) { | ||
301 | if (core->initSerial(ui->serialPortCB->currentText(), ui->baudRateLE->currentText().toInt())) { | 644 | if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) { | ||
302 | connect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | 645 | connect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | ||
303 | connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | 646 | connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | ||
304 | ui->connectPB->setText(tr("Disconnect")); | 647 | buttonConnect->setText(tr("Disconnect")); | ||
305 | addLog(tr("Serial connected")); | 648 | addLog(tr("Serial connected")); | ||
306 | if (ui->pluginCB->currentText().contains(tr("Autodetect"))) { | 649 | if (comboPlugin->currentText().contains(tr("Autodetect"))) { | ||
307 | addLog(tr("No plugin loaded !")); | 650 | addLog(tr("No plugin loaded !")); | ||
308 | addLog(tr("Requesting Firmware...")); | 651 | addLog(tr("Requesting Firmware...")); | ||
309 | core->detectFirmware(); | 652 | core->detectFirmware(); | ||
310 | } else { | 653 | } else { | ||
311 | core->loadFirmwarePlugin(ui->pluginCB->currentText()); | 654 | core->loadFirmwarePlugin(comboPlugin->currentText()); | ||
312 | } | 655 | } | ||
313 | } else { | 656 | } else { | ||
314 | addLog(tr("Failed to open serial in r/w mode")); | 657 | addLog(tr("Failed to open serial in r/w mode")); | ||
315 | } | 658 | } | ||
316 | } else { | 659 | } else { | ||
317 | disconnect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | 660 | disconnect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | ||
318 | disconnect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | 661 | disconnect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | ||
319 | core->closeConnection(); | 662 | core->closeConnection(); | ||
320 | core->setState(AtCore::DISCONNECTED); | 663 | core->setState(AtCore::DISCONNECTED); | ||
321 | addLog(tr("Disconnected")); | 664 | addLog(tr("Disconnected")); | ||
322 | ui->connectPB->setText(tr("Connect")); | 665 | buttonConnect->setText(tr("Connect")); | ||
323 | } | 666 | } | ||
324 | } | 667 | } | ||
325 | 668 | | |||
326 | void MainWindow::sendPBClicked() | 669 | void MainWindow::sendPBClicked() | ||
327 | { | 670 | { | ||
328 | QString comm = ui->commandLE->text().toUpper(); | 671 | QString comm = lineCommand->text().toUpper(); | ||
329 | core->pushCommand(comm); | 672 | core->pushCommand(comm); | ||
330 | ui->commandLE->clear(); | 673 | lineCommand->clear(); | ||
331 | } | 674 | } | ||
332 | 675 | | |||
333 | void MainWindow::homeAllPBClicked() | 676 | void MainWindow::homeAllPBClicked() | ||
334 | { | 677 | { | ||
335 | addSLog(tr("Home All")); | 678 | addSLog(tr("Home All")); | ||
336 | core->home(); | 679 | core->home(); | ||
337 | } | 680 | } | ||
338 | 681 | | |||
Show All 12 Lines | |||||
351 | void MainWindow::homeZPBClicked() | 694 | void MainWindow::homeZPBClicked() | ||
352 | { | 695 | { | ||
353 | addSLog(tr("Home Z")); | 696 | addSLog(tr("Home Z")); | ||
354 | core->home(AtCore::Z); | 697 | core->home(AtCore::Z); | ||
355 | } | 698 | } | ||
356 | 699 | | |||
357 | void MainWindow::bedTempPBClicked() | 700 | void MainWindow::bedTempPBClicked() | ||
358 | { | 701 | { | ||
359 | if (ui->cb_andWait->isChecked()) { | 702 | if (checkAndWait->isChecked()) { | ||
360 | addSLog(GCode::description(GCode::M190)); | 703 | addSLog(GCode::description(GCode::M190)); | ||
361 | } else { | 704 | } else { | ||
362 | addSLog(GCode::description(GCode::M140)); | 705 | addSLog(GCode::description(GCode::M140)); | ||
363 | } | 706 | } | ||
364 | core->setBedTemp(ui->bedTempSB->value(), ui->cb_andWait->isChecked()); | 707 | core->setBedTemp(sbBedTemp->value(), checkAndWait->isChecked()); | ||
365 | } | 708 | } | ||
366 | 709 | | |||
367 | void MainWindow::extTempPBClicked() | 710 | void MainWindow::extTempPBClicked() | ||
368 | { | 711 | { | ||
369 | if (ui->cb_andWait->isChecked()) { | 712 | if (checkAndWait->isChecked()) { | ||
370 | addSLog(GCode::description(GCode::M109)); | 713 | addSLog(GCode::description(GCode::M109)); | ||
371 | } else { | 714 | } else { | ||
372 | addSLog(GCode::description(GCode::M104)); | 715 | addSLog(GCode::description(GCode::M104)); | ||
373 | } | 716 | } | ||
374 | core->setExtruderTemp(ui->extTempSB->value(), ui->extTempSelCB->currentIndex(), ui->cb_andWait->isChecked()); | 717 | core->setExtruderTemp(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked()); | ||
375 | } | 718 | } | ||
376 | 719 | | |||
377 | void MainWindow::mvAxisPBClicked() | 720 | void MainWindow::mvAxisPBClicked() | ||
378 | { | 721 | { | ||
379 | addSLog(GCode::description(GCode::G1)); | 722 | addSLog(GCode::description(GCode::G1)); | ||
380 | if (ui->mvAxisCB->currentIndex() == 0) { | 723 | if (comboMoveAxis->currentIndex() == 0) { | ||
381 | core->move(AtCore::X, ui->mvAxisSB->value()); | 724 | core->move(AtCore::X, sbMoveAxis->value()); | ||
382 | } else if (ui->mvAxisCB->currentIndex() == 1) { | 725 | } else if (comboMoveAxis->currentIndex() == 1) { | ||
383 | core->move(AtCore::Y, ui->mvAxisSB->value()); | 726 | core->move(AtCore::Y, sbMoveAxis->value()); | ||
384 | } else if (ui->mvAxisCB->currentIndex() == 2) { | 727 | } else if (comboMoveAxis->currentIndex() == 2) { | ||
385 | core->move(AtCore::Z, ui->mvAxisSB->value()); | 728 | core->move(AtCore::Z, sbMoveAxis->value()); | ||
386 | } | 729 | } | ||
387 | } | 730 | } | ||
388 | 731 | | |||
389 | void MainWindow::fanSpeedPBClicked() | 732 | void MainWindow::fanSpeedPBClicked() | ||
390 | { | 733 | { | ||
391 | addSLog(GCode::description(GCode::M106)); | 734 | addSLog(GCode::description(GCode::M106)); | ||
392 | core->setFanSpeed(ui->fanSpeedSB->value(), ui->fanSpeedSelCB->currentIndex()); | 735 | core->setFanSpeed(sbFanSpeed->value(), comboFanSelect->currentIndex()); | ||
393 | } | 736 | } | ||
394 | 737 | | |||
395 | void MainWindow::printPBClicked() | 738 | void MainWindow::printPBClicked() | ||
396 | { | 739 | { | ||
397 | QString fileName; | 740 | QString fileName; | ||
398 | switch (core->state()) { | 741 | switch (core->state()) { | ||
399 | 742 | | |||
400 | case AtCore::DISCONNECTED: | 743 | case AtCore::DISCONNECTED: | ||
401 | QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); | 744 | QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); | ||
402 | break; | 745 | break; | ||
403 | 746 | | |||
404 | case AtCore::CONNECTING: | 747 | case AtCore::CONNECTING: | ||
405 | QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); | 748 | QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); | ||
406 | ui->pluginCB->setCurrentText(QStringLiteral("repetier")); | 749 | comboPlugin->setCurrentText(QStringLiteral("repetier")); | ||
407 | break; | 750 | break; | ||
408 | 751 | | |||
409 | case AtCore::IDLE: | 752 | case AtCore::IDLE: | ||
410 | fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), QStringLiteral("*.gcode")); | 753 | fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), QStringLiteral("*.gcode")); | ||
411 | if (fileName.isNull()) { | 754 | if (fileName.isNull()) { | ||
412 | addLog(tr("No File Selected")); | 755 | addLog(tr("No File Selected")); | ||
413 | } else { | 756 | } else { | ||
414 | addLog(tr("Print: %1").arg(fileName)); | 757 | addLog(tr("Print: %1").arg(fileName)); | ||
415 | core->print(fileName); | 758 | core->print(fileName); | ||
416 | } | 759 | } | ||
417 | break; | 760 | break; | ||
418 | 761 | | |||
419 | case AtCore::BUSY: | 762 | case AtCore::BUSY: | ||
420 | core->pause(ui->postPauseLE->text()); | 763 | core->pause(linePostPause->text()); | ||
421 | break; | 764 | break; | ||
422 | 765 | | |||
423 | case AtCore::PAUSE: | 766 | case AtCore::PAUSE: | ||
424 | core->resume(); | 767 | core->resume(); | ||
425 | break; | 768 | break; | ||
426 | 769 | | |||
427 | default: | 770 | default: | ||
428 | qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; | 771 | qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; | ||
Show All 16 Lines | 785 | if (core->state() != AtCore::DISCONNECTED) { | |||
445 | } else { | 788 | } else { | ||
446 | core->detectFirmware(); | 789 | core->detectFirmware(); | ||
447 | } | 790 | } | ||
448 | } | 791 | } | ||
449 | } | 792 | } | ||
450 | 793 | | |||
451 | void MainWindow::flowRatePBClicked() | 794 | void MainWindow::flowRatePBClicked() | ||
452 | { | 795 | { | ||
453 | core->setFlowRate(ui->flowRateSB->value()); | 796 | core->setFlowRate(sbFlowRate->value()); | ||
454 | } | 797 | } | ||
455 | 798 | | |||
456 | void MainWindow::printerSpeedPBClicked() | 799 | void MainWindow::printerSpeedPBClicked() | ||
457 | { | 800 | { | ||
458 | core->setPrinterSpeed(ui->printerSpeedSB->value()); | 801 | core->setPrinterSpeed(sbPrintSpeed->value()); | ||
459 | } | 802 | } | ||
460 | 803 | | |||
461 | void MainWindow::printerStateChanged(AtCore::STATES state) | 804 | void MainWindow::printerStateChanged(AtCore::STATES state) | ||
462 | { | 805 | { | ||
463 | QString stateString; | 806 | QString stateString; | ||
464 | switch (state) { | 807 | switch (state) { | ||
465 | case AtCore::IDLE: | 808 | case AtCore::IDLE: | ||
466 | ui->printPB->setText(tr("Print File")); | 809 | buttonPrint->setText(tr("Print File")); | ||
467 | stateString = QStringLiteral("Connected to ") + core->connectedPort(); | 810 | stateString = QStringLiteral("Connected to ") + core->connectedPort(); | ||
468 | break; | 811 | break; | ||
469 | 812 | | |||
470 | case AtCore::STARTPRINT: | 813 | case AtCore::STARTPRINT: | ||
471 | stateString = QStringLiteral("START PRINT"); | 814 | stateString = QStringLiteral("START PRINT"); | ||
472 | ui->printPB->setText(tr("Pause Print")); | 815 | buttonPrint->setText(tr("Pause Print")); | ||
473 | ui->printLayout->setVisible(true); | 816 | printProgressWidget->setVisible(true); | ||
474 | printTime->start(); | 817 | printTime->start(); | ||
475 | printTimer->start(); | 818 | printTimer->start(); | ||
476 | break; | 819 | break; | ||
477 | 820 | | |||
478 | case AtCore::FINISHEDPRINT: | 821 | case AtCore::FINISHEDPRINT: | ||
479 | stateString = QStringLiteral("Finished Print"); | 822 | stateString = QStringLiteral("Finished Print"); | ||
480 | ui->printPB->setText(tr("Print File")); | 823 | buttonPrint->setText(tr("Print File")); | ||
481 | ui->printLayout->setVisible(false); | 824 | printProgressWidget->setVisible(false); | ||
482 | printTimer->stop(); | 825 | printTimer->stop(); | ||
483 | break; | 826 | break; | ||
484 | 827 | | |||
485 | case AtCore::PAUSE: | 828 | case AtCore::PAUSE: | ||
486 | stateString = QStringLiteral("Paused"); | 829 | stateString = QStringLiteral("Paused"); | ||
487 | ui->printPB->setText(tr("Resume Print")); | 830 | buttonPrint->setText(tr("Resume Print")); | ||
488 | break; | 831 | break; | ||
489 | 832 | | |||
490 | case AtCore::BUSY: | 833 | case AtCore::BUSY: | ||
491 | stateString = QStringLiteral("Printing"); | 834 | stateString = QStringLiteral("Printing"); | ||
492 | ui->printPB->setText(tr("Pause Print")); | 835 | buttonPrint->setText(tr("Pause Print")); | ||
493 | break; | 836 | break; | ||
494 | 837 | | |||
495 | case AtCore::DISCONNECTED: | 838 | case AtCore::DISCONNECTED: | ||
496 | stateString = QStringLiteral("Not Connected"); | 839 | stateString = QStringLiteral("Not Connected"); | ||
497 | ui->commandDock->setDisabled(true); | 840 | commandDock->setDisabled(true); | ||
498 | ui->moveDock->setDisabled(true); | 841 | moveDock->setDisabled(true); | ||
499 | ui->tempControlsDock->setDisabled(true); | 842 | tempControlsDock->setDisabled(true); | ||
500 | ui->printDock->setDisabled(true); | 843 | printDock->setDisabled(true); | ||
501 | ui->sdDock->setDisabled(true); | 844 | sdDock->setDisabled(true); | ||
502 | break; | 845 | break; | ||
503 | 846 | | |||
504 | case AtCore::CONNECTING: | 847 | case AtCore::CONNECTING: | ||
505 | stateString = QStringLiteral("Connecting"); | 848 | stateString = QStringLiteral("Connecting"); | ||
506 | ui->commandDock->setDisabled(false); | 849 | commandDock->setDisabled(false); | ||
507 | ui->moveDock->setDisabled(false); | 850 | moveDock->setDisabled(false); | ||
508 | ui->tempControlsDock->setDisabled(false); | 851 | tempControlsDock->setDisabled(false); | ||
509 | ui->printDock->setDisabled(false); | 852 | printDock->setDisabled(false); | ||
510 | ui->sdDock->setDisabled(false); | 853 | sdDock->setDisabled(false); | ||
511 | break; | 854 | break; | ||
512 | 855 | | |||
513 | case AtCore::STOP: | 856 | case AtCore::STOP: | ||
514 | stateString = QStringLiteral("Stoping Print"); | 857 | stateString = QStringLiteral("Stoping Print"); | ||
515 | break; | 858 | break; | ||
516 | 859 | | |||
517 | case AtCore::ERRORSTATE: | 860 | case AtCore::ERRORSTATE: | ||
518 | stateString = QStringLiteral("Command ERROR"); | 861 | stateString = QStringLiteral("Command ERROR"); | ||
519 | break; | 862 | break; | ||
520 | } | 863 | } | ||
521 | ui->lblState->setText(stateString); | 864 | lblState->setText(stateString); | ||
522 | } | 865 | } | ||
523 | 866 | | |||
524 | void MainWindow::populateCBs() | 867 | void MainWindow::populateCBs() | ||
525 | { | 868 | { | ||
526 | // Extruders | 869 | // Extruders | ||
527 | for (int count = 0; count < core->extruderCount(); count++) { | 870 | for (int count = 0; count < core->extruderCount(); count++) { | ||
528 | ui->extTempSelCB->insertItem(count, tr("Extruder %1").arg(count)); | 871 | comboExtruderSelect->insertItem(count, tr("Extruder %1").arg(count)); | ||
529 | } | 872 | } | ||
530 | 873 | | |||
531 | // Fan | 874 | // Fan | ||
532 | for (int count = 0; count < fanCount; count++) { | 875 | for (int count = 0; count < fanCount; count++) { | ||
533 | ui->fanSpeedSelCB->insertItem(count, tr("Fan %1 speed").arg(count)); | 876 | comboFanSelect->insertItem(count, tr("Fan %1 speed").arg(count)); | ||
534 | } | 877 | } | ||
535 | } | 878 | } | ||
536 | 879 | | |||
537 | void MainWindow::showMessage() | 880 | void MainWindow::showMessage() | ||
538 | { | 881 | { | ||
539 | core->showMessage(ui->messageLE->text()); | 882 | core->showMessage(lineMessage->text()); | ||
540 | } | 883 | } | ||
541 | 884 | | |||
542 | void MainWindow::updatePrintTime() | 885 | void MainWindow::updatePrintTime() | ||
543 | { | 886 | { | ||
544 | QTime temp(0, 0, 0); | 887 | QTime temp(0, 0, 0); | ||
545 | ui->time->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); | 888 | lblTime->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); | ||
546 | } | 889 | } | ||
547 | 890 | | |||
548 | void MainWindow::printProgressChanged(int progress) | 891 | void MainWindow::printProgressChanged(int progress) | ||
549 | { | 892 | { | ||
550 | ui->printingProgress->setValue(progress); | 893 | printingProgress->setValue(progress); | ||
551 | if (progress > 0) { | 894 | if (progress > 0) { | ||
552 | QTime temp(0, 0, 0); | 895 | QTime temp(0, 0, 0); | ||
553 | ui->timeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); | 896 | lblTimeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); | ||
554 | } else { | 897 | } else { | ||
555 | ui->timeLeft->setText(QStringLiteral("??:??:??")); | 898 | lblTimeLeft->setText(QStringLiteral("??:??:??")); | ||
556 | } | 899 | } | ||
557 | } | 900 | } | ||
558 | void MainWindow::toggleDockTitles() | 901 | void MainWindow::toggleDockTitles(bool checked) | ||
559 | { | 902 | { | ||
560 | if (ui->actionShowDockTitles->isChecked()) { | 903 | if (checked) { | ||
561 | delete ui->connectDock->titleBarWidget(); | 904 | delete connectDock->titleBarWidget(); | ||
562 | delete ui->logDock->titleBarWidget(); | 905 | delete logDock->titleBarWidget(); | ||
563 | delete ui->tempTimelineDock->titleBarWidget(); | 906 | delete tempTimelineDock->titleBarWidget(); | ||
564 | delete ui->commandDock->titleBarWidget(); | 907 | delete commandDock->titleBarWidget(); | ||
565 | delete ui->moveDock->titleBarWidget(); | 908 | delete moveDock->titleBarWidget(); | ||
566 | delete ui->tempControlsDock->titleBarWidget(); | 909 | delete tempControlsDock->titleBarWidget(); | ||
567 | delete ui->printDock->titleBarWidget(); | 910 | delete printDock->titleBarWidget(); | ||
568 | delete ui->sdDock->titleBarWidget(); | 911 | delete sdDock->titleBarWidget(); | ||
569 | } else { | 912 | } else { | ||
570 | ui->connectDock->setTitleBarWidget(new QWidget()); | 913 | connectDock->setTitleBarWidget(new QWidget()); | ||
571 | ui->logDock->setTitleBarWidget(new QWidget()); | 914 | logDock->setTitleBarWidget(new QWidget()); | ||
572 | ui->tempTimelineDock->setTitleBarWidget(new QWidget()); | 915 | tempTimelineDock->setTitleBarWidget(new QWidget()); | ||
573 | ui->commandDock->setTitleBarWidget(new QWidget()); | 916 | commandDock->setTitleBarWidget(new QWidget()); | ||
574 | ui->moveDock->setTitleBarWidget(new QWidget()); | 917 | moveDock->setTitleBarWidget(new QWidget()); | ||
575 | ui->tempControlsDock->setTitleBarWidget(new QWidget()); | 918 | tempControlsDock->setTitleBarWidget(new QWidget()); | ||
576 | ui->printDock->setTitleBarWidget(new QWidget()); | 919 | printDock->setTitleBarWidget(new QWidget()); | ||
577 | ui->sdDock->setTitleBarWidget(new QWidget()); | 920 | sdDock->setTitleBarWidget(new QWidget()); | ||
578 | } | | |||
579 | } | 921 | } | ||
580 | | ||||
581 | void MainWindow::about() | | |||
582 | { | | |||
583 | About *aboutDialog = new About(this); | | |||
584 | aboutDialog->exec(); | | |||
585 | } | 922 | } | ||
586 | 923 | | |||
587 | void MainWindow::axisControlClicked(QLatin1Char axis, int value) | 924 | void MainWindow::axisControlClicked(QLatin1Char axis, int value) | ||
588 | { | 925 | { | ||
589 | core->setRelativePosition(); | 926 | core->setRelativePosition(); | ||
590 | core->move(axis, value); | 927 | core->move(axis, value); | ||
591 | core->setAbsolutePosition(); | 928 | core->setAbsolutePosition(); | ||
592 | } | 929 | } | ||
593 | 930 | | |||
594 | void MainWindow::disableMotorsPBClicked() | 931 | void MainWindow::disableMotorsPBClicked() | ||
595 | { | 932 | { | ||
596 | core->setIdleHold(0); | 933 | core->setIdleHold(0); | ||
597 | } | 934 | } | ||
598 | 935 | | |||
599 | void MainWindow::sdChanged(bool mounted) | 936 | void MainWindow::sdChanged(bool mounted) | ||
600 | { | 937 | { | ||
601 | QString labelText = mounted ? QStringLiteral("SD") : QString(); | 938 | QString labelText = mounted ? QStringLiteral("SD") : QString(); | ||
602 | ui->lbl_sd->setText(labelText); | 939 | lblSd->setText(labelText); | ||
603 | } | 940 | } | ||
604 | 941 | | |||
605 | void MainWindow::getSdList() | 942 | void MainWindow::getSdList() | ||
606 | { | 943 | { | ||
607 | core->sdFileList(); | 944 | core->sdFileList(); | ||
608 | } | 945 | } | ||
609 | 946 | | |||
610 | void MainWindow::sdPrintPBClicked() | 947 | void MainWindow::sdPrintPBClicked() | ||
611 | { | 948 | { | ||
612 | if (ui->sdFileListView->currentRow() < 0) { | 949 | if (listSdFiles->currentRow() < 0) { | ||
613 | QMessageBox::information(this, QStringLiteral("Print Error"), QStringLiteral("You must Select a file from the list")); | 950 | QMessageBox::information(this, QStringLiteral("Print Error"), QStringLiteral("You must Select a file from the list")); | ||
614 | } else { | 951 | } else { | ||
615 | core->print(ui->sdFileListView->currentItem()->text(), true); | 952 | core->print(listSdFiles->currentItem()->text(), true); | ||
616 | } | 953 | } | ||
617 | } | 954 | } | ||
618 | 955 | | |||
619 | void MainWindow::sdDelPBClicked() | 956 | void MainWindow::sdDelPBClicked() | ||
620 | { | 957 | { | ||
621 | if (ui->sdFileListView->currentRow() < 0) { | 958 | if (listSdFiles->currentRow() < 0) { | ||
622 | QMessageBox::information(this, QStringLiteral("Delete Error"), QStringLiteral("You must Select a file from the list")); | 959 | QMessageBox::information(this, QStringLiteral("Delete Error"), QStringLiteral("You must Select a file from the list")); | ||
623 | } else { | 960 | } else { | ||
624 | core->sdDelete(ui->sdFileListView->currentItem()->text()); | 961 | core->sdDelete(listSdFiles->currentItem()->text()); | ||
625 | ui->sdFileListView->setCurrentRow(-1); | 962 | listSdFiles->setCurrentRow(-1); | ||
626 | } | 963 | } | ||
627 | } | 964 | } |
use tr so we can have translation.