32 #include "hblayoutdirectionnotifier_p.h" |
32 #include "hblayoutdirectionnotifier_p.h" |
33 #include "hbiconanimation_p.h" |
33 #include "hbiconanimation_p.h" |
34 #include "hbimagetraces_p.h" |
34 #include "hbimagetraces_p.h" |
35 #include "hbiconimpl_p.h" |
35 #include "hbiconimpl_p.h" |
36 #include "hbpixmapiconimpl_p.h" |
36 #include "hbpixmapiconimpl_p.h" |
|
37 #include "hbbadgeicon_p.h" |
|
38 |
37 #include <hbinstance.h> |
39 #include <hbinstance.h> |
38 #include <hbiconanimator.h> |
40 #include <hbiconanimator.h> |
39 #include <hbiconanimator_p.h> |
41 #include <hbiconanimator_p.h> |
40 #include "hbbadgeicon_p.h" |
42 |
41 |
43 |
42 #include <QObject> |
44 #include <QObject> |
43 #include <QPainter> |
45 #include <QPainter> |
44 #include <QDebug> |
46 #include <QDebug> |
45 |
47 |
65 void appendLoadFail(QIcon::Mode mode, QIcon::State state); |
67 void appendLoadFail(QIcon::Mode mode, QIcon::State state); |
66 void removeLoadFail(QIcon::Mode mode, QIcon::State state); |
68 void removeLoadFail(QIcon::Mode mode, QIcon::State state); |
67 void unLoadIcon(bool unloadedByServer = false); |
69 void unLoadIcon(bool unloadedByServer = false); |
68 |
70 |
69 void addBadge(Qt::Alignment alignment, |
71 void addBadge(Qt::Alignment alignment, |
70 const HbIcon& badge, |
72 const HbIcon &badge, |
71 int z=0); |
73 int z, |
72 bool removeBadge(const HbIcon& badge); |
74 const QSizeF &sizeFactor, |
|
75 Qt::AspectRatioMode aspectRatio); |
|
76 bool removeBadge(const HbIcon &badge); |
73 void removeAllBadges(); |
77 void removeAllBadges(); |
74 const QList<HbBadgeIconInfo> badges() const; |
78 const QList<HbBadgeIconInfo> badges() const; |
75 bool isBadged() const; |
79 bool isBadged() const; |
76 |
80 |
|
81 QColor colorToUse(const QString &iconName) const; |
|
82 |
77 public: |
83 public: |
78 QSizeF size; |
84 QSizeF size; |
79 |
85 |
80 struct IconName |
86 struct IconName { |
81 { |
|
82 QIcon::Mode mode; |
87 QIcon::Mode mode; |
83 QIcon::State state; |
88 QIcon::State state; |
84 QString name; |
89 QString name; |
85 }; |
90 }; |
86 |
91 |
117 // If this pointer is 0, animations are not used. |
121 // If this pointer is 0, animations are not used. |
118 HbIconAnimator *animator; |
122 HbIconAnimator *animator; |
119 |
123 |
120 // Variables introduced for handling colorizable icons |
124 // Variables introduced for handling colorizable icons |
121 QColor color; |
125 QColor color; |
122 |
126 // The color coming from the color group associated with a widget in its css. |
|
127 QColor themedColor; |
|
128 |
123 //Icon Implementation interface which provides abstraction for the type of icon ( Pixmap, NVG, SgImage etc). |
129 //Icon Implementation interface which provides abstraction for the type of icon ( Pixmap, NVG, SgImage etc). |
124 // Each class derived from HbIconImpl will have to implement the paint(), pixmap() and defaultSize() API |
130 // Each class derived from HbIconImpl will have to implement the paint(), pixmap() and defaultSize() API |
125 HbIconImpl *icon; |
131 HbIconImpl *icon; |
126 |
132 |
127 // Icons decorating this engine |
133 // Icons decorating this engine |
133 }; |
139 }; |
134 |
140 |
135 // Class HbIconEnginePrivate |
141 // Class HbIconEnginePrivate |
136 |
142 |
137 HbIconEnginePrivate::HbIconEnginePrivate(const QString &iconName) : |
143 HbIconEnginePrivate::HbIconEnginePrivate(const QString &iconName) : |
138 size(), |
|
139 iconNames(), |
|
140 pixmap(), |
|
141 aspectRatioMode(Qt::KeepAspectRatio), |
144 aspectRatioMode(Qt::KeepAspectRatio), |
142 mode(QIcon::Normal), |
145 mode(QIcon::Normal), |
143 state(QIcon::Off), |
146 state(QIcon::Off), |
144 defaultSize(), |
|
145 defaultSizeFailed(false), |
147 defaultSizeFailed(false), |
146 loadFailed(0), |
148 loadFailed(0), |
147 flags(0), |
149 flags(0), |
148 mirroringMode(HbIcon::Default), |
150 mirroringMode(HbIcon::Default), |
149 defaultMirroring(Unknown), |
151 defaultMirroring(Unknown), |
150 animator(0), |
152 animator(0), |
151 color(QColor()), |
|
152 icon(0), |
153 icon(0), |
153 badgeInfo(0), |
154 badgeInfo(0), |
154 signalConnectionsSet(false), |
155 signalConnectionsSet(false), |
155 iconType(INVALID_FORMAT) |
156 iconType(INVALID_FORMAT) |
156 { |
157 { |
161 } |
162 } |
162 |
163 |
163 HbIconEnginePrivate::HbIconEnginePrivate(const HbIconEnginePrivate &other) : |
164 HbIconEnginePrivate::HbIconEnginePrivate(const HbIconEnginePrivate &other) : |
164 size(other.size), |
165 size(other.size), |
165 iconNames(other.iconNames), |
166 iconNames(other.iconNames), |
166 // Pixmap is cleared if other object uses animation |
167 pixmap(other.animator ? QPixmap() : other.pixmap), // Pixmap is cleared if other object uses animation. |
167 pixmap(other.animator ? QPixmap() : other.pixmap), |
|
168 aspectRatioMode(other.aspectRatioMode), |
168 aspectRatioMode(other.aspectRatioMode), |
169 mode(other.mode), |
169 mode(other.mode), |
170 state(other.state), |
170 state(other.state), |
171 defaultSize(other.defaultSize), |
171 defaultSize(other.defaultSize), |
172 defaultSizeFailed(other.defaultSizeFailed), |
172 defaultSizeFailed(other.defaultSizeFailed), |
173 loadFailed(other.loadFailed), |
173 loadFailed(other.loadFailed), |
174 flags(other.flags), |
174 flags(other.flags), |
175 mirroringMode(other.mirroringMode), |
175 mirroringMode(other.mirroringMode), |
176 defaultMirroring(other.defaultMirroring), |
176 defaultMirroring(other.defaultMirroring), |
177 // Animator is instance specific and not copied |
177 animator(0), // Animator is instance specific and not copied. |
178 animator(0), |
178 color(other.color), // No copy for themedColor, that one is an internal, instance-specific setting. |
179 color(other.color), |
179 icon(0), // HbIconImpl is instance specific, it is recreated when icon is painted. |
180 // HbIconImpl is instance specific, it is recreated when icon is painted |
|
181 icon(0), |
|
182 badgeInfo(0), |
180 badgeInfo(0), |
183 signalConnectionsSet(false), |
181 signalConnectionsSet(false), |
184 iconType(INVALID_FORMAT) |
182 iconType(INVALID_FORMAT) |
185 { |
183 { |
186 if (other.badgeInfo) { |
184 if (other.badgeInfo) { |
188 *badgeInfo = *other.badgeInfo; |
186 *badgeInfo = *other.badgeInfo; |
189 } |
187 } |
190 } |
188 } |
191 |
189 |
192 HbIconEnginePrivate::HbIconEnginePrivate(QDataStream &stream) : |
190 HbIconEnginePrivate::HbIconEnginePrivate(QDataStream &stream) : |
193 size(), |
|
194 iconNames(), |
|
195 pixmap(), |
|
196 aspectRatioMode(Qt::KeepAspectRatio), |
191 aspectRatioMode(Qt::KeepAspectRatio), |
197 mode(QIcon::Normal), |
192 mode(QIcon::Normal), |
198 state(QIcon::Off), |
193 state(QIcon::Off), |
199 defaultSize(), |
|
200 defaultSizeFailed(false), |
194 defaultSizeFailed(false), |
201 loadFailed(0), |
195 loadFailed(0), |
202 flags(0), |
196 flags(0), |
203 mirroringMode(HbIcon::Default), |
197 mirroringMode(HbIcon::Default), |
204 defaultMirroring(Unknown), |
198 defaultMirroring(Unknown), |
205 animator(0), |
199 animator(0), |
206 color(QColor()), |
|
207 icon(0), |
200 icon(0), |
208 badgeInfo(new HbBadgeIcon), |
201 badgeInfo(new HbBadgeIcon), |
209 signalConnectionsSet(false), |
202 signalConnectionsSet(false), |
210 iconType(INVALID_FORMAT) |
203 iconType(INVALID_FORMAT) |
211 { |
204 { |
231 stream >> temp; |
224 stream >> temp; |
232 mirroringMode = (HbIcon::MirroringMode)temp; |
225 mirroringMode = (HbIcon::MirroringMode)temp; |
233 stream >> temp; |
226 stream >> temp; |
234 defaultMirroring = (HbIconEnginePrivate::DefaultMirroring)temp; |
227 defaultMirroring = (HbIconEnginePrivate::DefaultMirroring)temp; |
235 stream >> color; |
228 stream >> color; |
|
229 // Do not store themedColor, see the copy ctor. |
236 |
230 |
237 badgeInfo->internalize(stream); |
231 badgeInfo->internalize(stream); |
238 } |
232 } |
239 |
233 |
240 void HbIconEnginePrivate::externalize(QDataStream &stream) |
234 void HbIconEnginePrivate::externalize(QDataStream &stream) |
241 { |
235 { |
242 // Externalize parameters that are needed to reconstruct the icon |
236 // Externalize parameters that are needed to reconstruct the icon |
243 stream << size; |
237 stream << size; |
244 stream << iconNames.count(); |
238 stream << iconNames.count(); |
245 Q_FOREACH(const IconName &name, iconNames) { |
239 Q_FOREACH(const IconName & name, iconNames) { |
246 stream << (qint32)(name.mode); |
240 stream << (qint32)(name.mode); |
247 stream << (qint32)(name.state); |
241 stream << (qint32)(name.state); |
248 stream << name.name; |
242 stream << name.name; |
249 } |
243 } |
250 stream << (qint32)flags; |
244 stream << (qint32)flags; |
323 { |
318 { |
324 // If mirroring mode is default, check automatic mirroring from loader. |
319 // If mirroring mode is default, check automatic mirroring from loader. |
325 if (mirroringMode == HbIcon::Default && defaultMirroring == Unknown) { |
320 if (mirroringMode == HbIcon::Default && defaultMirroring == Unknown) { |
326 HbIconLoader *loader = HbIconLoader::global(); |
321 HbIconLoader *loader = HbIconLoader::global(); |
327 defaultMirroring = loader->isAutomaticallyMirrored( |
322 defaultMirroring = loader->isAutomaticallyMirrored( |
328 iconName(QIcon::Normal, QIcon::Off)) ? Enabled : Disabled; |
323 iconName(QIcon::Normal, QIcon::Off)) ? Enabled : Disabled; |
329 } |
324 } |
330 |
325 |
331 bool basedOnLayoutDir = false; |
326 bool basedOnLayoutDir = false; |
332 // Handle the different mirroring modes |
327 // Handle the different mirroring modes |
333 |
328 |
336 if (defaultMirroring == Enabled) { |
331 if (defaultMirroring == Enabled) { |
337 basedOnLayoutDir = true; |
332 basedOnLayoutDir = true; |
338 } else if (defaultMirroring == Disabled) { |
333 } else if (defaultMirroring == Disabled) { |
339 return false; |
334 return false; |
340 } |
335 } |
341 // Forced |
336 // Forced |
342 } else if (mirroringMode == HbIcon::Forced) { |
337 } else if (mirroringMode == HbIcon::Forced) { |
343 return true; |
338 return true; |
344 // Prevented |
339 // Prevented |
345 } else if (mirroringMode == HbIcon::Prevented) { |
340 } else if (mirroringMode == HbIcon::Prevented) { |
346 return false; |
341 return false; |
347 // LayoutDirection |
342 // LayoutDirection |
348 } else if (mirroringMode == HbIcon::LayoutDirection) { |
343 } else if (mirroringMode == HbIcon::LayoutDirection) { |
349 basedOnLayoutDir = true; |
344 basedOnLayoutDir = true; |
350 } |
345 } |
351 |
346 |
352 if (basedOnLayoutDir) { |
347 if (basedOnLayoutDir) { |
353 // e.g. some unit tests do not have primary window at this point so need to do NULL checks here. |
348 // e.g. some unit tests do not have primary window at this point so need to do NULL checks here. |
354 if (hbInstance) { |
349 if (hbInstance) { |
355 QList<HbMainWindow*> allWindows = hbInstance->allMainWindows(); |
350 QList<HbMainWindow *> allWindows = hbInstance->allMainWindows(); |
356 |
351 |
357 if ( !allWindows.isEmpty() && |
352 if (!allWindows.isEmpty() && |
358 allWindows.value(0) && |
353 allWindows.value(0) && |
359 allWindows.value(0)->layoutDirection() == Qt::RightToLeft) { |
354 allWindows.value(0)->layoutDirection() == Qt::RightToLeft) { |
360 return true; |
355 return true; |
361 } |
356 } |
362 return false; |
357 return false; |
363 } |
358 } |
364 } |
359 } |
430 inline bool isMonoIcon(const QString &name) |
425 inline bool isMonoIcon(const QString &name) |
431 { |
426 { |
432 // Even when the Colorized flag is not set certain icons from the theme must be |
427 // Even when the Colorized flag is not set certain icons from the theme must be |
433 // colorized. These mono icons are recognized from their name. The check should not be |
428 // colorized. These mono icons are recognized from their name. The check should not be |
434 // done for normal files, only for logical theme graphics names. |
429 // done for normal files, only for logical theme graphics names. |
435 return name.startsWith("qtg_mono_") && !name.contains('.'); |
430 return name.startsWith(QLatin1String("qtg_mono_")) && !name.contains('.'); |
|
431 } |
|
432 |
|
433 QColor HbIconEnginePrivate::colorToUse(const QString &iconName) const |
|
434 { |
|
435 if (flags.testFlag(HbIcon::Colorized) || isMonoIcon(iconName)) { |
|
436 return color.isValid() ? color : themedColor; |
|
437 } else { |
|
438 return QColor(); |
|
439 } |
436 } |
440 } |
437 |
441 |
438 void HbIconEnginePrivate::addBadge(Qt::Alignment align, |
442 void HbIconEnginePrivate::addBadge(Qt::Alignment align, |
439 const HbIcon& icon, |
443 const HbIcon &icon, |
440 int z) |
444 int z, |
|
445 const QSizeF &sizeFactor, |
|
446 Qt::AspectRatioMode aspectRatio) |
441 { |
447 { |
442 if (!badgeInfo) { |
448 if (!badgeInfo) { |
443 badgeInfo = new HbBadgeIcon(); |
449 badgeInfo = new HbBadgeIcon(); |
444 } |
450 } |
445 badgeInfo->addBadge(align, icon, z); |
451 badgeInfo->addBadge(align, icon, z, sizeFactor, aspectRatio); |
446 } |
452 } |
447 |
453 |
448 bool HbIconEnginePrivate::removeBadge(const HbIcon& badge) |
454 bool HbIconEnginePrivate::removeBadge(const HbIcon &badge) |
449 { |
455 { |
450 return badgeInfo ? badgeInfo->removeBadge(badge) : false; |
456 return badgeInfo ? badgeInfo->removeBadge(badge) : false; |
451 } |
457 } |
452 |
458 |
453 void HbIconEnginePrivate::removeAllBadges() |
459 void HbIconEnginePrivate::removeAllBadges() |
475 QIconEngineV2(), |
481 QIconEngineV2(), |
476 d(new HbIconEnginePrivate(QString())) |
482 d(new HbIconEnginePrivate(QString())) |
477 { |
483 { |
478 // Register the HbIconEngine Instance to HbIconLoader |
484 // Register the HbIconEngine Instance to HbIconLoader |
479 HbIconLoader *loader = HbIconLoader::global(); |
485 HbIconLoader *loader = HbIconLoader::global(); |
480 loader->storeIconEngineInfo(this); |
486 loader->storeIconEngineInfo(this); |
481 } |
487 } |
482 |
488 |
483 HbIconEngine::HbIconEngine(const QString &iconName) : |
489 HbIconEngine::HbIconEngine(const QString &iconName) : |
484 QObject(), |
490 QObject(), |
485 QIconEngineV2(), |
491 QIconEngineV2(), |
486 d(new HbIconEnginePrivate(iconName)) |
492 d(new HbIconEnginePrivate(iconName)) |
487 { |
493 { |
488 // Register the HbIconEngine Instance to HbIconLoader |
494 // Register the HbIconEngine Instance to HbIconLoader |
489 HbIconLoader *loader = HbIconLoader::global(); |
495 HbIconLoader *loader = HbIconLoader::global(); |
490 loader->storeIconEngineInfo(this); |
496 loader->storeIconEngineInfo(this); |
491 } |
497 } |
492 |
498 |
493 HbIconEngine::HbIconEngine(const HbIconEngine &other) : |
499 HbIconEngine::HbIconEngine(const HbIconEngine &other) : |
494 QObject(), |
500 QObject(), |
672 if (!name.isEmpty()) { |
678 if (!name.isEmpty()) { |
673 HbIconLoader *loader = HbIconLoader::global(); |
679 HbIconLoader *loader = HbIconLoader::global(); |
674 |
680 |
675 // If requested size is not the same as set in the engine, get a new pixmap from loader |
681 // If requested size is not the same as set in the engine, get a new pixmap from loader |
676 if (pixelSize != size().toSize()) { |
682 if (pixelSize != size().toSize()) { |
677 // Clear the old icon first |
683 // Clear the old icon first |
678 d->unLoadIcon(); |
684 d->unLoadIcon(); |
679 |
685 |
680 d->icon = loader->loadIcon( |
686 d->icon = loader->loadIcon( |
681 name, |
687 name, |
682 HbIconLoader::AnyType, |
688 HbIconLoader::AnyType, |
683 HbIconLoader::AnyPurpose, |
689 HbIconLoader::AnyPurpose, |
684 s, |
690 s, |
685 Qt::KeepAspectRatio, |
691 Qt::KeepAspectRatio, |
686 modeForLoader, |
692 modeForLoader, |
687 d->iconLoaderOptions(), |
693 d->iconLoaderOptions(), |
688 0, |
694 0, |
689 (d->flags.testFlag(HbIcon::Colorized) || isMonoIcon(name)) ? d->color : QColor()); |
695 d->colorToUse(name)); |
690 |
696 |
691 if (d->icon){ |
697 if (d->icon) { |
692 // Draw badges on this pixmap |
698 // Draw badges on this pixmap |
693 QPainter painter(&d->pixmap); |
699 QPainter painter(&d->pixmap); |
694 if (d->badgeInfo) { |
700 if (d->badgeInfo) { |
695 d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored()); |
701 d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored()); |
696 } |
702 } |
697 d->pixmap = d->icon->pixmap(); |
703 d->pixmap = d->icon->pixmap(); |
698 return d->pixmap; |
704 return d->pixmap; |
699 } |
705 } |
700 |
706 |
701 } |
707 } |
702 // Requested size was same as set in engine, use the pixmap stored in engine |
708 // Requested size was same as set in engine, use the pixmap stored in engine |
703 else { |
709 else { |
704 if (!d->icon || Qt::KeepAspectRatio != d->aspectRatioMode || mode != d->mode || state != d->state) { |
710 if (!d->icon || Qt::KeepAspectRatio != d->aspectRatioMode || mode != d->mode || state != d->state) { |
705 d->aspectRatioMode = Qt::KeepAspectRatio; |
711 d->aspectRatioMode = Qt::KeepAspectRatio; |
706 d->mode = mode; |
712 d->mode = mode; |
707 d->state = state; |
713 d->state = state; |
708 // Clear the old icon first |
714 // Clear the old icon first |
709 d->unLoadIcon(); |
715 d->unLoadIcon(); |
710 d->icon = loader->loadIcon( |
716 d->icon = loader->loadIcon( |
711 name, |
717 name, |
712 HbIconLoader::AnyType, |
718 HbIconLoader::AnyType, |
713 HbIconLoader::AnyPurpose, |
719 HbIconLoader::AnyPurpose, |
714 s, |
720 s, |
715 Qt::KeepAspectRatio, |
721 Qt::KeepAspectRatio, |
716 modeForLoader, |
722 modeForLoader, |
717 d->iconLoaderOptions(), |
723 d->iconLoaderOptions(), |
718 0, |
724 0, |
719 (d->flags.testFlag(HbIcon::Colorized) || isMonoIcon(name)) ? d->color : QColor()); |
725 d->colorToUse(name)); |
720 |
726 |
721 // If loading failed, store information so it is not retried. |
727 // If loading failed, store information so it is not retried. |
722 if (!d->icon) { |
728 if (!d->icon) { |
723 d->appendLoadFail(mode, state); |
729 d->appendLoadFail(mode, state); |
724 } |
730 } |
725 } |
731 } |
726 if (d->icon) { |
732 if (d->icon) { |
727 d->pixmap = d->icon->pixmap(); |
733 d->pixmap = d->icon->pixmap(); |
728 // Draw badges on this pixmap |
734 // Draw badges on this pixmap |
729 QPainter painter(&d->pixmap); |
735 QPainter painter(&d->pixmap); |
730 if (d->badgeInfo){ |
736 if (d->badgeInfo) { |
731 d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored()); |
737 d->badgeInfo->paint(&painter, QRectF(QPointF(0, 0), pixelSize), mode, state, d->isMirrored()); |
732 } |
738 } |
733 return d->pixmap; |
739 return d->pixmap; |
734 } |
740 } |
735 } |
741 } |
752 QColor HbIconEngine::color() const |
758 QColor HbIconEngine::color() const |
753 { |
759 { |
754 return d->color; |
760 return d->color; |
755 } |
761 } |
756 |
762 |
|
763 void HbIconEngine::setThemedColor(const QColor &color) |
|
764 { |
|
765 if (d->themedColor != color) { |
|
766 clearStoredIconContent(); |
|
767 d->themedColor = color; |
|
768 } |
|
769 } |
|
770 |
|
771 QColor HbIconEngine::themedColor() const |
|
772 { |
|
773 return d->themedColor; |
|
774 } |
|
775 |
757 QSizeF HbIconEngine::defaultSize() const |
776 QSizeF HbIconEngine::defaultSize() const |
758 { |
777 { |
759 QString name = iconName(); |
778 QString name = iconName(); |
760 if (!d->defaultSizeFailed && !d->defaultSize.isValid() && !name.isEmpty()) { |
779 if (!d->defaultSizeFailed && !d->defaultSize.isValid() && !name.isEmpty()) { |
761 if (d->icon){ |
780 if (d->icon) { |
762 d->defaultSize = d->icon->defaultSize(); |
781 d->defaultSize = d->icon->defaultSize(); |
763 } else { |
782 } else { |
764 HbIconLoader *loader = HbIconLoader::global(); |
783 HbIconLoader *loader = HbIconLoader::global(); |
765 d->defaultSize = loader->defaultSize(name, QString(), d->iconLoaderOptions()); |
784 d->defaultSize = loader->defaultSize(name, QString(), d->iconLoaderOptions()); |
|
785 if (d->flags & HbIcon::ResolutionCorrected) { |
|
786 HbIconLoader::global()->applyResolutionCorrection(d->defaultSize); |
|
787 } |
766 } |
788 } |
767 // If default size could not get retrieved, |
789 // If default size could not get retrieved, |
768 // store information about that so it does not need to be checked again. |
790 // store information about that so it does not need to be checked again. |
769 if (!d->defaultSize.isValid()) { |
791 if (!d->defaultSize.isValid()) { |
770 d->defaultSizeFailed = true; |
792 d->defaultSizeFailed = true; |
780 |
802 |
781 void HbIconEngine::setSize(const QSizeF &size) |
803 void HbIconEngine::setSize(const QSizeF &size) |
782 { |
804 { |
783 if (size != d->size) { |
805 if (size != d->size) { |
784 d->size = size; |
806 d->size = size; |
|
807 // Update default size if size is set before painting |
|
808 // to obtain the actual default size of the image |
|
809 if (!d->icon && !d->defaultSize.isValid()) { |
|
810 defaultSize(); |
|
811 } |
785 // Size changed, invalidate pixmap stored in this object. |
812 // Size changed, invalidate pixmap stored in this object. |
786 clearStoredIconContent(); |
813 clearStoredIconContent(KeepDefaultSize); |
787 } |
814 } |
788 } |
815 } |
789 |
816 |
790 void HbIconEngine::paint( QPainter *painter, |
817 void HbIconEngine::paint(QPainter *painter, |
791 const QRect &rect, |
818 const QRect &rect, |
792 QIcon::Mode mode, |
819 QIcon::Mode mode, |
793 QIcon::State state ) |
820 QIcon::State state) |
794 { |
821 { |
795 // This method is called by QIcon and it should paint the icon with the size defined by 'rect'. |
822 // This method is called by QIcon and it should paint the icon with the size defined by 'rect'. |
796 HbIconImpl* icon = NULL; |
823 HbIconImpl *icon = 0; |
797 |
824 |
798 // update the rendering mode |
825 // update the rendering mode |
799 HbIconLoader::global()->updateRenderingMode(painter->paintEngine()->type()); |
826 QPaintEngine *paintEngine = painter->paintEngine(); |
800 |
827 if (paintEngine) { |
|
828 HbIconLoader::global()->updateRenderingMode(paintEngine->type()); |
|
829 } |
|
830 |
801 icon = paintHelper(rect.size(), Qt::KeepAspectRatio, mode, state); |
831 icon = paintHelper(rect.size(), Qt::KeepAspectRatio, mode, state); |
802 if (icon){ |
832 if (icon) { |
803 icon->paint(painter, rect, Qt::AlignCenter); |
833 icon->paint(painter, rect, Qt::AlignCenter); |
804 HbIconLoader::global()->unLoadIcon(icon); |
834 HbIconLoader::global()->unLoadIcon(icon); |
805 icon->dispose(); |
835 icon->dispose(); |
806 } |
836 |
807 |
837 // Now paint any necessary badges. |
808 // Now paint any necessary badges. |
838 if (d->badgeInfo) { |
809 if (d->badgeInfo) { |
839 d->badgeInfo->paint(painter, rect, mode, state, icon->isMirrored()); |
810 d->badgeInfo->paint(painter, rect, mode, state, icon->isMirrored()); |
840 } |
811 } |
841 } |
812 } |
842 } |
813 |
843 |
814 void HbIconEngine::paint( QPainter *painter, |
844 void HbIconEngine::paint(QPainter *painter, |
815 const QRectF &rect, |
845 const QRectF &rect, |
816 Qt::AspectRatioMode aspectRatioMode, |
846 Qt::AspectRatioMode aspectRatioMode, |
817 Qt::Alignment alignment, |
847 Qt::Alignment alignment, |
818 QIcon::Mode mode, |
848 QIcon::Mode mode, |
819 QIcon::State state) |
849 QIcon::State state) |
820 { |
850 { |
821 // If loading the pixmap has failed, do not retry forever |
851 // If loading the pixmap has failed, do not retry forever |
822 if (loadFailed(mode, state)) { |
852 if (loadFailed(mode, state)) { |
823 return; |
853 return; |
824 } |
854 } |
831 } |
861 } |
832 |
862 |
833 // FrameSet animations need to be reloaded if size related parameters have changed, |
863 // FrameSet animations need to be reloaded if size related parameters have changed, |
834 // so delete the current animation in that case. |
864 // so delete the current animation in that case. |
835 HbIconAnimation *anim = animation(); |
865 HbIconAnimation *anim = animation(); |
836 if (anim && anim->type() == HbIconAnimation::FrameSet) { |
866 if (anim && anim->type() == HbIconAnimation::FrameSet) { |
837 if ( ( (!s.isEmpty() || !anim->size().isEmpty()) && s != anim->size() ) || |
867 if (((!s.isEmpty() || !anim->size().isEmpty()) && s != anim->size()) || |
838 aspectRatioMode != anim->aspectRatioMode()) { |
868 aspectRatioMode != anim->aspectRatioMode()) { |
839 #ifdef HB_ICON_TRACES |
869 #ifdef HB_ICON_TRACES |
840 qDebug("HbIconEngine: deleting anim"); |
870 qDebug("HbIconEngine: deleting anim"); |
841 #endif |
871 #endif |
842 delete anim; |
872 delete anim; |
843 d->animator->d->animation = 0; |
873 d->animator->d->animation = 0; |
857 d->mode = mode; |
887 d->mode = mode; |
858 d->state = state; |
888 d->state = state; |
859 // If icon parameters changed unload the icon first, and get the new icon |
889 // If icon parameters changed unload the icon first, and get the new icon |
860 d->unLoadIcon(); |
890 d->unLoadIcon(); |
861 // Update the rendering mode |
891 // Update the rendering mode |
862 HbIconLoader::global()->updateRenderingMode(painter->paintEngine()->type()); |
892 QPaintEngine *paintEngine = painter->paintEngine(); |
|
893 if (paintEngine) { |
|
894 HbIconLoader::global()->updateRenderingMode(paintEngine->type()); |
|
895 } |
863 d->icon = paintHelper(s, aspectRatioMode, mode, state); |
896 d->icon = paintHelper(s, aspectRatioMode, mode, state); |
864 if ( d->icon && d->icon->isCreatedOnServer() ) { |
897 if (d->icon && d->icon->isCreatedOnServer()) { |
865 d->iconType = d->icon->iconData().type; |
898 d->iconType = d->icon->iconData().type; |
866 } |
899 } |
867 } |
900 } |
868 |
901 |
869 // Adjust the alignment and draw the icon. |
902 // Adjust the alignment and draw the icon. |
908 // set afterwards (after construction but before the first paint). |
941 // set afterwards (after construction but before the first paint). |
909 ensureSignalConnections(); |
942 ensureSignalConnections(); |
910 |
943 |
911 QString name = iconName(mode, state); |
944 QString name = iconName(mode, state); |
912 QIcon::Mode modeForLoader = mode; |
945 QIcon::Mode modeForLoader = mode; |
913 HbIconImpl *icon = NULL; |
946 HbIconImpl *icon = 0; |
914 if (name.isEmpty()) { |
947 if (name.isEmpty()) { |
915 // Icon name not defined for this mode and state, use default icon name |
948 // Icon name not defined for this mode and state, use default icon name |
916 name = iconName(QIcon::Normal, QIcon::Off); |
949 name = iconName(QIcon::Normal, QIcon::Off); |
917 } else { |
950 } else { |
918 // Icon name was defined for this mode and state, do not apply mode in loader |
951 // Icon name was defined for this mode and state, do not apply mode in loader |
938 else { |
971 else { |
939 if (!name.isEmpty()) { |
972 if (!name.isEmpty()) { |
940 HbIconLoader *loader = HbIconLoader::global(); |
973 HbIconLoader *loader = HbIconLoader::global(); |
941 |
974 |
942 icon = loader->loadIcon( |
975 icon = loader->loadIcon( |
943 name, |
976 name, |
944 HbIconLoader::AnyType, |
977 HbIconLoader::AnyType, |
945 HbIconLoader::AnyPurpose, |
978 HbIconLoader::AnyPurpose, |
946 size, |
979 size, |
947 aspectRatioMode, |
980 aspectRatioMode, |
948 modeForLoader, |
981 modeForLoader, |
949 d->iconLoaderOptions(), |
982 d->iconLoaderOptions(), |
950 d->animator, |
983 d->animator, |
951 (d->flags.testFlag(HbIcon::Colorized) || isMonoIcon(name)) ? d->color : QColor()); |
984 d->colorToUse(name)); |
952 |
985 |
953 // If loading failed, store information so it is not retried in every repaint. |
986 // If loading failed, store information so it is not retried in every repaint. |
954 if (!icon) { |
987 if (!icon) { |
955 d->appendLoadFail(mode, state); |
988 d->appendLoadFail(mode, state); |
956 } |
989 } |
979 but does not touch the settings, e.g. the size, state, flags, unlike clear(). |
1012 but does not touch the settings, e.g. the size, state, flags, unlike clear(). |
980 |
1013 |
981 This function is called when some parameters change so that the content has |
1014 This function is called when some parameters change so that the content has |
982 to be reloaded, and in low-graphics-memory situations to get rid of all |
1015 to be reloaded, and in low-graphics-memory situations to get rid of all |
983 cached image data for the icon. |
1016 cached image data for the icon. |
984 |
1017 |
985 The goal in the OOGM case is to destroy all unnecessary QPixmaps which will in turn |
1018 The goal in the OOGM case is to destroy all unnecessary QPixmaps which will in turn |
986 lead to freeing graphics memory (in case we are running on the OpenVG paint engine). |
1019 lead to freeing graphics memory (in case we are running on the OpenVG paint engine). |
987 The data will be reloaded (well, at least tried to be reloaded) when the icon is |
1020 The data will be reloaded (well, at least tried to be reloaded) when the icon is |
988 painted the next time. |
1021 painted the next time. |
989 */ |
1022 */ |
990 void HbIconEngine::clearStoredIconContent(bool resetIconSize, bool unloadedByServer) |
1023 void HbIconEngine::clearStoredIconContent(ClearingFlags flags) |
991 { |
1024 { |
992 #ifdef HB_ICON_TRACES |
1025 #ifdef HB_ICON_TRACES |
993 qDebug("HbIconEngine %x: clearStoredIconContent", (int) this); |
1026 qDebug("HbIconEngine %x: clearStoredIconContent", (int) this); |
994 #endif |
1027 #endif |
995 |
1028 |
996 d->pixmap = QPixmap(); |
1029 d->pixmap = QPixmap(); |
997 d->unLoadIcon(unloadedByServer); |
1030 d->unLoadIcon(flags.testFlag(UnloadedByServer)); |
998 d->defaultSize = QSizeF(); |
1031 if (!(flags.testFlag(KeepDefaultSize))) { |
999 if (resetIconSize) { |
1032 d->defaultSize = QSizeF(); |
|
1033 } |
|
1034 if (flags.testFlag(ResetIconSize)) { |
1000 d->size = QSizeF(); |
1035 d->size = QSizeF(); |
1001 } |
1036 } |
1002 d->defaultSizeFailed = false; |
1037 d->defaultSizeFailed = false; |
1003 d->loadFailed.clear(); |
1038 d->loadFailed.clear(); |
1004 |
1039 |
1039 |
1074 |
1040 void HbIconEngine::themeChange(const QStringList &updatedFiles) |
1075 void HbIconEngine::themeChange(const QStringList &updatedFiles) |
1041 { |
1076 { |
1042 // Theme has changed, clear stored icon content |
1077 // Theme has changed, clear stored icon content |
1043 // Server side icon cache is already cleared when theme is changed |
1078 // Server side icon cache is already cleared when theme is changed |
1044 if (updatedFiles.count() == 0 || (d->icon && updatedFiles.contains(d->icon->iconFileName())) ) { |
1079 if (updatedFiles.count() == 0 || (d->icon && updatedFiles.contains(d->icon->iconFileName()))) { |
1045 clearStoredIconContent(false, true); |
1080 clearStoredIconContent(UnloadedByServer); |
1046 } |
1081 } |
1047 } |
1082 } |
1048 |
1083 |
1049 void HbIconEngine::handleLayoutDirectionChanged() |
1084 void HbIconEngine::handleLayoutDirectionChanged() |
1050 { |
1085 { |
1051 if ((d->mirroringMode == HbIcon::Default && d->defaultMirroring == HbIconEnginePrivate::Enabled) || |
1086 if ((d->mirroringMode == HbIcon::Default && d->defaultMirroring == HbIconEnginePrivate::Enabled) || |
1052 d->mirroringMode == HbIcon::LayoutDirection) { |
1087 d->mirroringMode == HbIcon::LayoutDirection) { |
1053 // This icon is automatically mirrored based on layout direction. |
1088 // This icon is automatically mirrored based on layout direction. |
1054 |
1089 |
1055 // Clear the stored icon content and its default size because the layout direction just changed. |
1090 // Clear the stored icon content and its default size because the layout direction just changed. |
1056 // Lazy loading is used, new pixmap will be rasterized when it's required by paint method. |
1091 // Lazy loading is used, new pixmap will be rasterized when it's required by paint method. |
1057 clearStoredIconContent(); |
1092 clearStoredIconContent(); |
1115 if (anim) { |
1150 if (anim) { |
1116 // Update parameters in animation |
1151 // Update parameters in animation |
1117 anim->setSize(size()); |
1152 anim->setSize(size()); |
1118 anim->setAspectRatioMode(d->aspectRatioMode); |
1153 anim->setAspectRatioMode(d->aspectRatioMode); |
1119 anim->setMode(d->mode); |
1154 anim->setMode(d->mode); |
1120 // Get the current frame as pixmap from the animation |
1155 // Get the current frame as pixmap from the animation |
1121 return anim->currentFrame(); |
1156 return anim->currentFrame(); |
1122 } else { |
1157 } else { |
1123 return QPixmap(); |
1158 return QPixmap(); |
1124 } |
1159 } |
1125 } |
1160 } |
1126 |
1161 |
1127 /*! |
1162 /*! |
1128 * Removes the item in the cache if the ref. count is 0 and does delete on |
1163 * Removes the item in the cache if the ref. count is 0 and does delete on |
1129 * HbIconImpl and Resets the IconImpl. |
1164 * HbIconImpl and Resets the IconImpl. |
1130 */ |
1165 */ |
1131 void HbIconEngine::resetIconImpl() const |
1166 void HbIconEngine::resetIconImpl() const |
1132 { |
1167 { |
1133 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
1168 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
1134 if ( (d->iconType == SGIMAGE) || (d->iconType == NVG) ) { |
1169 if ((d->iconType == SGIMAGE) || (d->iconType == NVG)) { |
1135 if ( d->icon ) { |
1170 if (d->icon) { |
1136 d->icon->decrementRefCount(); |
1171 d->icon->decrementRefCount(); |
1137 if ( d->icon->refCount() == 0 && d->icon->isCreatedOnServer() ) { |
1172 if (d->icon->refCount() == 0 && d->icon->isCreatedOnServer()) { |
1138 HbIconLoader *loader = HbIconLoader::global(); |
1173 HbIconLoader *loader = HbIconLoader::global(); |
1139 loader->removeItemInCache(d->icon); |
1174 loader->removeItemInCache(d->icon); |
1140 d->icon->dispose(); |
1175 d->icon->dispose(); |
1141 } |
1176 } |
1142 d->icon = 0; |
1177 d->icon = 0; |
1143 } |
1178 } |
1144 } |
1179 } |
1145 #endif |
1180 #endif |
1146 } |
1181 } |
1147 |
1182 |
1148 void HbIconEngine::addBadge(Qt::Alignment align, |
1183 void HbIconEngine::addBadge(Qt::Alignment align, |
1149 const HbIcon& icon, |
1184 const HbIcon &icon, |
1150 int z) |
1185 int z, |
1151 { |
1186 const QSizeF &sizeFactor, |
1152 d->addBadge(align, icon, z); |
1187 Qt::AspectRatioMode aspectRatio) |
1153 } |
1188 { |
1154 |
1189 d->addBadge(align, icon, z, sizeFactor, aspectRatio); |
1155 bool HbIconEngine::removeBadge(const HbIcon& badge) |
1190 } |
|
1191 |
|
1192 bool HbIconEngine::removeBadge(const HbIcon &badge) |
1156 { |
1193 { |
1157 return d->removeBadge(badge); |
1194 return d->removeBadge(badge); |
1158 } |
1195 } |
1159 |
1196 |
1160 void HbIconEngine::removeAllBadges() |
1197 void HbIconEngine::removeAllBadges() |