diff --git a/src/atelierui.rc b/src/atelierui.rc
index 8538cda..c4d9346 100644
--- a/src/atelierui.rc
+++ b/src/atelierui.rc
@@ -1,29 +1,23 @@
-
-
-
+
diff --git a/src/icons/application-exit.svg b/src/icons/application-exit.svg
new file mode 100644
index 0000000..13c5930
--- /dev/null
+++ b/src/icons/application-exit.svg
@@ -0,0 +1,3 @@
+
diff --git a/src/icons/camera-web.svg b/src/icons/camera-web.svg
new file mode 100644
index 0000000..1d9acbe
--- /dev/null
+++ b/src/icons/camera-web.svg
@@ -0,0 +1,68 @@
+
+
+
+
diff --git a/src/icons/dark_3d.svg b/src/icons/dark_3d.svg
new file mode 100644
index 0000000..188ee0d
--- /dev/null
+++ b/src/icons/dark_3d.svg
@@ -0,0 +1,29 @@
+
diff --git a/src/icons/dark_add.svg b/src/icons/dark_add.svg
new file mode 100644
index 0000000..21ab466
--- /dev/null
+++ b/src/icons/dark_add.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/dark_configure.svg b/src/icons/dark_configure.svg
new file mode 100644
index 0000000..0017410
--- /dev/null
+++ b/src/icons/dark_configure.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/dark_connect.svg b/src/icons/dark_connect.svg
new file mode 100644
index 0000000..cb0989b
--- /dev/null
+++ b/src/icons/dark_connect.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/dark_disconnect.svg b/src/icons/dark_disconnect.svg
new file mode 100644
index 0000000..d9d5ab1
--- /dev/null
+++ b/src/icons/dark_disconnect.svg
@@ -0,0 +1,22 @@
+
diff --git a/src/icons/dark_home.svg b/src/icons/dark_home.svg
new file mode 100644
index 0000000..de26392
--- /dev/null
+++ b/src/icons/dark_home.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/dark_open.svg b/src/icons/dark_open.svg
new file mode 100644
index 0000000..ef9cbb3
--- /dev/null
+++ b/src/icons/dark_open.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/dark_pause.svg b/src/icons/dark_pause.svg
new file mode 100644
index 0000000..7651133
--- /dev/null
+++ b/src/icons/dark_pause.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/dark_start.svg b/src/icons/dark_start.svg
new file mode 100644
index 0000000..4a78d03
--- /dev/null
+++ b/src/icons/dark_start.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/dark_stop.svg b/src/icons/dark_stop.svg
new file mode 100644
index 0000000..caa9596
--- /dev/null
+++ b/src/icons/dark_stop.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/kwrite.svg b/src/icons/kwrite.svg
new file mode 100644
index 0000000..4e50ca7
--- /dev/null
+++ b/src/icons/kwrite.svg
@@ -0,0 +1,1421 @@
+
+
+
+
diff --git a/src/icons/light_3d.svg b/src/icons/light_3d.svg
new file mode 100644
index 0000000..fd59ccf
--- /dev/null
+++ b/src/icons/light_3d.svg
@@ -0,0 +1,29 @@
+
diff --git a/src/icons/light_add.svg b/src/icons/light_add.svg
new file mode 100644
index 0000000..2935b6e
--- /dev/null
+++ b/src/icons/light_add.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/light_configure.svg b/src/icons/light_configure.svg
new file mode 100644
index 0000000..ddab8a1
--- /dev/null
+++ b/src/icons/light_configure.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/light_connect.svg b/src/icons/light_connect.svg
new file mode 100644
index 0000000..3d810e7
--- /dev/null
+++ b/src/icons/light_connect.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/light_disconnect.svg b/src/icons/light_disconnect.svg
new file mode 100644
index 0000000..e1d5fcb
--- /dev/null
+++ b/src/icons/light_disconnect.svg
@@ -0,0 +1,22 @@
+
diff --git a/src/icons/light_home.svg b/src/icons/light_home.svg
new file mode 100644
index 0000000..096d549
--- /dev/null
+++ b/src/icons/light_home.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/light_open.svg b/src/icons/light_open.svg
new file mode 100644
index 0000000..1b18e58
--- /dev/null
+++ b/src/icons/light_open.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/light_pause.svg b/src/icons/light_pause.svg
new file mode 100644
index 0000000..992839c
--- /dev/null
+++ b/src/icons/light_pause.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/light_start.svg b/src/icons/light_start.svg
new file mode 100644
index 0000000..e9f13f6
--- /dev/null
+++ b/src/icons/light_start.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/icons/light_stop.svg b/src/icons/light_stop.svg
new file mode 100644
index 0000000..2ec3cd1
--- /dev/null
+++ b/src/icons/light_stop.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index e8617e4..d72493a 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,196 +1,205 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - laysrodrigues@gmail.com
Chris Rizzitello - rizzitello@kde.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
MainWindow::MainWindow(QWidget *parent) :
KXmlGuiWindow(parent),
m_currEditorView(nullptr),
m_instances(new QTabWidget(this))
{
+ m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light");
+
initWidgets();
setupActions();
connect(m_instances, &QTabWidget::tabCloseRequested, [this] (int index){
QWidget *tempWidget= m_instances->widget(index);
delete tempWidget;
if(m_instances->count() == 1) {
m_instances->setTabsClosable(false);
m_instances->setMovable(false);
}
});
}
void MainWindow::initWidgets()
{
setupLateralArea();
newAtCoreInstance();
// View:
// Sidebar, Sidevar Controls, Printer Tabs.
// Sidevar Controls and Printer Tabs can be resized, Sidebar cant.
auto *centralLayout = new QHBoxLayout();
auto splitter = new QSplitter();
splitter->addWidget(m_lateral.m_stack);
splitter->addWidget(m_instances);
auto addTabBtn =new QToolButton();
addTabBtn->setText("+");
addTabBtn->setToolTip(i18n("Create new instance"));
addTabBtn->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T));
connect(addTabBtn, &QToolButton::clicked, this, &MainWindow::newAtCoreInstance);
m_instances->setCornerWidget(addTabBtn, Qt::TopLeftCorner);
centralLayout->addWidget(m_lateral.m_toolBar);
centralLayout->addWidget(splitter);
auto *centralWidget = new QWidget();
centralWidget->setLayout(centralLayout);
setCentralWidget(centralWidget);
}
void MainWindow::newAtCoreInstance()
{
auto newInstanceWidget = new AtCoreInstanceWidget();
QString name = QString::number(m_instances->addTab(newInstanceWidget, i18n("Connect a printer")));
newInstanceWidget->setObjectName(name);
connect(this, &MainWindow::profilesChanged, newInstanceWidget, &AtCoreInstanceWidget::updateProfileData);
connect(newInstanceWidget, &AtCoreInstanceWidget::requestProfileDialog, [ this ] {
std::unique_ptr pd(new ProfilesDialog);
pd->exec();
emit(profilesChanged());
});
connect(newInstanceWidget, &AtCoreInstanceWidget::connectionChanged, this, &MainWindow::atCoreInstanceNameChange);
if(m_instances->count() > 1) {
m_instances->setTabsClosable(true);
m_instances->setMovable(true);
m_instances->setCurrentIndex(m_instances->count()-1);
}
}
// Move to LateralArea.
void MainWindow::setupLateralArea()
{
m_lateral.m_toolBar = new QWidget();
m_lateral.m_stack = new QStackedWidget();
auto buttonLayout = new QVBoxLayout();
auto setupButton = [this, buttonLayout](const QString& key, const QString& text, const QIcon& icon, QWidget *w) {
auto *btn = new QPushButton(m_lateral.m_toolBar);
btn->setToolTip(text);
btn->setAutoExclusive(true);
btn->setCheckable(true);
//3d view is on top set it checked so users see its selected.
btn->setChecked(key == "3d");
btn->setIcon(icon);
btn->setFixedSize(48,48);
btn->setIconSize(QSize(48,48));
btn->setFlat(true);
m_lateral.m_stack->addWidget(w);
m_lateral.m_map[key] = {btn, w};
buttonLayout->addWidget(btn);
connect(btn, &QToolButton::toggled, [this, w](bool checked) {
if (checked)
m_lateral.m_stack->setCurrentWidget(w);
});
};
auto *gcodeEditor = new GCodeEditorWidget(this);
connect(gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, [this](KTextEditor::View* view){
guiFactory()->removeClient(m_currEditorView);
guiFactory()->addClient(view);
m_currEditorView = view;
});
-
- setupButton("3d", i18n("&3D"), QIcon::fromTheme("draw-cuboid", QIcon(":/icon/atelier")), new Viewer3D(this));
- setupButton("gcode", i18n("&GCode"), QIcon::fromTheme("accessories-text-editor", QIcon(":/icon/atelier")), gcodeEditor);
- setupButton("video", i18n("&Video"), QIcon::fromTheme("camera-web", QIcon(":/icon/atelier")), new VideoMonitorWidget(this));
+ setupButton("3d", i18n("&3D"), QIcon::fromTheme("draw-cuboid", QIcon(QString(":/%1/3d").arg(m_theme))), new Viewer3D(this));
+ setupButton("gcode", i18n("&GCode"), QIcon::fromTheme("accessories-text-editor", QIcon(":/icon/edit")), gcodeEditor);
+ setupButton("video", i18n("&Video"), QIcon::fromTheme("camera-web", QIcon(":/icon/video")), new VideoMonitorWidget(this));
buttonLayout->addStretch();
m_lateral.m_toolBar->setLayout(buttonLayout);
}
void MainWindow::setupActions()
{
// Actions for the Toolbar
QAction *action;
- action = actionCollection()->addAction(QStringLiteral("open_gcode"));
- action->setIcon(QIcon::fromTheme("document-open", style()->standardIcon(QStyle::SP_DirOpenIcon)));
- action->setText(i18n("&Open GCode"));
+ action = actionCollection()->addAction(QStringLiteral("open"));
+ action->setIcon(QIcon::fromTheme("document-open", QIcon(QString(":/%1/open").arg(m_theme))));
+
+ action->setText(i18n("&Open"));
actionCollection()->setDefaultShortcut(action, QKeySequence::Open);
connect(action, &QAction::triggered, this, &MainWindow::openFile);
action = actionCollection()->addAction(QStringLiteral("new_instance"));
- action->setIcon(QIcon::fromTheme("list-add", QIcon()));
+ action->setIcon(QIcon::fromTheme("list-add", QIcon(QString(":/%1/addTab").arg(m_theme))));
+
action->setText(i18n("&New Connection"));
actionCollection()->setDefaultShortcut(action, QKeySequence::AddTab);
connect(action, &QAction::triggered, this, &MainWindow::newAtCoreInstance);
action = actionCollection()->addAction(QStringLiteral("profiles"));
- action->setIcon(QIcon::fromTheme("document-properties", QIcon()));
+ action->setIcon(QIcon::fromTheme("document-properties", QIcon(QString(":/%1/configure").arg(m_theme))));
+
action->setText(i18n("&Profiles"));
connect(action, &QAction::triggered, [this] {
std::unique_ptr pd(new ProfilesDialog);
pd->exec();
emit(profilesChanged());
});
- action = KStandardAction::quit(this, SLOT(close()), actionCollection());
+ action = actionCollection()->addAction(QStringLiteral("quit"));
+ action->setIcon(QIcon::fromTheme("application-exit", QIcon(":/icon/exit")));
+
+ action->setText(i18n("&Quit"));
+ actionCollection()->setDefaultShortcut(action, QKeySequence::Quit);
+ connect(action, &QAction::triggered, this, &MainWindow::close);
setupGUI(Default, ":/atelierui");
}
void MainWindow::openFile()
{
QUrl fileName = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"),
QUrl::fromLocalFile(QDir::homePath()), i18n("GCode(*.gco *.gcode);;All Files(*.*)"));
if (!fileName.isEmpty()) {
m_lateral.get("gcode")->loadFile(fileName);
m_lateral.get("3d")->drawModel(fileName.toString());
const int tabs = m_instances->count();
m_openFiles.append(fileName);
for(int i=0; i < tabs; ++i){
auto instance = qobject_cast(m_instances->widget(i));
instance->setOpenFiles(m_openFiles);
}
}
}
void MainWindow::atCoreInstanceNameChange(const QString &name)
{
m_instances->setTabText(sender()->objectName().toInt(),name);
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 17e17d7..9062562 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -1,65 +1,65 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - laysrodrigues@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
struct LateralArea {
// Area with the the lateral buttons that will open the views.
// Kind like the KDevelop stuff but way simpler.
using Btn2Widget = QPair;
using WidgetMap = QMap;
QWidget *m_toolBar;
QStackedWidget *m_stack;
WidgetMap m_map;
template T* get(const QString& s) {
return qobject_cast(m_map[s].second);
}
};
class MainWindow : public KXmlGuiWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
private:
QList m_openFiles;
+ QString m_theme;
KTextEditor::View *m_currEditorView;
LateralArea m_lateral;
QTabWidget *m_instances;
-
void setupLateralArea();
void newAtCoreInstance();
void initWidgets();
void setupActions();
void openFile();
void atCoreInstanceNameChange(const QString &name);
signals:
void extruderCountChanged(int count);
void profilesChanged();
};
diff --git a/src/resources.qrc b/src/resources.qrc
index 16b9827..16c8bc6 100644
--- a/src/resources.qrc
+++ b/src/resources.qrc
@@ -1,9 +1,36 @@
../deploy/atelier.png
+ icons/application-exit.svg
+ icons/camera-web.svg
+ icons/kwrite.svg
+
+ icons/light_configure.svg
+ icons/light_open.svg
+ icons/light_3d.svg
+ icons/light_add.svg
+ icons/light_home.svg
+ icons/light_connect.svg
+ icons/light_disconnect.svg
+ icons/light_start.svg
+ icons/light_stop.svg
+ icons/light_pause.svg
+
+
+ icons/dark_configure.svg
+ icons/dark_open.svg
+ icons/dark_3d.svg
+ icons/dark_add.svg
+ icons/dark_home.svg
+ icons/dark_connect.svg
+ icons/dark_disconnect.svg
+ icons/dark_start.svg
+ icons/dark_stop.svg
+ icons/dark_pause.svg
+
+
atelierui.rc
-
diff --git a/src/widgets/atcoreinstancewidget.cpp b/src/widgets/atcoreinstancewidget.cpp
index e091021..1e59c63 100644
--- a/src/widgets/atcoreinstancewidget.cpp
+++ b/src/widgets/atcoreinstancewidget.cpp
@@ -1,464 +1,467 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2017>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "atcoreinstancewidget.h"
#include "ui_atcoreinstancewidget.h"
#include
#include
#include
#include
#include "choosefiledialog.h"
AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent):
QWidget(parent),
m_mainToolBar(nullptr),
m_toolBar(nullptr),
m_printAction(nullptr)
{
+ m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ;
ui = new Ui::AtCoreInstanceWidget;
ui->setupUi(this);
-
ui->printProgressWidget->setVisible(false);
buildMainToolbar();
buildToolbar();
buildConnectionToolbar();
enableControls(false);
updateProfileData();
initConnectsToAtCore();
m_mainToolBar->setHidden(true);
+
}
AtCoreInstanceWidget::~AtCoreInstanceWidget()
{
m_core.closeConnection();
delete ui;
}
void AtCoreInstanceWidget::buildToolbar()
{
m_toolBar = new QToolBar();
auto lb = new QAction;
- lb->setIcon(QIcon::fromTheme("go-home", style()->standardIcon(QStyle::SP_DirHomeIcon)));
+ lb->setIcon(QIcon::fromTheme("go-home", QIcon(QString(":/%1/home").arg(m_theme))));
+
lb->setDisabled(true);
m_toolBar->addAction(lb);
auto homeAll = new QAction("All");
connect(homeAll, &QAction::triggered, [this]{
m_core.home();
});
m_toolBar->addAction(homeAll);
for(auto homes : std::map{{"X", AtCore::X}, {"Y", AtCore::Y}, {"Z", AtCore::Z}}) {
auto home = new QAction(homes.first);
connect(home, &QAction::triggered, [this, homes] {
m_core.home(homes.second);
});
m_toolBar->addAction(home);
}
m_toolBar->addSeparator();
auto *axis = new QAction("Axis");
axis->setCheckable(true);
axis->setChecked(true);
connect(axis, &QAction::toggled, ui->axisViewWidget, &AxisControl::setVisible);
auto controls = new QAction("Controls");
controls->setCheckable(true);
controls->setChecked(true);
connect(controls, &QAction::toggled, ui->bedExtWidget, &BedExtruderWidget::setVisible);
auto plot = new QAction("Temperature Plot");
plot->setCheckable(true);
plot->setChecked(true);
connect(plot, &QAction::toggled, ui->plotWidget, &PlotWidget::setVisible);
m_toolBar->addAction(axis);
m_toolBar->addAction(controls);
m_toolBar->addAction(plot);
ui->toolBarLayout->addWidget(m_toolBar);
ui->toolBarLayout->addStretch();
}
void AtCoreInstanceWidget::buildMainToolbar(){
m_mainToolBar = new QToolBar();
m_mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_printAction = new QAction(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)),i18n("Print"));
connect(m_printAction, &QAction::triggered, [ this ](){
if(m_core.state() == AtCore::BUSY) {
pausePrint();
return;
}
if (m_core.state() == AtCore::IDLE){
print();
} else if (m_core.state() == AtCore::PAUSE) {
m_core.resume();
}
});
m_mainToolBar->addAction(m_printAction);
- auto stopAction = new QAction(QIcon::fromTheme("media-playback-stop", style()->standardIcon(QStyle::SP_MediaStop)), i18n("Stop"));
+ auto stopAction = new QAction(QIcon::fromTheme("media-playback-stop", QIcon(QString(":/%1/stop").arg(m_theme))), i18n("Stop"));
+
connect(stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint);
connect(stopAction, &QAction::triggered, [this](){
m_printAction->setText(i18n("Print"));
- m_printAction->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)));
+ m_printAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(QString(":/%1/start").arg(m_theme))));
});
m_mainToolBar->addAction(stopAction);
auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors"));
connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors);
m_mainToolBar->addAction(disableMotorsAction);
ui->mainToolBarLayout->addWidget(m_mainToolBar);
}
void AtCoreInstanceWidget::buildConnectionToolbar()
{
m_connectToolBar = new QToolBar();
m_comboPort = new QComboBox;
m_comboPort->setEditable(true);
QLabel *deviceLabel = new QLabel(i18n("Device"));
QHBoxLayout *deviceLayout = new QHBoxLayout;
deviceLayout->addWidget(deviceLabel);
deviceLayout->addWidget(m_comboPort,100);
m_comboProfile = new QComboBox;
m_comboProfile->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
QHBoxLayout *profileLayout = new QHBoxLayout;
QLabel *profileLabel = new QLabel(i18n("Profile"));
profileLayout->addWidget(profileLabel);
profileLayout->addWidget(m_comboProfile,100);
QHBoxLayout *connectLayout = new QHBoxLayout;
connectLayout->addLayout(deviceLayout,50);
connectLayout->addLayout(profileLayout,50);
m_connectWidget = new QWidget();
m_connectWidget->setLayout(connectLayout);
m_connectToolBar->addWidget(m_connectWidget);
- m_connectButton = new QPushButton(QIcon::fromTheme("network-connect", style()->standardIcon(QStyle::SP_DialogCloseButton)), i18n("Connect"));
+ m_connectButton = new QPushButton(QIcon::fromTheme("network-connect", QIcon(QString(":/%1/connect").arg(m_theme))), i18n("Connect"));
m_connectButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
connect(this, &AtCoreInstanceWidget::disableDisconnect, m_connectButton, &QPushButton::setDisabled);
connect(m_connectButton, &QPushButton::clicked, this, &AtCoreInstanceWidget::connectButtonClicked);
ui->mainToolBarLayout->addWidget(m_connectToolBar);
ui->mainToolBarLayout->addWidget(m_connectButton);
}
void AtCoreInstanceWidget::connectButtonClicked()
{
if(m_core.state() == AtCore::DISCONNECTED) {
if (m_comboProfile->currentText().isEmpty()) {
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."));
emit(requestProfileDialog());
return;
}
if (m_comboPort->currentText().isEmpty()) {
QMessageBox::critical(this, i18n("Error"), i18n("Please, connect a serial device to continue!"));
return;
}
//Get profile data before connecting.
QString profile = m_comboProfile->currentText();
m_settings.beginGroup("GeneralSettings");
m_settings.beginGroup(profile);
QMap data;
data["bps"] = m_settings.value(QStringLiteral("bps"), QStringLiteral("115200"));
data["bedTemp"] = m_settings.value(QStringLiteral("maximumTemperatureBed"), QStringLiteral("0"));
data["hotendTemp"] = m_settings.value(QStringLiteral("maximumTemperatureExtruder"), QStringLiteral("0"));
data["firmware"] = m_settings.value(QStringLiteral("firmware"),QStringLiteral("Auto-Detect"));
data["postPause"] = m_settings.value(QStringLiteral("postPause"),QStringLiteral(""));
data["name"] = profile;
m_settings.endGroup();
m_settings.endGroup();
//then connect
m_core.initSerial(m_comboPort->currentText(), data["bps"].toInt());
if(m_core.state() == AtCore::CONNECTING){
profileData = data;
QString fw = profileData["firmware"].toString();
if( fw != QString("Auto-Detect")){
m_core.loadFirmwarePlugin(fw);
}
emit(connectionChanged(profileData["name"].toString()));
}
} else {
m_core.closeConnection();
emit(connectionChanged(i18n("Connect a Printer")));
}
}
void AtCoreInstanceWidget::initConnectsToAtCore()
{
m_core.setSerialTimerInterval(100);
// Handle device changes
connect(&m_core, &AtCore::portsChanged, this, &AtCoreInstanceWidget::updateSerialPort);
// Handle AtCore status change
connect(&m_core, &AtCore::stateChanged, this, &AtCoreInstanceWidget::handlePrinterStatusChanged);
// If the number of extruders from the printer change, we need to update the radiobuttons on the widget
connect(this, &AtCoreInstanceWidget::extruderCountChanged, ui->bedExtWidget, &BedExtruderWidget::setExtruderCount);
// Bed and Extruder temperatures management
connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &m_core, &AtCore::setBedTemp);
connect(ui->bedExtWidget, &BedExtruderWidget::extTemperatureChanged, &m_core, &AtCore::setExtruderTemp);
// Connect AtCore temperatures changes on Atelier Plot
connect(&m_core.temperature(), &Temperature::bedTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x00, 0, temp);
ui->plotWidget->appendPoint(i18n("Actual Bed"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateBedTemp(temp);
});
connect(&m_core.temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x01, 0, temp);
ui->plotWidget->appendPoint(i18n("Target Bed"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateBedTargetTemp(temp);
});
connect(&m_core.temperature(), &Temperature::extruderTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x02, 0, temp);
ui->plotWidget->appendPoint(i18n("Actual Ext.1"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateExtTemp(temp);
});
connect(&m_core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x03, 0, temp);
ui->plotWidget->appendPoint(i18n("Target Ext.1"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateExtTargetTemp(temp);
});
connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ this ](QString command) {
ui->logWidget->addLog("Push " + command);
m_core.pushCommand(command);
});
// Fan, Flow and Speed management
connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &m_core, &AtCore::setFanSpeed);
connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &m_core, &AtCore::setFlowRate);
connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &m_core, &AtCore::setPrinterSpeed);
connect(ui->axisViewWidget, &AxisControl::clicked, this, &AtCoreInstanceWidget::axisControlClicked);
}
void AtCoreInstanceWidget::printFile(const QUrl& fileName)
{
if (!fileName.isEmpty() && (m_core.state() == AtCore::IDLE)) {
m_core.print(fileName.toLocalFile());
}
}
void AtCoreInstanceWidget::print(){
switch (m_files.size()){
case 0:
QMessageBox::warning(this, i18n("Error"),
i18n("There's no GCode File open. \n Please select a file and try again."),
QMessageBox::Ok);
break;
case 1:
printFile(m_files.at(0));
break;
default:
auto dialog = new ChooseFileDialog(this, m_files);
if(dialog->exec() == QDialog::Accepted){
printFile(dialog->choosenFile());
}
}
}
void AtCoreInstanceWidget::pausePrint()
{
if(m_core.state() == AtCore::BUSY) {
m_core.pause(profileData["postPause"].toString());
} else if (m_core.state() == AtCore::PAUSE) {
m_core.resume();
}
}
void AtCoreInstanceWidget::stopPrint()
{
m_core.stop();
}
void AtCoreInstanceWidget::disableMotors()
{
m_core.disableMotors(0);
}
void AtCoreInstanceWidget::handlePrinterStatusChanged(AtCore::STATES newState)
{
static QString stateString;
switch (newState) {
case AtCore::CONNECTING: {
m_core.setSerialTimerInterval(0);
m_connectButton->setText(i18n("Disconnect"));
- m_connectButton->setIcon(QIcon::fromTheme("network-disconnect"));
+ m_connectButton->setIcon(QIcon::fromTheme("network-disconnect", QIcon(QString(":/%1/disconnect").arg(m_theme))));
m_connectToolBar->setHidden(true);
m_mainToolBar->setHidden(false);
stateString = i18n("Connecting...");
connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand);
connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands);
} break;
case AtCore::IDLE: {
stateString = i18n("Connected to ") + m_core.serial()->portName();
emit extruderCountChanged(m_core.extruderCount());
ui->logWidget->addLog(i18n("Serial connected"));
emit disableDisconnect(false);
enableControls(true);
} break;
case AtCore::DISCONNECTED: {
stateString = i18n("Not Connected");
disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand);
disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands);
ui->logWidget->addLog(i18n("Serial disconnected"));
m_core.setSerialTimerInterval(100);
m_connectButton->setText(i18n("Connect"));
- m_connectButton->setIcon(QIcon::fromTheme("network-connect"));
+ m_connectButton->setIcon(QIcon::fromTheme("network-connect",QIcon(QString(":/%1/connect").arg(m_theme))));
m_connectToolBar->setHidden(false);
m_mainToolBar->setHidden(true);
enableControls(false);
} break;
case AtCore::STARTPRINT: {
stateString = i18n("Starting Print");
ui->printProgressWidget->setVisible(true);
connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar);
} break;
case AtCore::FINISHEDPRINT: {
stateString = i18n("Finished Print");
ui->printProgressWidget->setVisible(false);
disconnect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar);
m_printAction->setText(i18n("Print"));
- m_printAction->setIcon(QIcon::fromTheme("document-edit", style()->standardIcon(QStyle::SP_MediaPlay)));
+ m_printAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(QString(":/%1/start").arg(m_theme))));
} break;
case AtCore::BUSY: {
stateString = i18n("Printing");
emit disableDisconnect(true);
m_printAction->setText(i18n("Pause"));
- m_printAction->setIcon(QIcon::fromTheme("media-playback-pause", style()->standardIcon(QStyle::SP_MediaPause)));
+ m_printAction->setIcon(QIcon::fromTheme("media-playback-pause", QIcon(QString(":/%1/pause").arg(m_theme))));
} break;
case AtCore::PAUSE: {
stateString = i18n("Paused");
m_printAction->setText(i18n("Resume"));
- m_printAction->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)));
+ m_printAction->setIcon(QIcon::fromTheme("media-playback-start", QIcon(QString(":/%1/start").arg(m_theme))));
} break;
case AtCore::STOP: {
stateString = i18n("Stoping Print");
} break;
case AtCore::ERRORSTATE: {
stateString = i18n("Error");
} break;
default:
qWarning("AtCore State not Recognized.");
break;
}
ui->lblState->setText(stateString);
}
void AtCoreInstanceWidget::checkTemperature(uint sensorType, uint number, uint temp)
{
static QString msg;
switch (sensorType) {
case 0x00: // bed
msg = QString::fromLatin1("Bed Temperature ");
break;
case 0x01: // bed target
msg = QString::fromLatin1("Bed Target Temperature ");
break;
case 0x02: // extruder
msg = QString::fromLatin1("Extruder Temperature ");
break;
case 0x03: // extruder target
msg = QString::fromLatin1("Extruder Target Temperature ");
break;
case 0x04: // enclosure
msg = QString::fromLatin1("Enclosure Temperature ");
break;
case 0x05: // enclosure target
msg = QString::fromLatin1("Enclosure Target Temperature ");
break;
}
msg.append(QString::fromLatin1("[%1] : %2"));
msg = msg.arg(QString::number(number))
.arg(QString::number(temp));
ui->logWidget->addRLog(msg);
}
void AtCoreInstanceWidget::checkReceivedCommand(const QByteArray &message)
{
ui->logWidget->addRLog(QString::fromUtf8(message));
}
void AtCoreInstanceWidget::checkPushedCommands(const QByteArray &bmsg)
{
QString msg = QString::fromUtf8(bmsg);
QRegExp _newLine(QChar::fromLatin1('\n'));
QRegExp _return(QChar::fromLatin1('\r'));
msg.replace(_newLine, QStringLiteral("\\n"));
msg.replace(_return, QStringLiteral("\\r"));
ui->logWidget->addSLog(msg);
}
void AtCoreInstanceWidget::axisControlClicked(QChar axis, int value)
{
m_core.setRelativePosition();
m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value))));
m_core.setAbsolutePosition();
}
void AtCoreInstanceWidget::enableControls(bool b)
{
ui->mainTab->setEnabled(b);
m_mainToolBar->setEnabled(b);
m_toolBar->setEnabled(b);
}
bool AtCoreInstanceWidget::connected()
{
return (m_core.state() != AtCore::DISCONNECTED);
}
void AtCoreInstanceWidget::setOpenFiles(const QList& files)
{
m_files = files;
}
void AtCoreInstanceWidget::updateSerialPort(const QStringList &ports)
{
m_comboPort->clear();
m_comboPort->addItems(ports);
}
void AtCoreInstanceWidget::updateProfileData()
{
m_settings.beginGroup("GeneralSettings");
QStringList profiles = m_settings.childGroups();
m_settings.endGroup();
m_comboProfile->clear();
m_comboProfile->addItems(profiles);
}
diff --git a/src/widgets/atcoreinstancewidget.h b/src/widgets/atcoreinstancewidget.h
index af4966d..26e1836 100644
--- a/src/widgets/atcoreinstancewidget.h
+++ b/src/widgets/atcoreinstancewidget.h
@@ -1,93 +1,94 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2017>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
namespace Ui
{
class AtCoreInstanceWidget;
}
/**
* @todo write docs
*/
class AtCoreInstanceWidget : public QWidget
{
Q_OBJECT
public:
/**
* Default constructor
*/
AtCoreInstanceWidget(QWidget* parent = nullptr);
/**
* Destructor
*/
~AtCoreInstanceWidget();
void startConnection(const QString& serialPort, const QMap& profile);
bool connected();
void setOpenFiles(const QList& files);
public slots:
void updateProfileData();
private:
Ui::AtCoreInstanceWidget* ui;
AtCore m_core;
QToolBar *m_mainToolBar;
QComboBox *m_comboPort;
QComboBox *m_comboProfile;
QPushButton *m_connectButton;
QToolBar *m_connectToolBar;
QWidget *m_connectWidget;
QToolBar *m_toolBar;
QMap profileData;
QList m_files;
QAction *m_printAction;
QSettings m_settings;
+ QString m_theme;
void initConnectsToAtCore();
void printFile(const QUrl& fileName);
void pausePrint();
void stopPrint();
void disableMotors();
void checkReceivedCommand(const QByteArray &message);
void checkPushedCommands(const QByteArray &bmsg);
void handlePrinterStatusChanged(AtCore::STATES newState);
void checkTemperature(uint sensorType, uint number, uint temp);
void axisControlClicked(QChar axis, int value);
void enableControls(bool b);
void buildToolbar();
void buildMainToolbar();
void print();
void updateSerialPort(const QStringList &ports);
void buildConnectionToolbar();
void connectButtonClicked();
signals:
void connectionChanged(QString name);
void disableDisconnect(bool b);
void extruderCountChanged(int count);
void requestProfileDialog();
};