59 accompanied with the file extension. |
59 accompanied with the file extension. |
60 |
60 |
61 E.g. logical name of the icon is "frame". Assuming the icon file is in SVG-T format, |
61 E.g. logical name of the icon is "frame". Assuming the icon file is in SVG-T format, |
62 the filename should be "frame.svg". |
62 the filename should be "frame.svg". |
63 |
63 |
64 If the given icon name is a logical icon name and not an absolute filename, |
64 The icon name can be either a logical icon name that is fetched from the theme |
65 it is searched in the icon locations of the theming framework. |
65 or an absolute filename. Logical icon names should not include a filename extension. |
66 |
66 |
67 An absolute icon filename can point e.g. in application's resource file. |
67 An absolute icon filename must include full path and filename extension. |
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 |
362 * by calling HbIcon::setIconName. |
382 * by calling HbIcon::setIconName. |
363 */ |
383 */ |
364 HbIcon::HbIcon() |
384 HbIcon::HbIcon() |
365 { |
385 { |
366 // Construct shared_null if not done yet. |
386 // Construct shared_null if not done yet. |
367 if ( !shared_null ) { |
387 if (!shared_null) { |
368 shared_null = new HbIconPrivate; |
388 shared_null = new HbIconPrivate; |
369 } |
389 } |
370 d = shared_null; |
390 d = shared_null; |
371 } |
391 } |
372 |
392 |
373 /*! Constructs a new icon with the icon name \a iconName. |
393 /*! Constructs a new icon with the icon name \a iconName. |
374 */ |
394 */ |
375 HbIcon::HbIcon( const QString &iconName ) |
395 HbIcon::HbIcon(const QString &iconName) |
376 { |
396 { |
377 d = new HbIconPrivate(iconName); |
397 d = new HbIconPrivate(iconName); |
378 } |
398 } |
379 |
399 |
380 /*! Constructs a new icon to be a copy of the given QIcon. |
400 /*! Constructs a new icon to be a copy of the given QIcon. |
381 * Due to the limitations listed below, this constructor should be used only for |
401 * Due to the limitations listed below, this constructor should be used only for |
382 * compatibility reasons if a QIcon instance needs to be passed as a parameter |
402 * compatibility reasons if a QIcon instance needs to be passed as a parameter |
383 * to a method taking a HbIcon parameter. |
403 * to a method taking a HbIcon parameter. |
384 * \note If this constructor is used, there are the following limitations in the HbIcon methods. |
404 * \note If this constructor is used, there are the following limitations in the HbIcon methods. |
385 * - HbIcon::defaultSize() always returns QSizeF(). |
405 * - HbIcon::defaultSize() may return QSizeF(). |
386 * - HbIcon::paint() ignores the parameter aspectRatioMode and converts the given QRectF to QRect. |
406 * - HbIcon::paint() ignores the parameter aspectRatioMode and converts the given QRectF to QRect. |
387 * - HbIcon::iconName() returns empty string by default. |
407 * - HbIcon::iconName() returns empty string by default. |
388 * - HbIcon::pixmap() returns null pixmap. |
408 * - HbIcon::pixmap() returns null pixmap. |
389 * - Colorization and mirroring support are not available. |
409 * - Colorization and mirroring support are not available. |
390 * This method should only be used if absolute necessary, as this is not ideal for hardware accelerated environment. |
410 * This method should only be used if absolute necessary, as this is not ideal for hardware accelerated environment |
391 */ |
411 * and there may be huge differences in painting performance when compared to a native HbIcon. |
392 HbIcon::HbIcon( const QIcon &icon ) |
412 */ |
|
413 HbIcon::HbIcon(const QIcon &icon) |
393 { |
414 { |
394 d = new HbIconPrivate(icon); |
415 d = new HbIconPrivate(icon); |
395 } |
416 } |
396 |
417 |
397 /*! |
418 /*! |
398 * Copy constructs a new icon using the \a other icon. |
419 * Copy constructs a new icon using the \a other icon. |
399 * Copy-on-write semantics is used, so this only does a shallow copy. |
420 * Copy-on-write semantics is used, so this only does a shallow copy. |
400 */ |
421 */ |
401 HbIcon::HbIcon( const HbIcon &other ) : |
422 HbIcon::HbIcon(const HbIcon &other) : |
402 d( other.d ) |
423 d(other.d) |
403 { |
424 { |
404 } |
425 } |
405 |
426 |
406 /*! |
427 /*! |
407 * Assigns the \a other icon to this icon and returns a reference to |
428 * Assigns the \a other icon to this icon and returns a reference to |
408 * this icon. Copy-on-write semantics is used, so this only does a shallow copy. |
429 * this icon. Copy-on-write semantics is used, so this only does a shallow copy. |
409 */ |
430 */ |
410 HbIcon &HbIcon::operator=( const HbIcon &other ) |
431 HbIcon &HbIcon::operator=(const HbIcon &other) |
411 { |
432 { |
412 if ( &other != this ) { |
433 if (&other != this) { |
413 d = other.d; |
434 d = other.d; |
414 } |
435 } |
415 return *this; |
436 return *this; |
416 } |
437 } |
417 |
438 |
484 * |
505 * |
485 * This setting will be ignored for regular files when the HbIcon::Colorized flag |
506 * This setting will be ignored for regular files when the HbIcon::Colorized flag |
486 * is not set. This does not apply to theme elements, for them the color is |
507 * is not set. This does not apply to theme elements, for them the color is |
487 * always taken into account when the logical graphics name indicates that it is |
508 * always taken into account when the logical graphics name indicates that it is |
488 * a mono icon. |
509 * a mono icon. |
489 * |
510 * |
490 * Note that if a widget css defines a color for an icon primitive then the style will take |
511 * Note that if a widget defines a color for its icon primitive (as most standard |
491 * care of calling setColor() with the correct color from the theme whenever the theme |
512 * widgets do) then the style will take care of colorizing with the correct color |
492 * changes. Typical examples of such widgets are the itemviews (e.g. list, grid). Therefore |
513 * from the theme whenever the theme changes. Therefore mono icons shown in such |
493 * mono icons shown in such widgets will automatically be colorized with a theme-specific |
514 * widgets will automatically be colorized with a theme-specific color if the |
494 * color if the icon is either a mono icon coming from the theme or the icon has the |
515 * icon is either a mono icon coming from the theme or the icon has the |
495 * HbIcon::Colorized flag set. |
516 * HbIcon::Colorized flag set. |
496 * |
517 * |
497 * \warning Currently this method makes use of pixmap() routine in case of NVG icons. |
518 * However it is possible to override this theme-specific color with a custom one |
498 * pixmap() slows down the hardware accelerated rendering. |
519 * by calling this function. |
499 * |
520 * |
|
521 * \warning Currently this method makes use of pixmap() routine in case of NVG icons. |
|
522 * pixmap() slows down the hardware accelerated rendering. |
|
523 * |
500 * \sa HbIcon::color(), HbIcon::Colorized |
524 * \sa HbIcon::color(), HbIcon::Colorized |
501 */ |
525 */ |
502 void HbIcon::setColor(const QColor &color) |
526 void HbIcon::setColor(const QColor &color) |
503 { |
527 { |
504 if (d->engine) { |
528 if (d->engine) { |
535 return QString(); |
559 return QString(); |
536 } |
560 } |
537 } |
561 } |
538 |
562 |
539 /*! |
563 /*! |
540 * Sets the name of the icon. |
564 * Sets the name of the icon. It can be either a logical icon name that is fetched from the theme |
|
565 * or an absolute filename. Logical icon names should not include a filename extension. |
541 * This icon name is used if there is no name set separately for the specified icon mode and state. |
566 * This icon name is used if there is no name set separately for the specified icon mode and state. |
542 * \sa HbIcon::iconName() |
567 * \sa HbIcon::iconName() |
543 */ |
568 */ |
544 void HbIcon::setIconName( const QString &iconName ) |
569 void HbIcon::setIconName(const QString &iconName) |
545 { |
570 { |
546 if (d->engine && d->engine->iconName() != iconName) { |
571 if (d->engine && d->engine->iconName() != iconName) { |
547 d.detach(); |
572 d.detach(); |
548 d->engine->setIconName(iconName); |
573 d->engine->setIconName(iconName); |
549 } else { |
574 } else { |
550 // Icon was earlier copy constructed from QIcon, but now its name is set, |
575 // Icon was earlier copy constructed from QIcon, but now its name is set, |
551 // so it becomes a 'real' HbIcon. |
576 // so it becomes a 'real' HbIcon. |
552 d.detach(); |
577 d.detach(); |
553 d->engine = new HbIconEngine(iconName); |
578 d->engine = new HbIconEngine(iconName); |
554 d->engine->setSize(d->size); |
579 d->engine->setSize(d->size); |
555 // Have to instantiate a temporary QIcon because |
580 // Have to instantiate a temporary QIcon because |
556 // QIcon's assignment operator shares the engine. |
581 // QIcon's assignment operator shares the engine. |
557 QIcon temp(d->engine); |
582 QIcon temp(d->engine); |
558 d->qicon = temp; |
583 d->qicon = temp; |
559 } |
584 } |
560 } |
585 } |
583 * Sets the name of the icon in the specified \a mode and \a state. |
608 * Sets the name of the icon in the specified \a mode and \a state. |
584 * \note Passing an empty \a iconName removes the icon name definition specific to |
609 * \note Passing an empty \a iconName removes the icon name definition specific to |
585 * the given mode and state. |
610 * the given mode and state. |
586 * \sa HbIcon::iconName() |
611 * \sa HbIcon::iconName() |
587 */ |
612 */ |
588 void HbIcon::setIconName( const QString &iconName, QIcon::Mode mode, QIcon::State state ) |
613 void HbIcon::setIconName(const QString &iconName, QIcon::Mode mode, QIcon::State state) |
589 { |
614 { |
590 if ( d->engine && d->engine->iconName(mode, state) != iconName) { |
615 if (d->engine && d->engine->iconName(mode, state) != iconName) { |
591 d.detach(); |
616 d.detach(); |
592 d->engine->setIconName(iconName, mode, state); |
617 d->engine->setIconName(iconName, mode, state); |
593 } |
618 } |
594 } |
619 } |
595 |
620 |
596 /*! Paints the icon in the given \a painter with the specified drawing parameters. |
621 /*! Paints the icon in the given \a painter with the specified drawing parameters. |
597 * \note If the constructor HbIcon::HbIcon(const QIcon &icon) is used, the parameter |
622 * \note If the constructor HbIcon::HbIcon(const QIcon &icon) is used, the parameter |
598 * \a aspectRatioMode is ignored and Qt::KeepAspectRatio is used. Also in that case the icon |
623 * \a aspectRatioMode is ignored and Qt::KeepAspectRatio is used. Also in that case the icon |
599 * is not scaled exactly to the given size but the best size match returned by the QIcon |
624 * is not scaled exactly to the given size but the best size match returned by the QIcon |
600 * instance is used. |
625 * instance is used. |
601 */ |
626 */ |
602 void HbIcon::paint( QPainter *painter, |
627 void HbIcon::paint(QPainter *painter, |
603 const QRectF &rect, |
628 const QRectF &rect, |
604 Qt::AspectRatioMode aspectRatioMode, |
629 Qt::AspectRatioMode aspectRatioMode, |
605 Qt::Alignment alignment, |
630 Qt::Alignment alignment, |
606 QIcon::Mode mode, |
631 QIcon::Mode mode, |
607 QIcon::State state) const |
632 QIcon::State state) const |
608 { |
633 { |
609 if ( !rect.isEmpty() && d.constData() != shared_null ) { |
634 if (!rect.isEmpty() && d.constData() != shared_null) { |
610 if ( d->engine ) { |
635 if (d->engine) { |
611 d->engine->paint( painter, rect, aspectRatioMode, alignment, mode, state ); |
636 d->engine->paint(painter, rect, aspectRatioMode, alignment, mode, state); |
612 } else { |
637 } else { |
613 // This HbIcon was copy constructed from QIcon and |
638 // This HbIcon was copy constructed from QIcon and |
614 // we cannot use HbIconEngine for painting. |
639 // we cannot use HbIconEngine for painting. |
615 QSizeF size = this->size(); |
640 QSizeF size = this->size(); |
616 if ( !size.isValid() ) { |
641 if (!size.isValid()) { |
617 // If size is not set, have to use rect size because QIcon |
642 // If size is not set, have to use rect size because QIcon |
618 // does not provide defaultSize information. |
643 // does not provide defaultSize information. |
619 size = rect.size(); |
644 size = rect.size(); |
620 } |
645 } |
621 |
646 |
622 QPixmap pixmap = d->qicon.pixmap( size.toSize(), mode, state ); |
647 QPixmap pixmap = d->qicon.pixmap(size.toSize(), mode, state); |
623 QSizeF pixmapSize = pixmap.size(); |
648 QSizeF pixmapSize = pixmap.size(); |
|
649 |
|
650 // QIcon::pixmap() will not do upscaling. |
|
651 if (pixmapSize.width() < size.width() || pixmapSize.height() < size.height()) { |
|
652 // Native HbIcons are scaled using SmoothTransformation so use the same. |
|
653 pixmap = pixmap.scaled(size.toSize(), aspectRatioMode, Qt::SmoothTransformation); |
|
654 pixmapSize = pixmap.size(); |
|
655 } |
|
656 |
624 // Adjust the alignment |
657 // Adjust the alignment |
625 QPointF topLeft = rect.topLeft(); |
658 QPointF topLeft = rect.topLeft(); |
626 |
659 |
627 if ( alignment & Qt::AlignRight ) { |
660 if (alignment & Qt::AlignRight) { |
628 topLeft.setX( rect.right() - pixmapSize.width() ); |
661 topLeft.setX(rect.right() - pixmapSize.width()); |
629 } else if ( alignment & Qt::AlignHCenter ) { |
662 } else if (alignment & Qt::AlignHCenter) { |
630 topLeft.setX( topLeft.x() + (rect.width() - pixmapSize.width()) / 2 ); |
663 topLeft.setX(topLeft.x() + (rect.width() - pixmapSize.width()) / 2); |
631 } |
664 } |
632 |
665 |
633 if ( alignment & Qt::AlignBottom ) { |
666 if (alignment & Qt::AlignBottom) { |
634 topLeft.setY( rect.bottom() - pixmapSize.height() ); |
667 topLeft.setY(rect.bottom() - pixmapSize.height()); |
635 } else if ( alignment & Qt::AlignVCenter ) { |
668 } else if (alignment & Qt::AlignVCenter) { |
636 topLeft.setY( topLeft.y() + (rect.height() - pixmapSize.height()) / 2 ); |
669 topLeft.setY(topLeft.y() + (rect.height() - pixmapSize.height()) / 2); |
637 } |
670 } |
638 |
671 |
639 painter->drawPixmap( topLeft, pixmap, pixmap.rect() ); |
672 painter->drawPixmap(topLeft, pixmap, pixmap.rect()); |
640 |
673 |
641 // Draw the badges on this icon |
674 // Draw the badges on this icon |
642 if ( d->badgeInfo ) { |
675 if (d->badgeInfo) { |
643 d->badgeInfo->paint(painter, rect, mode, state, false); |
676 d->badgeInfo->paint(painter, rect, mode, state, false); |
644 } |
677 } |
645 } |
678 } |
646 } |
679 } |
647 } |
680 } |
690 } |
725 } |
691 } |
726 } |
692 |
727 |
693 /*! Sets the \a height of the icon. Its width is computed using the aspect ratio of the icon. |
728 /*! Sets the \a height of the icon. Its width is computed using the aspect ratio of the icon. |
694 */ |
729 */ |
695 void HbIcon::setHeight( qreal height ) |
730 void HbIcon::setHeight(qreal height) |
696 { |
731 { |
697 QSizeF size = defaultSize(); |
732 QSizeF size = defaultSize(); |
698 if ( size.height() > 0 ) { |
733 if (size.height() > 0) { |
699 qreal ar = size.width() / size.height(); |
734 qreal ar = size.width() / size.height(); |
700 setSize( QSizeF( ar * height , height) ); |
735 setSize(QSizeF(ar * height , height)); |
701 } |
736 } |
702 } |
737 } |
703 |
738 |
704 /*! Sets the \a width of the icon. Its height is computed using the aspect ratio of the icon. |
739 /*! Sets the \a width of the icon. Its height is computed using the aspect ratio of the icon. |
705 */ |
740 */ |
706 void HbIcon::setWidth( qreal width ) |
741 void HbIcon::setWidth(qreal width) |
707 { |
742 { |
708 QSizeF size = defaultSize(); |
743 QSizeF size = defaultSize(); |
709 if ( size.width() > 0 ) { |
744 if (size.width() > 0) { |
710 qreal ar = size.height() / size.width(); |
745 qreal ar = size.height() / size.width(); |
711 setSize( QSizeF( width, ar * width ) ); |
746 setSize(QSizeF(width, ar * width)); |
712 } |
747 } |
713 } |
748 } |
714 |
749 |
715 /*! Returns the width of the icon. |
750 /*! Returns the width of the icon. |
716 */ |
751 */ |
717 qreal HbIcon::width() const |
752 qreal HbIcon::width() const |
718 { |
753 { |
719 return size().width(); |
754 return size().width(); |
720 } |
755 } |
721 |
756 |
722 /*! Returns the height of the icon. |
757 /*! Returns the height of the icon. |
800 |
835 |
801 /*! |
836 /*! |
802 * Returns a reference to a QIcon instance representing this icon. |
837 * Returns a reference to a QIcon instance representing this icon. |
803 * \note The returned reference is valid only for the life time of this HbIcon instance. |
838 * \note The returned reference is valid only for the life time of this HbIcon instance. |
804 */ |
839 */ |
805 QIcon & HbIcon::qicon() const |
840 QIcon &HbIcon::qicon() const |
806 { |
841 { |
807 return d->qicon; |
842 return d->qicon; |
808 } |
843 } |
809 |
844 |
810 /*! |
845 /*! |
811 * Equality operator. It compares the icon names for all the state and mode combinations. |
846 * Equality operator. It compares the icon names for all the state and mode combinations. |
812 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
847 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
813 * set for the icons are not used for the comparison. |
848 * set for the icons are not used for the comparison. |
814 */ |
849 */ |
815 bool HbIcon::operator==( const HbIcon &other ) const |
850 bool HbIcon::operator==(const HbIcon &other) const |
816 { |
851 { |
817 return !( *this != other ); |
852 return !(*this != other); |
818 } |
853 } |
819 |
854 |
820 /*! |
855 /*! |
821 * Inequality operator. It compares the icon names for all the state and mode combinations. |
856 * Inequality operator. It compares the icon names for all the state and mode combinations. |
822 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
857 * It also compares the badges, the color and the mirroring mode of the icon. The sizes |
823 * set for the icons are not used for the comparison. |
858 * set for the icons are not used for the comparison. |
824 */ |
859 */ |
825 bool HbIcon::operator!=( const HbIcon &other ) const |
860 bool HbIcon::operator!=(const HbIcon &other) const |
826 { |
861 { |
827 // NULL icons are equal |
862 // NULL icons are equal |
828 if ( isNull() && other.isNull() ) { |
863 if (isNull() && other.isNull()) { |
829 if ( d->badgeInfo && other.d->badgeInfo ) { |
864 if (d->badgeInfo && other.d->badgeInfo) { |
830 if ( d->badgeInfo->badges() != other.d->badgeInfo->badges() ) { |
865 if (d->badgeInfo->badges() != other.d->badgeInfo->badges()) { |
831 return true; |
866 return true; |
832 } |
867 } |
833 } |
868 } |
834 return false; |
869 return false; |
835 } |
870 } |
836 |
871 |
837 const HbIconEngine *engine1 = d->engine; |
872 const HbIconEngine *engine1 = d->engine; |
838 const HbIconEngine *engine2 = other.d->engine; |
873 const HbIconEngine *engine2 = other.d->engine; |
839 |
874 |
840 // If both icons do not have engines, they are unequal. |
875 // If both icons do not have engines, they are unequal. |
841 // An icon does not have an engine if it is constructed with a QIcon. |
876 // An icon does not have an engine if it is constructed with a QIcon. |
842 if ( !engine1 || !engine2 ) { |
877 if (!engine1 || !engine2) { |
843 return true; |
|
844 } |
|
845 |
|
846 if ( engine1->iconName() != engine2->iconName() || |
|
847 engine1->iconName( QIcon::Normal, QIcon::Off ) != engine2->iconName( QIcon::Normal, QIcon::Off ) || |
|
848 engine1->iconName( QIcon::Normal, QIcon::On ) != engine2->iconName( QIcon::Normal, QIcon::On ) || |
|
849 engine1->iconName( QIcon::Disabled, QIcon::Off ) != engine2->iconName( QIcon::Disabled, QIcon::Off ) || |
|
850 engine1->iconName( QIcon::Disabled, QIcon::On ) != engine2->iconName( QIcon::Disabled, QIcon::On ) || |
|
851 engine1->iconName( QIcon::Active, QIcon::Off ) != engine2->iconName( QIcon::Active, QIcon::Off ) || |
|
852 engine1->iconName( QIcon::Active, QIcon::On ) != engine2->iconName( QIcon::Active, QIcon::On ) || |
|
853 engine1->iconName( QIcon::Selected, QIcon::Off ) != engine2->iconName( QIcon::Selected, QIcon::Off ) || |
|
854 engine1->iconName( QIcon::Selected, QIcon::On ) != engine2->iconName( QIcon::Selected, QIcon::On ) ) { |
|
855 |
|
856 return true; |
878 return true; |
857 } |
879 } |
858 |
880 |
|
881 if (engine1->iconName() != engine2->iconName() || |
|
882 engine1->iconName(QIcon::Normal, QIcon::Off) != engine2->iconName(QIcon::Normal, QIcon::Off) || |
|
883 engine1->iconName(QIcon::Normal, QIcon::On) != engine2->iconName(QIcon::Normal, QIcon::On) || |
|
884 engine1->iconName(QIcon::Disabled, QIcon::Off) != engine2->iconName(QIcon::Disabled, QIcon::Off) || |
|
885 engine1->iconName(QIcon::Disabled, QIcon::On) != engine2->iconName(QIcon::Disabled, QIcon::On) || |
|
886 engine1->iconName(QIcon::Active, QIcon::Off) != engine2->iconName(QIcon::Active, QIcon::Off) || |
|
887 engine1->iconName(QIcon::Active, QIcon::On) != engine2->iconName(QIcon::Active, QIcon::On) || |
|
888 engine1->iconName(QIcon::Selected, QIcon::Off) != engine2->iconName(QIcon::Selected, QIcon::Off) || |
|
889 engine1->iconName(QIcon::Selected, QIcon::On) != engine2->iconName(QIcon::Selected, QIcon::On)) { |
|
890 |
|
891 return true; |
|
892 } |
|
893 |
859 // If they have different badges, they are unequal |
894 // If they have different badges, they are unequal |
860 if ( engine1->badges() != engine2->badges() ) { |
895 if (engine1->badges() != engine2->badges()) { |
861 return true; |
896 return true; |
862 } |
897 } |
863 |
898 |
864 if ( engine1->color() != engine2->color() ){ |
899 if (engine1->color() != engine2->color()) { |
865 return true; |
900 return true; |
866 } |
901 } |
867 |
902 |
868 // two icons are considered different if their mirroring modes are different |
903 // two icons are considered different if their mirroring modes are different |
869 if ( engine1->mirroringMode() != engine2->mirroringMode() ){ |
904 if (engine1->mirroringMode() != engine2->mirroringMode()) { |
870 return true; |
905 return true; |
871 } |
906 } |
872 |
907 |
873 return false; |
908 return false; |
874 } |
909 } |
875 |
910 |
876 /*! |
911 /*! |
877 * Adds a badge icon to the existing icon. The badge icons |
912 * Adds a badge icon to the existing icon. The badge icons |
878 * are drawn relative to the alignment you specify with the |
913 * are drawn relative to the alignment you specify with the |
879 * z-order you provide. |
914 * z-order you provide. |
|
915 * |
|
916 * By default the badge icon will use its default size. If this is |
|
917 * not suitable (which is typical in case of vector graphics) then |
|
918 * call setSize() explicitly on \a badge before passing it to this |
|
919 * function. |
|
920 * |
|
921 * The aspect ratio for the badge is kept by default, but this can be |
|
922 * changed in the \a aspectRatio argument. |
|
923 * |
|
924 * \sa addProportionalBadge() |
880 */ |
925 */ |
881 bool HbIcon::addBadge( Qt::Alignment alignment, |
926 bool HbIcon::addBadge(Qt::Alignment alignment, |
882 const HbIcon& badge, |
927 const HbIcon &badge, |
883 int z ) |
928 int z, |
|
929 Qt::AspectRatioMode aspectRatio) |
884 { |
930 { |
885 d.detach(); |
931 d.detach(); |
886 return d->addBadge(alignment, badge, z); |
932 return d->addBadge(alignment, badge, z, QSizeF(), aspectRatio); |
|
933 } |
|
934 |
|
935 /*! |
|
936 * Adds a badge icon to the existing icon. The badge icons |
|
937 * are drawn relative to the alignment you specify with the |
|
938 * z-order you provide. |
|
939 * |
|
940 * With this function the size of the badge icon will be proportional |
|
941 * to the size of the badged icon. If the size needs to be explicitly |
|
942 * specified then use addBadge() instead. |
|
943 * |
|
944 * \a sizeFactor's x and y values must be between 0 and 1. They |
|
945 * specify how much space the badge takes. For example (0.25, 0.25) |
|
946 * causes both the width and height to be 1/4 of the full icon width |
|
947 * and height. |
|
948 * |
|
949 * The aspect ratio for the badge is kept by default, but this can be |
|
950 * changed in the \a aspectRatio argument. |
|
951 * |
|
952 * \sa addBadge() |
|
953 */ |
|
954 bool HbIcon::addProportionalBadge(Qt::Alignment alignment, |
|
955 const HbIcon &badge, |
|
956 const QSizeF &sizeFactor, |
|
957 int z, |
|
958 Qt::AspectRatioMode aspectRatio) |
|
959 { |
|
960 d.detach(); |
|
961 return d->addBadge(alignment, badge, z, sizeFactor, aspectRatio); |
887 } |
962 } |
888 |
963 |
889 /*! |
964 /*! |
890 * Removes badge icon(s) from the icon. |
965 * Removes badge icon(s) from the icon. |
891 */ |
966 */ |
892 bool HbIcon::removeBadge( const HbIcon& badge ) |
967 bool HbIcon::removeBadge(const HbIcon &badge) |
893 { |
968 { |
894 d.detach(); |
969 d.detach(); |
895 return d->removeBadge( badge ); |
970 return d->removeBadge(badge); |
896 } |
971 } |
897 |
972 |
898 /*! |
973 /*! |
899 Remove all badge icons from this icon |
974 Remove all badge icons from this icon |
900 */ |
975 */ |