Merge pull request #1245 from shun-iwasawa/fix_filebrowser_hierarchy

Fix of the file browser and popups hierarchy
This commit is contained in:
Jeremy Bullock 2017-05-31 23:25:15 -06:00 committed by GitHub
commit 5af8251baa
6 changed files with 59 additions and 35 deletions

View file

@ -61,6 +61,7 @@
#include <QGroupBox>
#include <QCoreApplication>
#include <QMainWindow>
#include <QApplication>
//***********************************************************************************
// 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<FileBrowserPopup *>(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();
}

View file

@ -144,6 +144,10 @@ protected slots:
virtual void onFilePathsSelected(
const std::set<TFilePath> &paths,
const std::list<std::vector<TFrameId>> &fIds);
// utility function
public:
static void setModalBrowserToParent(QWidget *widget);
};
//********************************************************************************

View file

@ -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());
}
}
}
}

View file

@ -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;
}
//-----------------------------------------------------------------------------

View file

@ -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

View file

@ -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());
}
}
}