Re #4224: Enable .otx file drag&drop on main window

This commit is contained in:
Damjan Adamic
2017-01-20 19:35:46 +01:00
parent f3521728ef
commit 0a351112dd
2 changed files with 17 additions and 38 deletions
+15 -37
View File
@@ -555,13 +555,12 @@ void MainWindow::openDocURL()
QDesktopServices::openUrl(QUrl(link)); 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()) { if (!fileName.isEmpty()) {
g.eepromDir(QFileInfo(fileName).dir().absolutePath()); if (updateLastUsedDir) {
g.eepromDir(QFileInfo(fileName).dir().absolutePath());
}
QMdiSubWindow *existing = findMdiChild(fileName); QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) { 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() void MainWindow::save()
{ {
if (activeMdiChild() && activeMdiChild()->save()) if (activeMdiChild() && activeMdiChild()->save())
@@ -594,18 +601,7 @@ void MainWindow::openRecentFile()
QAction *action = qobject_cast<QAction *>(sender()); QAction *action = qobject_cast<QAction *>(sender());
if (action) { if (action) {
QString fileName = action->data().toString(); QString fileName = action->data().toString();
openFile(fileName, false);
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();
}
}
} }
} }
@@ -1402,28 +1398,10 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
void MainWindow::dropEvent(QDropEvent *event) void MainWindow::dropEvent(QDropEvent *event)
{ {
if(getCurrentBoard()== BOARD_HORUS)
return;
QList<QUrl> urls = event->mimeData()->urls(); QList<QUrl> urls = event->mimeData()->urls();
if (urls.isEmpty()) if (urls.isEmpty()) return;
return;
QString fileName = urls.first().toLocalFile(); QString fileName = urls.first().toLocalFile();
if (fileName.isEmpty()) openFile(fileName);
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();
}
} }
void MainWindow::autoClose() void MainWindow::autoClose()
+1
View File
@@ -162,6 +162,7 @@ class MainWindow : public QMainWindow
void updateIconSizeActions(); void updateIconSizeActions();
void updateLanguageActions(); void updateLanguageActions();
void updateIconThemeActions(); void updateIconThemeActions();
void openFile(const QString & fileName, bool updateLastUsedDir = false);
QString strippedName(const QString & fullFileName); QString strippedName(const QString & fullFileName);