diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d0952c3..c1c2e18 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,118 +1,141 @@ /* 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 "ui_mainwindow.h" #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent), ui(new Ui::MainWindow), + leftToolbar(new QToolBar()), profilesDialog(new ProfilesDialog(this)), connectSettingsDialog(new ConnectSettingsDialog(this)) { ui->setupUi(this); setupActions(); initWidgets(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::initWidgets() { // When a new profile is added on the Profile Dialog it needs to update the profiles on connection dialog connect(profilesDialog, &ProfilesDialog::updateProfiles, connectSettingsDialog, &ConnectSettingsDialog::updateProfiles); connect(connectSettingsDialog, &ConnectSettingsDialog::startConnection, this, &MainWindow::newConnection); - + ui->gcodeDockWidget->setHidden(true); + ui->videoDockWidget->setHidden(true); + buildToolbar(); // connectSettingsDialog->setFirmwareList(core.availableFirmwarePlugins()); // profilesDialog->setBaudRates(core.serial()->validBaudRates()); } +void MainWindow::buildToolbar() +{ + leftToolbar->setOrientation(Qt::Vertical); + leftToolbar->setMovable(true); + leftToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + addToolBar(Qt::LeftToolBarArea, leftToolbar); +} + void MainWindow::setupActions() { // Actions for the Toolbar QAction *action; action = actionCollection()->addAction(QStringLiteral("open_gcode")); action->setText(i18n("&Open GCode")); connect(action, &QAction::triggered, this, &MainWindow::openFile); action = actionCollection()->addAction(QStringLiteral("connect")); action->setText(i18n("&Connect")); connect(action, &QAction::triggered, connectSettingsDialog, &ConnectSettingsDialog::show); action = actionCollection()->addAction(QStringLiteral("profiles")); action->setText(i18n("&Profiles")); connect(action, &QAction::triggered, profilesDialog, &ProfilesDialog::show); + + action = actionCollection()->addAction(QStringLiteral("3d"), ui->view3DdockWidget->toggleViewAction()); + action->setText(i18n("&3D")); + leftToolbar->addAction(action); + + action = actionCollection()->addAction(QStringLiteral("gcode"), ui->gcodeDockWidget->toggleViewAction()); + action->setText(i18n("&GCode")); + leftToolbar->addAction(action); + + action = actionCollection()->addAction(QStringLiteral("video"), ui->videoDockWidget->toggleViewAction()); + action->setText(i18n("&Video")); + leftToolbar->addAction(action); #ifdef Q_OS_LINUX //only set icons from theme on linux actionCollection()->action(QStringLiteral("profiles"))->setIcon(QIcon::fromTheme("emblem-favorite")); #endif //use style's standardIcon for the icons we can. actionCollection()->action(QStringLiteral("open_gcode"))->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)); action = KStandardAction::quit(qApp, SLOT(quit()), actionCollection()); setupGUI(Default, "atelierui.rc"); } void MainWindow::openFile() { QUrl fileNameFromDialog = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"), QDir::homePath(), i18n("GCode (*.gco *.gcode)")); if (!fileNameFromDialog.isEmpty()) { fileName = fileNameFromDialog; ui->gcodeEditorWidget->loadFile(fileName); guiFactory()->addClient(ui->gcodeEditorWidget->gcodeView()); ui->view3DWidget->drawModel(fileName.toString()); const int tabs = ui->tabWidget->count(); QList files; files.append(fileName); for(int i=0; i < tabs; ++i){ auto instance = qobject_cast(ui->tabWidget->widget(i)); instance->setOpenFiles(files); } } } void MainWindow::newConnection(const QString& port, const QMap& profile) { const int tabs = ui->tabWidget->count(); if(ui->tabWidget->count() == 1){ auto instance = qobject_cast(ui->tabWidget->currentWidget()); if(!instance->connected()){ instance->startConnection(port, profile); return; } } auto newInstanceWidget = new AtCoreInstanceWidget(); ui->tabWidget->addTab(newInstanceWidget, QString::number(tabs+1)); newInstanceWidget->startConnection(port, profile); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 14b386f..ce8cdc3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,50 +1,53 @@ /* 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 namespace Ui { class MainWindow; } class MainWindow : public KXmlGuiWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; QStringList firmwaresList; QUrl fileName; + QToolBar *leftToolbar; ProfilesDialog *profilesDialog; ConnectSettingsDialog *connectSettingsDialog; void initWidgets(); + void buildToolbar(); void setupActions(); void openFile(); void newConnection(const QString& port, const QMap& profile); }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index b86772f..b01e155 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1,144 +1,121 @@ MainWindow 0 0 534 471 Atelier - + 1 - - - - Qt::LeftToRight - - - - - - 0 - - - - - 0 - 0 - 258 - 310 - - - - Qt::RightToLeft - - - 3D View - - - - - - 0 - 0 - 258 - 310 - - - - GCode Editor - - - - - - 0 - 0 - 258 - 310 - - - - Video Monitoring - - - - 0 0 534 30 Fi&le Edit Qt::NoContextMenu false + + + &3DView + + + 1 + + + + + + &GCode + + + 1 + + + + + + &Video + + + 1 + + + + + + Teste + + GCodeEditorWidget QWidget
widgets/gcodeeditorwidget.h
1
Viewer3D QWidget
widgets/3dview/viewer3d.h
1
VideoMonitorWidget QWidget
widgets/videomonitorwidget.h
1
AtCoreInstanceWidget QWidget
widgets/atcoreinstancewidget.h
1
diff --git a/src/widgets/gcodeeditorwidget.cpp b/src/widgets/gcodeeditorwidget.cpp index 4f05451..6fbe9bd 100644 --- a/src/widgets/gcodeeditorwidget.cpp +++ b/src/widgets/gcodeeditorwidget.cpp @@ -1,51 +1,58 @@ /* 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 . */ #include "gcodeeditorwidget.h" #include #include #include GCodeEditorWidget::GCodeEditorWidget(QWidget *parent) : QWidget(parent) { - editor = KTextEditor::Editor::instance(); - doc = editor->createDocument(this); - doc->setMode("G-Code"); - view = doc->createView(this); + m_editor = KTextEditor::Editor::instance(); QVBoxLayout *layout = new QVBoxLayout(); - layout->addWidget(view); + m_view = newDoc()->createView(this); + layout->addWidget(m_view); this->setLayout(layout); setupInterface(); } void GCodeEditorWidget::loadFile(const QUrl &fileName) { + auto doc = newDoc(); doc->openUrl(fileName); doc->setHighlightingMode(QString("G-Code")); } KTextEditor::View *GCodeEditorWidget::gcodeView() const { - return view; + return m_view; } void GCodeEditorWidget::setupInterface() { - interface = qobject_cast(view); - interface->setConfigValue("line-numbers", true); + m_interface = qobject_cast(m_view); + m_interface->setConfigValue("line-numbers", true); +} + +KTextEditor::Document* GCodeEditorWidget::newDoc() +{ + auto doc = m_editor->createDocument(this); + doc->setMode("G-Code"); + return doc; } + diff --git a/src/widgets/gcodeeditorwidget.h b/src/widgets/gcodeeditorwidget.h index f1aad2a..f7d8d48 100644 --- a/src/widgets/gcodeeditorwidget.h +++ b/src/widgets/gcodeeditorwidget.h @@ -1,41 +1,42 @@ /* 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 class GCodeEditorWidget : public QWidget { Q_OBJECT public: explicit GCodeEditorWidget(QWidget *parent = nullptr); void loadFile(const QUrl &fileName); KTextEditor::View *gcodeView() const; private: - KTextEditor::Editor *editor; - KTextEditor::Document *doc; - KTextEditor::View *view; - KTextEditor::ConfigInterface *interface; + KTextEditor::Editor *m_editor; + KTextEditor::View *m_view; + KTextEditor::ConfigInterface *m_interface; + QList m_documents; void setupInterface(); + KTextEditor::Document* newDoc(); };