Mercurial > hg > sonic-visualiser
diff main/MainWindow.cpp @ 121:3fff180a254b
* Add basics of an Export Image File function
author | Chris Cannam |
---|---|
date | Mon, 12 Mar 2007 15:36:31 +0000 |
parents | b4110b17bca8 |
children | a45733cc3939 |
line wrap: on
line diff
--- a/main/MainWindow.cpp Fri Mar 09 18:18:30 2007 +0000 +++ b/main/MainWindow.cpp Mon Mar 12 15:36:31 2007 +0000 @@ -311,6 +311,8 @@ return ff->getOpenFileName(type, m_sessionFile); case FileFinder::SessionOrAudioFile: return ff->getOpenFileName(type, m_sessionFile); + case FileFinder::ImageFile: + return ff->getOpenFileName(type, m_sessionFile); case FileFinder::AnyFile: if (getMainModel() != 0 && m_paneStack != 0 && @@ -337,6 +339,8 @@ return ff->getSaveFileName(type, m_sessionFile); case FileFinder::SessionOrAudioFile: return ff->getSaveFileName(type, m_sessionFile); + case FileFinder::ImageFile: + return ff->getSaveFileName(type, m_sessionFile); case FileFinder::AnyFile: return ff->getSaveFileName(type, m_sessionFile); } @@ -484,6 +488,14 @@ menu->addSeparator(); + action = new QAction(tr("Export Image File..."), this); + action->setStatusTip(tr("Export a single pane to an image file")); + connect(action, SIGNAL(triggered()), this, SLOT(exportImage())); + connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool))); + menu->addAction(action); + + menu->addSeparator(); + action = new QAction(tr("Open Lo&cation..."), this); action->setShortcut(tr("Ctrl+Shift+O")); action->setStatusTip(tr("Open or import a file from a remote URL")); @@ -1619,6 +1631,7 @@ emit canExportAudio(haveMainModel); emit canExportLayer(haveMainModel && (haveCurrentEditableLayer || haveCurrentColour3DPlot)); + emit canExportImage(haveMainModel && haveCurrentPane); emit canDeleteCurrentLayer(haveCurrentLayer); emit canRenameLayer(haveCurrentLayer); emit canEditLayer(haveCurrentEditableLayer); @@ -2278,6 +2291,29 @@ } } +void +MainWindow::exportImage() +{ + Pane *pane = m_paneStack->getCurrentPane(); + if (!pane) return; + + QString path = getSaveFileName(FileFinder::ImageFile); + + if (path == "") return; + + if (QFileInfo(path).suffix() == "") path += ".png"; + + QImage *image = pane->toNewImage(); + if (!image) return; + + if (!image->save(path, "PNG")) { + QMessageBox::critical(this, tr("Failed to save image file"), + tr("Failed to save image file %1").arg(path)); + } + + delete image; +} + MainWindow::FileOpenStatus MainWindow::openAudioFile(QString path, AudioFileOpenMode mode) {