File indexing completed on 2024-05-05 05:50:51
0001 /* Atelier KDE Printer Host for 3D Printing 0002 Copyright (C) <2016> 0003 Author: Lays Rodrigues - lays.rodrigues@kde.org 0004 Chris Rizzitello - rizzitello@kde.org 0005 0006 This program is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU General Public License as published by 0008 the Free Software Foundation, either version 3 of the License, or 0009 (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 #pragma once 0020 0021 #include "widgets/gcodeeditorwidget.h" 0022 #include <KTextEditor/View> 0023 #include <KXmlGui/KXmlGuiWindow> 0024 #include <QMap> 0025 #include <QPair> 0026 #include <QPushButton> 0027 #include <QStackedWidget> 0028 #include <QUrl> 0029 0030 struct LateralArea { 0031 // Area with the the lateral buttons that will open the views. 0032 // Kind like the KDevelop stuff but way simpler. 0033 using Btn2Widget = QPair<QPushButton *, QWidget *>; 0034 using WidgetMap = QMap<QString, Btn2Widget>; 0035 0036 QWidget *m_toolBar; 0037 QStackedWidget *m_stack; 0038 WidgetMap m_map; 0039 template<typename T> T *get(const QString &s) 0040 { 0041 return qobject_cast<T *>(m_map[s].second); 0042 } 0043 template<typename T> T *getButton(const QString &s) 0044 { 0045 return qobject_cast<T *>(m_map[s].first); 0046 } 0047 }; 0048 0049 class MainWindow : public KXmlGuiWindow 0050 { 0051 Q_OBJECT 0052 0053 public: 0054 explicit MainWindow(QWidget *parent = nullptr); 0055 0056 protected: 0057 void closeEvent(QCloseEvent *event) override; 0058 void dragEnterEvent(QDragEnterEvent *event) override; 0059 void dropEvent(QDropEvent *event) override; 0060 0061 private: 0062 GCodeEditorWidget *m_gcodeEditor = nullptr; 0063 KTextEditor::View *m_currEditorView = nullptr; 0064 int m_currInstance; 0065 LateralArea m_lateral; 0066 QList<QUrl> m_openFiles; 0067 QString m_theme; 0068 QTabWidget *m_instances = nullptr; 0069 bool askToClose(); 0070 bool askToSave(const QVector<QUrl> &fileList); 0071 QString getTheme(); 0072 void initWidgets(); 0073 void loadFile(const QUrl &fileName); 0074 void newAtCoreInstance(); 0075 void openActionTriggered(); 0076 void processDropEvent(const QList<QUrl> &fileList); 0077 void setupActions(); 0078 void setupLateralArea(); 0079 void toggleGCodeActions(); 0080 void updateBedSize(const QSize &newSize); 0081 void updateClientFactory(KTextEditor::View *view); 0082 0083 signals: 0084 void extruderCountChanged(int count); 0085 void profilesChanged(); 0086 };