diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -17,16 +17,35 @@ */ #pragma once -#include -#include #include #include +#include +#include +#include +#include +#include +#include +#include namespace Ui { class MainWindow; } +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 @@ -38,7 +57,11 @@ private: Ui::MainWindow *ui; QList m_openFiles; - KTextEditor::View *m_curr_editor_view; + KTextEditor::View *m_currEditorView; + LateralArea m_lateral; + QTabWidget *m_instances; + + void setupLateralArea(); void initWidgets(); void setupActions(); void openFile(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -16,21 +16,31 @@ 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 #include #include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent), ui(new Ui::MainWindow), - m_curr_editor_view(nullptr) + m_currEditorView(nullptr), + m_instances(new QTabWidget(this)) { ui->setupUi(this); initWidgets(); @@ -44,11 +54,60 @@ void MainWindow::initWidgets() { - connect(ui->gcodeEditorWidget, &GCodeEditorWidget::updateClientFactory, this, [ & ](KTextEditor::View* view){ - guiFactory()->removeClient(m_curr_editor_view); - guiFactory()->addClient(view); - m_curr_editor_view = view; - }); + auto newInstanceWidget = new AtCoreInstanceWidget(); + m_instances->addTab(newInstanceWidget, i18n("Connect your printer")); + + setupLateralArea(); + + // 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); + centralLayout->addWidget(m_lateral.m_toolBar); + centralLayout->addWidget(splitter); + ui->centralwidget->setLayout(centralLayout); +} + +// 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); + btn->setIcon(icon); + btn->setIconSize(QSize(64,64)); + 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, [&](KTextEditor::View* view){ + guiFactory()->removeClient(m_currEditorView); + guiFactory()->addClient(view); + m_currEditorView = view; + }); + + setupButton("3d", i18n("&3D"), QIcon(":/icon/atelier"), new Viewer3D(this)); + setupButton("gcode", i18n("&GCode"), QIcon(":/icon/atelier"), gcodeEditor); + setupButton("video", i18n("&Video"), QIcon(":/icon/atelier"), new VideoMonitorWidget(this)); + buttonLayout->addStretch(); + m_lateral.m_toolBar->setLayout(buttonLayout); } void MainWindow::setupActions() @@ -90,26 +149,35 @@ void MainWindow::openFile() { - QUrl fileNameFromDialog = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"), + QUrl fileName = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"), QDir::homePath(), i18n("GCode (*.gco *.gcode)")); - if (!fileNameFromDialog.isEmpty()) { - ui->gcodeEditorWidget->loadFile(fileNameFromDialog); - ui->view3DWidget->drawModel(fileNameFromDialog.toString()); - m_openFiles.append(fileNameFromDialog); + + 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::newConnection(const QString& port, const QMap& profile) { - const int tabs = ui->tabWidget->count(); + const int tabs = m_instances->count(); if(tabs == 1){ - auto instance = qobject_cast(ui->tabWidget->currentWidget()); + auto instance = qobject_cast(m_instances->currentWidget()); if(!instance->connected()){ instance->startConnection(port, profile); - ui->tabWidget->setTabText(ui->tabWidget->currentIndex(), profile["name"].toString()); + m_instances->setTabText(m_instances->currentIndex(), profile["name"].toString()); return; } } auto newInstanceWidget = new AtCoreInstanceWidget(); - ui->tabWidget->addTab(newInstanceWidget, profile["name"].toString()); + m_instances->addTab(newInstanceWidget, profile["name"].toString()); newInstanceWidget->startConnection(port, profile); } diff --git a/src/mainwindow.ui b/src/mainwindow.ui --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -6,134 +6,21 @@ 0 0 - 484 - 446 + 1074 + 833 Atelier - - - - - - 0 - - - - - 0 - 0 - 233 - 285 - - - - Page 1 - - - - - Page - - - - - - 0 - 0 - 233 - 285 - - - - Page 2 - - - - - - - - 0 - - - - Tab 1 - - - - - - - - - 6 - 418 - 801 - 46 - - - - - 100 - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Printer State: - - - - - - - Not Connected - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 0 - 0 - - - - - - - + 0 0 - 484 - 30 + 1074 + 36 @@ -157,33 +44,12 @@ false + + + 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 -
-