Changeset View
Changeset View
Standalone View
Standalone View
src/mainwindow.cpp
Show All 34 Lines | |||||
35 | MainWindow::MainWindow(QWidget *parent) : | 35 | MainWindow::MainWindow(QWidget *parent) : | ||
36 | KXmlGuiWindow(parent) | 36 | KXmlGuiWindow(parent) | ||
37 | , m_currEditorView(nullptr) | 37 | , m_currEditorView(nullptr) | ||
38 | , m_theme(getTheme()) | 38 | , m_theme(getTheme()) | ||
39 | , m_instances(new QTabWidget(this)) | 39 | , m_instances(new QTabWidget(this)) | ||
40 | { | 40 | { | ||
41 | initWidgets(); | 41 | initWidgets(); | ||
42 | setupActions(); | 42 | setupActions(); | ||
43 | setAcceptDrops(true); | ||||
44 | | ||||
43 | connect(m_instances, &QTabWidget::tabCloseRequested, [this](int index) { | 45 | connect(m_instances, &QTabWidget::tabCloseRequested, [this](int index) { | ||
44 | auto tempWidget = qobject_cast<AtCoreInstanceWidget *>(m_instances->widget(index)); | 46 | auto tempWidget = qobject_cast<AtCoreInstanceWidget *>(m_instances->widget(index)); | ||
45 | if (tempWidget->isPrinting()) { | 47 | if (tempWidget->isPrinting()) { | ||
46 | if (askToClose()) { | 48 | if (askToClose()) { | ||
47 | delete tempWidget; | 49 | delete tempWidget; | ||
48 | } else { | 50 | } else { | ||
49 | return; | 51 | return; | ||
50 | } | 52 | } | ||
Show All 22 Lines | 74 | if (askToClose()) { | |||
73 | event->accept(); | 75 | event->accept(); | ||
74 | } else { | 76 | } else { | ||
75 | event->ignore(); | 77 | event->ignore(); | ||
76 | } | 78 | } | ||
77 | } | 79 | } | ||
78 | disconnect(m_gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, &MainWindow::updateClientFactory); | 80 | disconnect(m_gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, &MainWindow::updateClientFactory); | ||
79 | } | 81 | } | ||
80 | 82 | | |||
83 | void MainWindow::dragEnterEvent(QDragEnterEvent *event) | ||||
84 | { | ||||
85 | event->accept(); | ||||
86 | } | ||||
87 | | ||||
88 | void MainWindow::dropEvent(QDropEvent *event) | ||||
89 | { | ||||
90 | const QMimeData *mimeData = event->mimeData(); | ||||
91 | if (mimeData->hasUrls()) { | ||||
92 | processDropEvent(mimeData->urls()); | ||||
93 | } | ||||
94 | } | ||||
95 | | ||||
96 | void MainWindow::processDropEvent(const QList<QUrl> &fileList) | ||||
97 | { | ||||
98 | for (const auto &url : fileList) { | ||||
99 | //Loop thru the urls and only load ones ending our "supported" formats | ||||
100 | QString ext = url.toLocalFile().split('.').last(); | ||||
patrickelectric: This kind of style is not used anywhere and is not kde standard, please check around the code. | |||||
Im not sure exactly what you are refering to in the above comment. rizzitello: Im not sure exactly what you are refering to in the above comment. | |||||
101 | if (ext.contains("gcode", Qt::CaseInsensitive) | ||||
102 | || ext.contains("gco", Qt::CaseInsensitive)) { | ||||
103 | loadFile(url); | ||||
104 | } | ||||
105 | } | ||||
106 | } | ||||
107 | | ||||
81 | void MainWindow::initWidgets() | 108 | void MainWindow::initWidgets() | ||
82 | { | 109 | { | ||
83 | setupLateralArea(); | 110 | setupLateralArea(); | ||
84 | newAtCoreInstance(); | 111 | newAtCoreInstance(); | ||
85 | // View: | 112 | // View: | ||
86 | // Sidebar, Sidebar Controls, Printer Tabs. | 113 | // Sidebar, Sidebar Controls, Printer Tabs. | ||
87 | // Sidebar Controls and Printer Tabs can be resized, Sidebar can't. | 114 | // Sidebar Controls and Printer Tabs can be resized, Sidebar can't. | ||
88 | auto splitter = new QSplitter(); | 115 | auto splitter = new QSplitter(); | ||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 206 | { | |||
181 | m_lateral.m_stack->setCurrentWidget(w); | 208 | m_lateral.m_stack->setCurrentWidget(w); | ||
182 | } | 209 | } | ||
183 | toggleGCodeActions(); | 210 | toggleGCodeActions(); | ||
184 | }); | 211 | }); | ||
185 | }; | 212 | }; | ||
186 | 213 | | |||
187 | m_gcodeEditor = new GCodeEditorWidget(this); | 214 | m_gcodeEditor = new GCodeEditorWidget(this); | ||
188 | connect(m_gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, &MainWindow::updateClientFactory); | 215 | connect(m_gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, &MainWindow::updateClientFactory); | ||
189 | setupButton("3d", i18n("&3D"), QIcon::fromTheme("draw-cuboid", QIcon(QString(":/%1/3d").arg(m_theme))), new Viewer3D(this)); | 216 | | ||
217 | auto *viewer3D = new Viewer3D(this); | ||||
218 | connect(viewer3D, &Viewer3D::droppedUrls, this, &MainWindow::processDropEvent); | ||||
patrickelectric: ,SPACE SPACE SPACE SPACE i18n ? | |||||
219 | | ||||
220 | setupButton("3d", i18n("&3D"), QIcon::fromTheme("draw-cuboid", QIcon(QString(":/%1/3d").arg(m_theme))), viewer3D); | ||||
190 | setupButton("gcode", i18n("&GCode"), QIcon::fromTheme("accessories-text-editor", QIcon(":/icon/edit")), m_gcodeEditor); | 221 | setupButton("gcode", i18n("&GCode"), QIcon::fromTheme("accessories-text-editor", QIcon(":/icon/edit")), m_gcodeEditor); | ||
191 | setupButton("video", i18n("&Video"), QIcon::fromTheme("camera-web", QIcon(":/icon/video")), new VideoMonitorWidget(this)); | 222 | setupButton("video", i18n("&Video"), QIcon::fromTheme("camera-web", QIcon(":/icon/video")), new VideoMonitorWidget(this)); | ||
192 | buttonLayout->addStretch(); | 223 | buttonLayout->addStretch(); | ||
193 | m_lateral.m_toolBar->setLayout(buttonLayout); | 224 | m_lateral.m_toolBar->setLayout(buttonLayout); | ||
194 | } | 225 | } | ||
195 | 226 | | |||
196 | void MainWindow::setupActions() | 227 | void MainWindow::setupActions() | ||
197 | { | 228 | { | ||
198 | // Actions for the Toolbar | 229 | // Actions for the Toolbar | ||
199 | QAction *action; | 230 | QAction *action; | ||
200 | action = actionCollection()->addAction(QStringLiteral("open")); | 231 | action = actionCollection()->addAction(QStringLiteral("open")); | ||
201 | action->setIcon(QIcon::fromTheme("document-open", QIcon(QString(":/%1/open").arg(m_theme)))); | 232 | action->setIcon(QIcon::fromTheme("document-open", QIcon(QString(":/%1/open").arg(m_theme)))); | ||
202 | 233 | | |||
203 | action->setText(i18n("&Open")); | 234 | action->setText(i18n("&Open")); | ||
204 | actionCollection()->setDefaultShortcut(action, QKeySequence::Open); | 235 | actionCollection()->setDefaultShortcut(action, QKeySequence::Open); | ||
205 | connect(action, &QAction::triggered, this, &MainWindow::openFile); | 236 | connect(action, &QAction::triggered, this, &MainWindow::openActionTriggered); | ||
206 | 237 | | |||
207 | action = actionCollection()->addAction(QStringLiteral("new_instance")); | 238 | action = actionCollection()->addAction(QStringLiteral("new_instance")); | ||
208 | action->setIcon(QIcon::fromTheme("list-add", QIcon(QString(":/%1/addTab").arg(m_theme)))); | 239 | action->setIcon(QIcon::fromTheme("list-add", QIcon(QString(":/%1/addTab").arg(m_theme)))); | ||
209 | 240 | | |||
210 | action->setText(i18n("&New Connection")); | 241 | action->setText(i18n("&New Connection")); | ||
211 | actionCollection()->setDefaultShortcut(action, QKeySequence::AddTab); | 242 | actionCollection()->setDefaultShortcut(action, QKeySequence::AddTab); | ||
212 | connect(action, &QAction::triggered, this, &MainWindow::newAtCoreInstance); | 243 | connect(action, &QAction::triggered, this, &MainWindow::newAtCoreInstance); | ||
213 | 244 | | |||
Show All 12 Lines | |||||
226 | 257 | | |||
227 | action->setText(i18n("&Quit")); | 258 | action->setText(i18n("&Quit")); | ||
228 | actionCollection()->setDefaultShortcut(action, QKeySequence::Quit); | 259 | actionCollection()->setDefaultShortcut(action, QKeySequence::Quit); | ||
229 | connect(action, &QAction::triggered, this, &MainWindow::close); | 260 | connect(action, &QAction::triggered, this, &MainWindow::close); | ||
230 | 261 | | |||
231 | setupGUI(Default, "atelierui"); | 262 | setupGUI(Default, "atelierui"); | ||
232 | } | 263 | } | ||
233 | 264 | | |||
234 | void MainWindow::openFile() | 265 | void MainWindow::openActionTriggered() | ||
235 | { | 266 | { | ||
236 | QUrl fileName = QFileDialog::getOpenFileUrl( | 267 | QList<QUrl> fileList = QFileDialog::getOpenFileUrls( | ||
237 | this | 268 | this | ||
238 | , i18n("Open GCode") | 269 | , i18n("Open GCode") | ||
239 | , QUrl::fromLocalFile(QDir::homePath()) | 270 | , QUrl::fromLocalFile(QDir::homePath()) | ||
240 | , i18n("GCode(*.gco *.gcode);;All Files(*.*)") | 271 | , i18n("GCode(*.gco *.gcode);;All Files(*.*)") | ||
241 | ); | 272 | ); | ||
273 | for (const auto &url : fileList) { | ||||
274 | loadFile(url); | ||||
275 | } | ||||
276 | } | ||||
242 | 277 | | |||
278 | void MainWindow::loadFile(const QUrl &fileName) | ||||
279 | { | ||||
243 | if (!fileName.isEmpty()) { | 280 | if (!fileName.isEmpty()) { | ||
244 | 281 | | |||
245 | m_lateral.get<GCodeEditorWidget>("gcode")->loadFile(fileName); | 282 | m_lateral.get<GCodeEditorWidget>("gcode")->loadFile(fileName); | ||
246 | m_lateral.get<Viewer3D>("3d")->drawModel(fileName.toString()); | 283 | m_lateral.get<Viewer3D>("3d")->drawModel(fileName.toString()); | ||
247 | 284 | | |||
248 | const int tabs = m_instances->count(); | 285 | const int tabs = m_instances->count(); | ||
249 | m_openFiles.append(fileName); | 286 | m_openFiles.append(fileName); | ||
250 | 287 | | |||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |
This kind of style is not used anywhere and is not kde standard, please check around the code.