Changeset View
Changeset View
Standalone View
Standalone View
mainWindow/kpMainWindow_File.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
51 | #include <QImageWriter> | 51 | #include <QImageWriter> | ||
52 | #include <QMimeDatabase> | 52 | #include <QMimeDatabase> | ||
53 | #include <QPrintPreviewDialog> | 53 | #include <QPrintPreviewDialog> | ||
54 | 54 | | |||
55 | #include <kactioncollection.h> | 55 | #include <kactioncollection.h> | ||
56 | #include <KSharedConfig> | 56 | #include <KSharedConfig> | ||
57 | #include <kconfiggroup.h> | 57 | #include <kconfiggroup.h> | ||
58 | #include <KPluralHandlingSpinBox> | 58 | #include <KPluralHandlingSpinBox> | ||
59 | #include <kfiledialog.h> // kdelibs4support | | |||
60 | #include <kmessagebox.h> | 59 | #include <kmessagebox.h> | ||
61 | #include <krecentfilesaction.h> | 60 | #include <krecentfilesaction.h> | ||
62 | #include <kstandardshortcut.h> | 61 | #include <kstandardshortcut.h> | ||
63 | #include <kstandardaction.h> | 62 | #include <kstandardaction.h> | ||
64 | #include <ktoolinvocation.h> | 63 | #include <ktoolinvocation.h> | ||
65 | #include <KLocalizedString> | 64 | #include <KLocalizedString> | ||
66 | #include <kdeprintdialog.h> // kdelibs4support | 65 | #include <kdeprintdialog.h> // kdelibs4support | ||
67 | 66 | | |||
▲ Show 20 Lines • Show All 673 Lines • ▼ Show 20 Line(s) | 736 | if (d->document->url ().isEmpty () || | |||
741 | // from file so it has been set initially to an invalid value. | 740 | // from file so it has been set initially to an invalid value. | ||
742 | (d->document->saveOptions ()->mimeTypeHasConfigurableQuality () && | 741 | (d->document->saveOptions ()->mimeTypeHasConfigurableQuality () && | ||
743 | d->document->saveOptions ()->qualityIsInvalid ()) || | 742 | d->document->saveOptions ()->qualityIsInvalid ()) || | ||
744 | (localOnly && !d->document->url ().isLocalFile ())) | 743 | (localOnly && !d->document->url ().isLocalFile ())) | ||
745 | { | 744 | { | ||
746 | return saveAs (localOnly); | 745 | return saveAs (localOnly); | ||
747 | } | 746 | } | ||
748 | 747 | | |||
749 | if (d->document->save (false/*no overwrite prompt*/, | 748 | if (d->document->save (!d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) | ||
750 | !d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) | | |||
751 | { | 749 | { | ||
752 | addRecentURL (d->document->url ()); | 750 | addRecentURL (d->document->url ()); | ||
753 | return true; | 751 | return true; | ||
754 | } | 752 | } | ||
755 | 753 | | |||
756 | return false; | 754 | return false; | ||
757 | } | 755 | } | ||
758 | 756 | | |||
Show All 14 Lines | 770 | QUrl kpMainWindow::askForSaveURL (const QString &caption, | |||
773 | const QString &startURL, | 771 | const QString &startURL, | ||
774 | const kpImage &imageToBeSaved, | 772 | const kpImage &imageToBeSaved, | ||
775 | const kpDocumentSaveOptions &startSaveOptions, | 773 | const kpDocumentSaveOptions &startSaveOptions, | ||
776 | const kpDocumentMetaInfo &docMetaInfo, | 774 | const kpDocumentMetaInfo &docMetaInfo, | ||
777 | const QString &forcedSaveOptionsGroup, | 775 | const QString &forcedSaveOptionsGroup, | ||
778 | bool localOnly, | 776 | bool localOnly, | ||
779 | kpDocumentSaveOptions *chosenSaveOptions, | 777 | kpDocumentSaveOptions *chosenSaveOptions, | ||
780 | bool isSavingForFirstTime, | 778 | bool isSavingForFirstTime, | ||
781 | bool *allowOverwritePrompt, | | |||
782 | bool *allowLossyPrompt) | 779 | bool *allowLossyPrompt) | ||
783 | { | 780 | { | ||
784 | #if DEBUG_KP_MAIN_WINDOW | 781 | #if DEBUG_KP_MAIN_WINDOW | ||
785 | qCDebug(kpLogMainWindow) << "kpMainWindow::askForURL() startURL=" << startURL; | 782 | qCDebug(kpLogMainWindow) << "kpMainWindow::askForURL() startURL=" << startURL; | ||
786 | startSaveOptions.printDebug ("\tstartSaveOptions"); | 783 | startSaveOptions.printDebug ("\tstartSaveOptions"); | ||
787 | #endif | 784 | #endif | ||
788 | 785 | | |||
789 | bool reparsedConfiguration = false; | 786 | bool reparsedConfiguration = false; | ||
Show All 10 Lines | 796 | } \ | |||
800 | \ | 797 | \ | ||
801 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | 798 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | ||
802 | 799 | | |||
803 | 800 | | |||
804 | if (chosenSaveOptions) { | 801 | if (chosenSaveOptions) { | ||
805 | *chosenSaveOptions = kpDocumentSaveOptions (); | 802 | *chosenSaveOptions = kpDocumentSaveOptions (); | ||
806 | } | 803 | } | ||
807 | 804 | | |||
808 | if (allowOverwritePrompt) { | | |||
809 | *allowOverwritePrompt = true; // play it safe for now | | |||
810 | } | | |||
811 | | ||||
812 | if (allowLossyPrompt) { | 805 | if (allowLossyPrompt) { | ||
813 | *allowLossyPrompt = true; // play it safe for now | 806 | *allowLossyPrompt = true; // play it safe for now | ||
814 | } | 807 | } | ||
815 | 808 | | |||
816 | 809 | | |||
817 | kpDocumentSaveOptions fdSaveOptions = startSaveOptions; | 810 | kpDocumentSaveOptions fdSaveOptions = startSaveOptions; | ||
818 | 811 | | |||
819 | QStringList mimeTypes; | 812 | QStringList mimeTypes; | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
884 | #endif | 877 | #endif | ||
885 | 878 | | |||
886 | auto *saveOptionsWidget = | 879 | auto *saveOptionsWidget = | ||
887 | new kpDocumentSaveOptionsWidget (imageToBeSaved, | 880 | new kpDocumentSaveOptionsWidget (imageToBeSaved, | ||
888 | fdSaveOptions, | 881 | fdSaveOptions, | ||
889 | docMetaInfo, | 882 | docMetaInfo, | ||
890 | this); | 883 | this); | ||
891 | 884 | | |||
892 | KFileDialog fd (QUrl (startURL), QString(), this, | 885 | QFileDialog fd(this); | ||
893 | saveOptionsWidget); | 886 | fd.setAcceptMode (QFileDialog::AcceptSave); | ||
894 | saveOptionsWidget->setVisualParent (&fd); | 887 | fd.setOption (QFileDialog::DontUseNativeDialog); | ||
cfeck: Is there hope that Qt could be tricked into supporting native file dialogs that allow Qt… | |||||
Ouch, this "not use native dialog" is a *severe* usability regression. At first I thought it was a bug that it was using the Qt dialog. There's no editable address bar, there's no places panel, the mime type detection based on input filename (e.g. if I input ".jpg" it should switch to save as JPEG). broulik: Ouch, this "not use native dialog" is a *severe* usability regression. At first I thought it… | |||||
888 | fd.setDirectoryUrl (QUrl (startURL)); | ||||
895 | fd.setWindowTitle (caption); | 889 | fd.setWindowTitle (caption); | ||
896 | fd.setOperationMode (KFileDialog::Saving); | 890 | fd.setMimeTypeFilters (mimeTypes); | ||
897 | fd.setMimeFilter (mimeTypes, fdSaveOptions.mimeType ()); | 891 | fd.selectMimeTypeFilter (fdSaveOptions.mimeType ()); | ||
898 | if (localOnly) { | 892 | if (localOnly) { | ||
899 | fd.setMode (KFile::File | KFile::LocalOnly); | 893 | fd.setSupportedSchemes ({QStringLiteral("file")}); | ||
894 | } | ||||
895 | | ||||
896 | // insert the checkbox below the filter box | ||||
897 | if (QGridLayout* gl = qobject_cast<QGridLayout*>(fd.layout ())) { | ||||
898 | gl->addWidget (saveOptionsWidget, gl->rowCount (), 0, 1, gl->columnCount ()); | ||||
900 | } | 899 | } | ||
900 | saveOptionsWidget->setVisualParent (&fd); | ||||
901 | 901 | | |||
902 | connect (&fd, &KFileDialog::filterChanged, | 902 | connect (&fd, &QFileDialog::filterSelected, | ||
903 | saveOptionsWidget, &kpDocumentSaveOptionsWidget::setMimeType); | 903 | this, [saveOptionsWidget, &fd]() { | ||
904 | saveOptionsWidget->setMimeType(fd.selectedMimeTypeFilter()); | ||||
905 | }); | ||||
904 | 906 | | |||
905 | if ( fd.exec() == QDialog::Accepted ) | 907 | if ( fd.exec() == QDialog::Accepted ) | ||
906 | { | 908 | { | ||
907 | kpDocumentSaveOptions newSaveOptions = saveOptionsWidget->documentSaveOptions (); | 909 | kpDocumentSaveOptions newSaveOptions = saveOptionsWidget->documentSaveOptions (); | ||
908 | #if DEBUG_KP_MAIN_WINDOW | 910 | #if DEBUG_KP_MAIN_WINDOW | ||
909 | newSaveOptions.printDebug ("\tnewSaveOptions"); | 911 | newSaveOptions.printDebug ("\tnewSaveOptions"); | ||
910 | #endif | 912 | #endif | ||
911 | 913 | | |||
912 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | 914 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | ||
913 | 915 | | |||
914 | // Save options user forced - probably want to use them in future | 916 | // Save options user forced - probably want to use them in future | ||
915 | kpDocumentSaveOptions::saveDefaultDifferences (cfg, | 917 | kpDocumentSaveOptions::saveDefaultDifferences (cfg, | ||
916 | fdSaveOptions, newSaveOptions); | 918 | fdSaveOptions, newSaveOptions); | ||
917 | cfg.sync (); | 919 | cfg.sync (); | ||
918 | 920 | | |||
919 | 921 | | |||
920 | if (chosenSaveOptions) { | 922 | if (chosenSaveOptions) { | ||
921 | *chosenSaveOptions = newSaveOptions; | 923 | *chosenSaveOptions = newSaveOptions; | ||
922 | } | 924 | } | ||
923 | 925 | | |||
924 | 926 | const QList<QUrl> selectedUrls = fd.selectedUrls (); | |||
925 | bool shouldAllowOverwritePrompt = | 927 | if (selectedUrls.isEmpty()) { // shouldn't happen | ||
926 | (fd.selectedUrl () != QUrl (startURL) || | 928 | return {}; | ||
927 | newSaveOptions.mimeType () != startSaveOptions.mimeType ()); | | |||
928 | if (allowOverwritePrompt) | | |||
929 | { | | |||
930 | *allowOverwritePrompt = shouldAllowOverwritePrompt; | | |||
931 | #if DEBUG_KP_MAIN_WINDOW | | |||
932 | qCDebug(kpLogMainWindow) << "\tallowOverwritePrompt=" << *allowOverwritePrompt; | | |||
933 | #endif | | |||
934 | } | 929 | } | ||
930 | const QUrl selectedUrl = selectedUrls.at(0); | ||||
935 | 931 | | |||
936 | if (allowLossyPrompt) | 932 | if (allowLossyPrompt) | ||
937 | { | 933 | { | ||
938 | // SYNC: kpDocumentSaveOptions elements - everything except quality | 934 | // SYNC: kpDocumentSaveOptions elements - everything except quality | ||
939 | // (one quality setting is "just as lossy" as another so no | 935 | // (one quality setting is "just as lossy" as another so no | ||
940 | // need to continually warn due to quality change) | 936 | // need to continually warn due to quality change) | ||
941 | *allowLossyPrompt = | 937 | *allowLossyPrompt = | ||
942 | (isSavingForFirstTime || | 938 | (isSavingForFirstTime || | ||
943 | shouldAllowOverwritePrompt || | 939 | selectedUrl != QUrl (startURL) || | ||
944 | newSaveOptions.mimeType () != startSaveOptions.mimeType () || | 940 | newSaveOptions.mimeType () != startSaveOptions.mimeType () || | ||
945 | newSaveOptions.colorDepth () != startSaveOptions.colorDepth () || | 941 | newSaveOptions.colorDepth () != startSaveOptions.colorDepth () || | ||
946 | newSaveOptions.dither () != startSaveOptions.dither ()); | 942 | newSaveOptions.dither () != startSaveOptions.dither ()); | ||
947 | #if DEBUG_KP_MAIN_WINDOW | 943 | #if DEBUG_KP_MAIN_WINDOW | ||
948 | qCDebug(kpLogMainWindow) << "\tallowLossyPrompt=" << *allowLossyPrompt; | 944 | qCDebug(kpLogMainWindow) << "\tallowLossyPrompt=" << *allowLossyPrompt; | ||
949 | #endif | 945 | #endif | ||
950 | } | 946 | } | ||
951 | 947 | | |||
952 | 948 | | |||
953 | #if DEBUG_KP_MAIN_WINDOW | 949 | #if DEBUG_KP_MAIN_WINDOW | ||
954 | qCDebug(kpLogMainWindow) << "\tselectedUrl=" << fd.selectedUrl (); | 950 | qCDebug(kpLogMainWindow) << "\tselectedUrl=" << selectedUrl; | ||
955 | #endif | 951 | #endif | ||
956 | return fd.selectedUrl (); | 952 | return selectedUrl; | ||
957 | } | 953 | } | ||
958 | 954 | | |||
959 | return {}; | 955 | return {}; | ||
960 | #undef SETUP_READ_CFG | 956 | #undef SETUP_READ_CFG | ||
961 | } | 957 | } | ||
962 | 958 | | |||
963 | //--------------------------------------------------------------------- | 959 | //--------------------------------------------------------------------- | ||
964 | 960 | | |||
965 | // private slot | 961 | // private slot | ||
966 | bool kpMainWindow::saveAs (bool localOnly) | 962 | bool kpMainWindow::saveAs (bool localOnly) | ||
967 | { | 963 | { | ||
968 | kpDocumentSaveOptions chosenSaveOptions; | 964 | kpDocumentSaveOptions chosenSaveOptions; | ||
969 | bool allowOverwritePrompt, allowLossyPrompt; | 965 | bool allowLossyPrompt; | ||
970 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Save Image As"), | 966 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Save Image As"), | ||
971 | d->document->url ().url (), | 967 | d->document->url ().url (), | ||
972 | d->document->imageWithSelection (), | 968 | d->document->imageWithSelection (), | ||
973 | *d->document->saveOptions (), | 969 | *d->document->saveOptions (), | ||
974 | *d->document->metaInfo (), | 970 | *d->document->metaInfo (), | ||
975 | kpSettingsGroupFileSaveAs, | 971 | kpSettingsGroupFileSaveAs, | ||
976 | localOnly, | 972 | localOnly, | ||
977 | &chosenSaveOptions, | 973 | &chosenSaveOptions, | ||
978 | !d->document->savedAtLeastOnceBefore (), | 974 | !d->document->savedAtLeastOnceBefore (), | ||
979 | &allowOverwritePrompt, | | |||
980 | &allowLossyPrompt); | 975 | &allowLossyPrompt); | ||
981 | 976 | | |||
982 | 977 | | |||
983 | if (chosenURL.isEmpty ()) { | 978 | if (chosenURL.isEmpty ()) { | ||
984 | return false; | 979 | return false; | ||
985 | } | 980 | } | ||
986 | 981 | | |||
987 | 982 | | |||
988 | if (!d->document->saveAs (chosenURL, chosenSaveOptions, | 983 | if (!d->document->saveAs (chosenURL, chosenSaveOptions, | ||
989 | allowOverwritePrompt, | | |||
990 | allowLossyPrompt)) | 984 | allowLossyPrompt)) | ||
991 | { | 985 | { | ||
992 | return false; | 986 | return false; | ||
993 | } | 987 | } | ||
994 | 988 | | |||
995 | 989 | | |||
996 | addRecentURL (chosenURL); | 990 | addRecentURL (chosenURL); | ||
997 | 991 | | |||
Show All 13 Lines | |||||
1011 | //--------------------------------------------------------------------- | 1005 | //--------------------------------------------------------------------- | ||
1012 | 1006 | | |||
1013 | // private slot | 1007 | // private slot | ||
1014 | bool kpMainWindow::slotExport () | 1008 | bool kpMainWindow::slotExport () | ||
1015 | { | 1009 | { | ||
1016 | toolEndShape (); | 1010 | toolEndShape (); | ||
1017 | 1011 | | |||
1018 | kpDocumentSaveOptions chosenSaveOptions; | 1012 | kpDocumentSaveOptions chosenSaveOptions; | ||
1019 | bool allowOverwritePrompt, allowLossyPrompt; | 1013 | bool allowLossyPrompt; | ||
1020 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Export"), | 1014 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Export"), | ||
1021 | d->lastExportURL.url (), | 1015 | d->lastExportURL.url (), | ||
1022 | d->document->imageWithSelection (), | 1016 | d->document->imageWithSelection (), | ||
1023 | d->lastExportSaveOptions, | 1017 | d->lastExportSaveOptions, | ||
1024 | *d->document->metaInfo (), | 1018 | *d->document->metaInfo (), | ||
1025 | kpSettingsGroupFileExport, | 1019 | kpSettingsGroupFileExport, | ||
1026 | false/*allow remote files*/, | 1020 | false/*allow remote files*/, | ||
1027 | &chosenSaveOptions, | 1021 | &chosenSaveOptions, | ||
1028 | d->exportFirstTime, | 1022 | d->exportFirstTime, | ||
1029 | &allowOverwritePrompt, | | |||
1030 | &allowLossyPrompt); | 1023 | &allowLossyPrompt); | ||
1031 | 1024 | | |||
1032 | 1025 | | |||
1033 | if (chosenURL.isEmpty ()) { | 1026 | if (chosenURL.isEmpty ()) { | ||
1034 | return false; | 1027 | return false; | ||
1035 | } | 1028 | } | ||
1036 | 1029 | | |||
1037 | if (!kpDocument::savePixmapToFile (d->document->imageWithSelection (), | 1030 | if (!kpDocument::savePixmapToFile (d->document->imageWithSelection (), | ||
1038 | chosenURL, | 1031 | chosenURL, | ||
1039 | chosenSaveOptions, *d->document->metaInfo (), | 1032 | chosenSaveOptions, *d->document->metaInfo (), | ||
1040 | allowOverwritePrompt, | | |||
1041 | allowLossyPrompt, | 1033 | allowLossyPrompt, | ||
1042 | this)) | 1034 | this)) | ||
1043 | { | 1035 | { | ||
1044 | return false; | 1036 | return false; | ||
1045 | } | 1037 | } | ||
1046 | 1038 | | |||
1047 | 1039 | | |||
1048 | addRecentURL (chosenURL); | 1040 | addRecentURL (chosenURL); | ||
▲ Show 20 Lines • Show All 474 Lines • Show Last 20 Lines |
Is there hope that Qt could be tricked into supporting native file dialogs that allow Qt widgets as extensions? I am not really happy with the pure Qt save dialog. It lacks all the bookmarks from the Places panel.