void TTCurrentFrame::saveCurrentFrame() { QString szTemp; QString extension; QString format; QStringList fileList; QString fileName; QFileDialog* fileDlg; // no video file open if ( !TTCut::isVideoOpen ) return; // get the image file name fileDlg = new QFileDialog( this, "save current frame", TTCut::lastDirPath, "Portable Network Graphics (*.png);;JPEG (*.jpg);;Bitmap (*.bmp)" ); // enable specifying a file that doesn't exist fileDlg->setFileMode( QFileDialog::AnyFile ); fileDlg->setAcceptMode( QFileDialog::AcceptSave ); // input filename specified if ( fileDlg->exec() == QDialog::Accepted ) { szTemp = fileDlg->selectedFilter(); fileList = fileDlg->selectedFiles(); fileName = fileList.at(0); if ( szTemp == "Portable Network Graphics (*.png)" ) { format = "PNG"; extension = "png"; } else if ( szTemp == "JPEG (*.jpg)" ) { format = "JPG"; extension = "jpg"; } else if ( szTemp == "Bitmap (*.bmp)" ) { format = "BMP"; extension = "bmp"; } else { qDebug( "unsupported format" ); return; } fileName = ttChangeFileExt( fileName, qPrintable(extension) ); mpegWindow->saveCurrentFrame( fileName, qPrintable(format) ); } delete fileDlg; }
std::string CtrlHelper::openFile(const std::string& caption, std::vector<FileDialogFilter> filter, FileDialogFilter* selection) { QFileDialog dialog; std::string fs = getFilterString(filter); dialog.setNameFilter(fs.c_str()); dialog.setViewMode(QFileDialog::Detail); dialog.setWindowTitle(caption.c_str()); if (dialog.exec()) { // pass selected filter back to the caller? if (selection) { std::string fs = dialog.selectedFilter().toUtf8().constData(); for (FileDialogFilter& f : filter) { if (f.getFilterString() == fs) {*selection = f;} } } std::string file = dialog.selectedFiles().at(0).toUtf8().constData(); return file; } return ""; }
void CDPWizard::promptForFileName(QLineEdit * theLineEdit, QString theShortName, QString theLongName) { QSettings myQSettings; QString myFilterList; FileReader::getGdalDriverMap(myFilterList); QString myWorkDirString = myQSettings.readEntry("/qgis/cdpwizard/DefaultDirectories/" + theShortName + "Dir",QDir::homeDirPath()); std::cout << "Filter List: " << myFilterList << std::endl; QString myFileNameQString; QFileDialog myFileDialog (myWorkDirString,myFilterList,0,"Select " + theLongName ,"Select " + theLongName); QString myLastFilter = myQSettings.readEntry("/qgis/cdpwizard/DefaultDirectories/" + theShortName + "Filter",""); if (!myLastFilter.isEmpty()) { myFileDialog.setSelectedFilter(myLastFilter); } if ( myFileDialog.exec() == QDialog::Accepted ) { myFileNameQString = myFileDialog.selectedFile(); theLineEdit->setText(myFileNameQString); QFileInfo myFileInfo(myFileNameQString); myQSettings.writeEntry("/qgis/cdpwizard/DefaultDirectories/" + theShortName + "Dir",myFileInfo.dirPath()); myQSettings.writeEntry("/qgis/cdpwizard/DefaultDirectories/" + theShortName + "Filter",myFileDialog.selectedFilter()); checkInputFilenames(); } }
/** * Shows a dialog for choosing a file name. Opening the file is up to * the caller. * * @return File name with path and extension to determine the file type * or an empty string if the dialog was cancelled. */ QString QG_FileDialog::getOpenFileName(QWidget* parent, RS2::FormatType* type) { RS_DEBUG->print("QG_FileDialog::getOpenFileName"); // read default settings: RS_SETTINGS->beginGroup("/Paths"); QString defDir = RS_SETTINGS->readEntry("/Open", RS_SYSTEM->getHomeDir()); //QString defFilter = RS_SETTINGS->readEntry("/OpenFilter", // "Drawing Exchange (*.dxf *.DXF)"); QString defFilter = "Drawing Exchange (*.dxf)"; RS_SETTINGS->endGroup(); RS_DEBUG->print("defDir: %s", defDir.toLatin1().data()); RS_DEBUG->print("defFilter: %s", defFilter.toLatin1().data()); QString fDxfOld(QObject::tr("Old Drawing Exchange %1").arg("(*.dxf *.DXF)")); QString fDxfrw(QObject::tr("Drawing Exchange %1").arg("(*.dxf)")); QString fDxf1(QObject::tr("QCad 1.x file %1").arg("(*.dxf *.DXF)")); QString fLff(QObject::tr("LFF Font %1").arg("(*.lff)")); QString fCxf(QObject::tr("Font %1").arg("(*.cxf)")); QString fJww(QObject::tr("Jww %1").arg("(*.jww)")); RS_DEBUG->print("fDxfrw: %s", fDxfrw.toLatin1().data()); RS_DEBUG->print("fDxf1: %s", fDxf1.toLatin1().data()); RS_DEBUG->print("fCxf: %s", fCxf.toLatin1().data()); RS_DEBUG->print("fJww: %s", fJww.toLatin1().data()); QString fn = ""; bool cancel = false; QFileDialog* fileDlg = new QFileDialog(parent, "File Dialog"); QStringList filters; filters.append(fDxfrw); filters.append(fDxf1); filters.append(fLff); filters.append(fCxf); filters.append(fJww); fileDlg->setNameFilters(filters); fileDlg->setFileMode(QFileDialog::ExistingFile); fileDlg->setWindowTitle(QObject::tr("Open Drawing")); fileDlg->setDirectory(defDir); fileDlg->selectNameFilter(defFilter); /** preview RVT PORT preview is currently not supported by QT4 RS_Graphic* gr = new RS_Graphic; QG_GraphicView* prev = new QG_GraphicView(parent); prev->setContainer(gr); prev->setBorders(1, 1, 1, 1); fileDlg->setContentsPreviewEnabled(true); fileDlg->setContentsPreview(prev, prev); */ if (fileDlg->exec()==QDialog::Accepted) { QStringList fl = fileDlg->selectedFiles(); if (!fl.isEmpty()) fn = fl[0]; fn = QDir::toNativeSeparators( QFileInfo(fn).absoluteFilePath() ); if (type!=NULL) { if (fileDlg->selectedNameFilter()==fDxf1) { *type = RS2::FormatDXF1; } else if (fileDlg->selectedNameFilter()==fDxfrw) { *type = RS2::FormatDXFRW; } else if (fileDlg->selectedNameFilter()==fCxf) { *type = RS2::FormatCXF; } else if (fileDlg->selectedNameFilter()==fJww) { *type = RS2::FormatJWW; } } cancel = false; } else { cancel = true; } // store new default settings: if (!cancel) { RS_SETTINGS->beginGroup("/Paths"); RS_SETTINGS->writeEntry("/Open", QFileInfo(fn).absolutePath()); RS_SETTINGS->writeEntry("/OpenFilter", fileDlg->selectedFilter()); RS_SETTINGS->endGroup(); } RS_DEBUG->print("QG_FileDialog::getOpenFileName: fileName: %s", fn.toLatin1().data()); RS_DEBUG->print("QG_FileDialog::getOpenFileName: OK"); // RVT PORT delete prev; // RVT PORT delete gr; delete fileDlg; return fn; }
/** * Shows a dialog for choosing a file name. Saving the file is up to * the caller. * * @param type Will contain the file type that was chosen by the user. * Can be NULL to be ignored. * * @return File name with path and extension to determine the file type * or an empty string if the dialog was cancelled. */ QString QG_FileDialog::getSaveFileName(QWidget* parent, RS2::FormatType* type) { // read default settings: RS_SETTINGS->beginGroup("/Paths"); QString defDir = RS_SETTINGS->readEntry("/Save", RS_SYSTEM->getHomeDir()); QString defFilter = RS_SETTINGS->readEntry("/SaveFilter", "Drawing Exchange DXF 2007 (*.dxf)"); //QString defFilter = "Drawing Exchange (*.dxf)"; RS_SETTINGS->endGroup(); // prepare file save as dialog: QFileDialog* fileDlg = new QFileDialog(parent,"Save as"); QStringList filters; bool done = false; bool cancel = false; QString fn = ""; filters.append("Drawing Exchange DXF 2007 (*.dxf)"); filters.append("Drawing Exchange DXF 2004 (*.dxf)"); filters.append("Drawing Exchange DXF 2000 (*.dxf)"); filters.append("Drawing Exchange DXF R14 (*.dxf)"); filters.append("Drawing Exchange DXF R12 (*.dxf)"); filters.append("LFF Font (*.lff)"); filters.append("Font (*.cxf)"); filters.append("JWW (*.jww)"); fileDlg->setFilters(filters); fileDlg->setFileMode(QFileDialog::AnyFile); fileDlg->setWindowTitle(QObject::tr("Save Drawing As")); fileDlg->setDirectory(defDir); fileDlg->setAcceptMode(QFileDialog::AcceptSave); fileDlg->selectFilter(defFilter); // run dialog: do { // accepted: if (fileDlg->exec()==QDialog::Accepted) { QStringList fl = fileDlg->selectedFiles(); if (!fl.isEmpty()) fn = fl[0]; fn = QDir::toNativeSeparators( QFileInfo(fn).absoluteFilePath() ); cancel = false; // append default extension: // TODO, since we are starting to suppor tmore extensions, we need to find a better way to add the default if (QFileInfo(fn).fileName().indexOf('.')==-1) { if (fileDlg->selectedFilter()=="LFF Font (*.lff)") { fn+=".lff"; } else if (fileDlg->selectedFilter()=="Font (*.cxf)") { fn+=".cxf"; } else { fn+=".dxf"; } } // set format: if (type!=NULL) { if (fileDlg->selectedNameFilter()=="LFF Font (*.lff)") { *type = RS2::FormatLFF; } else if (fileDlg->selectedNameFilter()=="Font (*.cxf)") { *type = RS2::FormatCXF; } else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF 2004 (*.dxf)") { *type = RS2::FormatDXFRW2004; } else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF 2000 (*.dxf)") { *type = RS2::FormatDXFRW2000; } else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF R14 (*.dxf)") { *type = RS2::FormatDXFRW14; } else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF R12 (*.dxf)") { *type = RS2::FormatDXFRW12; } else if (fileDlg->selectedNameFilter()=="JWW (*.jww)") { *type = RS2::FormatJWW; } else { *type = RS2::FormatDXFRW; } } #if !defined (_WIN32) && !defined (__APPLE__) // overwrite warning: if(QFileInfo(fn).exists()) { int choice = QMessageBox::warning(parent, QObject::tr("Save Drawing As"), QObject::tr("%1 already exists.\n" "Do you want to replace it?") .arg(fn), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,QMessageBox::Cancel); switch (choice) { case QMessageBox::Yes: done = true; break; default: done = false; break; } } else { done = true; } #else done = true; #endif } else { done = true; cancel = true; fn = ""; } } while(!done); // store new default settings: if (!cancel) { RS_SETTINGS->beginGroup("/Paths"); RS_SETTINGS->writeEntry("/Save", QFileInfo(fn).absolutePath()); //RS_SETTINGS->writeEntry("/SaveFilter", fileDlg->selectedFilter()); RS_SETTINGS->endGroup(); } delete fileDlg; return fn; }
void WatchVector::on_tbSaveImage_clicked() { static QStringList history; static QDir directory = QDir::current(); if (m_pImageView) { QFileDialog *sDialog = new QFileDialog(this, QString("Save image")); sDialog->setAcceptMode(QFileDialog::AcceptSave); sDialog->setFileMode(QFileDialog::AnyFile); QStringList formatDesc; formatDesc << "Portable Network Graphics (*.png)" << "Windows Bitmap (*.bmp)" << "Joint Photographic Experts Group (*.jpg, *.jepg)" << "Portable Pixmap (*.ppm)" << "Tagged Image File Format (*.tif, *.tiff)" << "X11 Bitmap (*.xbm, *.xpm)"; sDialog->setFilters(formatDesc); if (!(history.isEmpty())) { sDialog->setHistory(history); } sDialog->setDirectory(directory); if (sDialog->exec()) { QStringList files = sDialog->selectedFiles(); if (!files.isEmpty()) { QString selected = files[0]; QFileInfo fileInfo(selected); QImage *img; img = drawNewImage(false); if (!(img->save(selected))) { QString forceFilter; QString filter = sDialog->selectedFilter(); if (filter == QString("Portable Network Graphics (*.png)")) { forceFilter.append("png"); } else if (filter == QString("Windows Bitmap (*.bmp)")) { forceFilter.append("bmp"); } else if (filter == QString("Joint Photographic Experts Group (*.jpg, *.jepg)")) { forceFilter.append("jpg"); } else if (filter == QString("Portable Pixmap (*.ppm)")) { forceFilter.append("ppm"); } else if (filter == QString("Tagged Image File Format (*.tif, *.tiff)")) { forceFilter.append("tif"); } else if (filter == QString("X11 Bitmap (*.xbm, *.xpm)")) { forceFilter.append("xbm"); } img->save(selected, forceFilter.toLatin1().data()); } delete img; } } history = sDialog->history(); directory = sDialog->directory(); delete sDialog; } }
QString QmitkToFRecorderWidget::getSaveFileName(mitk::ToFImageWriter::ToFImageType& tofImageType, bool& distanceImageSelected, bool& amplitudeImageSelected, bool& intensityImageSelected, bool& rgbImageSelected, bool& rawDataSelected, QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options ) { QString selectedFileName = ""; QComboBox* combo = new QComboBox; combo->addItem("3D"); combo->addItem("2D + t"); QHBoxLayout* checkBoxGroup = new QHBoxLayout(); QCheckBox* distanceImageCheckBox = new QCheckBox; distanceImageCheckBox->setText("Distance image"); distanceImageCheckBox->setChecked(distanceImageSelected); QCheckBox* amplitudeImageCheckBox = new QCheckBox; amplitudeImageCheckBox->setText("Amplitude image"); amplitudeImageCheckBox->setChecked(amplitudeImageSelected); QCheckBox* intensityImageCheckBox = new QCheckBox; intensityImageCheckBox->setText("Intensity image"); intensityImageCheckBox->setChecked(intensityImageSelected); QCheckBox* rgbImageCheckBox = new QCheckBox; rgbImageCheckBox->setText("RGB image"); rgbImageCheckBox->setChecked(rgbImageSelected); QCheckBox* rawDataCheckBox = new QCheckBox; rawDataCheckBox->setText("Raw data"); rawDataCheckBox->setChecked(false); rawDataCheckBox->setEnabled(false); checkBoxGroup->addWidget(distanceImageCheckBox); checkBoxGroup->addWidget(amplitudeImageCheckBox); checkBoxGroup->addWidget(intensityImageCheckBox); checkBoxGroup->addWidget(rgbImageCheckBox); checkBoxGroup->addWidget(rawDataCheckBox); QFileDialog* fileDialog = new QFileDialog(parent, caption, dir, filter); QLayout* layout = fileDialog->layout(); QGridLayout* gridbox = qobject_cast<QGridLayout*>(layout); if (gridbox) { gridbox->addWidget(new QLabel("ToF-Image type:")); gridbox->addWidget(combo); int lastRow = gridbox->rowCount(); gridbox->addLayout(checkBoxGroup, lastRow, 0, 1, -1); } fileDialog->setLayout(gridbox); fileDialog->setAcceptMode(QFileDialog::AcceptSave); if (selectedFilter) { fileDialog->selectNameFilter(*selectedFilter); } if (fileDialog->exec() == QDialog::Accepted) { if (selectedFilter) { *selectedFilter = fileDialog->selectedFilter(); } if (combo->currentIndex() == 0) { tofImageType = mitk::ToFImageWriter::ToFImageType3D; } else { tofImageType = mitk::ToFImageWriter::ToFImageType2DPlusT; } distanceImageSelected = distanceImageCheckBox->isChecked(); amplitudeImageSelected = amplitudeImageCheckBox->isChecked(); intensityImageSelected = intensityImageCheckBox->isChecked(); rgbImageSelected = rgbImageCheckBox->isChecked(); rawDataSelected = rawDataCheckBox->isChecked(); selectedFileName = fileDialog->selectedFiles().value(0); } delete fileDialog; return selectedFileName; }