void LevelEdit::dropEvent(QDropEvent *e) { this->raise(); this->setFocus(Qt::ActiveWindowFocusReason); qApp->setActiveWindow(this); bool requestReload = false; foreach (const QUrl &url, e->mimeData()->urls()) { const QString &fileName = url.toLocalFile(); if(QFileInfo(fileName).isDir()) { SmartImporter * importer = new SmartImporter((QWidget*)this, fileName, (QWidget*)this); if(importer->isValid()){ if(importer->attemptFastImport()){ requestReload = true; delete importer; break; } } delete importer; } } if(requestReload) emit forceReload(); }
//Reload opened file data void MainWindow::on_actionReload_triggered() { if(_is_reloading) return; _is_reloading=true; BoolReseter rst(&_is_reloading); Q_UNUSED(rst); QString filePath; QRect wnGeom; if (activeChildWindow()==1) { LevelData FileData; filePath = activeLvlEditWin()->curFile; if(activeLvlEditWin()->isUntitled) { QMessageBox::warning(this, tr("File not saved"), tr("File doesn't saved on disk."), QMessageBox::Ok); return; } if (!QFileInfo(filePath).exists() ) { QMessageBox::critical(this, tr("File open error"), tr("Can't open the file.\nFile not exist."), QMessageBox::Ok); return; } if(activeLvlEditWin()->LvlData.modified) { QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"), tr("Do you want to save before reload stuff?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel); if((ret==QMessageBox::Cancel)||(ret==0)) return; else if(ret==QMessageBox::Yes) save(); } //Open level file FileData = FileFormats::OpenLevelFile(filePath); if( !FileData.ReadFileValid ){ statusBar()->showMessage(tr("Reloading error"), 2000); return;} FileData.playmusic = GlobalSettings::autoPlayMusic; activeLvlEditWin()->LvlData.modified = false; QFile file(filePath+".meta"); if(QFileInfo(filePath+".meta").exists()) { if (file.open(QIODevice::ReadOnly)) { QString metaRaw; QTextStream meta(&file); meta.setCodec("UTF-8"); metaRaw = meta.readAll(); if(FileData.metaData.script) { delete FileData.metaData.script; FileData.metaData.script = NULL; } FileData.metaData = FileFormats::ReadNonSMBX64MetaData(metaRaw, filePath+".meta"); } else { QMessageBox::critical(this, tr("File open error"), tr("Can't open the file."), QMessageBox::Ok); } } //Remember last section ID and positions! int lastSection=0; QMap<int, QPair<long, long> > sectionPoss; lastSection = activeLvlEditWin()->LvlData.CurSection; SetCurrentLevelSection(lastSection);//Need to remember position of current section for(int i=0; i<activeLvlEditWin()->LvlData.sections.size(); i++) { LevelSection sct = activeLvlEditWin()->LvlData.sections[i]; sectionPoss[sct.id]=QPair<long, long >(sct.PositionX, sct.PositionY); } activeLvlEditWin()->close();//Close old widget without closing of sub-window //Get pointer to current sub-window QMdiSubWindow *window = ui->centralWidget->activeSubWindow(); //Get geometry of current subwindow wnGeom = ui->centralWidget->activeSubWindow()->geometry(); //delete window->widget(); LevelEdit *chLvlWin = new LevelEdit(window); connect(chLvlWin, SIGNAL(forceReload()), this, SLOT(on_actionReload_triggered())); window->setWidget(chLvlWin); GraphicsWorkspace* gr = static_cast<GraphicsWorkspace *>(chLvlWin->getGraphicsView()); connect(gr, SIGNAL(zoomValueChanged(QString)), zoom, SLOT(setText(QString))); //ui->centralWidget->activeSubWindow()->close(); LevelEdit *child = chLvlWin;//createLvlChild(); LvlMusPlay::setNoMusic(); setMusic(false); if ((bool) (child->loadFile(filePath, FileData, configs, GlobalSettings::LvlOpts))) { child->show(); ui->centralWidget->activeSubWindow()->setGeometry(wnGeom); child->updateGeometry(); child->ResetPosition(); statusBar()->showMessage(tr("Level file reloaded"), 2000); LvlMusPlay::musicForceReset=true; //reset musics updateMenus(true); child->setFocus(); //Restore saved section positions for(int i=0; i<child->LvlData.sections.size(); i++) { if(sectionPoss.contains(child->LvlData.sections[i].id)) { child->LvlData.sections[i].PositionX=sectionPoss[child->LvlData.sections[i].id].first; child->LvlData.sections[i].PositionY=sectionPoss[child->LvlData.sections[i].id].second; } } SetCurrentLevelSection(lastSection); if(GlobalSettings::autoPlayMusic) ui->actionPlayMusic->setChecked(true); } else { WriteToLog(QtDebugMsg, ">>File loading aborted"); child->show(); WriteToLog(QtDebugMsg, ">>Window showed"); if(activeChildWindow()==1) activeLvlEditWin()->LvlData.modified = false; WriteToLog(QtDebugMsg, ">>Option set"); ui->centralWidget->activeSubWindow()->close(); WriteToLog(QtDebugMsg, ">>Windows closed"); } } else if (activeChildWindow()==2) { filePath = activeNpcEditWin()->curFile; QFile fileIn(filePath); if(activeNpcEditWin()->isUntitled) { QMessageBox::warning(this, tr("File not saved"), tr("File doesn't saved on disk."), QMessageBox::Ok); return; } if(activeNpcEditWin()->isModyfied) { QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"), tr("Do you want to save before reload stuff?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel); if((ret==QMessageBox::Cancel)||(ret==0)) return; else if(ret==QMessageBox::Yes) save(); } if (!fileIn.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("File open error"), tr("Can't open the file."), QMessageBox::Ok); return; } NPCConfigFile FileData = FileFormats::ReadNpcTXTFile(fileIn); if( !FileData.ReadFileValid ) return; wnGeom = ui->centralWidget->activeSubWindow()->geometry(); activeNpcEditWin()->isModyfied = false; activeNpcEditWin()->close(); //NpcEdit *child = createNPCChild(); QMdiSubWindow *npcWindow = ui->centralWidget->activeSubWindow(); NpcEdit *child = new NpcEdit(&configs, npcWindow); npcWindow->setWidget(child); if (child->loadFile(filePath, FileData)) { statusBar()->showMessage(tr("NPC Config reloaded"), 2000); child->show(); ui->centralWidget->activeSubWindow()->setGeometry(wnGeom); updateMenus(true); } else { child->close(); npcWindow->close(); } } else if (activeChildWindow()==3) { WorldData FileData; filePath = activeWldEditWin()->curFile; if(activeWldEditWin()->isUntitled) { QMessageBox::warning(this, tr("File not saved"), tr("File doesn't saved on disk."), QMessageBox::Ok); return; } if (!QFileInfo(filePath).exists() ) { QMessageBox::critical(this, tr("File open error"), tr("Can't open the file.\nFile not exist."), QMessageBox::Ok); return; } if(activeWldEditWin()->WldData.modified){ QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"), tr("Do you want to save before reload stuff?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel); if((ret==QMessageBox::Cancel)||(ret==0)) return; else if(ret==QMessageBox::Yes) save(); } FileData = FileFormats::OpenWorldFile(filePath); if( !FileData.ReadFileValid ){ statusBar()->showMessage(tr("Reloading error"), 2000); return;} FileData.filename = QFileInfo(filePath).baseName(); FileData.path = QFileInfo(filePath).absoluteDir().absolutePath(); FileData.playmusic = GlobalSettings::autoPlayMusic; activeWldEditWin()->WldData.modified = false; QFile file(filePath+".meta"); if(QFileInfo(filePath+".meta").exists()) { if (file.open(QIODevice::ReadOnly)) { QString metaRaw; QTextStream meta(&file); meta.setCodec("UTF-8"); metaRaw = meta.readAll(); FileData.metaData = FileFormats::ReadNonSMBX64MetaData(metaRaw, filePath+".meta"); } else { QMessageBox::critical(this, tr("File open error"), tr("Can't open the file."), QMessageBox::Ok); } } wnGeom = ui->centralWidget->activeSubWindow()->geometry(); QMdiSubWindow *worldWindow = ui->centralWidget->activeSubWindow(); long posX = activeWldEditWin()->scene->_viewPort->horizontalScrollBar()->value(); long posY = activeWldEditWin()->scene->_viewPort->verticalScrollBar()->value(); activeWldEditWin()->close(); WorldEdit *child = new WorldEdit(worldWindow); connect(child, SIGNAL(forceReload()), this, SLOT(on_actionReload_triggered())); worldWindow->setWidget(child); GraphicsWorkspace* gr = static_cast<GraphicsWorkspace *>(child->getGraphicsView()); connect(gr, SIGNAL(zoomValueChanged(QString)), zoom, SLOT(setText(QString))); if ( (bool)(child->loadFile(filePath, FileData, configs, GlobalSettings::LvlOpts)) ) { child->show(); ui->centralWidget->activeSubWindow()->setGeometry(wnGeom); child->updateGeometry(); child->ResetPosition(); updateMenus(true); dock_WldSettingsBox->setCurrentWorldSettings(); if(FileData.HubStyledWorld) { dock_WldSettingsBox->setVisible(true); dock_WldSettingsBox->raise(); } child->scene->_viewPort->horizontalScrollBar()->setValue(posX); child->scene->_viewPort->verticalScrollBar()->setValue(posY); statusBar()->showMessage(tr("World map file loaded"), 2000); } else { WriteToLog(QtDebugMsg, ">>File loading aborted"); child->show(); WriteToLog(QtDebugMsg, ">>Window showed"); if(activeChildWindow()==3) activeWldEditWin()->WldData.modified = false; WriteToLog(QtDebugMsg, ">>Option set"); ui->centralWidget->activeSubWindow()->close(); WriteToLog(QtDebugMsg, ">>Windows closed"); } } dock_LvlItemBox->clearFilter(); }
void ImageSequenceSource::reloadImageSequence() { if (!currentDir_.empty()) forceReload(); }
PhotoView::Actions::Actions( PhotoView * photoView ): _photoView( photoView ) { // // Zoom // noZoom = createAction( tr( "No Zoom (100% / &1:1)" ), Qt::Key_1, NoZoom ); CONNECT_ACTION( noZoom, photoView, setZoomMode() ); zoomIn = createAction( tr( "Zoom In (Enlarge)" ), Qt::Key_Plus ); CONNECT_ACTION( zoomIn, photoView, zoomIn() ); zoomOut = createAction( tr( "Zoom Out (Shrink)" ), Qt::Key_Minus ); CONNECT_ACTION( zoomOut, photoView, zoomOut() ); zoomFitImage = createAction( tr( "Zoom to &Fit Window" ), Qt::Key_F, ZoomFitImage ); addShortcut( zoomFitImage, Qt::Key_M ); CONNECT_ACTION( zoomFitImage, photoView, setZoomMode() ); zoomFitWidth = createAction( tr( "Zoom to Fit Window &Width" ), Qt::Key_W, ZoomFitWidth ); CONNECT_ACTION( zoomFitWidth, photoView, setZoomMode() ); zoomFitHeight = createAction( tr( "Zoom to Fit Window &Height" ), Qt::Key_H, ZoomFitHeight ); CONNECT_ACTION( zoomFitHeight, photoView, setZoomMode() ); zoomFitBest = createAction( tr( "&Best Zoom for Window Width or Height" ), Qt::Key_B, ZoomFitBest ); CONNECT_ACTION( zoomFitBest, photoView, setZoomMode() ); // // Navigation // loadNext = createAction( tr( "Load &Next Image" ), Qt::Key_Space, NavigateNext ); addShortcut( loadNext, Qt::Key_PageDown ); CONNECT_ACTION( loadNext, photoView, navigate() ); loadPrevious = createAction( tr( "Load &Previous Image" ), Qt::Key_Backspace, NavigatePrevious ); addShortcut( loadPrevious, Qt::Key_PageUp ); CONNECT_ACTION( loadPrevious, photoView, navigate() ); loadFirst = createAction( tr( "Load &First Image" ), Qt::Key_Home, NavigateFirst ); CONNECT_ACTION( loadFirst, photoView, navigate() ); loadLast = createAction( tr( "Load &Last Image" ), Qt::Key_End, NavigateLast ); CONNECT_ACTION( loadLast, photoView, navigate() ); // // Misc // forceReload = createAction( tr( "Force &Reload" ), Qt::Key_F5 ); CONNECT_ACTION( forceReload, photoView, forceReload() ); toggleFullscreen = createAction( tr( "Toggle F&ullscreen" ), Qt::Key_Return ); CONNECT_ACTION( toggleFullscreen, photoView, toggleFullscreen() ); quit = createAction( tr ( "&Quit" ), Qt::Key_Q ); addShortcut( quit, Qt::Key_Escape ); CONNECT_ACTION( quit, qApp, quit() ); }
//Reload opened file data void MainWindow::on_actionReload_triggered() { if(m_isFileReloading) return; m_isFileReloading = true; BoolReseter rst(&m_isFileReloading); Q_UNUSED(rst); QString filePath; QRect wnGeom; int activeWindow = activeChildWindow(LastActiveSubWindow); if(activeWindow == WND_Level) { LevelEdit *lvlEdit = activeLvlEditWin(LastActiveSubWindow); LevelData FileData; filePath = lvlEdit->curFile; if(lvlEdit->isUntitled) { QMessageBox::warning(this, tr("File not saved"), tr("File doesn't saved on disk."), QMessageBox::Ok); return; } if(!QFileInfo(filePath).exists()) { QMessageBox::critical(this, tr("File open error"), tr("Can't open the file!\nFile not exist."), QMessageBox::Ok); return; } if(lvlEdit->LvlData.meta.modified) { QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"), tr("Do you want to save before reload stuff?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); if((ret == QMessageBox::Cancel) || (ret == 0)) return; else if(ret == QMessageBox::Yes) save(); } //Open level file if(!FileFormats::OpenLevelFile(filePath, FileData)) { formatErrorMsgBox(filePath, FileData.meta.ERROR_info, FileData.meta.ERROR_linenum, FileData.meta.ERROR_linedata); statusBar()->showMessage(tr("Reloading error"), 2000); return; } FileData.playmusic = GlobalSettings::autoPlayMusic; lvlEdit->LvlData.meta.modified = false; //Remember last section ID and positions! int lastSection = 0; QHash<int, QPair<long, long> > sectionPoss; lastSection = lvlEdit->LvlData.CurSection; SetCurrentLevelSection(lastSection); //Need to remember position of current section for(int i = 0; i < lvlEdit->LvlData.sections.size(); i++) { LevelSection sct = lvlEdit->LvlData.sections[i]; sectionPoss[sct.id] = QPair<long, long >(sct.PositionX, sct.PositionY); } long posX = lvlEdit->scene->m_viewPort->horizontalScrollBar()->value(); long posY = lvlEdit->scene->m_viewPort->verticalScrollBar()->value(); lvlEdit->close();//Close old widget without closing of sub-window //Get geometry of current subwindow wnGeom = LastActiveSubWindow->geometry(); //delete window->widget(); LevelEdit *chLvlWin = new LevelEdit(this, LastActiveSubWindow); connect(chLvlWin, SIGNAL(forceReload()), this, SLOT(on_actionReload_triggered())); LastActiveSubWindow->setWidget(chLvlWin); GraphicsWorkspace *gr = static_cast<GraphicsWorkspace *>(chLvlWin->getGraphicsView()); connect(gr, SIGNAL(zoomValueChanged(QString)), zoom, SLOT(setText(QString))); //LastActiveSubWindow->close(); LevelEdit *child = chLvlWin;//createLvlChild(); LvlMusPlay::setNoMusic(); setMusic(); if(static_cast<bool>(child->loadFile(filePath, FileData, configs, GlobalSettings::LvlOpts))) { child->show(); LastActiveSubWindow->setGeometry(wnGeom); child->updateGeometry(); child->ResetPosition(); statusBar()->showMessage(tr("Level file reloaded"), 2000); LvlMusPlay::musicForceReset = true; //reset musics updateMenus(LastActiveSubWindow, true); child->setFocus(); //Restore saved section positions for(int i = 0; i < child->LvlData.sections.size(); i++) { if(sectionPoss.contains(child->LvlData.sections[i].id)) { QPair<long, long> &sct = sectionPoss[child->LvlData.sections[i].id]; child->LvlData.sections[i].PositionX = sct.first; child->LvlData.sections[i].PositionY = sct.second; } } SetCurrentLevelSection(lastSection); child->scene->m_viewPort->horizontalScrollBar()->setValue(static_cast<int>(posX)); child->scene->m_viewPort->verticalScrollBar()->setValue(static_cast<int>(posY)); if(GlobalSettings::autoPlayMusic) ui->actionPlayMusic->setChecked(true); child->showCustomStuffWarnings(); } else { LogDebug(">>File loading aborted"); LogDebug(">>Window showed"); child->LvlData.meta.modified = false; LogDebug(">>Option set"); LastActiveSubWindow->close(); LogDebug(">>Windows closed"); } } else if(activeWindow == WND_NpcTxt) { NpcEdit *npcEdit = activeNpcEditWin(LastActiveSubWindow); filePath = npcEdit->curFile; if(npcEdit->isUntitled) { QMessageBox::warning(this, tr("File not saved"), tr("File doesn't saved on disk."), QMessageBox::Ok); return; } if(npcEdit->isModyfied) { QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"), tr("Do you want to save before reload stuff?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); if((ret == QMessageBox::Cancel) || (ret == 0)) return; else if(ret == QMessageBox::Yes) save(); } // if (!fileIn.open(QIODevice::ReadOnly)) { // QMessageBox::critical(this, tr("File open error"), // tr("Can't open the file!"), QMessageBox::Ok); // return; // } NPCConfigFile FileData; if(!FileFormats::ReadNpcTXTFileF(filePath, FileData)) { QMessageBox::critical(this, QObject::tr("File open error"), tr("Can't read the file"), QMessageBox::Ok); return; } wnGeom = LastActiveSubWindow->geometry(); npcEdit->isModyfied = false; npcEdit->close(); //NpcEdit *child = createNPCChild(); //QMdiSubWindow *npcWindow = LastActiveSubWindow; NpcEdit *child = new NpcEdit(&configs, LastActiveSubWindow); LastActiveSubWindow->setWidget(child); if(child->loadFile(filePath, FileData)) { statusBar()->showMessage(tr("NPC Config reloaded"), 2000); child->show(); LastActiveSubWindow->setGeometry(wnGeom); updateMenus(LastActiveSubWindow, true); } else { child->close(); LastActiveSubWindow->close(); } } else if(activeWindow == WND_World) { WorldEdit *wldEdit = activeWldEditWin(LastActiveSubWindow); WorldData FileData; filePath = wldEdit->curFile; if(wldEdit->isUntitled) { QMessageBox::warning(this, tr("File not saved"), tr("File doesn't saved on disk."), QMessageBox::Ok); return; } if(!QFileInfo(filePath).exists()) { QMessageBox::critical(this, tr("File open error"), tr("Can't open the file!\nFile not exist."), QMessageBox::Ok); return; } if(wldEdit->WldData.meta.modified) { QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"), tr("Do you want to save before reload stuff?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); if((ret == QMessageBox::Cancel) || (ret == 0)) return; else if(ret == QMessageBox::Yes) save(); } if(!FileFormats::OpenWorldFile(filePath, FileData)) { formatErrorMsgBox(filePath, FileData.meta.ERROR_info, FileData.meta.ERROR_linenum, FileData.meta.ERROR_linedata); statusBar()->showMessage(tr("Reloading error"), 2000); return; } QFileInfo finfo(filePath); FileData.meta.filename = util::getBaseFilename(finfo.fileName()); FileData.meta.path = finfo.absoluteDir().absolutePath(); FileData.playmusic = GlobalSettings::autoPlayMusic; wldEdit->WldData.meta.modified = false; wnGeom = LastActiveSubWindow->geometry(); QMdiSubWindow *worldWindow = LastActiveSubWindow; long posX = wldEdit->scene->m_viewPort->horizontalScrollBar()->value(); long posY = wldEdit->scene->m_viewPort->verticalScrollBar()->value(); wldEdit->close(); WorldEdit *child = new WorldEdit(this, worldWindow); connect(child, &WorldEdit::forceReload, this, &MainWindow::on_actionReload_triggered); worldWindow->setWidget(child); GraphicsWorkspace *gr = static_cast<GraphicsWorkspace *>(child->getGraphicsView()); connect(gr, SIGNAL(zoomValueChanged(QString)), zoom, SLOT(setText(QString))); if(bool(child->loadFile(filePath, FileData, configs, GlobalSettings::LvlOpts))) { child->show(); LastActiveSubWindow->setGeometry(wnGeom); child->updateGeometry(); child->ResetPosition(); updateMenus(LastActiveSubWindow, true); dock_WldSettingsBox->setCurrentWorldSettings(); if(FileData.HubStyledWorld) { dock_WldSettingsBox->setVisible(true); dock_WldSettingsBox->raise(); } child->scene->m_viewPort->horizontalScrollBar()->setValue(static_cast<int>(posX)); child->scene->m_viewPort->verticalScrollBar()->setValue(static_cast<int>(posY)); statusBar()->showMessage(tr("World map file loaded"), 2000); child->showCustomStuffWarnings(); } else { LogDebug(">>File loading aborted"); //child->show(); LogDebug(">>Window showed"); child->WldData.meta.modified = false; LogDebug(">>Option set"); LastActiveSubWindow->close(); LogDebug(">>Windows closed"); } } dock_LvlItemBox->clearFilter(); }