Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/imagesplit/imagesplit.cpp
Context not available. | |||||
137 | 137 | | |||
---|---|---|---|---|---|
138 | 138 | | |||
139 | bool stop = false; | 139 | bool stop = false; | ||
140 | | ||||
141 | QString mimeType; | ||||
142 | QString filepath; | ||||
143 | QString homepath; | ||||
144 | QString suffix; | ||||
145 | | ||||
140 | if (dlgImagesplit->autoSave()) { | 146 | if (dlgImagesplit->autoSave()) { | ||
141 | KoFileDialog dialog(viewManager()->mainWindow(), KoFileDialog::OpenDirectory, "OpenDocument"); | 147 | KoFileDialog dialog(viewManager()->mainWindow(), KoFileDialog::OpenDirectory, "OpenDocument"); | ||
142 | dialog.setCaption(i18n("Save Image on Split")); | 148 | dialog.setCaption(i18n("Save Image on Split")); | ||
Context not available. | |||||
149 | 155 | | |||
150 | if (directory.isEmpty()) | 156 | if (directory.isEmpty()) | ||
151 | return; | 157 | return; | ||
152 | for (int i = 0, k = 1; i < (numVerticalLines + 1); i++) { | 158 | | ||
153 | for (int j = 0; j < (numHorizontalLines + 1); j++, k++) { | 159 | mimeType = listMimeFilter.at(dlgImagesplit->cmbIndex); | ||
154 | QString mimeTypeSelected = listMimeFilter.at(dlgImagesplit->cmbIndex); | 160 | homepath = directory.toLocalFile(); | ||
155 | QString homepath = directory.toLocalFile(); | 161 | suffix = KisMimeDatabase::suffixesForMimeType(mimeType).first(); | ||
156 | QString suffix = KisMimeDatabase::suffixesForMimeType(mimeTypeSelected).first(); | 162 | qDebug() << "suffix" << suffix; | ||
157 | qDebug() << "suffix" << suffix; | 163 | if (suffix.startsWith("*.")) { | ||
158 | if (suffix.startsWith("*.")) { | 164 | suffix = suffix.remove(0, 1); | ||
159 | suffix = suffix.remove(0, 1); | 165 | } | ||
160 | } | 166 | qDebug() << "\tsuffix" << suffix; | ||
161 | qDebug() << "\tsuffix" << suffix; | 167 | if (!suffix.startsWith(".")) { | ||
162 | if (!suffix.startsWith(".")) { | 168 | suffix = suffix.prepend('.'); | ||
163 | suffix = suffix.prepend('.'); | | |||
164 | } | | |||
165 | qDebug() << "\tsuffix" << suffix; | | |||
166 | QString fileName = dlgImagesplit->suffix() + '_' + QString::number(k) + suffix; | | |||
167 | QString url = homepath + '/' + fileName; | | |||
168 | if (!saveAsImage(QRect((i * img_width), (j * img_height), img_width, img_height), listMimeFilter.at(dlgImagesplit->cmbIndex), url)) { | | |||
169 | stop = true; | | |||
170 | break; | | |||
171 | } | | |||
172 | } | | |||
173 | if (stop) { | | |||
174 | break; | | |||
175 | } | | |||
176 | } | 169 | } | ||
170 | qDebug() << "\tsuffix" << suffix; | ||||
171 | } | ||||
172 | | ||||
173 | int row; | ||||
174 | int column; | ||||
175 | int outerLoop; | ||||
176 | int innerLoop; | ||||
177 | | ||||
178 | if (dlgImagesplit->sortHorizontal()) { | ||||
179 | outerLoop = numHorizontalLines + 1; | ||||
180 | innerLoop = numVerticalLines + 1; | ||||
177 | } | 181 | } | ||
178 | else { | 182 | else { | ||
183 | outerLoop = numVerticalLines + 1; | ||||
184 | innerLoop = numHorizontalLines + 1; | ||||
185 | } | ||||
186 | | ||||
187 | | ||||
188 | for (int i = 0, k = 1; i < outerLoop; i++) { | ||||
189 | for (int j = 0; j < innerLoop; j++, k++) { | ||||
190 | if (dlgImagesplit->sortHorizontal()) { | ||||
191 | row = i; | ||||
192 | column = j; | ||||
193 | } | ||||
194 | else { | ||||
195 | row = j; | ||||
196 | column = i; | ||||
197 | } | ||||
179 | 198 | | |||
180 | for (int i = 0; i < (numVerticalLines + 1); i++) { | 199 | if (dlgImagesplit->autoSave()) { | ||
181 | for (int j = 0; j < (numHorizontalLines + 1); j++) { | 200 | QString fileName = dlgImagesplit->suffix() + '_' + QString::number(k) + suffix; | ||
201 | filepath = homepath + '/' + fileName; | ||||
202 | mimeType = listMimeFilter.at(dlgImagesplit->cmbIndex); | ||||
203 | } | ||||
204 | else { | ||||
182 | KoFileDialog dialog(viewManager()->mainWindow(), KoFileDialog::SaveFile, "OpenDocument"); | 205 | KoFileDialog dialog(viewManager()->mainWindow(), KoFileDialog::SaveFile, "OpenDocument"); | ||
183 | dialog.setCaption(i18n("Save Image on Split")); | 206 | dialog.setCaption(i18n("Save Image on Split")); | ||
184 | dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); | 207 | dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); | ||
185 | dialog.setMimeTypeFilters(listMimeFilter, defaultMime); | 208 | dialog.setMimeTypeFilters(listMimeFilter, defaultMime); | ||
186 | 209 | | |||
187 | QUrl url = QUrl::fromUserInput(dialog.filename()); | 210 | QUrl url = QUrl::fromUserInput(dialog.filename()); | ||
211 | filepath = url.toLocalFile(); | ||||
188 | 212 | | |||
189 | QString mimefilter = KisMimeDatabase::mimeTypeForFile(url.toLocalFile(), false); | 213 | mimeType = KisMimeDatabase::mimeTypeForFile(url.toLocalFile(), false); | ||
190 | 214 | | |||
191 | if (url.isEmpty()) | 215 | if (url.isEmpty()) | ||
192 | return; | 216 | return; | ||
193 | if (!saveAsImage(QRect((i * img_width), (j * img_height), img_width, img_height), mimefilter, url.toLocalFile())) { | 217 | | ||
194 | stop = true; | | |||
195 | break; | | |||
196 | } | | |||
197 | } | 218 | } | ||
198 | if (stop) { | 219 | if (!saveAsImage(QRect((column * img_width), (row * img_height), img_width, img_height), mimeType, filepath)) { | ||
220 | stop = true; | ||||
199 | break; | 221 | break; | ||
200 | } | 222 | } | ||
201 | } | 223 | } | ||
202 | 224 | if (stop) { | |||
225 | break; | ||||
226 | } | ||||
203 | } | 227 | } | ||
204 | | ||||
205 | } | 228 | } | ||
206 | delete dlgImagesplit; | 229 | delete dlgImagesplit; | ||
207 | } | 230 | } | ||
Context not available. |