comparison main/MainWindow.cpp @ 1460:8ca62b402846 3.0-integration

Fix accidental breakage of PNG export while adding SVG export
author Chris Cannam
date Tue, 03 Jan 2017 14:36:31 +0000
parents 96057b1185cb
children f5180edc5dda
comparison
equal deleted inserted replaced
1459:9a3684f1393b 1460:8ca62b402846
350 350
351 void 351 void
352 MainWindow::setupMenus() 352 MainWindow::setupMenus()
353 { 353 {
354 if (!m_mainMenusCreated) { 354 if (!m_mainMenusCreated) {
355
356 #ifdef Q_OS_MAC
357 // Mac doesn't align menu labels when icons are shown: result is messy
358 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
359 #endif
360 355
361 #ifdef Q_OS_LINUX 356 #ifdef Q_OS_LINUX
362 // In Ubuntu 14.04 the window's menu bar goes missing entirely 357 // In Ubuntu 14.04 the window's menu bar goes missing entirely
363 // if the user is running any desktop environment other than Unity 358 // if the user is running any desktop environment other than Unity
364 // (in which the faux single-menubar appears). The user has a 359 // (in which the faux single-menubar appears). The user has a
2864 MainWindow::exportImage() 2859 MainWindow::exportImage()
2865 { 2860 {
2866 Pane *pane = m_paneStack->getCurrentPane(); 2861 Pane *pane = m_paneStack->getCurrentPane();
2867 if (!pane) return; 2862 if (!pane) return;
2868 2863
2869 //!!! QString path = getSaveFileName(FileFinder::ImageFile);
2870 // if (path == "") return;
2871 // if (QFileInfo(path).suffix() == "") path += ".png";
2872 QString path = getSaveFileName(FileFinder::ImageFile); 2864 QString path = getSaveFileName(FileFinder::ImageFile);
2873 if (path == "") return; 2865 if (path == "") return;
2874 if (QFileInfo(path).suffix() == "") path += ".svg"; 2866 if (QFileInfo(path).suffix() == "") path += ".png";
2875
2876 bool scalable = true; //!!!
2877 2867
2878 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty(); 2868 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
2879 2869
2880 QSize total, visible, selected; 2870 QSize total, visible, selected;
2881 total = pane->getRenderedImageSize(); 2871 total = pane->getRenderedImageSize();
2907 2897
2908 QSettings settings; 2898 QSettings settings;
2909 settings.beginGroup("MainWindow"); 2899 settings.beginGroup("MainWindow");
2910 int deflt = settings.value("lastimageexportregion", 0).toInt(); 2900 int deflt = settings.value("lastimageexportregion", 0).toInt();
2911 if (deflt == 2 && !haveSelection) deflt = 1; 2901 if (deflt == 2 && !haveSelection) deflt = 1;
2912 if (deflt == 0 && !scalable && total.width() > 32767) deflt = 1; 2902 if (deflt == 0 && total.width() > 32767) deflt = 1;
2913 2903
2914 ListInputDialog *lid = new ListInputDialog 2904 ListInputDialog *lid = new ListInputDialog
2915 (this, tr("Select region to export"), 2905 (this, tr("Select region to export"),
2916 tr("Which region of the current pane do you want to export as an image?"), 2906 tr("Which region of the current pane do you want to export as an image?"),
2917 items, deflt); 2907 items, deflt);
2918 2908
2919 if (!haveSelection) { 2909 if (!haveSelection) {
2920 lid->setItemAvailability(2, false); 2910 lid->setItemAvailability(2, false);
2921 } 2911 }
2922 if (!scalable && total.width() > 32767) { // appears to be limit of a QImage 2912 if (total.width() > 32767) { // appears to be limit of a QImage
2923 lid->setItemAvailability(0, false); 2913 lid->setItemAvailability(0, false);
2924 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image.")); 2914 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
2925 } 2915 }
2926 2916
2927 bool ok = lid->exec(); 2917 bool ok = lid->exec();
2930 2920
2931 if (!ok || item.isEmpty()) return; 2921 if (!ok || item.isEmpty()) return;
2932 2922
2933 settings.setValue("lastimageexportregion", deflt); 2923 settings.setValue("lastimageexportregion", deflt);
2934 2924
2935 if (scalable) { 2925 QImage *image = 0;
2936
2937 bool result = false;
2938
2939 if (item == items[0]) {
2940 result = pane->renderToSvgFile(path );
2941 } else if (item == items[1]) {
2942 result = pane->renderPartToSvgFile(path,
2943 pane->getFirstVisibleFrame(),
2944 pane->getLastVisibleFrame());
2945 } else if (haveSelection) {
2946 result = pane->renderPartToSvgFile(path, sf0, sf1);
2947 }
2948
2949 if (!result) {
2950 QMessageBox::critical(this, tr("Failed to save SVG file"),
2951 tr("Failed to save SVG file %1").arg(path));
2952 }
2953
2954 } else {
2955
2956 QImage *image = 0;
2957
2958 if (item == items[0]) {
2959 image = pane->renderToNewImage();
2960 } else if (item == items[1]) {
2961 image = pane->renderPartToNewImage(pane->getFirstVisibleFrame(),
2962 pane->getLastVisibleFrame());
2963 } else if (haveSelection) {
2964 image = pane->renderPartToNewImage(sf0, sf1);
2965 }
2966
2967 if (!image) return;
2968
2969 if (!image->save(path, "PNG")) {
2970 QMessageBox::critical(this, tr("Failed to save image file"),
2971 tr("Failed to save image file %1").arg(path));
2972 }
2973 2926
2974 delete image; 2927 if (item == items[0]) {
2975 } 2928 image = pane->renderToNewImage();
2929 } else if (item == items[1]) {
2930 image = pane->renderPartToNewImage(pane->getFirstVisibleFrame(),
2931 pane->getLastVisibleFrame());
2932 } else if (haveSelection) {
2933 image = pane->renderPartToNewImage(sf0, sf1);
2934 }
2935
2936 if (!image) return;
2937
2938 if (!image->save(path, "PNG")) {
2939 QMessageBox::critical(this, tr("Failed to save image file"),
2940 tr("Failed to save image file %1").arg(path));
2941 }
2942
2943 delete image;
2976 } 2944 }
2977 2945
2978 void 2946 void
2979 MainWindow::exportSVG() 2947 MainWindow::exportSVG()
2980 { 2948 {