Ejemplo n.º 1
0
QString FrameFileIO::loadFrameFile(QVector<CANFrame>* frameCache)
{
    QString filename;
    QFileDialog dialog;
    bool result = false;

    QStringList filters;
    filters.append(QString(tr("CRTD Logs (*.txt)")));
    filters.append(QString(tr("GVRET Logs (*.csv)")));
    filters.append(QString(tr("Generic ID/Data CSV (*.csv)")));
    filters.append(QString(tr("BusMaster Log (*.log)")));
    filters.append(QString(tr("Microchip Log (*.can)")));

    dialog.setFileMode(QFileDialog::ExistingFile);
    dialog.setNameFilters(filters);
    dialog.setViewMode(QFileDialog::Detail);

    if (dialog.exec() == QDialog::Accepted)
    {
        filename = dialog.selectedFiles()[0];

        QProgressDialog progress(qApp->activeWindow());
        progress.setWindowModality(Qt::WindowModal);
        progress.setLabelText("Loading file...");
        progress.setCancelButton(0);
        progress.setRange(0,0);
        progress.setMinimumDuration(0);
        progress.show();

        qApp->processEvents();

        if (dialog.selectedNameFilter() == filters[0]) result = loadCRTDFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[1]) result = loadNativeCSVFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[2]) result = loadGenericCSVFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[3]) result = loadLogFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[4]) result = loadMicrochipFile(filename, frameCache);

        progress.cancel();

        if (result)
        {
            QStringList fileList = filename.split('/');
            filename = fileList[fileList.length() - 1];
            return filename;
        }
        else return QString("");
    }
    return QString("");
}
Ejemplo n.º 2
0
void PaletteView::exportPalette(int start, int length) {
	if (start >= 512) {
		return;
	}
	if (start + length > 512) {
		length = 512 - start;
	}
	m_controller->threadInterrupt();
	QFileDialog* dialog = GBAApp::app()->getSaveFileDialog(this, tr("Export palette"), tr("Windows PAL (*.pal);;Adobe Color Table (*.act)"));
	if (!dialog->exec()) {
		m_controller->threadContinue();
		return;
	}
	QString filename = dialog->selectedFiles()[0];
	VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
	if (!vf) {
		m_controller->threadContinue();
		return;
	}
	QString filter = dialog->selectedNameFilter();
	if (filter.contains("*.pal")) {
		GBAExportPaletteRIFF(vf, length, &m_controller->thread()->gba->video.palette[start]);
	} else if (filter.contains("*.act")) {
		GBAExportPaletteACT(vf, length, &m_controller->thread()->gba->video.palette[start]);
	}
	vf->close(vf);
	m_controller->threadContinue();
}
Ejemplo n.º 3
0
File FileDialogs::openPlaylist()
{
    QStringList filters;
    filters << filterByType(File::M3U)
            << filterByType(File::CSV)
            << filterByType(File::JS);

    QFileDialog dialog;
    dialog.setAcceptMode(QFileDialog::AcceptOpen);
    dialog.setFileMode(QFileDialog::ExistingFile);
    dialog.setNameFilters(filters);

    QString fileName;
    File::Type type = File::Unknown;
    if (dialog.exec()) {
        fileName = dialog.selectedFiles()[0];

        for (int i = 0; i < 50; i++) {
            if (dialog.selectedNameFilter() == filterByType(File::Type(i))) {
                type = File::Type(i);
            }
        }
    }

    File file;
    file.path = fileName;
    file.type = type;
    return file;
}
Ejemplo n.º 4
0
File FileDialogs::savePlaylist()
{
    QStringList filters;
    filters << filterByType(File::M3U)
            << filterByType(File::M3UClean)
            << filterByType(File::M3UUdpxy)
            << filterByType(File::CSV)
            << filterByType(File::JS);

    QFileDialog dialog;
    dialog.setAcceptMode(QFileDialog::AcceptSave);
    dialog.setFileMode(QFileDialog::AnyFile);
    dialog.setConfirmOverwrite(true);
    dialog.setNameFilters(filters);

    QString fileName;
    File::Type type = File::Unknown;
    if (dialog.exec()) {
        fileName = dialog.selectedFiles()[0];

        for (int i = 0; i < 50; i++) {
            if (dialog.selectedNameFilter() == filterByType(File::Type(i))) {
                type = File::Type(i);
            }
        }
    }

    File file;
    file.path = fileName;
    file.type = type;
    return file;
}
Ejemplo n.º 5
0
void AppImportFile::open()
{
    const QString MetaIOImageFilter("MetaIO Image (*.mhd)"), DICOMImageFilter("DICOM Images (*.dcm)"), AllFilesFilter("All Files (*)");
    QStringList imagesFilter;
    imagesFilter << MetaIOImageFilter << DICOMImageFilter << AllFilesFilter;

    QFileDialog *openDialog = new QFileDialog(0);
    openDialog->setWindowTitle(tr("Select files to open..."));
    openDialog->setDirectory(m_workingDirectory);
    openDialog->setNameFilters(imagesFilter);
    openDialog->selectNameFilter (m_lastExtension);
    openDialog->setFileMode(QFileDialog::ExistingFiles);
    openDialog->setAcceptMode(QFileDialog::AcceptOpen);

    if (openDialog->exec() == QDialog::Accepted)
    {
        QStringList fileNames = openDialog->selectedFiles();

        emit selectedFiles(fileNames);

        m_workingDirectory = QFileInfo(fileNames.first()).dir().path();
        m_lastExtension = openDialog->selectedNameFilter();

        writeSettings();
    }
    delete openDialog;
}
Ejemplo n.º 6
0
void MainWindow::fileSelected(const QStringList &selected)
{
	QFileDialog *dialog = qobject_cast<QFileDialog*>(QObject::sender());
	Q_ASSERT(dialog);

	this->settings->setValue(QStringLiteral("paths/openFilter"), dialog->selectedNameFilter());
	dialog->close();
	dialog->deleteLater();

	for(QString file : selected)
		this->openFile(file);
}
Ejemplo n.º 7
0
void dtkPlotViewToolBar::onExport(void)
{
    const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats();

    QStringList filters;
    filters += "PDF Documents (*.pdf)";
#ifndef QWT_NO_SVG
    filters += "SVG Documents (*.svg)";
#endif
    filters += "Postscript Documents (*.ps)";

    for(int i = 0; i < imageFormats.size(); i++) {
        QString imageFilter;
        imageFilter += imageFormats[i].toUpper();
        imageFilter += " (*.";
        imageFilter += imageFormats[i];
        imageFilter += ")";
        filters += imageFilter;
    }

    QFileDialog *dialog = new QFileDialog(0, "Export plot", QDir::homePath(), filters.join(";;"));
    dialog->setStyleSheet("background-color: none ; color: none; background: none;");
    dialog->setAcceptMode(QFileDialog::AcceptSave);
    dialog->setConfirmOverwrite(true);
    dialog->setFileMode(QFileDialog::AnyFile);

    QRegExp filter_regex(QLatin1String("(?:^\\*\\.(?!.*\\()|\\(\\*\\.)(\\w+)"));
    if (dialog->exec() == QDialog::Accepted) {
        QString fileName = dialog->selectedFiles().first();
        QFileInfo info(fileName);
        if (info.suffix().isEmpty() && !dialog->selectedNameFilter().isEmpty()) {
            if (filter_regex.indexIn(dialog->selectedNameFilter()) != -1) {
                QString extension = filter_regex.cap(1);
                fileName += QLatin1String(".") + extension;
            }
        }
        this->onExport(fileName);
    }
}
Ejemplo n.º 8
0
void MainWindow::actionSaveAs()
{
	ModelInfo tmpModelinfo(m_modelinfo);

	QStringList filters;
	filters << "PIE3 models (*.pie)" << "PIE2 models (*.pie)" << "WZM models (*.wzm)" << "OBJ files (*.obj)";

	QList<wmit_filetype_t> types;
	types << WMIT_FT_PIE << WMIT_FT_PIE2 << WMIT_FT_WZM << WMIT_FT_OBJ;

	QFileDialog* fDialog = new QFileDialog();

	fDialog->setFileMode(QFileDialog::AnyFile);
	fDialog->setAcceptMode(QFileDialog::AcceptSave);
	fDialog->setNameFilters(filters);
	fDialog->setWindowTitle(tr("Choose output file"));
	fDialog->setDirectory(m_pathExport);
	fDialog->exec();

	if (fDialog->result() != QDialog::Accepted)
	{
		return;
	}

	if (!filters.contains(fDialog->selectedNameFilter()))
	{
		return;
	}

	tmpModelinfo.m_save_type = types[filters.indexOf(fDialog->selectedNameFilter())];

	// refresh export working dir
	m_pathExport = fDialog->directory().absolutePath();
	m_settings->setValue(WMIT_SETTINGS_EXPORTVAL, m_pathExport);

	QFileInfo finfo(fDialog->selectedFiles().first());
	tmpModelinfo.m_saveAsFile = finfo.filePath();

	QPointer<ExportDialog> dlg;

	switch (tmpModelinfo.m_save_type)
	{
	case WMIT_FT_PIE:
	case WMIT_FT_PIE2:
		tmpModelinfo.defaultPieCapsIfNeeded();
		dlg = new PieExportDialog(tmpModelinfo.m_pieCaps, this);
		if (dlg->exec() == QDialog::Accepted)
		{
			tmpModelinfo.m_pieCaps = static_cast<PieExportDialog*>(dlg.data())->getCaps();
		}

		if (finfo.suffix().toLower() != "pie")
			tmpModelinfo.m_saveAsFile += ".pie";
		break;
	case WMIT_FT_OBJ:
		if (finfo.suffix().toLower() != "obj")
			tmpModelinfo.m_saveAsFile += ".obj";
		break;
	case WMIT_FT_WZM:
		if (finfo.suffix().toLower() != "wzm")
			tmpModelinfo.m_saveAsFile += ".wzm";
		break;
	}

	if (dlg && dlg->result() != QDialog::Accepted)
	{
		return;
	}

	m_modelinfo = tmpModelinfo;
	PrependFileToRecentList(m_modelinfo.m_saveAsFile);

	saveModel(m_model, m_modelinfo);
}
Ejemplo n.º 9
0
/**
 * 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;
}
Ejemplo n.º 10
0
/**
 * 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;
}
Ejemplo n.º 11
0
void MainWindow::saveAs()
{
	QFileDialog* saveAsDialog = new QFileDialog(this, "Save File As", QDir::homePath(), "CheMVP Project File (*.chmvp);;Encapsulated PostScript (*.eps);;Portable Document Format (*.pdf);;Portable Network Graphic (*.png);;PostScript (*.ps);;Scalable Vector Graphic (*.svg);;Tagged Image File Format (*.tiff)");
	saveAsDialog->setAcceptMode(QFileDialog::AcceptSave);
	saveAsDialog->setFileMode(QFileDialog::AnyFile);
	if(saveAsDialog->exec())
	{
		currentSaveFile = saveAsDialog->selectedFiles().at(0);
		if(currentSaveFile.isEmpty())
			return;

		QString selectedExtension = saveAsDialog->selectedNameFilter();
		selectedExtension = selectedExtension.left(selectedExtension.length() - 1);
		selectedExtension = selectedExtension.right(selectedExtension.length() - selectedExtension.lastIndexOf(".") - 1);

		if(currentSaveFile.indexOf(".") == -1)
		{
			currentSaveFile += selectedExtension;
		}
		else
		{
			QString extension = currentSaveFile.right(currentSaveFile.length() - currentSaveFile.lastIndexOf(".") - 1);

			if(extension != QString("pdf") && extension != QString("svg") && extension != QString("ps")
				 && extension != QString("tif") && extension != QString("tiff") && extension != QString("eps")
				 && extension != QString("png") && extension != QString("chmvp"))
			{
				QMessageBox* error = new QMessageBox(this);
				error->setText("The specified file type is invalid!");
				error->setIcon(QMessageBox::Critical);
				error->setInformativeText("Please choose a valid file type.");
				error->setStandardButtons(QMessageBox::Ok);
				error->exec();
				delete error;
				MainWindow::saveAs();
				delete saveAsDialog;
				return;
			}
			else if(extension != selectedExtension)
			{
				QMessageBox* error = new QMessageBox(this);
				error->setText(QString("You cannot save this document with extension \".%1\" at the end of the name. The required extension is \".%2\".")
							   .arg(extension).arg(selectedExtension));
				error->setIcon(QMessageBox::Critical);
				error->setInformativeText(QString("You can choose to use both, so that your file name ends in \".%1.%2.\"")
										  .arg(extension).arg(selectedExtension));
				error->setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
				error->setButtonText(QMessageBox::Save, "Use both");
				error->setButtonText(QMessageBox::Discard, QString("Use .%1").arg(selectedExtension));
				int answer = error->exec();
				delete error;
				if(answer == QMessageBox::Save)
					currentSaveFile += "." + selectedExtension;
				else if(answer == QMessageBox::Discard)
				{
					currentSaveFile = currentSaveFile.left(currentSaveFile.lastIndexOf("."));
					currentSaveFile += "."+selectedExtension;
				}
				else
					return;
			}
		}

		if(currentSaveFile.endsWith(".chmvp"))
			saveProject(currentSaveFile);
		else
			saveImage(currentSaveFile);
	}
	delete saveAsDialog;
}