diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c59e7f3..c7c429d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,183 +1,178 @@ /* 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 #include #include #include #include #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent), - ui(new Ui::MainWindow), m_currEditorView(nullptr), m_instances(new QTabWidget(this)) { - ui->setupUi(this); 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); } }); } -MainWindow::~MainWindow() -{ - delete ui; -} - 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); centralLayout->addWidget(m_lateral.m_toolBar); centralLayout->addWidget(splitter); - ui->centralwidget->setLayout(centralLayout); + 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::connectionChanged, this, &MainWindow::atCoreInstanceNameChange); if(m_instances->count() > 1) { m_instances->setTabsClosable(true); m_instances->setMovable(true); } } // 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(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)); 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")); connect(action, &QAction::triggered, this, &MainWindow::openFile); action = actionCollection()->addAction(QStringLiteral("new_instance")); action->setIcon(QIcon::fromTheme("list-add", QIcon())); action->setText(i18n("&New Connection")); connect(action, &QAction::triggered, this, &MainWindow::newAtCoreInstance); action = actionCollection()->addAction(QStringLiteral("profiles")); action->setIcon(QIcon::fromTheme("document-properties", QIcon())); action->setText(i18n("&Profiles")); connect(action, &QAction::triggered, [this] { std::unique_ptr pd(new ProfilesDialog); pd->exec(); emit(profilesChanged()); }); action = KStandardAction::quit(qApp, SLOT(quit()), actionCollection()); setupGUI(Default, ":/atelierui"); } void MainWindow::openFile() { QUrl fileName = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"), QDir::homePath(), i18n("GCode (*.gco *.gcode)")); 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 8bd4f2e..17e17d7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,72 +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 -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 public: explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow(); private: - Ui::MainWindow *ui; QList m_openFiles; 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/mainwindow.ui b/src/mainwindow.ui deleted file mode 100644 index 3063a4c..0000000 --- a/src/mainwindow.ui +++ /dev/null @@ -1,55 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 0 - 0 - - - - Atelier - - - - - - 0 - 0 - 1074 - 36 - - - - - Fi&le - - - - - Edit - - - - - - - - Qt::NoContextMenu - - - false - - - - - Teste - - - - - -