diff --git a/toonz/sources/toonz/filebrowserpopup.cpp b/toonz/sources/toonz/filebrowserpopup.cpp index 8d49556..11c40c6 100644 --- a/toonz/sources/toonz/filebrowserpopup.cpp +++ b/toonz/sources/toonz/filebrowserpopup.cpp @@ -61,6 +61,7 @@ #include #include #include +#include //*********************************************************************************** // FileBrowserPopup implementation @@ -371,11 +372,32 @@ void FileBrowserPopup::showEvent(QShowEvent *) { m_nameField->setFocus(); } resize(m_dialogSize); +} - // Set ALL the file browsers non-modal (even if opened with exec()) - // in order to handle the info viewer and the flipbook which are opened - // with "Info..." and "View..." commands respectively. - setWindowModality(Qt::NonModal); +//----------------------------------------------------------------------------- +// utility function. Make the widget to be a child of modal file browser in +// order to allow control. + +void FileBrowserPopup::setModalBrowserToParent(QWidget *widget) { + if (!widget) return; + QWidget *pwidget = NULL; + foreach (pwidget, QApplication::topLevelWidgets()) { + if ((pwidget->isWindow()) && (pwidget->isModal()) && + (pwidget->isVisible())) { + FileBrowserPopup *popup = qobject_cast(pwidget); + if (popup) { + // According to the description of QDialog; + // "setParent() function will clear the window flags specifying the + // window-system properties for the widget (in particular it will reset + // the Qt::Dialog flag)." + // So keep the window flags and set back after calling setParent(). + Qt::WindowFlags flags = widget->windowFlags(); + widget->setParent(pwidget); + widget->setWindowFlags(flags); + return; + } + } + } } //*********************************************************************************** @@ -399,14 +421,6 @@ bool GenericLoadFilePopup::execute() { //----------------------------------------------------------------------------- TFilePath GenericLoadFilePopup::getPath() { - // In case that this function is called twice before closing the popup. - // Note that the file browser popup will be always non-modal even if opened - // with exec(). - // see FileBrowserPopup::showEvent() - if (isVisible()) { - activateWindow(); - return TFilePath(); - } return (exec() == QDialog::Rejected) ? TFilePath() : *m_selectedPaths.begin(); } @@ -458,14 +472,6 @@ bool GenericSaveFilePopup::execute() { //----------------------------------------------------------------------------- TFilePath GenericSaveFilePopup::getPath() { - // In case that this function is called twice before closing the popup. - // Note that the file browser popup will be always non-modal even if opened - // with exec(). - // see FileBrowserPopup::showEvent() - if (isVisible()) { - activateWindow(); - return TFilePath(); - } return (exec() == QDialog::Rejected) ? TFilePath() : *m_selectedPaths.begin(); } diff --git a/toonz/sources/toonz/filebrowserpopup.h b/toonz/sources/toonz/filebrowserpopup.h index ec07c38..ae5ba8e 100644 --- a/toonz/sources/toonz/filebrowserpopup.h +++ b/toonz/sources/toonz/filebrowserpopup.h @@ -144,6 +144,10 @@ protected slots: virtual void onFilePathsSelected( const std::set &paths, const std::list> &fIds); + + // utility function +public: + static void setModalBrowserToParent(QWidget *widget); }; //******************************************************************************** diff --git a/toonz/sources/toonz/fileselection.cpp b/toonz/sources/toonz/fileselection.cpp index 2a9d62f..c696e0c 100644 --- a/toonz/sources/toonz/fileselection.cpp +++ b/toonz/sources/toonz/fileselection.cpp @@ -183,7 +183,6 @@ public: return str; } }; - //----------------------------------------------------------------------------- } @@ -354,6 +353,7 @@ void FileSelection::viewFileInfo() { infoViewer = new InfoViewer(); m_infoViewers.append(infoViewer); } + FileBrowserPopup::setModalBrowserToParent(infoViewer); infoViewer->setItem(0, 0, files[j]); } } @@ -371,8 +371,12 @@ void FileSelection::viewFile() { (files[i].getType() == "mov" || files[i].getType() == "avi" || files[i].getType() == "3gp")) QDesktopServices::openUrl(QUrl("file:///" + toQString(files[i]))); - else - ::viewFile(files[i]); + else { + FlipBook *fb = ::viewFile(files[i]); + if (fb) { + FileBrowserPopup::setModalBrowserToParent(fb->parentWidget()); + } + } } } diff --git a/toonz/sources/toonz/flipbook.cpp b/toonz/sources/toonz/flipbook.cpp index 1b4d348..e2d8f7d 100644 --- a/toonz/sources/toonz/flipbook.cpp +++ b/toonz/sources/toonz/flipbook.cpp @@ -2177,9 +2177,10 @@ void FlipBook::loadAndCacheAllTlvImages(Level level, int fromFrame, //! some additional random access information may be retrieved (i.e. images may //! map //! to specific frames). -void viewFile(const TFilePath &path, int from, int to, int step, int shrink, - TSoundTrack *snd, FlipBook *flipbook, bool append, - bool isToonzOutput) { +// returns pointer to the opened flipbook to control modality. +FlipBook *viewFile(const TFilePath &path, int from, int to, int step, + int shrink, TSoundTrack *snd, FlipBook *flipbook, + bool append, bool isToonzOutput) { // In case the step and shrink informations are invalid, load them from // preferences if (step == -1 || shrink == -1) { @@ -2195,11 +2196,11 @@ void viewFile(const TFilePath &path, int from, int to, int step, int shrink, path.isLevelName()) { DVGui::warning(QObject::tr("%1 has an invalid extension format.") .arg(QString::fromStdString(path.getLevelName()))); - return; + return NULL; } // Windows Screen Saver - avoid - if (path.getType() == "scr") return; + if (path.getType() == "scr") return NULL; // Avi and movs may be viewed by an external viewer, depending on preferences if (path.getType() == "mov" || path.getType() == "avi" && !flipbook) { @@ -2207,7 +2208,7 @@ void viewFile(const TFilePath &path, int from, int to, int step, int shrink, QSettings().value("generatedMovieViewEnabled", str); if (str.toInt() != 0) { TSystem::showDocument(path); - return; + return NULL; } } @@ -2220,6 +2221,7 @@ void viewFile(const TFilePath &path, int from, int to, int step, int shrink, // Assign the passed level with associated infos flipbook->setLevel(path, 0, from, to, step, shrink, snd, append, isToonzOutput); + return flipbook; } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/flipbook.h b/toonz/sources/toonz/flipbook.h index b9e13ee..53933b7 100644 --- a/toonz/sources/toonz/flipbook.h +++ b/toonz/sources/toonz/flipbook.h @@ -298,9 +298,11 @@ public slots: }; // utility +// returns pointer to the opened flipbook to control modality. -void viewFile(const TFilePath &fp, int from = -1, int to = -1, int step = -1, - int shrink = -1, TSoundTrack *snd = 0, FlipBook *flipbook = 0, - bool append = false, bool isToonzOutput = false); +FlipBook *viewFile(const TFilePath &fp, int from = -1, int to = -1, + int step = -1, int shrink = -1, TSoundTrack *snd = 0, + FlipBook *flipbook = 0, bool append = false, + bool isToonzOutput = false); #endif // FLIPBOOK_H diff --git a/toonz/sources/toonz/levelsettingspopup.cpp b/toonz/sources/toonz/levelsettingspopup.cpp index e0e1d19..a7d3c52 100644 --- a/toonz/sources/toonz/levelsettingspopup.cpp +++ b/toonz/sources/toonz/levelsettingspopup.cpp @@ -1193,10 +1193,16 @@ public: for (i = 0; i < simpleLevels.size(); i++) { TFilePath path = simpleLevels[i]->getPath(); path = simpleLevels[i]->getScene()->decodeFilePath(path); + FlipBook *fb; if (TSystem::doesExistFileOrLevel(path)) - ::viewFile(path); - else - FlipBookPool::instance()->pop()->setLevel(simpleLevels[i]); + fb = ::viewFile(path); + else { + fb = FlipBookPool::instance()->pop(); + fb->setLevel(simpleLevels[i]); + } + if (fb) { + FileBrowserPopup::setModalBrowserToParent(fb->parentWidget()); + } } }