Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/atcoreinstancewidget.cpp
Show All 20 Lines | |||||
21 | #include <QToolBar> | 21 | #include <QToolBar> | ||
22 | #include <AtCore/SerialLayer> | 22 | #include <AtCore/SerialLayer> | ||
23 | #include <AtCore/GCodeCommands> | 23 | #include <AtCore/GCodeCommands> | ||
24 | #include <KLocalizedString> | 24 | #include <KLocalizedString> | ||
25 | #include "choosefiledialog.h" | 25 | #include "choosefiledialog.h" | ||
26 | 26 | | |||
27 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | 27 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | ||
28 | QWidget(parent), | 28 | QWidget(parent), | ||
29 | m_mainToolBar(nullptr), | | |||
30 | m_toolBar(nullptr), | 29 | m_toolBar(nullptr), | ||
31 | m_printAction(nullptr) | 30 | m_printAction(nullptr) | ||
32 | { | 31 | { | ||
33 | m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ; | 32 | m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ; | ||
34 | ui = new Ui::AtCoreInstanceWidget; | 33 | ui = new Ui::AtCoreInstanceWidget; | ||
35 | ui->setupUi(this); | 34 | ui->setupUi(this); | ||
36 | ui->printProgressWidget->setVisible(false); | 35 | ui->printProgressWidget->setVisible(false); | ||
37 | buildMainToolbar(); | | |||
38 | buildToolbar(); | 36 | buildToolbar(); | ||
39 | buildConnectionToolbar(); | 37 | buildConnectionToolbar(); | ||
40 | enableControls(false); | 38 | enableControls(false); | ||
41 | updateProfileData(); | 39 | updateProfileData(); | ||
42 | initConnectsToAtCore(); | 40 | initConnectsToAtCore(); | ||
43 | m_mainToolBar->setHidden(true); | 41 | m_toolBar->setHidden(true); | ||
44 | | ||||
45 | } | 42 | } | ||
46 | 43 | | |||
47 | AtCoreInstanceWidget::~AtCoreInstanceWidget() | 44 | AtCoreInstanceWidget::~AtCoreInstanceWidget() | ||
48 | { | 45 | { | ||
49 | m_core.closeConnection(); | 46 | m_core.closeConnection(); | ||
50 | delete ui; | 47 | delete ui; | ||
51 | } | 48 | } | ||
52 | 49 | | |||
53 | void AtCoreInstanceWidget::buildToolbar() | 50 | void AtCoreInstanceWidget::buildToolbar() | ||
54 | { | 51 | { | ||
55 | m_toolBar = new QToolBar(); | 52 | m_toolBar = new QToolBar(); | ||
53 | m_toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||||
56 | 54 | | |||
57 | auto lb = new QAction; | 55 | auto lb = new QAction; | ||
58 | lb->setIcon(QIcon::fromTheme("go-home", QIcon(QString(":/%1/home").arg(m_theme)))); | 56 | lb->setIcon(QIcon::fromTheme("go-home", QIcon(QString(":/%1/home").arg(m_theme)))); | ||
59 | 57 | | |||
60 | lb->setDisabled(true); | 58 | lb->setDisabled(true); | ||
61 | m_toolBar->addAction(lb); | 59 | m_toolBar->addAction(lb); | ||
62 | 60 | | |||
63 | auto homeAll = new QAction("All"); | 61 | auto homeAll = new QAction("All"); | ||
Show All 25 Lines | |||||
89 | auto plot = new QAction("Temperature Plot"); | 87 | auto plot = new QAction("Temperature Plot"); | ||
90 | plot->setCheckable(true); | 88 | plot->setCheckable(true); | ||
91 | plot->setChecked(true); | 89 | plot->setChecked(true); | ||
92 | connect(plot, &QAction::toggled, ui->plotWidget, &PlotWidget::setVisible); | 90 | connect(plot, &QAction::toggled, ui->plotWidget, &PlotWidget::setVisible); | ||
93 | 91 | | |||
94 | m_toolBar->addAction(axis); | 92 | m_toolBar->addAction(axis); | ||
95 | m_toolBar->addAction(controls); | 93 | m_toolBar->addAction(controls); | ||
96 | m_toolBar->addAction(plot); | 94 | m_toolBar->addAction(plot); | ||
97 | ui->toolBarLayout->addWidget(m_toolBar); | | |||
98 | ui->toolBarLayout->addStretch(); | | |||
99 | } | | |||
100 | | ||||
101 | void AtCoreInstanceWidget::buildMainToolbar(){ | | |||
102 | m_mainToolBar = new QToolBar(); | | |||
103 | m_mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | | |||
104 | 95 | | |||
105 | m_printAction = new QAction(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)),i18n("Print")); | 96 | m_printAction = new QAction(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)),i18n("Print")); | ||
106 | connect(m_printAction, &QAction::triggered, [ this ](){ | 97 | connect(m_printAction, &QAction::triggered, [ this ](){ | ||
107 | if(m_core.state() == AtCore::BUSY) { | 98 | if(m_core.state() == AtCore::BUSY) { | ||
108 | pausePrint(); | 99 | pausePrint(); | ||
109 | return; | 100 | return; | ||
110 | } | 101 | } | ||
111 | if (m_core.state() == AtCore::IDLE){ | 102 | if (m_core.state() == AtCore::IDLE){ | ||
112 | print(); | 103 | print(); | ||
113 | } else if (m_core.state() == AtCore::PAUSE) { | 104 | } else if (m_core.state() == AtCore::PAUSE) { | ||
114 | m_core.resume(); | 105 | m_core.resume(); | ||
115 | } | 106 | } | ||
116 | }); | 107 | }); | ||
117 | m_mainToolBar->addAction(m_printAction); | 108 | m_toolBar->addAction(m_printAction); | ||
118 | 109 | | |||
119 | auto stopAction = new QAction(QIcon::fromTheme("media-playback-stop", QIcon(QString(":/%1/stop").arg(m_theme))), i18n("Stop")); | 110 | auto stopAction = new QAction(QIcon::fromTheme("media-playback-stop", QIcon(QString(":/%1/stop").arg(m_theme))), i18n("Stop")); | ||
120 | 111 | | |||
121 | connect(stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint); | 112 | connect(stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint); | ||
122 | connect(stopAction, &QAction::triggered, [this](){ | 113 | connect(stopAction, &QAction::triggered, [this](){ | ||
123 | m_printAction->setText(i18n("Print")); | 114 | m_printAction->setText(i18n("Print")); | ||
124 | m_printAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(QString(":/%1/start").arg(m_theme)))); | 115 | m_printAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(QString(":/%1/start").arg(m_theme)))); | ||
125 | }); | 116 | }); | ||
126 | m_mainToolBar->addAction(stopAction); | 117 | m_toolBar->addAction(stopAction); | ||
127 | 118 | | |||
128 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | 119 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | ||
129 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | 120 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | ||
130 | m_mainToolBar->addAction(disableMotorsAction); | 121 | m_toolBar->addAction(disableMotorsAction); | ||
131 | 122 | | |||
132 | ui->mainToolBarLayout->addWidget(m_mainToolBar); | 123 | ui->toolBarLayout->addWidget(m_toolBar); | ||
133 | } | 124 | } | ||
134 | 125 | | |||
135 | void AtCoreInstanceWidget::buildConnectionToolbar() | 126 | void AtCoreInstanceWidget::buildConnectionToolbar() | ||
136 | { | 127 | { | ||
137 | m_connectToolBar = new QToolBar(); | 128 | m_connectToolBar = new QToolBar(); | ||
138 | m_comboPort = new QComboBox; | 129 | m_comboPort = new QComboBox; | ||
139 | m_comboPort->setEditable(true); | 130 | m_comboPort->setEditable(true); | ||
140 | QLabel *deviceLabel = new QLabel(i18n("Device")); | 131 | QLabel *deviceLabel = new QLabel(i18n("Device")); | ||
Show All 15 Lines | |||||
156 | m_connectWidget = new QWidget(); | 147 | m_connectWidget = new QWidget(); | ||
157 | m_connectWidget->setLayout(connectLayout); | 148 | m_connectWidget->setLayout(connectLayout); | ||
158 | m_connectToolBar->addWidget(m_connectWidget); | 149 | m_connectToolBar->addWidget(m_connectWidget); | ||
159 | 150 | | |||
160 | m_connectButton = new QPushButton(QIcon::fromTheme("network-connect", QIcon(QString(":/%1/connect").arg(m_theme))), i18n("Connect")); | 151 | m_connectButton = new QPushButton(QIcon::fromTheme("network-connect", QIcon(QString(":/%1/connect").arg(m_theme))), i18n("Connect")); | ||
161 | m_connectButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); | 152 | m_connectButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); | ||
162 | connect(this, &AtCoreInstanceWidget::disableDisconnect, m_connectButton, &QPushButton::setDisabled); | 153 | connect(this, &AtCoreInstanceWidget::disableDisconnect, m_connectButton, &QPushButton::setDisabled); | ||
163 | connect(m_connectButton, &QPushButton::clicked, this, &AtCoreInstanceWidget::connectButtonClicked); | 154 | connect(m_connectButton, &QPushButton::clicked, this, &AtCoreInstanceWidget::connectButtonClicked); | ||
164 | ui->mainToolBarLayout->addWidget(m_connectToolBar); | 155 | ui->toolBarLayout->addWidget(m_connectToolBar); | ||
165 | ui->mainToolBarLayout->addWidget(m_connectButton); | 156 | ui->toolBarLayout->addWidget(m_connectButton); | ||
166 | 157 | | |||
167 | } | 158 | } | ||
168 | 159 | | |||
169 | void AtCoreInstanceWidget::connectButtonClicked() | 160 | void AtCoreInstanceWidget::connectButtonClicked() | ||
170 | { | 161 | { | ||
171 | if(m_core.state() == AtCore::DISCONNECTED) { | 162 | if(m_core.state() == AtCore::DISCONNECTED) { | ||
172 | if (m_comboProfile->currentText().isEmpty()) { | 163 | if (m_comboProfile->currentText().isEmpty()) { | ||
173 | QMessageBox::information(this, i18n("No Profiles!"), i18n("Connecting Requires creating a profile for your printer. Create a profile in the next dialog then try again.")); | 164 | QMessageBox::information(this, i18n("No Profiles!"), i18n("Connecting Requires creating a profile for your printer. Create a profile in the next dialog then try again.")); | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | |||||
311 | { | 302 | { | ||
312 | static QString stateString; | 303 | static QString stateString; | ||
313 | switch (newState) { | 304 | switch (newState) { | ||
314 | case AtCore::CONNECTING: { | 305 | case AtCore::CONNECTING: { | ||
315 | m_core.setSerialTimerInterval(0); | 306 | m_core.setSerialTimerInterval(0); | ||
316 | m_connectButton->setText(i18n("Disconnect")); | 307 | m_connectButton->setText(i18n("Disconnect")); | ||
317 | m_connectButton->setIcon(QIcon::fromTheme("network-disconnect", QIcon(QString(":/%1/disconnect").arg(m_theme)))); | 308 | m_connectButton->setIcon(QIcon::fromTheme("network-disconnect", QIcon(QString(":/%1/disconnect").arg(m_theme)))); | ||
318 | m_connectToolBar->setHidden(true); | 309 | m_connectToolBar->setHidden(true); | ||
319 | m_mainToolBar->setHidden(false); | 310 | m_toolBar->setHidden(false); | ||
320 | stateString = i18n("Connecting..."); | 311 | stateString = i18n("Connecting..."); | ||
321 | connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 312 | connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | ||
322 | connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 313 | connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | ||
323 | } break; | 314 | } break; | ||
324 | case AtCore::IDLE: { | 315 | case AtCore::IDLE: { | ||
325 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | 316 | stateString = i18n("Connected to ") + m_core.serial()->portName(); | ||
326 | emit extruderCountChanged(m_core.extruderCount()); | 317 | emit extruderCountChanged(m_core.extruderCount()); | ||
327 | ui->logWidget->addLog(i18n("Serial connected")); | 318 | ui->logWidget->addLog(i18n("Serial connected")); | ||
328 | emit disableDisconnect(false); | 319 | emit disableDisconnect(false); | ||
329 | enableControls(true); | 320 | enableControls(true); | ||
330 | } break; | 321 | } break; | ||
331 | case AtCore::DISCONNECTED: { | 322 | case AtCore::DISCONNECTED: { | ||
332 | stateString = i18n("Not Connected"); | 323 | stateString = i18n("Not Connected"); | ||
333 | disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | 324 | disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); | ||
334 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | 325 | disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); | ||
335 | ui->logWidget->addLog(i18n("Serial disconnected")); | 326 | ui->logWidget->addLog(i18n("Serial disconnected")); | ||
336 | m_core.setSerialTimerInterval(100); | 327 | m_core.setSerialTimerInterval(100); | ||
337 | m_connectButton->setText(i18n("Connect")); | 328 | m_connectButton->setText(i18n("Connect")); | ||
338 | m_connectButton->setIcon(QIcon::fromTheme("network-connect",QIcon(QString(":/%1/connect").arg(m_theme)))); | 329 | m_connectButton->setIcon(QIcon::fromTheme("network-connect",QIcon(QString(":/%1/connect").arg(m_theme)))); | ||
339 | m_connectToolBar->setHidden(false); | 330 | m_connectToolBar->setHidden(false); | ||
340 | m_mainToolBar->setHidden(true); | 331 | m_toolBar->setHidden(true); | ||
341 | enableControls(false); | 332 | enableControls(false); | ||
342 | } break; | 333 | } break; | ||
343 | case AtCore::STARTPRINT: { | 334 | case AtCore::STARTPRINT: { | ||
344 | stateString = i18n("Starting Print"); | 335 | stateString = i18n("Starting Print"); | ||
345 | ui->printProgressWidget->setVisible(true); | 336 | ui->printProgressWidget->setVisible(true); | ||
346 | connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); | 337 | connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar); | ||
347 | } break; | 338 | } break; | ||
348 | case AtCore::FINISHEDPRINT: { | 339 | case AtCore::FINISHEDPRINT: { | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 422 | { | |||
432 | m_core.setRelativePosition(); | 423 | m_core.setRelativePosition(); | ||
433 | m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); | 424 | m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); | ||
434 | m_core.setAbsolutePosition(); | 425 | m_core.setAbsolutePosition(); | ||
435 | } | 426 | } | ||
436 | 427 | | |||
437 | void AtCoreInstanceWidget::enableControls(bool b) | 428 | void AtCoreInstanceWidget::enableControls(bool b) | ||
438 | { | 429 | { | ||
439 | ui->mainTab->setEnabled(b); | 430 | ui->mainTab->setEnabled(b); | ||
440 | m_mainToolBar->setEnabled(b); | | |||
441 | m_toolBar->setEnabled(b); | 431 | m_toolBar->setEnabled(b); | ||
442 | } | 432 | } | ||
443 | 433 | | |||
444 | bool AtCoreInstanceWidget::connected() | 434 | bool AtCoreInstanceWidget::connected() | ||
445 | { | 435 | { | ||
446 | return (m_core.state() != AtCore::DISCONNECTED); | 436 | return (m_core.state() != AtCore::DISCONNECTED); | ||
447 | } | 437 | } | ||
448 | 438 | | |||
Show All 19 Lines |