Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/atcoreinstancewidget.cpp
Show All 23 Lines | |||||
24 | #include <AtCore/GCodeCommands> | 24 | #include <AtCore/GCodeCommands> | ||
25 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
26 | #include "choosefiledialog.h" | 26 | #include "choosefiledialog.h" | ||
27 | 27 | | |||
28 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | 28 | AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent): | ||
29 | QWidget(parent), | 29 | QWidget(parent), | ||
30 | m_mainToolBar(nullptr), | 30 | m_mainToolBar(nullptr), | ||
31 | m_toolBar(nullptr), | 31 | m_toolBar(nullptr), | ||
32 | m_printAction(nullptr) | 32 | m_printAction(nullptr), | ||
33 | m_stopAction(nullptr) | ||||
33 | { | 34 | { | ||
34 | m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ; | 35 | m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ; | ||
35 | ui = new Ui::AtCoreInstanceWidget; | 36 | ui = new Ui::AtCoreInstanceWidget; | ||
36 | ui->setupUi(this); | 37 | ui->setupUi(this); | ||
37 | ui->printProgressWidget->setVisible(false); | 38 | ui->printProgressWidget->setVisible(false); | ||
38 | buildMainToolbar(); | 39 | buildMainToolbar(); | ||
39 | buildToolbar(); | 40 | buildToolbar(); | ||
40 | buildConnectionToolbar(); | 41 | buildConnectionToolbar(); | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 109 | connect(m_printAction, &QAction::triggered, [ this ](){ | |||
113 | if (m_core.state() == AtCore::IDLE){ | 114 | if (m_core.state() == AtCore::IDLE){ | ||
114 | print(); | 115 | print(); | ||
115 | } else if (m_core.state() == AtCore::PAUSE) { | 116 | } else if (m_core.state() == AtCore::PAUSE) { | ||
116 | m_core.resume(); | 117 | m_core.resume(); | ||
117 | } | 118 | } | ||
118 | }); | 119 | }); | ||
119 | m_mainToolBar->addAction(m_printAction); | 120 | m_mainToolBar->addAction(m_printAction); | ||
120 | 121 | | |||
121 | auto stopAction = new QAction(QIcon::fromTheme("media-playback-stop", QIcon(QString(":/%1/stop").arg(m_theme))), i18n("Stop")); | 122 | m_stopAction = new QAction(QIcon::fromTheme("media-playback-stop", QIcon(QString(":/%1/stop").arg(m_theme))), i18n("Stop")); | ||
122 | 123 | connect(m_stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint); | |||
123 | connect(stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint); | 124 | connect(m_stopAction, &QAction::triggered, [this](){ | ||
124 | connect(stopAction, &QAction::triggered, [this](){ | | |||
125 | m_printAction->setText(i18n("Print")); | 125 | m_printAction->setText(i18n("Print")); | ||
126 | m_printAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(QString(":/%1/start").arg(m_theme)))); | 126 | m_printAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(QString(":/%1/start").arg(m_theme)))); | ||
127 | }); | 127 | }); | ||
128 | m_mainToolBar->addAction(stopAction); | 128 | m_mainToolBar->addAction(m_stopAction); | ||
129 | 129 | | |||
130 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | 130 | auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors")); | ||
131 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | 131 | connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors); | ||
132 | m_mainToolBar->addAction(disableMotorsAction); | 132 | m_mainToolBar->addAction(disableMotorsAction); | ||
133 | 133 | | |||
134 | ui->mainToolBarLayout->addWidget(m_mainToolBar); | 134 | ui->mainToolBarLayout->addWidget(m_mainToolBar); | ||
135 | togglePrintButtons(m_files.size()); | ||||
135 | } | 136 | } | ||
136 | 137 | | |||
137 | void AtCoreInstanceWidget::buildConnectionToolbar() | 138 | void AtCoreInstanceWidget::buildConnectionToolbar() | ||
138 | { | 139 | { | ||
139 | m_connectToolBar = new QToolBar(); | 140 | m_connectToolBar = new QToolBar(); | ||
140 | m_comboPort = new QComboBox; | 141 | m_comboPort = new QComboBox; | ||
141 | m_comboPort->setEditable(true); | 142 | m_comboPort->setEditable(true); | ||
142 | QLabel *deviceLabel = new QLabel(i18n("Device")); | 143 | QLabel *deviceLabel = new QLabel(i18n("Device")); | ||
▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Line(s) | |||||
446 | bool AtCoreInstanceWidget::connected() | 447 | bool AtCoreInstanceWidget::connected() | ||
447 | { | 448 | { | ||
448 | return (m_core.state() != AtCore::DISCONNECTED); | 449 | return (m_core.state() != AtCore::DISCONNECTED); | ||
449 | } | 450 | } | ||
450 | 451 | | |||
451 | void AtCoreInstanceWidget::setOpenFiles(const QList<QUrl>& files) | 452 | void AtCoreInstanceWidget::setOpenFiles(const QList<QUrl>& files) | ||
452 | { | 453 | { | ||
453 | m_files = files; | 454 | m_files = files; | ||
455 | togglePrintButtons(m_files.size()); | ||||
454 | } | 456 | } | ||
455 | 457 | | |||
456 | void AtCoreInstanceWidget::updateSerialPort(const QStringList &ports) | 458 | void AtCoreInstanceWidget::updateSerialPort(const QStringList &ports) | ||
457 | { | 459 | { | ||
458 | m_comboPort->clear(); | 460 | m_comboPort->clear(); | ||
459 | m_comboPort->addItems(ports); | 461 | m_comboPort->addItems(ports); | ||
460 | } | 462 | } | ||
461 | 463 | | |||
462 | void AtCoreInstanceWidget::updateProfileData() | 464 | void AtCoreInstanceWidget::updateProfileData() | ||
463 | { | 465 | { | ||
464 | m_settings.beginGroup("GeneralSettings"); | 466 | m_settings.beginGroup("GeneralSettings"); | ||
465 | QStringList profiles = m_settings.childGroups(); | 467 | QStringList profiles = m_settings.childGroups(); | ||
466 | m_settings.endGroup(); | 468 | m_settings.endGroup(); | ||
467 | m_comboProfile->clear(); | 469 | m_comboProfile->clear(); | ||
468 | m_comboProfile->addItems(profiles); | 470 | m_comboProfile->addItems(profiles); | ||
469 | } | 471 | } | ||
472 | | ||||
473 | void AtCoreInstanceWidget::togglePrintButtons(bool shown) | ||||
474 | { | ||||
475 | m_printAction->setVisible(shown); | ||||
476 | m_stopAction->setVisible(shown); | ||||
477 | } |