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(tr("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 | setDangeriousDocksDisabled(true); | | |||
64 | populateCBs(); | | |||
65 | 54 | | |||
66 | //Icon for actionQuit | | |||
67 | #ifndef Q_OS_MAC | | |||
68 | ui->actionQuit->setIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); | | |||
69 | #endif | | |||
70 | | ||||
71 | //hide the printing progress bar. | | |||
72 | ui->printLayout->setVisible(false); | | |||
73 | | ||||
74 | ui->statusBar->addWidget(ui->statusBarWidget); | | |||
75 | printTime = new QTime(); | 55 | printTime = new QTime(); | ||
76 | printTimer = new QTimer(); | 56 | printTimer = new QTimer(); | ||
77 | printTimer->setInterval(1000); | 57 | printTimer->setInterval(1000); | ||
78 | printTimer->setSingleShot(false); | 58 | printTimer->setSingleShot(false); | ||
79 | connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); | 59 | connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); | ||
80 | 60 | | |||
81 | connect(ui->connectPB, &QPushButton::clicked, this, &MainWindow::connectPBClicked); | | |||
82 | connect(ui->saveLogPB, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); | | |||
83 | connect(ui->sendPB, &QPushButton::clicked, this, &MainWindow::sendPBClicked); | | |||
84 | connect(ui->commandLE, &QLineEdit::returnPressed, this, &MainWindow::sendPBClicked); | | |||
85 | connect(ui->homeAllPB, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); | | |||
86 | connect(ui->homeXPB, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); | | |||
87 | connect(ui->homeYPB, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); | | |||
88 | connect(ui->homeZPB, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); | | |||
89 | connect(ui->bedTempPB, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); | | |||
90 | connect(ui->extTempPB, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); | | |||
91 | connect(ui->mvAxisPB, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); | | |||
92 | connect(ui->fanSpeedPB, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); | | |||
93 | connect(ui->printPB, &QPushButton::clicked, this, &MainWindow::printPBClicked); | | |||
94 | connect(ui->sdPrintPB, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); | | |||
95 | connect(ui->sdDelPB, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); | | |||
96 | connect(ui->printerSpeedPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); | | |||
97 | connect(ui->flowRatePB, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked); | | |||
98 | connect(ui->showMessagePB, &QPushButton::clicked, this, &MainWindow::showMessage); | | |||
99 | connect(ui->pluginCB, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); | | |||
100 | connect(ui->disableMotorsPB, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); | | |||
101 | connect(ui->sdListPB, &QPushButton::clicked, this, &MainWindow::getSdList); | | |||
102 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | 61 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | ||
103 | connect(ui->stopPB, &QPushButton::clicked, core, &AtCore::stop); | | |||
104 | connect(ui->emergencyStopPB, &QPushButton::clicked, core, &AtCore::emergencyStop); | | |||
105 | connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); | | |||
106 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | 62 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | ||
107 | connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); | 63 | connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); | ||
108 | connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); | 64 | connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); | ||
109 | 65 | | |||
110 | connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { | 66 | connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { | ||
111 | ui->sdFileListView->clear(); | 67 | listSdFiles->clear(); | ||
112 | ui->sdFileListView->addItems(fileList); | 68 | listSdFiles->addItems(fileList); | ||
113 | }); | 69 | }); | ||
114 | 70 | | |||
115 | connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { | 71 | connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { | ||
116 | checkTemperature(0x00, 0, temp); | 72 | checkTemperature(0x00, 0, temp); | ||
117 | ui->plotWidget->appendPoint(tr("Actual Bed"), temp); | 73 | plotWidget->appendPoint(tr("Actual Bed"), temp); | ||
118 | ui->plotWidget->update(); | 74 | plotWidget->update(); | ||
119 | }); | 75 | }); | ||
120 | connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { | 76 | connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { | ||
121 | checkTemperature(0x01, 0, temp); | 77 | checkTemperature(0x01, 0, temp); | ||
122 | ui->plotWidget->appendPoint(tr("Target Bed"), temp); | 78 | plotWidget->appendPoint(tr("Target Bed"), temp); | ||
123 | ui->plotWidget->update(); | 79 | plotWidget->update(); | ||
124 | }); | 80 | }); | ||
125 | connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { | 81 | connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { | ||
126 | checkTemperature(0x02, 0, temp); | 82 | checkTemperature(0x02, 0, temp); | ||
127 | ui->plotWidget->appendPoint(tr("Actual Ext.1"), temp); | 83 | plotWidget->appendPoint(tr("Actual Ext.1"), temp); | ||
128 | ui->plotWidget->update(); | 84 | plotWidget->update(); | ||
129 | }); | 85 | }); | ||
130 | connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { | 86 | connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { | ||
131 | checkTemperature(0x03, 0, temp); | 87 | checkTemperature(0x03, 0, temp); | ||
132 | ui->plotWidget->appendPoint(tr("Target Ext.1"), temp); | 88 | plotWidget->appendPoint(tr("Target Ext.1"), temp); | ||
133 | ui->plotWidget->update(); | 89 | plotWidget->update(); | ||
134 | }); | 90 | }); | ||
91 | } | ||||
92 | | ||||
93 | void MainWindow::initMenu() | ||||
94 | { | ||||
95 | QMenu *menuFile = new QMenu(tr("File")); | ||||
96 | QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Quit")); | ||||
97 | connect(actionQuit, &QAction::triggered, this, &MainWindow::close); | ||||
98 | menuFile->addAction(actionQuit); | ||||
99 | | ||||
100 | menuView = new QMenu(tr("View")); | ||||
101 | QAction *actionShowDockTitles = new QAction(tr("Show Dock Titles")); | ||||
102 | actionShowDockTitles->setCheckable(true); | ||||
103 | actionShowDockTitles->setChecked(true); | ||||
104 | connect(actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); | ||||
105 | menuView->addAction(actionShowDockTitles); | ||||
106 | | ||||
107 | QMenu *menuHelp = new QMenu(tr("Help")); | ||||
108 | QAction *actionAbout = new QAction(tr("About")); | ||||
109 | actionAbout->setShortcut(QKeySequence(Qt::Key_F1)); | ||||
110 | connect(actionAbout, &QAction::triggered, [] { | ||||
111 | auto *dialog = new About; | ||||
112 | dialog->exec(); | ||||
113 | }); | ||||
114 | menuHelp->addAction(actionAbout); | ||||
135 | 115 | | |||
136 | connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::close); | 116 | menuBar()->addMenu(menuFile); | ||
137 | connect(ui->actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); | 117 | menuBar()->addMenu(menuView); | ||
138 | connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::about); | 118 | menuBar()->addMenu(menuHelp); | ||
139 | 119 | } | |||
140 | ui->menuView->insertAction(nullptr, ui->connectDock->toggleViewAction()); | 120 | | ||
141 | ui->menuView->insertAction(nullptr, ui->tempControlsDock->toggleViewAction()); | 121 | void MainWindow::initStatusBar() | ||
142 | ui->menuView->insertAction(nullptr, ui->commandDock->toggleViewAction()); | 122 | { | ||
143 | ui->menuView->insertAction(nullptr, ui->printDock->toggleViewAction()); | 123 | //first create the item for the print Progress. | ||
144 | ui->menuView->insertAction(nullptr, ui->moveDock->toggleViewAction()); | 124 | printingProgress = new QProgressBar; | ||
145 | ui->menuView->insertAction(nullptr, ui->tempTimelineDock->toggleViewAction()); | 125 | auto *newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); | ||
146 | ui->menuView->insertAction(nullptr, ui->logDock->toggleViewAction()); | 126 | connect(newButton, &QPushButton::clicked, core, &AtCore::stop); | ||
147 | ui->menuView->insertAction(nullptr, ui->sdDock->toggleViewAction()); | 127 | lblTime = new QLabel(QStringLiteral("00:00:00")); | ||
128 | lblTime->setAlignment(Qt::AlignHCenter); | ||||
129 | auto *newLabel = new QLabel(QStringLiteral(" / ")); | ||||
130 | lblTimeLeft = new QLabel(QStringLiteral("00:00:00")); | ||||
131 | lblTimeLeft->setAlignment(Qt::AlignHCenter); | ||||
132 | | ||||
133 | auto *hBoxLayout = new QHBoxLayout; | ||||
134 | hBoxLayout->addWidget(printingProgress); | ||||
135 | hBoxLayout->addWidget(newButton); | ||||
136 | hBoxLayout->addWidget(lblTime); | ||||
137 | hBoxLayout->addWidget(newLabel); | ||||
138 | hBoxLayout->addWidget(lblTimeLeft); | ||||
139 | printProgressWidget = new QWidget(); | ||||
140 | printProgressWidget->setLayout(hBoxLayout); | ||||
141 | | ||||
142 | //Then Create the full bar. | ||||
143 | newLabel = new QLabel(tr("AtCore State:")); | ||||
144 | lblState = new QLabel(tr("Not Connected")); | ||||
145 | lblSd = new QLabel(); | ||||
146 | | ||||
147 | hBoxLayout = new QHBoxLayout; | ||||
148 | hBoxLayout->addWidget(newLabel); | ||||
149 | hBoxLayout->addWidget(lblState); | ||||
150 | hBoxLayout->addSpacerItem(new QSpacerItem(10, 20, QSizePolicy::Fixed)); | ||||
151 | hBoxLayout->addWidget(lblSd); | ||||
152 | hBoxLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); | ||||
153 | hBoxLayout->addWidget(printProgressWidget); | ||||
154 | | ||||
155 | //Then put it all into a widget on the bar. | ||||
156 | QWidget *sBar = new QWidget(); | ||||
157 | sBar->setLayout(hBoxLayout); | ||||
158 | statusBar()->addPermanentWidget(sBar, 100); | ||||
159 | } | ||||
160 | | ||||
161 | void MainWindow::initWidgets() | ||||
162 | { | ||||
163 | //Make the Docks | ||||
164 | makeCommandDock(); | ||||
165 | makePrintDock(); | ||||
166 | makeTempTimelineDock(); | ||||
167 | makeLogDock(); | ||||
168 | makeConnectDock(); | ||||
169 | makeMoveDock(); | ||||
170 | makeTempControlsDock(); | ||||
171 | makeSdDock(); | ||||
172 | | ||||
173 | setDangeriousDocksDisabled(true); | ||||
148 | 174 | | |||
149 | //more dock stuff. | | |||
150 | setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); | 175 | setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); | ||
151 | setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); | 176 | setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); | ||
152 | tabifyDockWidget(ui->moveDock, ui->tempControlsDock); | 177 | tabifyDockWidget(moveDock, tempControlsDock); | ||
153 | tabifyDockWidget(ui->moveDock, ui->sdDock); | 178 | tabifyDockWidget(moveDock, sdDock); | ||
154 | ui->moveDock->raise(); | 179 | moveDock->raise(); | ||
155 | 180 | | |||
156 | tabifyDockWidget(ui->connectDock, ui->printDock); | 181 | tabifyDockWidget(connectDock, printDock); | ||
157 | tabifyDockWidget(ui->connectDock, ui->commandDock); | 182 | tabifyDockWidget(connectDock, commandDock); | ||
158 | ui->connectDock->raise(); | 183 | connectDock->raise(); | ||
159 | setCentralWidget(nullptr); | 184 | setCentralWidget(nullptr); | ||
185 | | ||||
186 | //More Gui stuff | ||||
187 | populateCBs(); | ||||
188 | //hide the printing progress bar. | ||||
189 | printProgressWidget->setVisible(false); | ||||
190 | } | ||||
191 | | ||||
192 | void MainWindow::makeCommandDock() | ||||
193 | { | ||||
194 | //The processing for making a dock is the same for all docks | ||||
195 | //Expose the least amount of object outside the creation function. | ||||
196 | | ||||
197 | // First we make our mainLayout for the dock. | ||||
198 | auto *mainLayout = new QVBoxLayout; | ||||
199 | | ||||
200 | //Begin making content from top to bottom or left to right. | ||||
201 | //Making child layouts in the order you want to put them | ||||
202 | // onto the mainLayout | ||||
203 | lineCommand = new QLineEdit; | ||||
204 | lineCommand->setPlaceholderText(tr("Send Command")); | ||||
205 | | ||||
206 | //we have a few buttons to make here. Lets name this newButton so its easier to reuse | ||||
207 | auto *newButton = new QPushButton(tr("Send")); | ||||
208 | connect(newButton, &QPushButton::clicked, this, &MainWindow::sendPBClicked); | ||||
209 | | ||||
210 | //When you have created a Row put the items into layout. | ||||
211 | auto *hBoxLayout = new QHBoxLayout; | ||||
212 | hBoxLayout->addWidget(lineCommand); | ||||
213 | hBoxLayout->addWidget(newButton); | ||||
214 | //Put the Layout or Widget on the mainLayout when its finished. | ||||
215 | //This will free your pointers for reuse. | ||||
216 | mainLayout->addLayout(hBoxLayout); | ||||
217 | | ||||
218 | //Start making items for the next layout to place onto the mainLayout. | ||||
219 | lineMessage = new QLineEdit; | ||||
220 | lineMessage->setPlaceholderText(tr("Show Message")); | ||||
221 | | ||||
222 | //Here we reuse our button pointer my having it point to a new button. | ||||
223 | newButton = new QPushButton(tr("Send")); | ||||
224 | connect(newButton, &QPushButton::clicked, this, &MainWindow::showMessage); | ||||
225 | | ||||
226 | //We reuse the hBoxLayout pointer in the same way as the button pointer. | ||||
227 | hBoxLayout = new QHBoxLayout; | ||||
228 | hBoxLayout->addWidget(lineMessage); | ||||
229 | hBoxLayout->addWidget(newButton); | ||||
230 | mainLayout->addLayout(hBoxLayout); | ||||
231 | | ||||
232 | //QDockWidget::setLayout is not ment to be used by us | ||||
233 | //We must instead Create a widget to hold or dock contents. | ||||
234 | auto *dockContents = new QWidget; | ||||
235 | dockContents->setLayout(mainLayout); | ||||
236 | | ||||
237 | //Finally create the dock, and set the Widget. | ||||
238 | commandDock = new QDockWidget(tr("Commands"), this); | ||||
239 | commandDock->setWidget(dockContents); | ||||
240 | | ||||
241 | //Push the toggle view action into our view menu | ||||
242 | menuView->insertAction(nullptr, commandDock->toggleViewAction()); | ||||
243 | | ||||
244 | //Place the Dock into a DockWidget Area. | ||||
245 | //Failure todo this will create some odd side effects at runtime | ||||
246 | addDockWidget(Qt::LeftDockWidgetArea, commandDock); | ||||
247 | } | ||||
248 | | ||||
249 | void MainWindow::makePrintDock() | ||||
250 | { | ||||
251 | auto *mainLayout = new QVBoxLayout; | ||||
252 | | ||||
253 | buttonPrint = new QPushButton(tr("Print File")); | ||||
254 | connect(buttonPrint, &QPushButton::clicked, this, &MainWindow::printPBClicked); | ||||
255 | | ||||
256 | auto *newButton = new QPushButton(tr("Emergency Stop")); | ||||
257 | connect(newButton, &QPushButton::clicked, core, &AtCore::emergencyStop); | ||||
258 | | ||||
259 | auto *hBoxLayout = new QHBoxLayout; | ||||
260 | hBoxLayout->addWidget(buttonPrint); | ||||
261 | hBoxLayout->addWidget(newButton); | ||||
262 | mainLayout->addLayout(hBoxLayout); | ||||
263 | | ||||
264 | auto *newLabel = new QLabel(tr("On Pause:")); | ||||
265 | linePostPause = new QLineEdit; | ||||
266 | linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); | ||||
267 | | ||||
268 | hBoxLayout = new QHBoxLayout; | ||||
269 | hBoxLayout->addWidget(newLabel); | ||||
270 | hBoxLayout->addWidget(linePostPause); | ||||
271 | mainLayout->addLayout(hBoxLayout); | ||||
272 | | ||||
273 | newLabel = new QLabel(tr("Printer Speed")); | ||||
274 | sbPrintSpeed = new QSpinBox; | ||||
275 | sbPrintSpeed->setRange(1, 300); | ||||
276 | sbPrintSpeed->setValue(100); | ||||
277 | sbPrintSpeed->setSuffix(QStringLiteral("%")); | ||||
278 | | ||||
279 | newButton = new QPushButton(tr("Set")); | ||||
280 | connect(newButton, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); | ||||
281 | | ||||
282 | hBoxLayout = new QHBoxLayout; | ||||
283 | hBoxLayout->addWidget(newLabel, 35); | ||||
284 | hBoxLayout->addWidget(sbPrintSpeed, 10); | ||||
285 | hBoxLayout->addWidget(newButton, 20); | ||||
286 | mainLayout->addLayout(hBoxLayout); | ||||
287 | | ||||
288 | newLabel = new QLabel(tr("Flow Rate")); | ||||
289 | sbFlowRate = new QSpinBox; | ||||
290 | sbFlowRate->setRange(1, 300); | ||||
291 | sbFlowRate->setValue(100); | ||||
292 | sbFlowRate->setSuffix(QStringLiteral("%")); | ||||
293 | | ||||
294 | newButton = new QPushButton(tr("Set")); | ||||
295 | connect(newButton, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked); | ||||
296 | | ||||
297 | hBoxLayout = new QHBoxLayout; | ||||
298 | hBoxLayout->addWidget(newLabel, 35); | ||||
299 | hBoxLayout->addWidget(sbFlowRate, 10); | ||||
300 | hBoxLayout->addWidget(newButton, 20); | ||||
301 | mainLayout->addLayout(hBoxLayout); | ||||
302 | | ||||
303 | auto *dockContents = new QWidget; | ||||
304 | dockContents->setLayout(mainLayout); | ||||
305 | | ||||
306 | printDock = new QDockWidget(tr("Print"), this); | ||||
307 | printDock->setWidget(dockContents); | ||||
308 | | ||||
309 | menuView->insertAction(nullptr, printDock->toggleViewAction()); | ||||
310 | addDockWidget(Qt::LeftDockWidgetArea, printDock); | ||||
311 | } | ||||
312 | | ||||
313 | void MainWindow::makeTempTimelineDock() | ||||
314 | { | ||||
315 | plotWidget = new PlotWidget; | ||||
316 | tempTimelineDock = new QDockWidget(tr("Temperature Timeline"), this); | ||||
317 | tempTimelineDock->setWidget(plotWidget); | ||||
318 | menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); | ||||
319 | addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); | ||||
320 | } | ||||
321 | | ||||
322 | void MainWindow::makeLogDock() | ||||
323 | { | ||||
324 | textLog = new QPlainTextEdit; | ||||
325 | textLog->setReadOnly(true); | ||||
326 | textLog->setMaximumBlockCount(1000); | ||||
327 | | ||||
328 | auto *newButton = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton), tr("Save Session Log")); | ||||
329 | connect(newButton, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); | ||||
330 | | ||||
331 | auto *mainLayout = new QVBoxLayout; | ||||
332 | mainLayout->addWidget(textLog); | ||||
333 | mainLayout->addWidget(newButton); | ||||
334 | | ||||
335 | auto *dockContents = new QWidget(); | ||||
336 | dockContents->setLayout(mainLayout); | ||||
337 | | ||||
338 | logDock = new QDockWidget(tr("Session Log"), this); | ||||
339 | logDock->setWidget(dockContents); | ||||
340 | | ||||
341 | menuView->insertAction(nullptr, logDock->toggleViewAction()); | ||||
342 | addDockWidget(Qt::RightDockWidgetArea, logDock); | ||||
343 | } | ||||
344 | | ||||
345 | void MainWindow::makeConnectDock() | ||||
346 | { | ||||
347 | auto *mainLayout = new QVBoxLayout; | ||||
348 | auto *newLabel = new QLabel(tr("Port:")); | ||||
349 | | ||||
350 | comboPort = new QComboBox; | ||||
351 | comboPort->setEditable(true); | ||||
352 | | ||||
353 | auto *hBoxLayout = new QHBoxLayout; | ||||
354 | hBoxLayout->addWidget(newLabel); | ||||
355 | hBoxLayout->addWidget(comboPort, 75); | ||||
356 | mainLayout->addLayout(hBoxLayout); | ||||
357 | | ||||
358 | newLabel = new QLabel(tr("Baud Rate:")); | ||||
359 | comboBAUD = new QComboBox; | ||||
360 | comboBAUD->addItems(core->portSpeeds()); | ||||
361 | comboBAUD->setCurrentIndex(9); | ||||
362 | | ||||
363 | hBoxLayout = new QHBoxLayout; | ||||
364 | hBoxLayout->addWidget(newLabel); | ||||
365 | hBoxLayout->addWidget(comboBAUD, 75); | ||||
366 | mainLayout->addLayout(hBoxLayout); | ||||
367 | | ||||
368 | newLabel = new QLabel(tr("Use Plugin:")); | ||||
369 | comboPlugin = new QComboBox; | ||||
370 | comboPlugin->addItem(tr("Autodetect")); | ||||
371 | comboPlugin->addItems(core->availableFirmwarePlugins()); | ||||
372 | connect(comboPlugin, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); | ||||
373 | | ||||
374 | hBoxLayout = new QHBoxLayout; | ||||
375 | hBoxLayout->addWidget(newLabel); | ||||
376 | hBoxLayout->addWidget(comboPlugin, 75); | ||||
377 | mainLayout->addLayout(hBoxLayout); | ||||
378 | | ||||
379 | buttonConnect = new QPushButton(tr("Connect")); | ||||
380 | connect(buttonConnect, &QPushButton::clicked, this, &MainWindow::connectPBClicked); | ||||
381 | mainLayout->addWidget(buttonConnect); | ||||
382 | | ||||
383 | auto *dockContents = new QWidget; | ||||
384 | dockContents->setLayout(mainLayout); | ||||
385 | | ||||
386 | connectDock = new QDockWidget(tr("Connect"), this); | ||||
387 | connectDock->setWidget(dockContents); | ||||
388 | | ||||
389 | menuView->insertAction(nullptr, connectDock->toggleViewAction()); | ||||
390 | addDockWidget(Qt::LeftDockWidgetArea, connectDock); | ||||
391 | } | ||||
392 | | ||||
393 | void MainWindow::makeMoveDock() | ||||
394 | { | ||||
395 | auto *mainLayout = new QVBoxLayout; | ||||
396 | auto *hBoxLayout = new QHBoxLayout; | ||||
397 | | ||||
398 | auto *newButton = new QPushButton(tr("Home All")); | ||||
399 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); | ||||
400 | hBoxLayout->addWidget(newButton); | ||||
401 | | ||||
402 | newButton = new QPushButton(tr("Home X")); | ||||
403 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); | ||||
404 | hBoxLayout->addWidget(newButton); | ||||
405 | | ||||
406 | newButton = new QPushButton(tr("Home Y")); | ||||
407 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); | ||||
408 | hBoxLayout->addWidget(newButton); | ||||
409 | | ||||
410 | newButton = new QPushButton(tr("Home Z")); | ||||
411 | connect(newButton, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); | ||||
412 | hBoxLayout->addWidget(newButton); | ||||
413 | | ||||
414 | mainLayout->addLayout(hBoxLayout); | ||||
415 | | ||||
416 | comboMoveAxis = new QComboBox; | ||||
417 | comboMoveAxis->addItem(tr("Move X Axis to")); | ||||
418 | comboMoveAxis->addItem(tr("Move Y Axis to")); | ||||
419 | comboMoveAxis->addItem(tr("Move Z Axis to")); | ||||
420 | | ||||
421 | sbMoveAxis = new QDoubleSpinBox; | ||||
422 | sbMoveAxis->setRange(0, 200); | ||||
423 | | ||||
424 | newButton = new QPushButton(tr("Go")); | ||||
425 | connect(newButton, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); | ||||
426 | | ||||
427 | hBoxLayout = new QHBoxLayout; | ||||
428 | hBoxLayout->addWidget(comboMoveAxis); | ||||
429 | hBoxLayout->addWidget(sbMoveAxis); | ||||
430 | hBoxLayout->addWidget(newButton); | ||||
431 | mainLayout->addLayout(hBoxLayout); | ||||
432 | | ||||
433 | newButton = new QPushButton(tr("Disable Motors")); | ||||
434 | connect(newButton, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); | ||||
435 | mainLayout->addWidget(newButton); | ||||
436 | | ||||
437 | auto *axisControl = new AxisControl; | ||||
438 | connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); | ||||
439 | mainLayout->addWidget(axisControl); | ||||
440 | | ||||
441 | auto *dockContents = new QWidget; | ||||
442 | dockContents->setLayout(mainLayout); | ||||
443 | | ||||
444 | moveDock = new QDockWidget(tr("Movement"), this); | ||||
445 | moveDock->setWidget(dockContents); | ||||
446 | | ||||
447 | menuView->insertAction(nullptr, moveDock->toggleViewAction()); | ||||
448 | addDockWidget(Qt::LeftDockWidgetArea, moveDock); | ||||
449 | } | ||||
450 | | ||||
451 | void MainWindow::makeTempControlsDock() | ||||
452 | { | ||||
453 | auto *mainLayout = new QVBoxLayout; | ||||
454 | checkAndWait = new QCheckBox(tr("Wait Untill Temperature Stablizes")); | ||||
455 | mainLayout->addWidget(checkAndWait); | ||||
456 | | ||||
457 | auto label = new QLabel(tr("Bed Temp")); | ||||
458 | | ||||
459 | sbBedTemp = new QSpinBox; | ||||
460 | sbBedTemp->setRange(0, 120); | ||||
461 | sbBedTemp->setSuffix(QStringLiteral("°C")); | ||||
462 | | ||||
463 | auto *newButton = new QPushButton(tr("Set")); | ||||
464 | connect(newButton, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); | ||||
465 | | ||||
466 | auto *hboxLayout = new QHBoxLayout; | ||||
467 | hboxLayout->addWidget(label, 80); | ||||
468 | hboxLayout->addWidget(sbBedTemp); | ||||
469 | hboxLayout->addWidget(newButton); | ||||
470 | mainLayout->addItem(hboxLayout); | ||||
471 | | ||||
472 | comboExtruderSelect = new QComboBox; | ||||
473 | sbExtruderTemp = new QSpinBox; | ||||
474 | sbExtruderTemp->setRange(0, 275); | ||||
475 | sbExtruderTemp->setSuffix(QStringLiteral("°C")); | ||||
476 | | ||||
477 | newButton = new QPushButton(tr("Set")); | ||||
478 | connect(newButton, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); | ||||
479 | hboxLayout = new QHBoxLayout; | ||||
480 | hboxLayout->addWidget(comboExtruderSelect, 80); | ||||
481 | hboxLayout->addWidget(sbExtruderTemp); | ||||
482 | hboxLayout->addWidget(newButton); | ||||
483 | mainLayout->addItem(hboxLayout); | ||||
484 | | ||||
485 | comboFanSelect = new QComboBox; | ||||
486 | sbFanSpeed = new QSpinBox; | ||||
487 | sbFanSpeed->setRange(0, 100); | ||||
488 | sbFanSpeed->setSuffix(QStringLiteral("%")); | ||||
489 | | ||||
490 | newButton = new QPushButton(tr("Set")); | ||||
491 | connect(newButton, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); | ||||
492 | hboxLayout = new QHBoxLayout; | ||||
493 | hboxLayout->addWidget(comboFanSelect, 80); | ||||
494 | hboxLayout->addWidget(sbFanSpeed); | ||||
495 | hboxLayout->addWidget(newButton); | ||||
496 | mainLayout->addItem(hboxLayout); | ||||
497 | | ||||
498 | auto *dockContents = new QWidget; | ||||
499 | dockContents->setLayout(mainLayout); | ||||
500 | | ||||
501 | tempControlsDock = new QDockWidget(tr("Temperatures"), this); | ||||
502 | tempControlsDock->setWidget(dockContents); | ||||
503 | | ||||
504 | menuView->insertAction(nullptr, tempControlsDock->toggleViewAction()); | ||||
505 | addDockWidget(Qt::LeftDockWidgetArea, tempControlsDock); | ||||
506 | } | ||||
507 | | ||||
508 | void MainWindow::makeSdDock() | ||||
509 | { | ||||
510 | auto *hBoxLayout = new QHBoxLayout; | ||||
511 | | ||||
512 | auto *newButton = new QPushButton(tr("Get List")); | ||||
513 | connect(newButton, &QPushButton::clicked, this, &MainWindow::getSdList); | ||||
514 | hBoxLayout->addWidget(newButton); | ||||
515 | | ||||
516 | newButton = new QPushButton(tr("Print Selected")); | ||||
517 | connect(newButton, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); | ||||
518 | hBoxLayout->addWidget(newButton); | ||||
519 | | ||||
520 | newButton = new QPushButton(tr("Delete Selected")); | ||||
521 | connect(newButton, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); | ||||
522 | hBoxLayout->addWidget(newButton); | ||||
523 | | ||||
524 | auto *groupFiles = new QGroupBox(tr("Files On Sd Card")); | ||||
525 | listSdFiles = new QListWidget; | ||||
526 | auto *groupLayout = new QVBoxLayout; | ||||
527 | groupLayout->addWidget(listSdFiles); | ||||
528 | groupFiles->setLayout(groupLayout); | ||||
529 | | ||||
530 | auto *mainLayout = new QVBoxLayout; | ||||
531 | mainLayout->addItem(hBoxLayout); | ||||
532 | mainLayout->addWidget(groupFiles); | ||||
533 | | ||||
534 | auto *dockContents = new QWidget; | ||||
535 | dockContents->setLayout(mainLayout); | ||||
536 | | ||||
537 | sdDock = new QDockWidget(tr("Sd Card"), this); | ||||
538 | sdDock->setWidget(dockContents); | ||||
539 | | ||||
540 | menuView->insertAction(nullptr, sdDock->toggleViewAction()); | ||||
541 | addDockWidget(Qt::LeftDockWidgetArea, sdDock); | ||||
160 | } | 542 | } | ||
161 | 543 | | |||
162 | void MainWindow::closeEvent(QCloseEvent *event) | 544 | void MainWindow::closeEvent(QCloseEvent *event) | ||
163 | { | 545 | { | ||
164 | core->close(); | 546 | core->close(); | ||
165 | event->accept(); | 547 | event->accept(); | ||
166 | } | 548 | } | ||
167 | 549 | | |||
168 | MainWindow::~MainWindow() | 550 | MainWindow::~MainWindow() | ||
169 | { | 551 | { | ||
170 | delete logFile; | 552 | delete logFile; | ||
171 | delete ui; | | |||
172 | } | 553 | } | ||
173 | 554 | | |||
174 | QString MainWindow::getTime() | 555 | QString MainWindow::getTime() | ||
175 | { | 556 | { | ||
176 | return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); | 557 | return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); | ||
177 | } | 558 | } | ||
178 | 559 | | |||
179 | QString MainWindow::logHeader() | 560 | QString MainWindow::logHeader() | ||
Show All 24 Lines | 576 | { | |||
204 | logFile->write(text.toLatin1()); | 585 | logFile->write(text.toLatin1()); | ||
205 | logFile->putChar('\n'); | 586 | logFile->putChar('\n'); | ||
206 | logFile->close(); | 587 | logFile->close(); | ||
207 | } | 588 | } | ||
208 | 589 | | |||
209 | void MainWindow::addLog(QString msg) | 590 | void MainWindow::addLog(QString msg) | ||
210 | { | 591 | { | ||
211 | QString message(logHeader() + msg); | 592 | QString message(logHeader() + msg); | ||
212 | ui->logTE->appendPlainText(message); | 593 | textLog->appendPlainText(message); | ||
213 | writeTempFile(message); | 594 | writeTempFile(message); | ||
214 | } | 595 | } | ||
215 | 596 | | |||
216 | void MainWindow::addRLog(QString msg) | 597 | void MainWindow::addRLog(QString msg) | ||
217 | { | 598 | { | ||
218 | QString message(rLogHeader() + msg); | 599 | QString message(rLogHeader() + msg); | ||
219 | ui->logTE->appendPlainText(message); | 600 | textLog->appendPlainText(message); | ||
220 | writeTempFile(message); | 601 | writeTempFile(message); | ||
221 | } | 602 | } | ||
222 | 603 | | |||
223 | void MainWindow::addSLog(QString msg) | 604 | void MainWindow::addSLog(QString msg) | ||
224 | { | 605 | { | ||
225 | QString message(sLogHeader() + msg); | 606 | QString message(sLogHeader() + msg); | ||
226 | ui->logTE->appendPlainText(message); | 607 | textLog->appendPlainText(message); | ||
227 | writeTempFile(message); | 608 | writeTempFile(message); | ||
228 | } | 609 | } | ||
229 | 610 | | |||
230 | void MainWindow::checkReceivedCommand(const QByteArray &message) | 611 | void MainWindow::checkReceivedCommand(const QByteArray &message) | ||
231 | { | 612 | { | ||
232 | addRLog(QString::fromUtf8(message)); | 613 | addRLog(QString::fromUtf8(message)); | ||
233 | } | 614 | } | ||
234 | 615 | | |||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
279 | } | 660 | } | ||
280 | /** | 661 | /** | ||
281 | * @brief MainWindow::locateSerialPort | 662 | * @brief MainWindow::locateSerialPort | ||
282 | * Locate all active serial ports on the computer and add to the list | 663 | * Locate all active serial ports on the computer and add to the list | ||
283 | * of serial ports | 664 | * of serial ports | ||
284 | */ | 665 | */ | ||
285 | void MainWindow::locateSerialPort(const QStringList &ports) | 666 | void MainWindow::locateSerialPort(const QStringList &ports) | ||
286 | { | 667 | { | ||
287 | ui->serialPortCB->clear(); | 668 | comboPort->clear(); | ||
288 | if (!ports.isEmpty()) { | 669 | if (!ports.isEmpty()) { | ||
289 | ui->serialPortCB->addItems(ports); | 670 | comboPort->addItems(ports); | ||
290 | addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); | 671 | addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); | ||
291 | } else { | 672 | } else { | ||
292 | QString portError(tr("No available ports! Please connect a serial device to continue!")); | 673 | QString portError(tr("No available ports! Please connect a serial device to continue!")); | ||
293 | if (! ui->logTE->toPlainText().endsWith(portError)) { | 674 | if (! textLog->toPlainText().endsWith(portError)) { | ||
294 | addLog(portError); | 675 | addLog(portError); | ||
295 | } | 676 | } | ||
296 | } | 677 | } | ||
297 | } | 678 | } | ||
298 | 679 | | |||
299 | void MainWindow::connectPBClicked() | 680 | void MainWindow::connectPBClicked() | ||
300 | { | 681 | { | ||
301 | if (core->state() == AtCore::DISCONNECTED) { | 682 | if (core->state() == AtCore::DISCONNECTED) { | ||
302 | if (core->initSerial(ui->serialPortCB->currentText(), ui->baudRateLE->currentText().toInt())) { | 683 | if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) { | ||
303 | connect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | 684 | connect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | ||
304 | connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | 685 | connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | ||
305 | ui->connectPB->setText(tr("Disconnect")); | 686 | buttonConnect->setText(tr("Disconnect")); | ||
306 | addLog(tr("Serial connected")); | 687 | addLog(tr("Serial connected")); | ||
307 | if (ui->pluginCB->currentText().contains(tr("Autodetect"))) { | 688 | if (comboPlugin->currentText().contains(tr("Autodetect"))) { | ||
308 | addLog(tr("No plugin loaded !")); | 689 | addLog(tr("No plugin loaded !")); | ||
309 | addLog(tr("Requesting Firmware...")); | 690 | addLog(tr("Requesting Firmware...")); | ||
310 | } else { | 691 | } else { | ||
311 | core->loadFirmwarePlugin(ui->pluginCB->currentText()); | 692 | core->loadFirmwarePlugin(comboPlugin->currentText()); | ||
312 | } | 693 | } | ||
313 | } else { | 694 | } else { | ||
314 | addLog(tr("Failed to open serial in r/w mode")); | 695 | addLog(tr("Failed to open serial in r/w mode")); | ||
315 | } | 696 | } | ||
316 | } else { | 697 | } else { | ||
317 | disconnect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | 698 | disconnect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); | ||
318 | disconnect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | 699 | disconnect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); | ||
319 | core->closeConnection(); | 700 | core->closeConnection(); | ||
320 | core->setState(AtCore::DISCONNECTED); | 701 | core->setState(AtCore::DISCONNECTED); | ||
321 | addLog(tr("Disconnected")); | 702 | addLog(tr("Disconnected")); | ||
322 | ui->connectPB->setText(tr("Connect")); | 703 | buttonConnect->setText(tr("Connect")); | ||
323 | } | 704 | } | ||
324 | } | 705 | } | ||
325 | 706 | | |||
326 | void MainWindow::sendPBClicked() | 707 | void MainWindow::sendPBClicked() | ||
327 | { | 708 | { | ||
328 | QString comm = ui->commandLE->text().toUpper(); | 709 | QString comm = lineCommand->text().toUpper(); | ||
329 | core->pushCommand(comm); | 710 | core->pushCommand(comm); | ||
330 | ui->commandLE->clear(); | 711 | lineCommand->clear(); | ||
331 | } | 712 | } | ||
332 | 713 | | |||
333 | void MainWindow::homeAllPBClicked() | 714 | void MainWindow::homeAllPBClicked() | ||
334 | { | 715 | { | ||
335 | addSLog(tr("Home All")); | 716 | addSLog(tr("Home All")); | ||
336 | core->home(); | 717 | core->home(); | ||
337 | } | 718 | } | ||
338 | 719 | | |||
Show All 12 Lines | |||||
351 | void MainWindow::homeZPBClicked() | 732 | void MainWindow::homeZPBClicked() | ||
352 | { | 733 | { | ||
353 | addSLog(tr("Home Z")); | 734 | addSLog(tr("Home Z")); | ||
354 | core->home(AtCore::Z); | 735 | core->home(AtCore::Z); | ||
355 | } | 736 | } | ||
356 | 737 | | |||
357 | void MainWindow::bedTempPBClicked() | 738 | void MainWindow::bedTempPBClicked() | ||
358 | { | 739 | { | ||
359 | if (ui->cb_andWait->isChecked()) { | 740 | if (checkAndWait->isChecked()) { | ||
360 | addSLog(GCode::description(GCode::M190)); | 741 | addSLog(GCode::description(GCode::M190)); | ||
361 | } else { | 742 | } else { | ||
362 | addSLog(GCode::description(GCode::M140)); | 743 | addSLog(GCode::description(GCode::M140)); | ||
363 | } | 744 | } | ||
364 | core->setBedTemp(ui->bedTempSB->value(), ui->cb_andWait->isChecked()); | 745 | core->setBedTemp(sbBedTemp->value(), checkAndWait->isChecked()); | ||
365 | } | 746 | } | ||
366 | 747 | | |||
367 | void MainWindow::extTempPBClicked() | 748 | void MainWindow::extTempPBClicked() | ||
368 | { | 749 | { | ||
369 | if (ui->cb_andWait->isChecked()) { | 750 | if (checkAndWait->isChecked()) { | ||
370 | addSLog(GCode::description(GCode::M109)); | 751 | addSLog(GCode::description(GCode::M109)); | ||
371 | } else { | 752 | } else { | ||
372 | addSLog(GCode::description(GCode::M104)); | 753 | addSLog(GCode::description(GCode::M104)); | ||
373 | } | 754 | } | ||
374 | core->setExtruderTemp(ui->extTempSB->value(), ui->extTempSelCB->currentIndex(), ui->cb_andWait->isChecked()); | 755 | core->setExtruderTemp(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked()); | ||
375 | } | 756 | } | ||
376 | 757 | | |||
377 | void MainWindow::mvAxisPBClicked() | 758 | void MainWindow::mvAxisPBClicked() | ||
378 | { | 759 | { | ||
379 | addSLog(GCode::description(GCode::G1)); | 760 | addSLog(GCode::description(GCode::G1)); | ||
380 | if (ui->mvAxisCB->currentIndex() == 0) { | 761 | if (comboMoveAxis->currentIndex() == 0) { | ||
381 | core->move(AtCore::X, ui->mvAxisSB->value()); | 762 | core->move(AtCore::X, sbMoveAxis->value()); | ||
382 | } else if (ui->mvAxisCB->currentIndex() == 1) { | 763 | } else if (comboMoveAxis->currentIndex() == 1) { | ||
383 | core->move(AtCore::Y, ui->mvAxisSB->value()); | 764 | core->move(AtCore::Y, sbMoveAxis->value()); | ||
384 | } else if (ui->mvAxisCB->currentIndex() == 2) { | 765 | } else if (comboMoveAxis->currentIndex() == 2) { | ||
385 | core->move(AtCore::Z, ui->mvAxisSB->value()); | 766 | core->move(AtCore::Z, sbMoveAxis->value()); | ||
386 | } | 767 | } | ||
387 | } | 768 | } | ||
388 | 769 | | |||
389 | void MainWindow::fanSpeedPBClicked() | 770 | void MainWindow::fanSpeedPBClicked() | ||
390 | { | 771 | { | ||
391 | addSLog(GCode::description(GCode::M106)); | 772 | addSLog(GCode::description(GCode::M106)); | ||
392 | core->setFanSpeed(ui->fanSpeedSB->value(), ui->fanSpeedSelCB->currentIndex()); | 773 | core->setFanSpeed(sbFanSpeed->value(), comboFanSelect->currentIndex()); | ||
393 | } | 774 | } | ||
394 | 775 | | |||
395 | void MainWindow::printPBClicked() | 776 | void MainWindow::printPBClicked() | ||
396 | { | 777 | { | ||
397 | QString fileName; | 778 | QString fileName; | ||
398 | switch (core->state()) { | 779 | switch (core->state()) { | ||
399 | 780 | | |||
400 | case AtCore::DISCONNECTED: | 781 | case AtCore::DISCONNECTED: | ||
401 | QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); | 782 | QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); | ||
402 | break; | 783 | break; | ||
403 | 784 | | |||
404 | case AtCore::CONNECTING: | 785 | 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")); | 786 | 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")); | 787 | comboPlugin->setCurrentText(QStringLiteral("repetier")); | ||
407 | break; | 788 | break; | ||
408 | 789 | | |||
409 | case AtCore::IDLE: | 790 | case AtCore::IDLE: | ||
410 | fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), QStringLiteral("*.gcode")); | 791 | fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), tr("*.gcode")); | ||
411 | if (fileName.isNull()) { | 792 | if (fileName.isNull()) { | ||
412 | addLog(tr("No File Selected")); | 793 | addLog(tr("No File Selected")); | ||
413 | } else { | 794 | } else { | ||
414 | addLog(tr("Print: %1").arg(fileName)); | 795 | addLog(tr("Print: %1").arg(fileName)); | ||
415 | core->print(fileName); | 796 | core->print(fileName); | ||
416 | } | 797 | } | ||
417 | break; | 798 | break; | ||
418 | 799 | | |||
419 | case AtCore::BUSY: | 800 | case AtCore::BUSY: | ||
420 | core->pause(ui->postPauseLE->text()); | 801 | core->pause(linePostPause->text()); | ||
421 | break; | 802 | break; | ||
422 | 803 | | |||
423 | case AtCore::PAUSE: | 804 | case AtCore::PAUSE: | ||
424 | core->resume(); | 805 | core->resume(); | ||
425 | break; | 806 | break; | ||
426 | 807 | | |||
427 | default: | 808 | default: | ||
428 | qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; | 809 | qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; | ||
Show All 14 Lines | 823 | if (core->state() != AtCore::DISCONNECTED) { | |||
443 | if (!currentText.contains(tr("Autodetect"))) { | 824 | if (!currentText.contains(tr("Autodetect"))) { | ||
444 | core->loadFirmwarePlugin(currentText); | 825 | core->loadFirmwarePlugin(currentText); | ||
445 | } | 826 | } | ||
446 | } | 827 | } | ||
447 | } | 828 | } | ||
448 | 829 | | |||
449 | void MainWindow::flowRatePBClicked() | 830 | void MainWindow::flowRatePBClicked() | ||
450 | { | 831 | { | ||
451 | core->setFlowRate(ui->flowRateSB->value()); | 832 | core->setFlowRate(sbFlowRate->value()); | ||
452 | } | 833 | } | ||
453 | 834 | | |||
454 | void MainWindow::printerSpeedPBClicked() | 835 | void MainWindow::printerSpeedPBClicked() | ||
455 | { | 836 | { | ||
456 | core->setPrinterSpeed(ui->printerSpeedSB->value()); | 837 | core->setPrinterSpeed(sbPrintSpeed->value()); | ||
457 | } | 838 | } | ||
458 | 839 | | |||
459 | void MainWindow::printerStateChanged(AtCore::STATES state) | 840 | void MainWindow::printerStateChanged(AtCore::STATES state) | ||
460 | { | 841 | { | ||
461 | QString stateString; | 842 | QString stateString; | ||
462 | switch (state) { | 843 | switch (state) { | ||
463 | case AtCore::IDLE: | 844 | case AtCore::IDLE: | ||
464 | ui->printPB->setText(tr("Print File")); | 845 | buttonPrint->setText(tr("Print File")); | ||
465 | stateString = QStringLiteral("Connected to ") + core->connectedPort(); | 846 | stateString = tr("Connected to ") + core->connectedPort(); | ||
466 | break; | 847 | break; | ||
467 | 848 | | |||
468 | case AtCore::STARTPRINT: | 849 | case AtCore::STARTPRINT: | ||
469 | stateString = QStringLiteral("START PRINT"); | 850 | stateString = tr("START PRINT"); | ||
470 | ui->printPB->setText(tr("Pause Print")); | 851 | buttonPrint->setText(tr("Pause Print")); | ||
471 | ui->printLayout->setVisible(true); | 852 | printProgressWidget->setVisible(true); | ||
472 | printTime->start(); | 853 | printTime->start(); | ||
473 | printTimer->start(); | 854 | printTimer->start(); | ||
474 | break; | 855 | break; | ||
475 | 856 | | |||
476 | case AtCore::FINISHEDPRINT: | 857 | case AtCore::FINISHEDPRINT: | ||
477 | stateString = QStringLiteral("Finished Print"); | 858 | stateString = tr("Finished Print"); | ||
478 | ui->printPB->setText(tr("Print File")); | 859 | buttonPrint->setText(tr("Print File")); | ||
479 | ui->printLayout->setVisible(false); | 860 | printProgressWidget->setVisible(false); | ||
480 | printTimer->stop(); | 861 | printTimer->stop(); | ||
481 | break; | 862 | break; | ||
482 | 863 | | |||
483 | case AtCore::PAUSE: | 864 | case AtCore::PAUSE: | ||
484 | stateString = QStringLiteral("Paused"); | 865 | stateString = tr("Paused"); | ||
485 | ui->printPB->setText(tr("Resume Print")); | 866 | buttonPrint->setText(tr("Resume Print")); | ||
486 | break; | 867 | break; | ||
487 | 868 | | |||
488 | case AtCore::BUSY: | 869 | case AtCore::BUSY: | ||
489 | stateString = QStringLiteral("Printing"); | 870 | stateString = tr("Printing"); | ||
490 | ui->printPB->setText(tr("Pause Print")); | 871 | buttonPrint->setText(tr("Pause Print")); | ||
491 | break; | 872 | break; | ||
492 | 873 | | |||
493 | case AtCore::DISCONNECTED: | 874 | case AtCore::DISCONNECTED: | ||
494 | stateString = QStringLiteral("Not Connected"); | 875 | stateString = QStringLiteral("Not Connected"); | ||
495 | setDangeriousDocksDisabled(true); | 876 | setDangeriousDocksDisabled(true); | ||
496 | break; | 877 | break; | ||
497 | 878 | | |||
498 | case AtCore::CONNECTING: | 879 | case AtCore::CONNECTING: | ||
499 | stateString = QStringLiteral("Connecting"); | 880 | stateString = QStringLiteral("Connecting"); | ||
500 | setDangeriousDocksDisabled(false); | 881 | setDangeriousDocksDisabled(false); | ||
501 | break; | 882 | break; | ||
502 | 883 | | |||
503 | case AtCore::STOP: | 884 | case AtCore::STOP: | ||
504 | stateString = QStringLiteral("Stoping Print"); | 885 | stateString = tr("Stoping Print"); | ||
505 | break; | 886 | break; | ||
506 | 887 | | |||
507 | case AtCore::ERRORSTATE: | 888 | case AtCore::ERRORSTATE: | ||
508 | stateString = QStringLiteral("Command ERROR"); | 889 | stateString = tr("Command ERROR"); | ||
509 | break; | 890 | break; | ||
510 | } | 891 | } | ||
511 | ui->lblState->setText(stateString); | 892 | lblState->setText(stateString); | ||
512 | } | 893 | } | ||
513 | 894 | | |||
514 | void MainWindow::populateCBs() | 895 | void MainWindow::populateCBs() | ||
515 | { | 896 | { | ||
516 | // Extruders | 897 | // Extruders | ||
517 | for (int count = 0; count < core->extruderCount(); count++) { | 898 | for (int count = 0; count < core->extruderCount(); count++) { | ||
518 | ui->extTempSelCB->insertItem(count, tr("Extruder %1").arg(count)); | 899 | comboExtruderSelect->insertItem(count, tr("Extruder %1").arg(count)); | ||
519 | } | 900 | } | ||
520 | 901 | | |||
521 | // Fan | 902 | // Fan | ||
522 | for (int count = 0; count < fanCount; count++) { | 903 | for (int count = 0; count < fanCount; count++) { | ||
523 | ui->fanSpeedSelCB->insertItem(count, tr("Fan %1 speed").arg(count)); | 904 | comboFanSelect->insertItem(count, tr("Fan %1 speed").arg(count)); | ||
524 | } | 905 | } | ||
525 | } | 906 | } | ||
526 | 907 | | |||
527 | void MainWindow::showMessage() | 908 | void MainWindow::showMessage() | ||
528 | { | 909 | { | ||
529 | core->showMessage(ui->messageLE->text()); | 910 | core->showMessage(lineMessage->text()); | ||
530 | } | 911 | } | ||
531 | 912 | | |||
532 | void MainWindow::updatePrintTime() | 913 | void MainWindow::updatePrintTime() | ||
533 | { | 914 | { | ||
534 | QTime temp(0, 0, 0); | 915 | QTime temp(0, 0, 0); | ||
535 | ui->time->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); | 916 | lblTime->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); | ||
536 | } | 917 | } | ||
537 | 918 | | |||
538 | void MainWindow::printProgressChanged(int progress) | 919 | void MainWindow::printProgressChanged(int progress) | ||
539 | { | 920 | { | ||
540 | ui->printingProgress->setValue(progress); | 921 | printingProgress->setValue(progress); | ||
541 | if (progress > 0) { | 922 | if (progress > 0) { | ||
542 | QTime temp(0, 0, 0); | 923 | QTime temp(0, 0, 0); | ||
543 | ui->timeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); | 924 | lblTimeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); | ||
544 | } else { | 925 | } else { | ||
545 | ui->timeLeft->setText(QStringLiteral("??:??:??")); | 926 | lblTimeLeft->setText(QStringLiteral("??:??:??")); | ||
546 | } | 927 | } | ||
547 | } | 928 | } | ||
548 | void MainWindow::toggleDockTitles() | 929 | void MainWindow::toggleDockTitles(bool checked) | ||
549 | { | 930 | { | ||
550 | if (ui->actionShowDockTitles->isChecked()) { | 931 | if (checked) { | ||
551 | delete ui->connectDock->titleBarWidget(); | 932 | delete connectDock->titleBarWidget(); | ||
552 | delete ui->logDock->titleBarWidget(); | 933 | delete logDock->titleBarWidget(); | ||
553 | delete ui->tempTimelineDock->titleBarWidget(); | 934 | delete tempTimelineDock->titleBarWidget(); | ||
554 | delete ui->commandDock->titleBarWidget(); | 935 | delete commandDock->titleBarWidget(); | ||
555 | delete ui->moveDock->titleBarWidget(); | 936 | delete moveDock->titleBarWidget(); | ||
556 | delete ui->tempControlsDock->titleBarWidget(); | 937 | delete tempControlsDock->titleBarWidget(); | ||
557 | delete ui->printDock->titleBarWidget(); | 938 | delete printDock->titleBarWidget(); | ||
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… | |||||
558 | delete ui->sdDock->titleBarWidget(); | 939 | delete sdDock->titleBarWidget(); | ||
559 | } else { | 940 | } else { | ||
560 | ui->connectDock->setTitleBarWidget(new QWidget()); | 941 | connectDock->setTitleBarWidget(new QWidget()); | ||
561 | ui->logDock->setTitleBarWidget(new QWidget()); | 942 | logDock->setTitleBarWidget(new QWidget()); | ||
562 | ui->tempTimelineDock->setTitleBarWidget(new QWidget()); | 943 | tempTimelineDock->setTitleBarWidget(new QWidget()); | ||
563 | ui->commandDock->setTitleBarWidget(new QWidget()); | 944 | commandDock->setTitleBarWidget(new QWidget()); | ||
564 | ui->moveDock->setTitleBarWidget(new QWidget()); | 945 | moveDock->setTitleBarWidget(new QWidget()); | ||
565 | ui->tempControlsDock->setTitleBarWidget(new QWidget()); | 946 | tempControlsDock->setTitleBarWidget(new QWidget()); | ||
566 | ui->printDock->setTitleBarWidget(new QWidget()); | 947 | printDock->setTitleBarWidget(new QWidget()); | ||
567 | ui->sdDock->setTitleBarWidget(new QWidget()); | 948 | sdDock->setTitleBarWidget(new QWidget()); | ||
568 | } | 949 | } | ||
569 | } | 950 | } | ||
570 | 951 | | |||
571 | void MainWindow::setDangeriousDocksDisabled(bool disabled) | 952 | void MainWindow::setDangeriousDocksDisabled(bool disabled) | ||
572 | { | 953 | { | ||
573 | ui->commandDock->widget()->setDisabled(disabled); | 954 | commandDock->widget()->setDisabled(disabled); | ||
574 | ui->moveDock->widget()->setDisabled(disabled); | 955 | moveDock->widget()->setDisabled(disabled); | ||
575 | ui->tempControlsDock->widget()->setDisabled(disabled); | 956 | tempControlsDock->widget()->setDisabled(disabled); | ||
576 | ui->printDock->widget()->setDisabled(disabled); | 957 | printDock->widget()->setDisabled(disabled); | ||
577 | ui->sdDock->widget()->setDisabled(disabled); | 958 | sdDock->widget()->setDisabled(disabled); | ||
578 | } | | |||
579 | | ||||
580 | void MainWindow::about() | | |||
581 | { | | |||
582 | About *aboutDialog = new About(this); | | |||
583 | aboutDialog->exec(); | | |||
584 | } | 959 | } | ||
585 | 960 | | |||
586 | void MainWindow::axisControlClicked(QLatin1Char axis, int value) | 961 | void MainWindow::axisControlClicked(QLatin1Char axis, int value) | ||
587 | { | 962 | { | ||
588 | core->setRelativePosition(); | 963 | core->setRelativePosition(); | ||
589 | core->move(axis, value); | 964 | core->move(axis, value); | ||
590 | core->setAbsolutePosition(); | 965 | core->setAbsolutePosition(); | ||
591 | } | 966 | } | ||
592 | 967 | | |||
593 | void MainWindow::disableMotorsPBClicked() | 968 | void MainWindow::disableMotorsPBClicked() | ||
594 | { | 969 | { | ||
595 | core->disableMotors(0); | 970 | core->disableMotors(0); | ||
596 | } | 971 | } | ||
597 | 972 | | |||
598 | void MainWindow::sdChanged(bool mounted) | 973 | void MainWindow::sdChanged(bool mounted) | ||
599 | { | 974 | { | ||
600 | QString labelText = mounted ? QStringLiteral("SD") : QString(); | 975 | QString labelText = mounted ? tr("SD") : QString(); | ||
601 | ui->lbl_sd->setText(labelText); | 976 | lblSd->setText(labelText); | ||
602 | } | 977 | } | ||
603 | 978 | | |||
604 | void MainWindow::getSdList() | 979 | void MainWindow::getSdList() | ||
605 | { | 980 | { | ||
606 | core->sdFileList(); | 981 | core->sdFileList(); | ||
607 | } | 982 | } | ||
608 | 983 | | |||
609 | void MainWindow::sdPrintPBClicked() | 984 | void MainWindow::sdPrintPBClicked() | ||
610 | { | 985 | { | ||
611 | if (ui->sdFileListView->currentRow() < 0) { | 986 | if (listSdFiles->currentRow() < 0) { | ||
612 | QMessageBox::information(this, QStringLiteral("Print Error"), QStringLiteral("You must Select a file from the list")); | 987 | QMessageBox::information(this, tr("Print Error"), tr("You must Select a file from the list")); | ||
613 | } else { | 988 | } else { | ||
614 | core->print(ui->sdFileListView->currentItem()->text(), true); | 989 | core->print(listSdFiles->currentItem()->text(), true); | ||
615 | } | 990 | } | ||
616 | } | 991 | } | ||
617 | 992 | | |||
618 | void MainWindow::sdDelPBClicked() | 993 | void MainWindow::sdDelPBClicked() | ||
619 | { | 994 | { | ||
620 | if (ui->sdFileListView->currentRow() < 0) { | 995 | if (listSdFiles->currentRow() < 0) { | ||
621 | QMessageBox::information(this, QStringLiteral("Delete Error"), QStringLiteral("You must Select a file from the list")); | 996 | QMessageBox::information(this, tr("Delete Error"), tr("You must Select a file from the list")); | ||
622 | } else { | 997 | } else { | ||
623 | core->sdDelete(ui->sdFileListView->currentItem()->text()); | 998 | core->sdDelete(listSdFiles->currentItem()->text()); | ||
624 | ui->sdFileListView->setCurrentRow(-1); | 999 | listSdFiles->setCurrentRow(-1); | ||
625 | } | 1000 | } | ||
626 | } | 1001 | } |
use tr so we can have translation.