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