# HG changeset patch # User Chris Cannam # Date 1173713791 0 # Node ID 3fff180a254b8c5bf7c97d9b00e3c8b556417338 # Parent 863a470df510a378e2d130c2b070afb6a17a4568 * Add basics of an Export Image File function diff -r 863a470df510 -r 3fff180a254b main/MainWindow.cpp --- 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) { diff -r 863a470df510 -r 3fff180a254b main/MainWindow.h --- a/main/MainWindow.h Fri Mar 09 18:18:30 2007 +0000 +++ b/main/MainWindow.h Mon Mar 12 15:36:31 2007 +0000 @@ -93,6 +93,7 @@ void canImportLayer(bool); void canExportAudio(bool); void canExportLayer(bool); + void canExportImage(bool); void canRenameLayer(bool); void canEditLayer(bool); void canSelect(bool); @@ -123,6 +124,7 @@ void exportAudio(); void importLayer(); void exportLayer(); + void exportImage(); void saveSession(); void saveSessionAs(); void newSession();