Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 123:a45733cc3939 sv1-1.0pre2
* Remove tip dialog for now. I don't like it enough
* Fixes to export image
author | Chris Cannam |
---|---|
date | Wed, 14 Mar 2007 14:39:39 +0000 |
parents | 3fff180a254b |
children | 8a39597edb51 |
comparison
equal
deleted
inserted
replaced
122:8ad3609080b3 | 123:a45733cc3939 |
---|---|
2301 | 2301 |
2302 if (path == "") return; | 2302 if (path == "") return; |
2303 | 2303 |
2304 if (QFileInfo(path).suffix() == "") path += ".png"; | 2304 if (QFileInfo(path).suffix() == "") path += ".png"; |
2305 | 2305 |
2306 QImage *image = pane->toNewImage(); | 2306 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty(); |
2307 | |
2308 QSize total, visible, selected; | |
2309 total = pane->getImageSize(); | |
2310 visible = pane->getImageSize(pane->getFirstVisibleFrame(), | |
2311 pane->getLastVisibleFrame()); | |
2312 | |
2313 size_t sf0 = 0, sf1 = 0; | |
2314 | |
2315 if (haveSelection) { | |
2316 MultiSelection::SelectionList selections = m_viewManager->getSelections(); | |
2317 sf0 = selections.begin()->getStartFrame(); | |
2318 MultiSelection::SelectionList::iterator e = selections.end(); | |
2319 --e; | |
2320 sf1 = e->getEndFrame(); | |
2321 selected = pane->getImageSize(sf0, sf1); | |
2322 } | |
2323 | |
2324 QStringList items; | |
2325 items << tr("Export the entire pane (%1x%2 pixels") | |
2326 .arg(total.width()).arg(total.height()); | |
2327 items << tr("Export the visible area only (%1x%2 pixels)") | |
2328 .arg(visible.width()).arg(visible.height()); | |
2329 if (haveSelection) { | |
2330 items << tr("Export the selection extent (%1x%2 pixels)") | |
2331 .arg(selected.width()).arg(selected.height()); | |
2332 } | |
2333 | |
2334 QSettings settings; | |
2335 settings.beginGroup("MainWindow"); | |
2336 int deflt = settings.value("lastimageexportregion", 0).toInt(); | |
2337 if (deflt == 2 && !haveSelection) deflt = 1; | |
2338 | |
2339 bool ok = false; | |
2340 QString item = ListInputDialog::getItem | |
2341 (this, tr("Select region to export"), | |
2342 tr("Which region of the current pane do you want to export as an image?"), | |
2343 items, deflt, &ok); | |
2344 | |
2345 if (!ok || item.isEmpty()) return; | |
2346 | |
2347 settings.setValue("lastimageexportregion", deflt); | |
2348 | |
2349 QImage *image = 0; | |
2350 | |
2351 if (item == items[0]) { | |
2352 image = pane->toNewImage(); | |
2353 } else if (item == items[1]) { | |
2354 image = pane->toNewImage(pane->getFirstVisibleFrame(), | |
2355 pane->getLastVisibleFrame()); | |
2356 } else if (haveSelection) { | |
2357 image = pane->toNewImage(sf0, sf1); | |
2358 } | |
2359 | |
2307 if (!image) return; | 2360 if (!image) return; |
2308 | 2361 |
2309 if (!image->save(path, "PNG")) { | 2362 if (!image->save(path, "PNG")) { |
2310 QMessageBox::critical(this, tr("Failed to save image file"), | 2363 QMessageBox::critical(this, tr("Failed to save image file"), |
2311 tr("Failed to save image file %1").arg(path)); | 2364 tr("Failed to save image file %1").arg(path)); |