From 0a351112dd001dd0cd36d6e40017bd0b14dcd0a0 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Fri, 20 Jan 2017 19:35:46 +0100 Subject: [PATCH] Re #4224: Enable .otx file drag&drop on main window --- companion/src/mainwindow.cpp | 52 +++++++++++------------------------- companion/src/mainwindow.h | 3 ++- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 94196807d..507dd28c3 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -555,13 +555,12 @@ void MainWindow::openDocURL() QDesktopServices::openUrl(QUrl(link)); } -void MainWindow::openFile() +void MainWindow::openFile(const QString & fileName, bool updateLastUsedDir) { - QString fileFilter; - fileFilter = tr(EEPROM_FILES_FILTER); - QString fileName = QFileDialog::getOpenFileName(this, tr("Open Models and Settings file"), g.eepromDir(), fileFilter); if (!fileName.isEmpty()) { - g.eepromDir(QFileInfo(fileName).dir().absolutePath()); + if (updateLastUsedDir) { + g.eepromDir(QFileInfo(fileName).dir().absolutePath()); + } QMdiSubWindow *existing = findMdiChild(fileName); if (existing) { @@ -577,6 +576,14 @@ void MainWindow::openFile() } } +void MainWindow::openFile() +{ + QString fileFilter; + fileFilter = tr(EEPROM_FILES_FILTER); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Models and Settings file"), g.eepromDir(), fileFilter); + openFile(fileName); +} + void MainWindow::save() { if (activeMdiChild() && activeMdiChild()->save()) @@ -594,18 +601,7 @@ void MainWindow::openRecentFile() QAction *action = qobject_cast(sender()); if (action) { QString fileName = action->data().toString(); - - QMdiSubWindow *existing = findMdiChild(fileName); - if (existing) { - mdiArea->setActiveSubWindow(existing); - } - else { - MdiChild *child = createMdiChild(); - if (child->loadFile(fileName)) { - statusBar()->showMessage(tr("File loaded"), 2000); - child->show(); - } - } + openFile(fileName, false); } } @@ -1402,28 +1398,10 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event) void MainWindow::dropEvent(QDropEvent *event) { - if(getCurrentBoard()== BOARD_HORUS) - return; QList urls = event->mimeData()->urls(); - if (urls.isEmpty()) - return; - + if (urls.isEmpty()) return; QString fileName = urls.first().toLocalFile(); - if (fileName.isEmpty()) - return; - g.eepromDir(QFileInfo(fileName).dir().absolutePath()); - - QMdiSubWindow *existing = findMdiChild(fileName); - if (existing) { - mdiArea->setActiveSubWindow(existing); - return; - } - - MdiChild *child = createMdiChild(); - if (child->loadFile(fileName)) { - statusBar()->showMessage(tr("File loaded"), 2000); - child->show(); - } + openFile(fileName); } void MainWindow::autoClose() diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index 4aa012510..8e5131af1 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -162,7 +162,8 @@ class MainWindow : public QMainWindow void updateIconSizeActions(); void updateLanguageActions(); void updateIconThemeActions(); - + void openFile(const QString & fileName, bool updateLastUsedDir = false); + QString strippedName(const QString & fullFileName); MdiChild * activeMdiChild();