Changeset View
Changeset View
Standalone View
Standalone View
src/mainwindow.cpp
Show All 10 Lines | 1 | /* Atelier KDE Printer Host for 3D Printing | |||
---|---|---|---|---|---|
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. | ||
15 | 15 | | |||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | 18 | */ | ||
19 | #include "mainwindow.h" | 19 | #include "mainwindow.h" | ||
rizzitello: New Empty line | |||||
20 | #include "ui_mainwindow.h" | 20 | #include "ui_mainwindow.h" | ||
21 | #include <QFileDialog> | 21 | #include <QFileDialog> | ||
22 | #include <KLocalizedString> | 22 | #include <KLocalizedString> | ||
23 | #include <KStandardAction> | 23 | #include <KStandardAction> | ||
24 | #include <KActionCollection> | 24 | #include <KActionCollection> | ||
25 | #include <KXMLGUIFactory> | 25 | #include <KXMLGUIFactory> | ||
26 | #include <dialogs/connectsettingsdialog.h> | 26 | #include <dialogs/connectsettingsdialog.h> | ||
27 | #include <dialogs/profilesdialog.h> | 27 | #include <dialogs/profilesdialog.h> | ||
28 | #include <widgets/gcodeeditorwidget.h> | 28 | #include <widgets/gcodeeditorwidget.h> | ||
29 | #include <set> | ||||
30 | #include <QToolButton> | ||||
29 | #include <memory> | 31 | #include <memory> | ||
32 | #include <QStackedWidget> | ||||
33 | #include <widgets/3dview/viewer3d.h> | ||||
34 | #include <widgets/videomonitorwidget.h> | ||||
35 | | ||||
patrickelectric: Alphabetic order. | |||||
patrickelectric: S goes before T. | |||||
30 | MainWindow::MainWindow(QWidget *parent) : | 36 | MainWindow::MainWindow(QWidget *parent) : | ||
patrickelectric: Where this is used ? | |||||
laysrodrigues: removed. | |||||
31 | KXmlGuiWindow(parent), | 37 | KXmlGuiWindow(parent), | ||
32 | ui(new Ui::MainWindow), | 38 | ui(new Ui::MainWindow), | ||
33 | m_curr_editor_view(nullptr) | 39 | m_curr_editor_view(nullptr) | ||
34 | { | 40 | { | ||
patrickelectric: Alphabetic order. | |||||
35 | ui->setupUi(this); | 41 | ui->setupUi(this); | ||
36 | initWidgets(); | 42 | initWidgets(); | ||
37 | setupActions(); | 43 | setupActions(); | ||
38 | } | 44 | } | ||
39 | 45 | | |||
40 | MainWindow::~MainWindow() | 46 | MainWindow::~MainWindow() | ||
41 | { | 47 | { | ||
42 | delete ui; | 48 | delete ui; | ||
43 | } | 49 | } | ||
44 | 50 | | |||
45 | void MainWindow::initWidgets() | 51 | void MainWindow::initWidgets() | ||
46 | { | 52 | { | ||
47 | connect(ui->gcodeEditorWidget, &GCodeEditorWidget::updateClientFactory, this, [ & ](KTextEditor::View* view){ | 53 | /* | ||
54 | auto instance = qobject_cast<AtCoreInstanceWidget*>(ui->tabWidget->currentWidget()); | ||||
55 | connectSettingsDialog->setFirmwareList(instance->firmwares()); | ||||
56 | profilesDialog->setBaudRates(instance->baudRates()); | ||||
57 | */ | ||||
58 | | ||||
59 | setupLateralArea(); | ||||
60 | } | ||||
61 | | ||||
62 | // Move to LateralArea. | ||||
63 | void MainWindow::setupLateralArea() | ||||
64 | { | ||||
65 | m_lateral.m_toolBar = new QWidget(); | ||||
66 | m_lateral.m_stack = new QStackedWidget(); | ||||
67 | auto *buttonLayout = new QVBoxLayout(); | ||||
68 | | ||||
69 | auto setupButton = [this, buttonLayout](const QString& s, QWidget *w) { | ||||
70 | QToolButton *btn = nullptr; | ||||
71 | btn = new QToolButton(m_lateral.m_toolBar); | ||||
72 | btn->setText(s); | ||||
73 | btn->setAutoExclusive(true); | ||||
74 | btn->setCheckable(true); | ||||
75 | m_lateral.m_stack->addWidget(w); | ||||
76 | m_lateral.m_map[s] = {btn, w}; | ||||
77 | | ||||
78 | buttonLayout->addWidget(btn); | ||||
79 | connect(btn, &QToolButton::toggled, [this, w](bool checked) { | ||||
80 | if (checked) | ||||
81 | m_lateral.m_stack->setCurrentWidget(w); | ||||
82 | }); | ||||
83 | }; | ||||
84 | | ||||
85 | auto *gcodeEditor = new GCodeEditorWidget(this); | ||||
86 | connect(gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, [&](KTextEditor::View* view){ | ||||
48 | guiFactory()->removeClient(m_curr_editor_view); | 87 | guiFactory()->removeClient(m_curr_editor_view); | ||
49 | guiFactory()->addClient(view); | 88 | guiFactory()->addClient(view); | ||
50 | m_curr_editor_view = view; | 89 | m_curr_editor_view = view; | ||
51 | }); | 90 | }); | ||
91 | | ||||
92 | setupButton(i18n("&3D"), new Viewer3D(this)); | ||||
93 | setupButton(i18n("&GCode"), gcodeEditor); | ||||
94 | setupButton(i18n("&Video"), new VideoMonitorWidget(this)); | ||||
95 | | ||||
96 | m_lateral.m_toolBar->setLayout(buttonLayout); | ||||
97 | m_lateral.m_toolBar->show(); | ||||
98 | m_lateral.m_stack->show(); | ||||
99 | | ||||
100 | | ||||
52 | } | 101 | } | ||
53 | 102 | | |||
54 | void MainWindow::setupActions() | 103 | void MainWindow::setupActions() | ||
55 | { | 104 | { | ||
56 | // Actions for the Toolbar | 105 | // Actions for the Toolbar | ||
57 | QAction *action; | 106 | QAction *action; | ||
58 | action = actionCollection()->addAction(QStringLiteral("open_gcode")); | 107 | action = actionCollection()->addAction(QStringLiteral("open_gcode")); | ||
59 | action->setText(i18n("&Open GCode")); | 108 | action->setText(i18n("&Open GCode")); | ||
Show All 27 Lines | |||||
87 | 136 | | |||
88 | setupGUI(Default, ":/atelierui"); | 137 | setupGUI(Default, ":/atelierui"); | ||
89 | } | 138 | } | ||
90 | 139 | | |||
91 | void MainWindow::openFile() | 140 | void MainWindow::openFile() | ||
92 | { | 141 | { | ||
93 | QUrl fileNameFromDialog = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"), | 142 | QUrl fileNameFromDialog = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"), | ||
94 | QDir::homePath(), i18n("GCode (*.gco *.gcode)")); | 143 | QDir::homePath(), i18n("GCode (*.gco *.gcode)")); | ||
144 | /* | ||||
95 | if (!fileNameFromDialog.isEmpty()) { | 145 | if (!fileNameFromDialog.isEmpty()) { | ||
96 | ui->gcodeEditorWidget->loadFile(fileNameFromDialog); | 146 | ui->gcodeEditorWidget->loadFile(fileNameFromDialog); | ||
97 | ui->view3DWidget->drawModel(fileNameFromDialog.toString()); | 147 | ui->view3DWidget->drawModel(fileNameFromDialog.toString()); | ||
98 | m_openFiles.append(fileNameFromDialog); | 148 | m_openFiles.append(fileNameFromDialog); | ||
99 | } | 149 | } | ||
150 | */ | ||||
100 | } | 151 | } | ||
@patrickelectric he is using here laysrodrigues: @patrickelectric he is using here | |||||
101 | void MainWindow::newConnection(const QString& port, const QMap<QString, QVariant>& profile) | 152 | void MainWindow::newConnection(const QString& port, const QMap<QString, QVariant>& profile) | ||
102 | { | 153 | { | ||
154 | /* | ||||
103 | const int tabs = ui->tabWidget->count(); | 155 | const int tabs = ui->tabWidget->count(); | ||
104 | if(tabs == 1){ | 156 | if(tabs == 1){ | ||
105 | auto instance = qobject_cast<AtCoreInstanceWidget*>(ui->tabWidget->currentWidget()); | 157 | auto instance = qobject_cast<AtCoreInstanceWidget*>(ui->tabWidget->currentWidget()); | ||
106 | if(!instance->connected()){ | 158 | if(!instance->connected()){ | ||
107 | instance->startConnection(port, profile); | 159 | instance->startConnection(port, profile); | ||
108 | ui->tabWidget->setTabText(ui->tabWidget->currentIndex(), profile["name"].toString()); | 160 | ui->tabWidget->setTabText(ui->tabWidget->currentIndex(), profile["name"].toString()); | ||
109 | return; | 161 | return; | ||
110 | } | 162 | } | ||
111 | } | 163 | } | ||
112 | auto newInstanceWidget = new AtCoreInstanceWidget(); | 164 | auto newInstanceWidget = new AtCoreInstanceWidget(); | ||
113 | ui->tabWidget->addTab(newInstanceWidget, profile["name"].toString()); | 165 | ui->tabWidget->addTab(newInstanceWidget, profile["name"].toString()); | ||
114 | newInstanceWidget->startConnection(port, profile); | 166 | newInstanceWidget->startConnection(port, profile); | ||
167 | */ | ||||
115 | } | 168 | } |
New Empty line