From cbeb905ae6bd1273ba16cb4af7c99a6c24e9a823 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 9 Feb 2018 17:39:31 +0000 Subject: [PATCH] Default to selected texture file format in save file browser. Refs #862 * We also do the reverse, if they selected a different extension we update the selected format. --- .../Windows/Dialogs/TextureSaveDialog.cpp | 39 +++++++++++++++---- .../Windows/Dialogs/TextureSaveDialog.h | 2 + 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp b/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp index d3731472f..508cfaa24 100644 --- a/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp @@ -214,7 +214,7 @@ void TextureSaveDialog::on_overlayTex_clicked() void TextureSaveDialog::on_fileFormat_currentIndexChanged(int index) { - saveData.destType = (FileType)qMax(0, ui->fileFormat->currentIndex()); + saveData.destType = selectedFileType(); ui->jpegCompression->setEnabled(saveData.destType == FileType::JPG); @@ -256,6 +256,11 @@ void TextureSaveDialog::on_fileFormat_currentIndexChanged(int index) adjustSize(); } +FileType TextureSaveDialog::selectedFileType() +{ + return (FileType)qMax(0, ui->fileFormat->currentIndex()); +} + void TextureSaveDialog::on_jpegCompression_valueChanged(double arg1) { saveData.jpegQuality = (int)arg1; @@ -538,19 +543,39 @@ void TextureSaveDialog::on_browse_clicked() { QString filter; + // put the selected filetype first + FileType curType = selectedFileType(); + QString ext = ToQStr(curType); + filter = tr("%1 Files").arg(ext) + lit(" (*.%1)").arg(ext.toLower()); + for(FileType i : values()) { - QString ext = ToQStr(i); + // skip the one we bumped to the front + if(i == curType) + continue; - if(filter.length() > 0) - filter += lit(";;"); - filter += tr("%1 Files (*.%2)").arg(ext).arg(ext.toLower()); + ext = ToQStr(i); + + filter += lit(";;") + tr("%1 Files").arg(ext) + lit(" (*.%1)").arg(ext.toLower()); } - QString *selectedFilter = NULL; + QString selectedFilter; QString filename = - RDDialog::getSaveFileName(this, tr("Save Texture As"), QString(), filter, selectedFilter); + RDDialog::getSaveFileName(this, tr("Save Texture As"), QString(), filter, &selectedFilter); + + // if they selected a different file type, update the selection. + for(FileType i : values()) + { + ext = ToQStr(i); + + if(selectedFilter.startsWith(tr("%1 Files").arg(ext))) + { + if(i != curType) + ui->fileFormat->setCurrentIndex(uint32_t(i)); + break; + } + } if(!filename.isEmpty()) { diff --git a/qrenderdoc/Windows/Dialogs/TextureSaveDialog.h b/qrenderdoc/Windows/Dialogs/TextureSaveDialog.h index 00417ae7a..5aead058a 100644 --- a/qrenderdoc/Windows/Dialogs/TextureSaveDialog.h +++ b/qrenderdoc/Windows/Dialogs/TextureSaveDialog.h @@ -83,6 +83,8 @@ private: void SetFilenameFromFiletype(); void SetFiletypeFromFilename(); + FileType selectedFileType(); + QTimer typingTimer; TextureDescription tex;