Changeset View
Changeset View
Standalone View
Standalone View
document/kpDocumentSaveOptions.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include <QString> | 42 | #include <QString> | ||
43 | 43 | | |||
44 | //--------------------------------------------------------------------- | 44 | //--------------------------------------------------------------------- | ||
45 | 45 | | |||
46 | class kpDocumentSaveOptionsPrivate | 46 | class kpDocumentSaveOptionsPrivate | ||
47 | { | 47 | { | ||
48 | public: | 48 | public: | ||
49 | QString m_mimeType; | 49 | QString m_mimeType; | ||
50 | int m_colorDepth; | 50 | int m_colorDepth{}; | ||
51 | bool m_dither; | 51 | bool m_dither{}; | ||
52 | int m_quality; | 52 | int m_quality{}; | ||
53 | }; | 53 | }; | ||
54 | 54 | | |||
55 | //--------------------------------------------------------------------- | 55 | //--------------------------------------------------------------------- | ||
56 | 56 | | |||
57 | kpDocumentSaveOptions::kpDocumentSaveOptions () | 57 | kpDocumentSaveOptions::kpDocumentSaveOptions () | ||
58 | : d (new kpDocumentSaveOptionsPrivate ()) | 58 | : d (new kpDocumentSaveOptionsPrivate ()) | ||
59 | { | 59 | { | ||
60 | d->m_mimeType = invalidMimeType (); | 60 | d->m_mimeType = invalidMimeType (); | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 134 | { | |||
135 | const QString usedPrefix = !prefix.isEmpty () ? | 135 | const QString usedPrefix = !prefix.isEmpty () ? | ||
136 | prefix + QLatin1String (": ") : | 136 | prefix + QLatin1String (": ") : | ||
137 | QString(); | 137 | QString(); | ||
138 | 138 | | |||
139 | qCDebug(kpLogDocument) << usedPrefix | 139 | qCDebug(kpLogDocument) << usedPrefix | ||
140 | << "mimeType=" << mimeType () | 140 | << "mimeType=" << mimeType () | ||
141 | << " colorDepth=" << colorDepth () | 141 | << " colorDepth=" << colorDepth () | ||
142 | << " dither=" << dither () | 142 | << " dither=" << dither () | ||
143 | << " quality=" << quality () | 143 | << " quality=" << quality (); | ||
144 | << endl; | | |||
145 | } | 144 | } | ||
146 | 145 | | |||
147 | //--------------------------------------------------------------------- | 146 | //--------------------------------------------------------------------- | ||
148 | 147 | | |||
149 | 148 | | |||
150 | // public | 149 | // public | ||
151 | QString kpDocumentSaveOptions::mimeType () const | 150 | QString kpDocumentSaveOptions::mimeType () const | ||
152 | { | 151 | { | ||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Line(s) | |||||
330 | 329 | | |||
331 | //--------------------------------------------------------------------- | 330 | //--------------------------------------------------------------------- | ||
332 | 331 | | |||
333 | 332 | | |||
334 | // public static | 333 | // public static | ||
335 | int kpDocumentSaveOptions::defaultQuality (const KConfigGroup &config) | 334 | int kpDocumentSaveOptions::defaultQuality (const KConfigGroup &config) | ||
336 | { | 335 | { | ||
337 | int val = config.readEntry (kpSettingForcedQuality, -1); | 336 | int val = config.readEntry (kpSettingForcedQuality, -1); | ||
338 | if (qualityIsInvalid (val)) | | |||
339 | val = -1; | | |||
340 | 337 | | |||
341 | return val; | 338 | return qualityIsInvalid (val) ? -1 : val; | ||
342 | } | 339 | } | ||
343 | 340 | | |||
344 | //--------------------------------------------------------------------- | 341 | //--------------------------------------------------------------------- | ||
345 | 342 | | |||
346 | // public static | 343 | // public static | ||
347 | void kpDocumentSaveOptions::saveDefaultQuality (KConfigGroup &config, int quality) | 344 | void kpDocumentSaveOptions::saveDefaultQuality (KConfigGroup &config, int quality) | ||
348 | { | 345 | { | ||
349 | config.writeEntry (kpSettingForcedQuality, quality); | 346 | config.writeEntry (kpSettingForcedQuality, quality); | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 411 | { | |||
431 | return mimeTypeList; | 428 | return mimeTypeList; | ||
432 | } | 429 | } | ||
433 | 430 | | |||
434 | //--------------------------------------------------------------------- | 431 | //--------------------------------------------------------------------- | ||
435 | 432 | | |||
436 | static bool mimeTypeSupportsProperty (const QString &mimeType, | 433 | static bool mimeTypeSupportsProperty (const QString &mimeType, | ||
437 | const QString &property, const QStringList &defaultMimeTypesWithPropertyList) | 434 | const QString &property, const QStringList &defaultMimeTypesWithPropertyList) | ||
438 | { | 435 | { | ||
439 | const QStringList mimeTypeList = mimeTypesSupportingProperty ( | 436 | const auto mimeTypeList = mimeTypesSupportingProperty ( | ||
440 | property, defaultMimeTypesWithPropertyList); | 437 | property, defaultMimeTypesWithPropertyList); | ||
441 | 438 | | |||
442 | return mimeTypeList.contains (mimeType); | 439 | return mimeTypeList.contains (mimeType); | ||
443 | } | 440 | } | ||
444 | 441 | | |||
445 | //--------------------------------------------------------------------- | 442 | //--------------------------------------------------------------------- | ||
446 | 443 | | |||
447 | 444 | | |||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 490 | { | |||
500 | 497 | | |||
501 | defaultList << QLatin1String ("image/x-portable-bitmap:1"); | 498 | defaultList << QLatin1String ("image/x-portable-bitmap:1"); | ||
502 | 499 | | |||
503 | // Grayscale actually (unenforced since depth not set to configurable) | 500 | // Grayscale actually (unenforced since depth not set to configurable) | ||
504 | defaultList << QLatin1String ("image/x-portable-graymap:8"); | 501 | defaultList << QLatin1String ("image/x-portable-graymap:8"); | ||
505 | 502 | | |||
506 | defaultList << QLatin1String ("image/x-xbitmap:1"); | 503 | defaultList << QLatin1String ("image/x-xbitmap:1"); | ||
507 | 504 | | |||
508 | const QStringList mimeTypeList = mimeTypesSupportingProperty ( | 505 | const auto mimeTypeList = mimeTypesSupportingProperty ( | ||
509 | kpSettingMimeTypeMaximumColorDepth, defaultList); | 506 | kpSettingMimeTypeMaximumColorDepth, defaultList); | ||
510 | 507 | | |||
511 | const QString mimeTypeColon = mimeType + QLatin1String (":"); | 508 | const QString mimeTypeColon = mimeType + QLatin1String (":"); | ||
512 | for (QStringList::const_iterator it = mimeTypeList.begin (); | 509 | for (const auto & it : mimeTypeList) | ||
513 | it != mimeTypeList.end (); | | |||
514 | ++it) | | |||
515 | { | 510 | { | ||
516 | if ((*it).startsWith (mimeTypeColon)) | 511 | if (it.startsWith (mimeTypeColon)) | ||
517 | { | 512 | { | ||
518 | int number = (*it).mid (mimeTypeColon.length ()).toInt (); | 513 | int number = it.mid (mimeTypeColon.length ()).toInt (); | ||
519 | if (!colorDepthIsInvalid (number)) | 514 | if (!colorDepthIsInvalid (number)) | ||
520 | { | 515 | { | ||
521 | return number; | 516 | return number; | ||
522 | } | 517 | } | ||
523 | } | 518 | } | ||
524 | } | 519 | } | ||
525 | 520 | | |||
526 | return 32; | 521 | return 32; | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 585 | { | |||
591 | return mimeTypeHasConfigurableQuality (mimeType ()); | 586 | return mimeTypeHasConfigurableQuality (mimeType ()); | ||
592 | } | 587 | } | ||
593 | 588 | | |||
594 | //--------------------------------------------------------------------- | 589 | //--------------------------------------------------------------------- | ||
595 | 590 | | |||
596 | // public | 591 | // public | ||
597 | int kpDocumentSaveOptions::isLossyForSaving (const QImage &image) const | 592 | int kpDocumentSaveOptions::isLossyForSaving (const QImage &image) const | ||
598 | { | 593 | { | ||
599 | int ret = 0; | 594 | auto ret = 0; | ||
600 | 595 | | |||
601 | if (mimeTypeMaximumColorDepth () < image.depth ()) | 596 | if (mimeTypeMaximumColorDepth () < image.depth ()) | ||
602 | { | 597 | { | ||
603 | ret |= MimeTypeMaximumColorDepthLow; | 598 | ret |= MimeTypeMaximumColorDepthLow; | ||
604 | } | 599 | } | ||
605 | 600 | | |||
606 | if (mimeTypeHasConfigurableColorDepth () && | 601 | if (mimeTypeHasConfigurableColorDepth () && | ||
607 | !colorDepthIsInvalid () /*REFACTOR: guarantee it is valid*/ && | 602 | !colorDepthIsInvalid () /*REFACTOR: guarantee it is valid*/ && | ||
Show All 16 Lines |