Changeset View
Changeset View
Standalone View
Standalone View
document/kpDocument_Open.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 62 | { | |||
---|---|---|---|---|---|
63 | saveOptions.setColorDepth(image.depth()); | 63 | saveOptions.setColorDepth(image.depth()); | ||
64 | saveOptions.setDither(false); // avoid double dithering when saving | 64 | saveOptions.setDither(false); // avoid double dithering when saving | ||
65 | 65 | | |||
66 | metaInfo.setDotsPerMeterX(image.dotsPerMeterX()); | 66 | metaInfo.setDotsPerMeterX(image.dotsPerMeterX()); | ||
67 | metaInfo.setDotsPerMeterY(image.dotsPerMeterY()); | 67 | metaInfo.setDotsPerMeterY(image.dotsPerMeterY()); | ||
68 | metaInfo.setOffset(image.offset()); | 68 | metaInfo.setOffset(image.offset()); | ||
69 | 69 | | |||
70 | QStringList keys = image.textKeys(); | 70 | QStringList keys = image.textKeys(); | ||
71 | for (int i = 0; i < keys.count(); i++) | 71 | for (int i = 0; i < keys.count(); i++) { | ||
72 | metaInfo.setText(keys[i], image.text(keys[i])); | 72 | metaInfo.setText(keys[i], image.text(keys[i])); | ||
73 | } | 73 | } | ||
74 | } | ||||
74 | 75 | | |||
75 | //--------------------------------------------------------------------- | 76 | //--------------------------------------------------------------------- | ||
76 | 77 | | |||
77 | // public static | 78 | // public static | ||
78 | QImage kpDocument::getPixmapFromFile(const QUrl &url, bool suppressDoesntExistDialog, | 79 | QImage kpDocument::getPixmapFromFile(const QUrl &url, bool suppressDoesntExistDialog, | ||
79 | QWidget *parent, | 80 | QWidget *parent, | ||
80 | kpDocumentSaveOptions *saveOptions, | 81 | kpDocumentSaveOptions *saveOptions, | ||
81 | kpDocumentMetaInfo *metaInfo) | 82 | kpDocumentMetaInfo *metaInfo) | ||
82 | { | 83 | { | ||
83 | qCDebug(kpLogDocument) << "kpDocument::getPixmapFromFile(" << url << "," << parent << ")"; | 84 | qCDebug(kpLogDocument) << "kpDocument::getPixmapFromFile(" << url << "," << parent << ")"; | ||
84 | 85 | | |||
85 | if (saveOptions) | 86 | if (saveOptions) { | ||
86 | *saveOptions = kpDocumentSaveOptions (); | 87 | *saveOptions = kpDocumentSaveOptions (); | ||
88 | } | ||||
87 | 89 | | |||
88 | if (metaInfo) | 90 | if (metaInfo) { | ||
89 | *metaInfo = kpDocumentMetaInfo (); | 91 | *metaInfo = kpDocumentMetaInfo (); | ||
92 | } | ||||
90 | 93 | | |||
91 | QString tempFile; | 94 | QString tempFile; | ||
92 | if (url.isEmpty () || !KIO::NetAccess::download (url, tempFile, parent)) | 95 | if (url.isEmpty () || !KIO::NetAccess::download (url, tempFile, parent)) | ||
93 | { | 96 | { | ||
94 | if (!suppressDoesntExistDialog) | 97 | if (!suppressDoesntExistDialog) | ||
95 | { | 98 | { | ||
96 | // TODO: Use "Cannot" instead of "Could not" in all dialogs in KolourPaint. | 99 | // TODO: Use "Cannot" instead of "Could not" in all dialogs in KolourPaint. | ||
97 | // Or at least choose one consistently. | 100 | // Or at least choose one consistently. | ||
98 | // | 101 | // | ||
99 | // TODO: Have captions for all dialogs in KolourPaint. | 102 | // TODO: Have captions for all dialogs in KolourPaint. | ||
100 | KMessageBox::sorry (parent, | 103 | KMessageBox::sorry (parent, | ||
101 | i18n ("Could not open \"%1\".", | 104 | i18n ("Could not open \"%1\".", | ||
102 | kpUrlFormatter::PrettyFilename (url))); | 105 | kpUrlFormatter::PrettyFilename (url))); | ||
103 | } | 106 | } | ||
104 | 107 | | |||
105 | return QImage (); | 108 | return QImage (); | ||
106 | } | 109 | } | ||
107 | 110 | | |||
108 | QMimeDatabase db; | 111 | QMimeDatabase db; | ||
109 | QMimeType mimeType = db.mimeTypeForFile(tempFile); | 112 | QMimeType mimeType = db.mimeTypeForFile(tempFile); | ||
110 | 113 | | |||
111 | if (saveOptions) | 114 | if (saveOptions) { | ||
112 | saveOptions->setMimeType(mimeType.name()); | 115 | saveOptions->setMimeType(mimeType.name()); | ||
116 | } | ||||
113 | 117 | | |||
114 | qCDebug(kpLogDocument) << "\ttempFile=" << tempFile; | 118 | qCDebug(kpLogDocument) << "\ttempFile=" << tempFile; | ||
115 | qCDebug(kpLogDocument) << "\tmimetype=" << mimeType.name(); | 119 | qCDebug(kpLogDocument) << "\tmimetype=" << mimeType.name(); | ||
116 | qCDebug(kpLogDocument) << "\tsrc=" << url.path (); | 120 | qCDebug(kpLogDocument) << "\tsrc=" << url.path (); | ||
117 | 121 | | |||
118 | QImageReader reader(tempFile); | 122 | QImageReader reader(tempFile); | ||
119 | reader.setAutoTransform(true); | 123 | reader.setAutoTransform(true); | ||
120 | reader.setDecideFormatFromContent(true); | 124 | reader.setDecideFormatFromContent(true); | ||
121 | 125 | | |||
122 | QImage image = reader.read(); | 126 | QImage image = reader.read(); | ||
123 | 127 | | |||
124 | KIO::NetAccess::removeTempFile(tempFile); | 128 | KIO::NetAccess::removeTempFile(tempFile); | ||
125 | 129 | | |||
126 | if (image.isNull ()) | 130 | if (image.isNull ()) | ||
127 | { | 131 | { | ||
128 | KMessageBox::sorry (parent, | 132 | KMessageBox::sorry (parent, | ||
129 | i18n ("Could not open \"%1\" - unsupported image format.\n" | 133 | i18n ("Could not open \"%1\" - unsupported image format.\n" | ||
130 | "The file may be corrupt.", | 134 | "The file may be corrupt.", | ||
131 | kpUrlFormatter::PrettyFilename (url))); | 135 | kpUrlFormatter::PrettyFilename (url))); | ||
132 | return QImage (); | 136 | return QImage (); | ||
133 | } | 137 | } | ||
134 | 138 | | |||
135 | qCDebug(kpLogDocument) << "\tpixmap: depth=" << image.depth () | 139 | qCDebug(kpLogDocument) << "\tpixmap: depth=" << image.depth () | ||
136 | << " hasAlphaChannel=" << image.hasAlphaChannel () | 140 | << " hasAlphaChannel=" << image.hasAlphaChannel (); | ||
137 | << endl; | | |||
138 | 141 | | |||
139 | if ( saveOptions && metaInfo ) | 142 | if ( saveOptions && metaInfo ) { | ||
140 | getDataFromImage(image, *saveOptions, *metaInfo); | 143 | getDataFromImage(image, *saveOptions, *metaInfo); | ||
144 | } | ||||
141 | 145 | | |||
142 | // make sure we always have Format_ARGB32_Premultiplied as this is the fastest to draw on | 146 | // make sure we always have Format_ARGB32_Premultiplied as this is the fastest to draw on | ||
143 | // and Qt can not draw onto Format_Indexed8 (Qt-4.7) | 147 | // and Qt can not draw onto Format_Indexed8 (Qt-4.7) | ||
144 | if ( image.format() != QImage::Format_ARGB32_Premultiplied ) | 148 | if ( image.format() != QImage::Format_ARGB32_Premultiplied ) { | ||
145 | image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); | 149 | image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); | ||
150 | } | ||||
146 | 151 | | |||
147 | return image; | 152 | return image; | ||
148 | } | 153 | } | ||
149 | 154 | | |||
150 | //--------------------------------------------------------------------- | 155 | //--------------------------------------------------------------------- | ||
151 | 156 | | |||
152 | void kpDocument::openNew (const QUrl &url) | 157 | void kpDocument::openNew (const QUrl &url) | ||
153 | { | 158 | { | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 214 | { | |||
215 | } | 220 | } | ||
216 | else | 221 | else | ||
217 | { | 222 | { | ||
218 | openNew (QUrl ()); | 223 | openNew (QUrl ()); | ||
219 | } | 224 | } | ||
220 | 225 | | |||
221 | return true; | 226 | return true; | ||
222 | } | 227 | } | ||
223 | else | 228 | | ||
224 | { | | |||
225 | return false; | 229 | return false; | ||
226 | } | 230 | | ||
227 | } | 231 | } | ||
228 | 232 | | |||
229 | //--------------------------------------------------------------------- | 233 | //--------------------------------------------------------------------- |