From 1cf94e546afc385e450c0e62141ba68a91aea821 Mon Sep 17 00:00:00 2001 From: Edgar Velazquez-Armendariz Date: Mon, 26 Nov 2012 13:29:42 -0500 Subject: [PATCH] Use the Qt static file dialogs only on Windows. Windows needs to use the static file dialog function to show the native GUI, but OSX needs to use the full functions to display a sheet in a native-like way; Linux seems to behave the same on both cases. --- src/mtsgui/CMakeLists.txt | 4 +- src/mtsgui/mainwindow.cpp | 98 +++++++++++++++++++++++++++++++++++++-- src/mtsgui/mainwindow.h | 6 +++ 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/src/mtsgui/CMakeLists.txt b/src/mtsgui/CMakeLists.txt index 8f0aed2c..15e9d0eb 100644 --- a/src/mtsgui/CMakeLists.txt +++ b/src/mtsgui/CMakeLists.txt @@ -134,9 +134,9 @@ include_directories(. ${CMAKE_CURRENT_BINARY_DIR}) QT4_ADD_RESOURCES(RC_SRCS ${RC_FILES}) source_group("Qt Resources" FILES ${RC_FILES}) -# Add our own qtmain +# Add our own qtmain and use the static file dialogs if (WIN32) - add_definitions(-D MTS_CUSTOM_QTMAIN) + add_definitions(-D MTS_CUSTOM_QTMAIN -DMTSGUI_STATIC_QFILEDIALOG=1) list(APPEND SRCS qtmain_win.cpp) endif() diff --git a/src/mtsgui/mainwindow.cpp b/src/mtsgui/mainwindow.cpp index 0e234992..4f49a7d3 100644 --- a/src/mtsgui/mainwindow.cpp +++ b/src/mtsgui/mainwindow.cpp @@ -538,6 +538,8 @@ void MainWindow::onProgressMessage(const RenderJob *job, const QString &name, updateUI(); } +#if MTSGUI_STATIC_QFILEDIALOG + void MainWindow::on_actionOpen_triggered() { QSettings settings; QStringList fileNames = QFileDialog::getOpenFileNames(this, QString(), @@ -556,6 +558,42 @@ void MainWindow::on_actionOpen_triggered() { } } +#else // MTSGUI_STATIC_QFILEDIALOG + +void MainWindow::on_actionOpen_triggered() { + QFileDialog *dialog = new QFileDialog(this, Qt::Sheet); + dialog->setNameFilter(tr("All supported formats (*.xml *.exr *.rgbe *.hdr *.pfm *.png *.jpg *.jpeg);;" + "Mitsuba scenes (*.xml);;High dynamic-range images (*.exr *.rgbe *.hdr *.pfm);;Low " + "dynamic-range images (*.png *.jpg *.jpeg)")); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->setAcceptMode(QFileDialog::AcceptOpen); + dialog->setViewMode(QFileDialog::Detail); + dialog->setWindowModality(Qt::WindowModal); + QSettings settings; + dialog->restoreState(settings.value("fileDialogState").toByteArray()); + connect(dialog, SIGNAL(finished(int)), this, SLOT(onOpenDialogClose(int))); + m_currentChild = dialog; + // prevent a tab drawing artifact on Qt/OSX + m_activeWindowHack = true; + dialog->show(); + qApp->processEvents(); + m_activeWindowHack = false; +} + +void MainWindow::onOpenDialogClose(int reason) { + QSettings settings; + QFileDialog *dialog = static_cast(sender()); + m_currentChild = NULL; + if (reason == QDialog::Accepted) { + QStringList fileNames = dialog->selectedFiles(); + settings.setValue("fileDialogState", dialog->saveState()); + for (int i=0; icloseAllWindows(); } @@ -1391,6 +1429,8 @@ inline float toSRGB(float value) { return 1.055f * std::pow(value, 0.41666f) - 0.055f; } +#if MTSGUI_STATIC_QFILEDIALOG + void MainWindow::on_actionExportImage_triggered() { QSettings settings; const QString fileName = QFileDialog::getSaveFileName(this, @@ -1400,11 +1440,63 @@ void MainWindow::on_actionExportImage_triggered() { "High dynamic range Radiance RGBE image (*.rgbe *.hdr);;" "High dynamic range Portable Float Map image (*.pfm);;" "Tonemapped low dynamic range image (*.png *.jpg *.jpeg)")); - + if (!fileName.isEmpty()) { + QSettings settings; + settings.setValue("exportFileDir", QFileInfo(fileName).absolutePath()); + exportImage(fileName); + } +} + +#else // MTSGUI_STATIC_QFILEDIALOG + +void MainWindow::on_actionExportImage_triggered() { + QFileDialog *dialog = new QFileDialog(this, tr("Export image .."), + "", tr("All supported formats (*.exr *.hdr *.rgbe *.pfm *.png *.jpg *.jpeg);;" + "High dynamic range OpenEXR image (*.exr);;" + "High dynamic range Radiance RGBE image (*.rgbe *.hdr);;" + "High dynamic range Portable Float Map image (*.pfm);;" + "Tonemapped low dynamic range image (*.png *.jpg *.jpeg)")); + + QSettings settings; + dialog->setViewMode(QFileDialog::Detail); + dialog->setAcceptMode(QFileDialog::AcceptSave); + +#if defined(__OSX__) + dialog->setOption(QFileDialog::DontUseNativeDialog, true); +#endif + + dialog->restoreState(settings.value("fileDialogState").toByteArray()); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->setWindowModality(Qt::WindowModal); + connect(dialog, SIGNAL(finished(int)), this, SLOT(onExportDialogClose(int))); + m_currentChild = dialog; + // prevent a tab drawing artifact on Qt/OSX + m_activeWindowHack = true; + dialog->show(); + qApp->processEvents(); + m_activeWindowHack = false; +} + +void MainWindow::onExportDialogClose(int reason) { + int currentIndex = ui->tabBar->currentIndex(); + SceneContext *ctx = m_context[currentIndex]; + + QSettings settings; + QFileDialog *dialog = static_cast(sender()); + m_currentChild = NULL; + + if (reason == QDialog::Accepted) { + QString fileName = dialog->selectedFiles().value(0); + settings.setValue("fileDialogState", dialog->saveState()); + exportImage(fileName); + } +} + +#endif // MTSGUI_STATIC_QFILEDIALOG + +void MainWindow::exportImage(const QString &fileName) { if (!fileName.isEmpty()) { Bitmap::EFileFormat format; - settings.setValue("exportFileDir", QFileInfo(fileName).absolutePath()); - if (fileName.endsWith(".exr")) { format = Bitmap::EOpenEXR; } else if (fileName.endsWith(".png")) { diff --git a/src/mtsgui/mainwindow.h b/src/mtsgui/mainwindow.h index 74b588ad..b266d82a 100644 --- a/src/mtsgui/mainwindow.h +++ b/src/mtsgui/mainwindow.h @@ -192,6 +192,10 @@ private slots: void updateUI(); void updateStatus(); void onPreviewSettingsClose(); +#if !MTSGUI_STATIC_QFILEDIALOG + void onOpenDialogClose(int reason); + void onExportDialogClose(int reason); +#endif void onSaveAsDialogClose(int reason); void onRenderSettingsClose(int reason); void onImportDialogClose(int reason); @@ -202,6 +206,8 @@ private slots: void onSelectionChanged(); private: + void exportImage(const QString &fileName); + Ui::MainWindow *ui; QAction *m_actRecent[MAX_RECENT_FILES]; QAction *m_clearRecent;