66 |
66 |
67 An absolute icon filename can point e.g. in application's resource file. |
67 An absolute icon filename can point e.g. in application's resource file. |
68 |
68 |
69 The icon can be resized with method HbIcon::setSize. |
69 The icon can be resized with method HbIcon::setSize. |
70 When resizing, by default the aspect ratio of the icon is preserved. |
70 When resizing, by default the aspect ratio of the icon is preserved. |
71 To change this, define the aspect ratio mode parameter in the method HbIcon::paint(). |
71 To change this, define the aspect ratio mode parameter in the method HbIcon::paint(). |
72 |
72 |
73 An icon itself can be a combination of existing icons; in this case the main icon is |
73 An icon itself can be a combination of existing icons; in this case the main icon is |
74 "badged" with smaller icons to form a distinct icon. You can badge icons in this way |
74 "badged" with smaller icons to form a distinct icon. You can badge icons in this way |
75 with the HbIcon::addBadge method, specifying the location where the badge should be drawn |
75 with the HbIcon::addBadge method, specifying the location where the badge should be drawn |
76 and a second HbIcon to draw at the indicated location. To prevent possible recursion , |
76 and a second HbIcon to draw at the indicated location. To prevent possible recursion , |
77 you can't badge an icon with a badge icon that is itself badged, however. |
77 you can't badge an icon with a badge icon that is itself badged, however. |
78 |
78 |
79 Scaled instances of the icons are shared by the framework |
79 Scaled instances of the icons are shared by the framework |
80 to decrease memory consumption. |
80 to decrease memory consumption. |
81 |
81 |
82 A brief example of how to create an icon and use it. |
82 A brief example of how to create an icon and use it. |
83 |
83 |
113 \b DoNotCache \b (0x01) Icon pixmap is not cached in the system wide icon pixmap cache. |
113 \b DoNotCache \b (0x01) Icon pixmap is not cached in the system wide icon pixmap cache. |
114 Setting this flag improves cache performance for other icons, if this icon does |
114 Setting this flag improves cache performance for other icons, if this icon does |
115 not need to be cached for being able to load it faster next time. |
115 not need to be cached for being able to load it faster next time. |
116 |
116 |
117 \b ResolutionCorrected \b (0x02) This flag is useful for making icon sizes automatically |
117 \b ResolutionCorrected \b (0x02) This flag is useful for making icon sizes automatically |
118 adapt to different screen resolutions (DPI values) and zoom factors used in the user |
118 adapt to different screen resolutions (DPI values) and zoom factors used in the user |
119 interface. The current display resolution (DPI value) and zoom factor are taken |
119 interface. The current display resolution (DPI value) and zoom factor are taken |
120 in consideration when defining the default size of the icon. This affects on what default |
120 in consideration when defining the default size of the icon. This affects on what default |
121 size is reported for the icon and also in which size the icon is rendered if its size is |
121 size is reported for the icon and also in which size the icon is rendered if its size is |
122 not set explicitly. The default DPI value is 144 and the default zoom factor 1.0. |
122 not set explicitly. The default DPI value is 144 and the default zoom factor 1.0. |
123 When this flag is set, the corrected default size of icon is defined as: |
123 When this flag is set, the corrected default size of icon is defined as: |
124 |
124 |
125 Corrected default size = original default size * current DPI value / default DPI |
125 Corrected default size = original default size * current DPI value / default DPI |
126 value * current zoom factor |
126 value * current zoom factor |
127 |
127 |
128 \note Currently this flag has an effect on vector icons only. |
128 \note Currently this flag has an effect on vector icons only. |
129 \note If the icon size is set explicitly this flag has no effect. |
129 \note If the icon size is set explicitly this flag has no effect. |
130 |
130 |
168 |
168 |
169 \b LayoutDirection This mirroring mode automatically mirrors the icon pixmap |
169 \b LayoutDirection This mirroring mode automatically mirrors the icon pixmap |
170 in a right-to-left layout. |
170 in a right-to-left layout. |
171 */ |
171 */ |
172 |
172 |
173 // Must be initialized dynamically because QIcon cannot be constructed |
173 // Must be initialized dynamically because QIcon cannot be constructed |
174 // when static variables are constructed. |
174 // when static variables are constructed. |
175 static HbIconPrivate *shared_null = 0; |
175 static HbIconPrivate *shared_null = 0; |
176 |
176 |
177 static const int iconMetaType = qRegisterMetaType<HbIcon>(); |
177 static const int iconMetaType = qRegisterMetaType<HbIcon>(); |
178 |
178 |
179 /*! |
179 /*! |
180 This constructor is used for shared_null instance only |
180 This constructor is used for shared_null instance only |
181 \internal |
181 \internal |
182 */ |
182 */ |
183 HbIconPrivate::HbIconPrivate() : |
183 HbIconPrivate::HbIconPrivate() : |
184 engine( new HbIconEngine(QString()) ), |
184 engine(new HbIconEngine(QString())), |
185 qicon(engine), |
185 qicon(engine), |
186 badgeInfo(0) |
186 badgeInfo(0) |
187 { |
187 { |
188 ref.ref(); // Need to do extra ref so the shared null does not get destructed |
188 ref.ref(); // Need to do extra ref so the shared null does not get destructed |
189 } |
189 } |
190 |
190 |
191 /*! |
191 /*! |
192 \internal |
192 \internal |
193 */ |
193 */ |
194 HbIconPrivate::HbIconPrivate( const QIcon &qicon ) : |
194 HbIconPrivate::HbIconPrivate(const QIcon &qicon) : |
195 engine(0), |
195 engine(0), |
196 qicon(qicon), |
196 qicon(qicon), |
197 badgeInfo(0) |
197 badgeInfo(0) |
198 { |
198 { |
199 } |
199 } |
200 |
200 |
201 /*! |
201 /*! |
202 \internal |
202 \internal |
203 */ |
203 */ |
204 HbIconPrivate::HbIconPrivate( const QString &iconName ) : |
204 HbIconPrivate::HbIconPrivate(const QString &iconName) : |
205 engine( new HbIconEngine(iconName) ), |
205 engine(new HbIconEngine(iconName)), |
206 qicon(engine), |
206 qicon(engine), |
207 badgeInfo(0) |
207 badgeInfo(0) |
208 { |
208 { |
209 } |
209 } |
210 |
210 |
211 /*! |
211 /*! |
212 \internal |
212 \internal |
213 */ |
213 */ |
214 HbIconPrivate::HbIconPrivate( const HbIconPrivate &other ) : |
214 HbIconPrivate::HbIconPrivate(const HbIconPrivate &other) : |
215 QSharedData( other ), |
215 QSharedData(other), |
216 size( other.size ), |
216 size(other.size), |
217 engine(0), |
217 engine(0), |
218 qicon(), |
218 qicon(), |
219 badgeInfo(0) |
219 badgeInfo(0) |
220 { |
220 { |
221 if ( other.engine ) { |
221 if (other.engine) { |
222 engine = new HbIconEngine( *other.engine ); |
222 engine = new HbIconEngine(*other.engine); |
223 // Have to instantiate a temporary QIcon because |
223 // Have to instantiate a temporary QIcon because |
224 // QIcon's copy constructor shares the engine. |
224 // QIcon's copy constructor shares the engine. |
225 QIcon temp(engine); |
225 QIcon temp(engine); |
226 qicon = temp; |
226 qicon = temp; |
227 } else { |
227 } else { |
228 // Copy constructed from qicon - so just copy the qicon. |
228 // Copy constructed from qicon - so just copy the qicon. |
229 qicon = other.qicon; |
229 qicon = other.qicon; |
230 if ( other.badgeInfo ) { |
230 if (other.badgeInfo) { |
231 badgeInfo = new HbBadgeIcon(*other.badgeInfo); |
231 badgeInfo = new HbBadgeIcon(*other.badgeInfo); |
232 } |
232 } |
233 } |
233 } |
234 } |
234 } |
235 |
235 |
236 /*! |
236 /*! |
237 \internal |
237 \internal |
342 |
342 |
343 /*! |
343 /*! |
344 \internal |
344 \internal |
345 */ |
345 */ |
346 bool HbIconPrivate::addBadge(Qt::Alignment align, |
346 bool HbIconPrivate::addBadge(Qt::Alignment align, |
347 const HbIcon& icon, |
347 const HbIcon &icon, |
348 int z) |
348 int z) |
349 { |
349 { |
350 if ( icon.isBadged() ) { |
350 if (icon.isBadged()) { |
351 return false; |
351 return false; |
352 } else if ( engine ) { |
352 } else if (engine) { |
353 engine->addBadge(align, icon, z); |
353 engine->addBadge(align, icon, z); |
354 } else { |
354 } else { |
355 if ( !badgeInfo ) { |
355 if (!badgeInfo) { |
356 badgeInfo = new HbBadgeIcon(); |
356 badgeInfo = new HbBadgeIcon(); |
357 } |
357 } |
358 badgeInfo->addBadge(align, icon, z); |
358 badgeInfo->addBadge(align, icon, z); |
359 } |
359 } |
360 return true; |
360 return true; |
361 } |
361 } |
362 |
362 |
363 /*! |
363 /*! |
364 \internal |
364 \internal |
365 */ |
365 */ |
366 bool HbIconPrivate::removeBadge(const HbIcon& badge) |
366 bool HbIconPrivate::removeBadge(const HbIcon &badge) |
367 { |
367 { |
368 bool result = false; |
368 bool result = false; |
369 |
369 |
370 if ( engine ) { |
370 if (engine) { |
371 result = engine->removeBadge(badge); |
371 result = engine->removeBadge(badge); |
372 } else if ( badgeInfo ) { |
372 } else if (badgeInfo) { |
373 result = badgeInfo->removeBadge(badge); |
373 result = badgeInfo->removeBadge(badge); |
374 } |
374 } |
375 |
375 |
376 return result; |
376 return result; |
377 } |
377 } |
405 * - HbIcon::iconName() returns empty string by default. |
405 * - HbIcon::iconName() returns empty string by default. |
406 * - HbIcon::pixmap() returns null pixmap. |
406 * - HbIcon::pixmap() returns null pixmap. |
407 * - Colorization and mirroring support are not available. |
407 * - Colorization and mirroring support are not available. |
408 * This method should only be used if absolute necessary, as this is not ideal for hardware accelerated environment. |
408 * This method should only be used if absolute necessary, as this is not ideal for hardware accelerated environment. |
409 */ |
409 */ |
410 HbIcon::HbIcon( const QIcon &icon ) |
410 HbIcon::HbIcon(const QIcon &icon) |
411 { |
411 { |
412 d = new HbIconPrivate(icon); |
412 d = new HbIconPrivate(icon); |
413 } |
413 } |
414 |
414 |
415 /*! |
415 /*! |
416 * Copy constructs a new icon using the \a other icon. |
416 * Copy constructs a new icon using the \a other icon. |
417 * Copy-on-write semantics is used, so this only does a shallow copy. |
417 * Copy-on-write semantics is used, so this only does a shallow copy. |
418 */ |
418 */ |
419 HbIcon::HbIcon( const HbIcon &other ) : |
419 HbIcon::HbIcon(const HbIcon &other) : |
420 d( other.d ) |
420 d(other.d) |
421 { |
421 { |
422 } |
422 } |
423 |
423 |
424 /*! |
424 /*! |
425 * Assigns the \a other icon to this icon and returns a reference to |
425 * Assigns the \a other icon to this icon and returns a reference to |
426 * this icon. Copy-on-write semantics is used, so this only does a shallow copy. |
426 * this icon. Copy-on-write semantics is used, so this only does a shallow copy. |
427 */ |
427 */ |
428 HbIcon &HbIcon::operator=( const HbIcon &other ) |
428 HbIcon &HbIcon::operator=(const HbIcon &other) |
429 { |
429 { |
430 if ( &other != this ) { |
430 if (&other != this) { |
431 d = other.d; |
431 d = other.d; |
432 } |
432 } |
433 return *this; |
433 return *this; |
434 } |
434 } |
435 |
435 |
502 * |
502 * |
503 * This setting will be ignored for regular files when the HbIcon::Colorized flag |
503 * This setting will be ignored for regular files when the HbIcon::Colorized flag |
504 * is not set. This does not apply to theme elements, for them the color is |
504 * is not set. This does not apply to theme elements, for them the color is |
505 * always taken into account when the logical graphics name indicates that it is |
505 * always taken into account when the logical graphics name indicates that it is |
506 * a mono icon. |
506 * a mono icon. |
507 * |
507 * |
508 * Note that if a widget defines a color for its icon primitive (as most standard |
508 * Note that if a widget defines a color for its icon primitive (as most standard |
509 * widgets do) then the style will take care of colorizing with the correct color |
509 * widgets do) then the style will take care of colorizing with the correct color |
510 * from the theme whenever the theme changes. Therefore mono icons shown in such |
510 * from the theme whenever the theme changes. Therefore mono icons shown in such |
511 * widgets will automatically be colorized with a theme-specific color if the |
511 * widgets will automatically be colorized with a theme-specific color if the |
512 * icon is either a mono icon coming from the theme or the icon has the |
512 * icon is either a mono icon coming from the theme or the icon has the |
513 * HbIcon::Colorized flag set. |
513 * HbIcon::Colorized flag set. |
514 * |
514 * |
515 * However it is possible to override this theme-specific color with a custom one |
515 * However it is possible to override this theme-specific color with a custom one |
516 * by calling this function. |
516 * by calling this function. |
517 * |
517 * |
518 * \warning Currently this method makes use of pixmap() routine in case of NVG icons. |
518 * \warning Currently this method makes use of pixmap() routine in case of NVG icons. |
519 * pixmap() slows down the hardware accelerated rendering. |
519 * pixmap() slows down the hardware accelerated rendering. |
520 * |
520 * |
521 * \sa HbIcon::color(), HbIcon::Colorized |
521 * \sa HbIcon::color(), HbIcon::Colorized |
522 */ |
522 */ |
523 void HbIcon::setColor(const QColor &color) |
523 void HbIcon::setColor(const QColor &color) |
524 { |
524 { |
525 if (d->engine) { |
525 if (d->engine) { |
560 /*! |
560 /*! |
561 * Sets the name of the icon. |
561 * Sets the name of the icon. |
562 * This icon name is used if there is no name set separately for the specified icon mode and state. |
562 * This icon name is used if there is no name set separately for the specified icon mode and state. |
563 * \sa HbIcon::iconName() |
563 * \sa HbIcon::iconName() |
564 */ |
564 */ |
565 void HbIcon::setIconName( const QString &iconName ) |
565 void HbIcon::setIconName(const QString &iconName) |
566 { |
566 { |
567 if (d->engine && d->engine->iconName() != iconName) { |
567 if (d->engine && d->engine->iconName() != iconName) { |
568 d.detach(); |
568 d.detach(); |
569 d->engine->setIconName(iconName); |
569 d->engine->setIconName(iconName); |
570 } else { |
570 } else { |
571 // Icon was earlier copy constructed from QIcon, but now its name is set, |
571 // Icon was earlier copy constructed from QIcon, but now its name is set, |
572 // so it becomes a 'real' HbIcon. |
572 // so it becomes a 'real' HbIcon. |
573 d.detach(); |
573 d.detach(); |
574 d->engine = new HbIconEngine(iconName); |
574 d->engine = new HbIconEngine(iconName); |
575 d->engine->setSize(d->size); |
575 d->engine->setSize(d->size); |
576 // Have to instantiate a temporary QIcon because |
576 // Have to instantiate a temporary QIcon because |
577 // QIcon's assignment operator shares the engine. |
577 // QIcon's assignment operator shares the engine. |
578 QIcon temp(d->engine); |
578 QIcon temp(d->engine); |
579 d->qicon = temp; |
579 d->qicon = temp; |
580 } |
580 } |
581 } |
581 } |
604 * Sets the name of the icon in the specified \a mode and \a state. |
604 * Sets the name of the icon in the specified \a mode and \a state. |
605 * \note Passing an empty \a iconName removes the icon name definition specific to |
605 * \note Passing an empty \a iconName removes the icon name definition specific to |
606 * the given mode and state. |
606 * the given mode and state. |
607 * \sa HbIcon::iconName() |
607 * \sa HbIcon::iconName() |
608 */ |
608 */ |
609 void HbIcon::setIconName( const QString &iconName, QIcon::Mode mode, QIcon::State state ) |
609 void HbIcon::setIconName(const QString &iconName, QIcon::Mode mode, QIcon::State state) |
610 { |
610 { |
611 if ( d->engine && d->engine->iconName(mode, state) != iconName) { |
611 if (d->engine && d->engine->iconName(mode, state) != iconName) { |
612 d.detach(); |
612 d.detach(); |
613 d->engine->setIconName(iconName, mode, state); |
613 d->engine->setIconName(iconName, mode, state); |
614 } |
614 } |
615 } |
615 } |
616 |
616 |
617 /*! Paints the icon in the given \a painter with the specified drawing parameters. |
617 /*! Paints the icon in the given \a painter with the specified drawing parameters. |
618 * \note If the constructor HbIcon::HbIcon(const QIcon &icon) is used, the parameter |
618 * \note If the constructor HbIcon::HbIcon(const QIcon &icon) is used, the parameter |
619 * \a aspectRatioMode is ignored and Qt::KeepAspectRatio is used. Also in that case the icon |
619 * \a aspectRatioMode is ignored and Qt::KeepAspectRatio is used. Also in that case the icon |
620 * is not scaled exactly to the given size but the best size match returned by the QIcon |
620 * is not scaled exactly to the given size but the best size match returned by the QIcon |
621 * instance is used. |
621 * instance is used. |
622 */ |
622 */ |
623 void HbIcon::paint( QPainter *painter, |
623 void HbIcon::paint(QPainter *painter, |
624 const QRectF &rect, |
624 const QRectF &rect, |
625 Qt::AspectRatioMode aspectRatioMode, |
625 Qt::AspectRatioMode aspectRatioMode, |
626 Qt::Alignment alignment, |
626 Qt::Alignment alignment, |
627 QIcon::Mode mode, |
627 QIcon::Mode mode, |
628 QIcon::State state) const |
628 QIcon::State state) const |
629 { |
629 { |
630 if ( !rect.isEmpty() && d.constData() != shared_null ) { |
630 if (!rect.isEmpty() && d.constData() != shared_null) { |
631 if ( d->engine ) { |
631 if (d->engine) { |
632 d->engine->paint( painter, rect, aspectRatioMode, alignment, mode, state ); |
632 d->engine->paint(painter, rect, aspectRatioMode, alignment, mode, state); |
633 } else { |
633 } else { |
634 // This HbIcon was copy constructed from QIcon and |
634 // This HbIcon was copy constructed from QIcon and |
635 // we cannot use HbIconEngine for painting. |
635 // we cannot use HbIconEngine for painting. |
636 QSizeF size = this->size(); |
636 QSizeF size = this->size(); |
637 if ( !size.isValid() ) { |
637 if (!size.isValid()) { |
638 // If size is not set, have to use rect size because QIcon |
638 // If size is not set, have to use rect size because QIcon |
639 // does not provide defaultSize information. |
639 // does not provide defaultSize information. |
640 size = rect.size(); |
640 size = rect.size(); |
641 } |
641 } |
642 |
642 |
643 QPixmap pixmap = d->qicon.pixmap( size.toSize(), mode, state ); |
643 QPixmap pixmap = d->qicon.pixmap(size.toSize(), mode, state); |
644 QSizeF pixmapSize = pixmap.size(); |
644 QSizeF pixmapSize = pixmap.size(); |
645 // Adjust the alignment |
645 // Adjust the alignment |
646 QPointF topLeft = rect.topLeft(); |
646 QPointF topLeft = rect.topLeft(); |
647 |
647 |
648 if ( alignment & Qt::AlignRight ) { |
648 if (alignment & Qt::AlignRight) { |
649 topLeft.setX( rect.right() - pixmapSize.width() ); |
649 topLeft.setX(rect.right() - pixmapSize.width()); |
650 } else if ( alignment & Qt::AlignHCenter ) { |
650 } else if (alignment & Qt::AlignHCenter) { |
651 topLeft.setX( topLeft.x() + (rect.width() - pixmapSize.width()) / 2 ); |
651 topLeft.setX(topLeft.x() + (rect.width() - pixmapSize.width()) / 2); |
652 } |
652 } |
653 |
653 |
654 if ( alignment & Qt::AlignBottom ) { |
654 if (alignment & Qt::AlignBottom) { |
655 topLeft.setY( rect.bottom() - pixmapSize.height() ); |
655 topLeft.setY(rect.bottom() - pixmapSize.height()); |
656 } else if ( alignment & Qt::AlignVCenter ) { |
656 } else if (alignment & Qt::AlignVCenter) { |
657 topLeft.setY( topLeft.y() + (rect.height() - pixmapSize.height()) / 2 ); |
657 topLeft.setY(topLeft.y() + (rect.height() - pixmapSize.height()) / 2); |
658 } |
658 } |
659 |
659 |
660 painter->drawPixmap( topLeft, pixmap, pixmap.rect() ); |
660 painter->drawPixmap(topLeft, pixmap, pixmap.rect()); |
661 |
661 |
662 // Draw the badges on this icon |
662 // Draw the badges on this icon |
663 if ( d->badgeInfo ) { |
663 if (d->badgeInfo) { |
664 d->badgeInfo->paint(painter, rect, mode, state, false); |
664 d->badgeInfo->paint(painter, rect, mode, state, false); |
665 } |
665 } |
666 } |
666 } |
667 } |
667 } |
668 } |
668 } |
673 QSizeF HbIcon::size() const |
673 QSizeF HbIcon::size() const |
674 { |
674 { |
675 if ((static_cast<int>(flags()) & HbIcon::ResolutionCorrected)) { |
675 if ((static_cast<int>(flags()) & HbIcon::ResolutionCorrected)) { |
676 if (d->size.isValid()) { |
676 if (d->size.isValid()) { |
677 return d->size; |
677 return d->size; |
678 } else { |
678 } else { |
679 QSizeF defSize(defaultSize()); |
679 QSizeF defSize(defaultSize()); |
680 HbIconLoader::global()->applyResolutionCorrection(defSize); |
680 HbIconLoader::global()->applyResolutionCorrection(defSize); |
681 return defSize; |
681 return defSize; |
682 } |
682 } |
683 } else if (d->size.isValid()) { |
683 } else if (d->size.isValid()) { |
684 return d->size; |
684 return d->size; |
685 } |
685 } |
686 return defaultSize(); |
686 return defaultSize(); |
687 } |
687 } |
688 |
688 |
689 /*! Returns the default size of the icon. |
689 /*! Returns the default size of the icon. |
690 */ |
690 */ |
691 QSizeF HbIcon::defaultSize() const |
691 QSizeF HbIcon::defaultSize() const |
692 { |
692 { |
693 // Default constructed icon? |
693 // Default constructed icon? |
694 if ( d.constData() == shared_null ) { |
694 if (d.constData() == shared_null) { |
695 return QSizeF(); |
695 return QSizeF(); |
696 } |
696 } |
697 |
697 |
698 // Do not cache default size in this class, |
698 // Do not cache default size in this class, |
699 // because it may change when icon definitions change. |
699 // because it may change when icon definitions change. |
711 } |
711 } |
712 } |
712 } |
713 |
713 |
714 /*! Sets the \a height of the icon. Its width is computed using the aspect ratio of the icon. |
714 /*! Sets the \a height of the icon. Its width is computed using the aspect ratio of the icon. |
715 */ |
715 */ |
716 void HbIcon::setHeight( qreal height ) |
716 void HbIcon::setHeight(qreal height) |
717 { |
717 { |
718 QSizeF size = defaultSize(); |
718 QSizeF size = defaultSize(); |
719 if ( size.height() > 0 ) { |
719 if (size.height() > 0) { |
720 qreal ar = size.width() / size.height(); |
720 qreal ar = size.width() / size.height(); |
721 setSize( QSizeF( ar * height , height) ); |
721 setSize(QSizeF(ar * height , height)); |
722 } |
722 } |
723 } |
723 } |
724 |
724 |
725 /*! Sets the \a width of the icon. Its height is computed using the aspect ratio of the icon. |
725 /*! Sets the \a width of the icon. Its height is computed using the aspect ratio of the icon. |
726 */ |
726 */ |
727 void HbIcon::setWidth( qreal width ) |
727 void HbIcon::setWidth(qreal width) |
728 { |
728 { |
729 QSizeF size = defaultSize(); |
729 QSizeF size = defaultSize(); |
730 if ( size.width() > 0 ) { |
730 if (size.width() > 0) { |
731 qreal ar = size.height() / size.width(); |
731 qreal ar = size.height() / size.width(); |
732 setSize( QSizeF( width, ar * width ) ); |
732 setSize(QSizeF(width, ar * width)); |
733 } |
733 } |
734 } |
734 } |
735 |
735 |
736 /*! Returns the width of the icon. |
736 /*! Returns the width of the icon. |
737 */ |
737 */ |
738 qreal HbIcon::width() const |
738 qreal HbIcon::width() const |
739 { |
739 { |
740 return size().width(); |
740 return size().width(); |
741 } |
741 } |
742 |
742 |
743 /*! Returns the height of the icon. |
743 /*! Returns the height of the icon. |
821 |
821 |
822 /*! |
822 /*! |
823 * Returns a reference to a QIcon instance representing this icon. |
823 * Returns a reference to a QIcon instance representing this icon. |
824 * \note The returned reference is valid only for the life time of this HbIcon instance. |
824 * \note The returned reference is valid only for the life time of this HbIcon instance. |
825 */ |
825 */ |
826 QIcon & HbIcon::qicon() const |
826 QIcon &HbIcon::qicon() const |
827 { |
827 { |
828 return d->qicon; |
828 return d->qicon; |
829 } |
829 } |
830 |
830 |
831 /*! |
831 /*! |
832 * Equality operator. It compares the icon names for all the state and mode combinations. |
832 * Equality operator. It compares the icon names for all the state and mode combinations. |
833 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
833 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
834 * set for the icons are not used for the comparison. |
834 * set for the icons are not used for the comparison. |
835 */ |
835 */ |
836 bool HbIcon::operator==( const HbIcon &other ) const |
836 bool HbIcon::operator==(const HbIcon &other) const |
837 { |
837 { |
838 return !( *this != other ); |
838 return !(*this != other); |
839 } |
839 } |
840 |
840 |
841 /*! |
841 /*! |
842 * Inequality operator. It compares the icon names for all the state and mode combinations. |
842 * Inequality operator. It compares the icon names for all the state and mode combinations. |
843 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
843 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
844 * set for the icons are not used for the comparison. |
844 * set for the icons are not used for the comparison. |
845 */ |
845 */ |
846 bool HbIcon::operator!=( const HbIcon &other ) const |
846 bool HbIcon::operator!=(const HbIcon &other) const |
847 { |
847 { |
848 // NULL icons are equal |
848 // NULL icons are equal |
849 if ( isNull() && other.isNull() ) { |
849 if (isNull() && other.isNull()) { |
850 if ( d->badgeInfo && other.d->badgeInfo ) { |
850 if (d->badgeInfo && other.d->badgeInfo) { |
851 if ( d->badgeInfo->badges() != other.d->badgeInfo->badges() ) { |
851 if (d->badgeInfo->badges() != other.d->badgeInfo->badges()) { |
852 return true; |
852 return true; |
853 } |
853 } |
854 } |
854 } |
855 return false; |
855 return false; |
856 } |
856 } |
857 |
857 |
858 const HbIconEngine *engine1 = d->engine; |
858 const HbIconEngine *engine1 = d->engine; |
859 const HbIconEngine *engine2 = other.d->engine; |
859 const HbIconEngine *engine2 = other.d->engine; |
860 |
860 |
861 // If both icons do not have engines, they are unequal. |
861 // If both icons do not have engines, they are unequal. |
862 // An icon does not have an engine if it is constructed with a QIcon. |
862 // An icon does not have an engine if it is constructed with a QIcon. |
863 if ( !engine1 || !engine2 ) { |
863 if (!engine1 || !engine2) { |
864 return true; |
|
865 } |
|
866 |
|
867 if ( engine1->iconName() != engine2->iconName() || |
|
868 engine1->iconName( QIcon::Normal, QIcon::Off ) != engine2->iconName( QIcon::Normal, QIcon::Off ) || |
|
869 engine1->iconName( QIcon::Normal, QIcon::On ) != engine2->iconName( QIcon::Normal, QIcon::On ) || |
|
870 engine1->iconName( QIcon::Disabled, QIcon::Off ) != engine2->iconName( QIcon::Disabled, QIcon::Off ) || |
|
871 engine1->iconName( QIcon::Disabled, QIcon::On ) != engine2->iconName( QIcon::Disabled, QIcon::On ) || |
|
872 engine1->iconName( QIcon::Active, QIcon::Off ) != engine2->iconName( QIcon::Active, QIcon::Off ) || |
|
873 engine1->iconName( QIcon::Active, QIcon::On ) != engine2->iconName( QIcon::Active, QIcon::On ) || |
|
874 engine1->iconName( QIcon::Selected, QIcon::Off ) != engine2->iconName( QIcon::Selected, QIcon::Off ) || |
|
875 engine1->iconName( QIcon::Selected, QIcon::On ) != engine2->iconName( QIcon::Selected, QIcon::On ) ) { |
|
876 |
|
877 return true; |
864 return true; |
878 } |
865 } |
879 |
866 |
|
867 if (engine1->iconName() != engine2->iconName() || |
|
868 engine1->iconName(QIcon::Normal, QIcon::Off) != engine2->iconName(QIcon::Normal, QIcon::Off) || |
|
869 engine1->iconName(QIcon::Normal, QIcon::On) != engine2->iconName(QIcon::Normal, QIcon::On) || |
|
870 engine1->iconName(QIcon::Disabled, QIcon::Off) != engine2->iconName(QIcon::Disabled, QIcon::Off) || |
|
871 engine1->iconName(QIcon::Disabled, QIcon::On) != engine2->iconName(QIcon::Disabled, QIcon::On) || |
|
872 engine1->iconName(QIcon::Active, QIcon::Off) != engine2->iconName(QIcon::Active, QIcon::Off) || |
|
873 engine1->iconName(QIcon::Active, QIcon::On) != engine2->iconName(QIcon::Active, QIcon::On) || |
|
874 engine1->iconName(QIcon::Selected, QIcon::Off) != engine2->iconName(QIcon::Selected, QIcon::Off) || |
|
875 engine1->iconName(QIcon::Selected, QIcon::On) != engine2->iconName(QIcon::Selected, QIcon::On)) { |
|
876 |
|
877 return true; |
|
878 } |
|
879 |
880 // If they have different badges, they are unequal |
880 // If they have different badges, they are unequal |
881 if ( engine1->badges() != engine2->badges() ) { |
881 if (engine1->badges() != engine2->badges()) { |
882 return true; |
882 return true; |
883 } |
883 } |
884 |
884 |
885 if ( engine1->color() != engine2->color() ){ |
885 if (engine1->color() != engine2->color()) { |
886 return true; |
886 return true; |
887 } |
887 } |
888 |
888 |
889 // two icons are considered different if their mirroring modes are different |
889 // two icons are considered different if their mirroring modes are different |
890 if ( engine1->mirroringMode() != engine2->mirroringMode() ){ |
890 if (engine1->mirroringMode() != engine2->mirroringMode()) { |
891 return true; |
891 return true; |
892 } |
892 } |
893 |
893 |
894 return false; |
894 return false; |
895 } |
895 } |