comparison main/MainWindow.cpp @ 1462:f5180edc5dda 3.0-integration

Merge
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 03 Jan 2017 14:34:46 +0000
parents 0a145f215a45 8ca62b402846
children f5c828d1f3e2
comparison
equal deleted inserted replaced
1461:0a145f215a45 1462:f5180edc5dda
2865 MainWindow::exportImage() 2865 MainWindow::exportImage()
2866 { 2866 {
2867 Pane *pane = m_paneStack->getCurrentPane(); 2867 Pane *pane = m_paneStack->getCurrentPane();
2868 if (!pane) return; 2868 if (!pane) return;
2869 2869
2870 //!!! QString path = getSaveFileName(FileFinder::ImageFile);
2871 // if (path == "") return;
2872 // if (QFileInfo(path).suffix() == "") path += ".png";
2873 QString path = getSaveFileName(FileFinder::ImageFile); 2870 QString path = getSaveFileName(FileFinder::ImageFile);
2874 if (path == "") return; 2871 if (path == "") return;
2875 if (QFileInfo(path).suffix() == "") path += ".svg"; 2872 if (QFileInfo(path).suffix() == "") path += ".png";
2876
2877 bool scalable = true; //!!!
2878 2873
2879 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty(); 2874 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
2880 2875
2881 QSize total, visible, selected; 2876 QSize total, visible, selected;
2882 total = pane->getRenderedImageSize(); 2877 total = pane->getRenderedImageSize();
2908 2903
2909 QSettings settings; 2904 QSettings settings;
2910 settings.beginGroup("MainWindow"); 2905 settings.beginGroup("MainWindow");
2911 int deflt = settings.value("lastimageexportregion", 0).toInt(); 2906 int deflt = settings.value("lastimageexportregion", 0).toInt();
2912 if (deflt == 2 && !haveSelection) deflt = 1; 2907 if (deflt == 2 && !haveSelection) deflt = 1;
2913 if (deflt == 0 && !scalable && total.width() > 32767) deflt = 1; 2908 if (deflt == 0 && total.width() > 32767) deflt = 1;
2914 2909
2915 ListInputDialog *lid = new ListInputDialog 2910 ListInputDialog *lid = new ListInputDialog
2916 (this, tr("Select region to export"), 2911 (this, tr("Select region to export"),
2917 tr("Which region of the current pane do you want to export as an image?"), 2912 tr("Which region of the current pane do you want to export as an image?"),
2918 items, deflt); 2913 items, deflt);
2919 2914
2920 if (!haveSelection) { 2915 if (!haveSelection) {
2921 lid->setItemAvailability(2, false); 2916 lid->setItemAvailability(2, false);
2922 } 2917 }
2923 if (!scalable && total.width() > 32767) { // appears to be limit of a QImage 2918 if (total.width() > 32767) { // appears to be limit of a QImage
2924 lid->setItemAvailability(0, false); 2919 lid->setItemAvailability(0, false);
2925 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image.")); 2920 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
2926 } 2921 }
2927 2922
2928 bool ok = lid->exec(); 2923 bool ok = lid->exec();
2931 2926
2932 if (!ok || item.isEmpty()) return; 2927 if (!ok || item.isEmpty()) return;
2933 2928
2934 settings.setValue("lastimageexportregion", deflt); 2929 settings.setValue("lastimageexportregion", deflt);
2935 2930
2936 if (scalable) { 2931 QImage *image = 0;
2937
2938 bool result = false;
2939
2940 if (item == items[0]) {
2941 result = pane->renderToSvgFile(path );
2942 } else if (item == items[1]) {
2943 result = pane->renderPartToSvgFile(path,
2944 pane->getFirstVisibleFrame(),
2945 pane->getLastVisibleFrame());
2946 } else if (haveSelection) {
2947 result = pane->renderPartToSvgFile(path, sf0, sf1);
2948 }
2949
2950 if (!result) {
2951 QMessageBox::critical(this, tr("Failed to save SVG file"),
2952 tr("Failed to save SVG file %1").arg(path));
2953 }
2954
2955 } else {
2956
2957 QImage *image = 0;
2958
2959 if (item == items[0]) {
2960 image = pane->renderToNewImage();
2961 } else if (item == items[1]) {
2962 image = pane->renderPartToNewImage(pane->getFirstVisibleFrame(),
2963 pane->getLastVisibleFrame());
2964 } else if (haveSelection) {
2965 image = pane->renderPartToNewImage(sf0, sf1);
2966 }
2967
2968 if (!image) return;
2969
2970 if (!image->save(path, "PNG")) {
2971 QMessageBox::critical(this, tr("Failed to save image file"),
2972 tr("Failed to save image file %1").arg(path));
2973 }
2974 2932
2975 delete image; 2933 if (item == items[0]) {
2976 } 2934 image = pane->renderToNewImage();
2935 } else if (item == items[1]) {
2936 image = pane->renderPartToNewImage(pane->getFirstVisibleFrame(),
2937 pane->getLastVisibleFrame());
2938 } else if (haveSelection) {
2939 image = pane->renderPartToNewImage(sf0, sf1);
2940 }
2941
2942 if (!image) return;
2943
2944 if (!image->save(path, "PNG")) {
2945 QMessageBox::critical(this, tr("Failed to save image file"),
2946 tr("Failed to save image file %1").arg(path));
2947 }
2948
2949 delete image;
2977 } 2950 }
2978 2951
2979 void 2952 void
2980 MainWindow::exportSVG() 2953 MainWindow::exportSVG()
2981 { 2954 {