src/hbcore/primitives/hbiconitem.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    34 
    34 
    35 /*!
    35 /*!
    36   @stable
    36   @stable
    37   @hbcore
    37   @hbcore
    38   \class HbIconItem
    38   \class HbIconItem
    39   \brief HbIconItem displays an HbIcon instance.
    39   \brief HbIconItem displays an icon provided in form of an HbIcon
    40 
    40 
    41 
    41 
    42   HbIconItem derives from HbWidgetBase and so can be added to a layout.
    42   HbIconItem derives from HbWidgetBase and so can be added to a layout.
    43   Use HbIconItem when you need your icon's position and size to be managed by a layout.
    43   Use HbIconItem when you need your icon's position and size to be managed by a layout.
    44 
    44 
    59   //Create new icon, set position and size for it
    59   //Create new icon, set position and size for it
    60   HbIconItem *icon = new HbIconItem("qtg_large_phonebook", this);
    60   HbIconItem *icon = new HbIconItem("qtg_large_phonebook", this);
    61   icon->setPos(10,150);
    61   icon->setPos(10,150);
    62   icon->setSize(icon->defaultSize());
    62   icon->setSize(icon->defaultSize());
    63   \endcode
    63   \endcode
    64   
    64 
    65   Example of how to add HbIconItem to a layout.
    65   Example of how to add HbIconItem to a layout.
    66   \code
    66   \code
    67   HbButton *button = new HbButton("Button 1");
    67   HbButton *button = new HbButton("Button 1");
    68   HbIconItem *icon = new HbIconItem("qtg_large_phonebook");
    68   HbIconItem *icon = new HbIconItem("qtg_large_phonebook");
    69   QGraphicsGridLayout *layout = new QGraphicsGridLayout();
    69   QGraphicsGridLayout *layout = new QGraphicsGridLayout();
   100 
   100 
   101 //Initialize the default values
   101 //Initialize the default values
   102 const QIcon::Mode HbIconItem::defaultMode = QIcon::Normal;
   102 const QIcon::Mode HbIconItem::defaultMode = QIcon::Normal;
   103 const QIcon::State HbIconItem::defaultState = QIcon::Off;
   103 const QIcon::State HbIconItem::defaultState = QIcon::Off;
   104 const Qt::AspectRatioMode HbIconItem::defaultAspectRatioMode = Qt::KeepAspectRatio;
   104 const Qt::AspectRatioMode HbIconItem::defaultAspectRatioMode = Qt::KeepAspectRatio;
   105 const Qt::Alignment HbIconItem::defaultAlignment = Qt::AlignCenter;
   105     
       
   106 // Note: No center aligning by default to prevent interesting rounding issues
       
   107 // in certain cases (e.g. 50.25x50.25 sized icon item would lead to having an
       
   108 // icon sized 50x50 drawn at (0.12499, 0.12499) which may or may not fit visually
       
   109 // the other primitives of the same widget).
       
   110 const Qt::Alignment HbIconItem::defaultAlignment = 0;
   106 
   111 
   107 bool HbIconItemPrivate::outlinesEnabled = false;
   112 bool HbIconItemPrivate::outlinesEnabled = false;
   108 
   113 
   109 HbIconItemPrivate::HbIconItemPrivate(const HbIcon &icon) :
   114 HbIconItemPrivate::HbIconItemPrivate(const HbIcon &icon) :
   110         mIcon(icon),
   115     mIcon(icon),
   111         mAnimator(),
   116     mAnimator(),
   112         mAlignment(HbIconItem::defaultAlignment),
   117     mAlignment(HbIconItem::defaultAlignment),
   113         mAspectRatioMode(HbIconItem::defaultAspectRatioMode),
   118     mAspectRatioMode(HbIconItem::defaultAspectRatioMode),
   114         mState(HbIconItem::defaultState),
   119     mState(HbIconItem::defaultState),
   115         mMode(HbIconItem::defaultMode)
   120     mMode(HbIconItem::defaultMode),
       
   121     mClearCachedRect(true)
   116 {
   122 {
   117     q_ptr = 0;
   123     q_ptr = 0;
   118 }
   124 }
   119 
   125 
   120 HbIconItemPrivate::~HbIconItemPrivate ()
   126 HbIconItemPrivate::~HbIconItemPrivate()
   121 {
   127 {
   122 }
   128 }
   123 
   129 
   124 void HbIconItemPrivate::updateIconItem()
   130 void HbIconItemPrivate::updateIconItem()
   125 {
   131 {
   126     Q_Q( HbIconItem );
   132     Q_Q(HbIconItem);
       
   133     if (!mIcon.isNull()) {
       
   134         // This must be done before the setIcon() call below due to the
       
   135         // possibility of detaching. Doing it afterwards would lead to
       
   136         // colorization errors as the themed color might potentially be set for
       
   137         // a different icon engine, not for the one that is used in painting.
       
   138         HbIconPrivate::d_ptr_detached(&mIcon)->setThemedColor(mThemedColor);
       
   139     }
   127     const QRectF boundingRect = q->rect();
   140     const QRectF boundingRect = q->rect();
   128     if (!boundingRect.size().isEmpty()) {
   141     if (!boundingRect.size().isEmpty()) {
   129         mIconRect = boundingRect;
   142         mIconRect = boundingRect;
   130         mIcon.setSize(mIconRect.size());
   143         mIcon.setSize(mIconRect.size());
   131         mAnimator.setIcon(mIcon);
   144         mAnimator.setIcon(mIcon);
   132         q->update();
   145         q->update();
   133     }
   146     }
   134 }
   147 }
   135 
   148 
       
   149 void HbIconItemPrivate::updateIconParams()
       
   150 {
       
   151     Q_Q(HbIconItem);
       
   152     if (mIconRect.isValid()) {
       
   153         if (!mIcon.isNull()) {
       
   154             HbIconPrivate::d_ptr_detached(&mIcon)->setThemedColor(mThemedColor);
       
   155         }
       
   156         mAnimator.setIcon(mIcon);
       
   157     }
       
   158     q->update();
       
   159 }
       
   160 
       
   161 void HbIconItemPrivate::recalculateBoundingRect() const
       
   162 {
       
   163     Q_Q(const HbIconItem);
       
   164     mBoundingRect = q->HbWidgetBase::boundingRect();
       
   165     //workaround for qt bug http://bugreports.qt.nokia.com/browse/QTBUG-8820
       
   166     mAdjustedRect.setWidth(qMax(qreal(0),mBoundingRect.width() - qreal(2.0)));
       
   167     mAdjustedRect.setHeight(qMax(qreal(0),mBoundingRect.height() - qreal(2.0)));
       
   168     //workaround ends
       
   169     mClearCachedRect = false;
       
   170 }
       
   171 
       
   172 void HbIconItemPrivate::setThemedColor(const QColor &color)
       
   173 {
       
   174     mThemedColor = color;
       
   175     updateIconItem();
       
   176 }
       
   177 
   136 /*!
   178 /*!
   137  Constructs a new HbIconItem with \a iconName and \a parent.
   179  Constructs a new HbIconItem with \a iconName and \a parent.
   138  \param iconName the name of the icon.
   180  \param iconName the name of the icon.
   139  See HbIcon for a description of how the icon name and the icon image filename are related.
   181  See HbIcon for a description of how the icon name and the icon image filename are related.
   140  \param parent the graphics item parent of this icon.
   182  \param parent the graphics item parent of this icon.
   141  */
   183  */
   142 HbIconItem::HbIconItem(const QString &iconName, QGraphicsItem *parent) :
   184 HbIconItem::HbIconItem(const QString &iconName, QGraphicsItem *parent) :
   143     HbWidgetBase(*new HbIconItemPrivate(iconName), parent)
   185     HbWidgetBase(*new HbIconItemPrivate(iconName), parent)
   144 {
   186 {
   145     Q_D( HbIconItem );
   187     Q_D(HbIconItem);
   146     d->q_ptr = this;
   188     d->q_ptr = this;
   147     // Set this graphics item to be updated on icon animations
   189     // Set this graphics item to be updated on icon animations
   148     d->mAnimator.setGraphicsItem(this);
   190     d->mAnimator.setGraphicsItem(this);
   149     HbOogmWatcher::instance()->registerIconItem(this);
   191     HbOogmWatcher::instance()->registerIconItem(this);
   150 }
   192 }
   155  \param parent the graphics item parent of this icon.
   197  \param parent the graphics item parent of this icon.
   156  */
   198  */
   157 HbIconItem::HbIconItem(const HbIcon &icon, QGraphicsItem *parent) :
   199 HbIconItem::HbIconItem(const HbIcon &icon, QGraphicsItem *parent) :
   158     HbWidgetBase(*new HbIconItemPrivate(icon), parent)
   200     HbWidgetBase(*new HbIconItemPrivate(icon), parent)
   159 {
   201 {
   160     Q_D( HbIconItem );
   202     Q_D(HbIconItem);
   161     d->q_ptr = this;
   203     d->q_ptr = this;
   162     // Set this graphics item to be updated on icon animations
   204     // Set this graphics item to be updated on icon animations
   163     d->mAnimator.setGraphicsItem(this);
   205     d->mAnimator.setGraphicsItem(this);
   164     HbOogmWatcher::instance()->registerIconItem(this);
   206     HbOogmWatcher::instance()->registerIconItem(this);
   165 }
   207 }
   169  \param parent the graphics item parent of this HbIconItem.
   211  \param parent the graphics item parent of this HbIconItem.
   170  */
   212  */
   171 HbIconItem::HbIconItem(QGraphicsItem *parent) :
   213 HbIconItem::HbIconItem(QGraphicsItem *parent) :
   172     HbWidgetBase(*new HbIconItemPrivate(QString()), parent)
   214     HbWidgetBase(*new HbIconItemPrivate(QString()), parent)
   173 {
   215 {
   174     Q_D( HbIconItem );
   216     Q_D(HbIconItem);
   175     d->q_ptr = this;
   217     d->q_ptr = this;
   176     // Set this graphics item to be updated on icon animations
   218     // Set this graphics item to be updated on icon animations
   177     d->mAnimator.setGraphicsItem(this);
   219     d->mAnimator.setGraphicsItem(this);
   178     HbOogmWatcher::instance()->registerIconItem(this);
   220     HbOogmWatcher::instance()->registerIconItem(this);
   179 }
   221 }
   180 
   222 
   181 
   223 
   182 /*!
   224 /*!
   183  \internal
   225  \internal
   184  */
   226  */
   185 HbIconItem::HbIconItem(HbIconItemPrivate &dd, QGraphicsItem * parent) :
   227 HbIconItem::HbIconItem(HbIconItemPrivate &dd, QGraphicsItem *parent) :
   186     HbWidgetBase(dd, parent)
   228     HbWidgetBase(dd, parent)
   187 {
   229 {
   188     // Set this graphics item to be updated on icon animations
   230     // Set this graphics item to be updated on icon animations
   189     dd.mAnimator.setGraphicsItem(this);
   231     dd.mAnimator.setGraphicsItem(this);
   190     HbOogmWatcher::instance()->registerIconItem(this);
   232     HbOogmWatcher::instance()->registerIconItem(this);
   193 /*!
   235 /*!
   194  Destructor.
   236  Destructor.
   195  */
   237  */
   196 HbIconItem::~HbIconItem()
   238 HbIconItem::~HbIconItem()
   197 {
   239 {
   198     HbOogmWatcher::instance()->unregisterIconItem(this);
   240     HbOogmWatcher *w = HbOogmWatcher::instance();
       
   241     if (w) {
       
   242         w->unregisterIconItem(this);
       
   243     }
   199 }
   244 }
   200 
   245 
   201 /*!
   246 /*!
   202  \return the HbIcon associated with this HbIconItem instance.
   247  \return the HbIcon associated with this HbIconItem instance.
   203 
   248 
   204  \sa setIcon
   249  \sa setIcon
   205  */
   250  */
   206 HbIcon HbIconItem::icon() const
   251 HbIcon HbIconItem::icon() const
   207 {
   252 {
   208     Q_D(const HbIconItem );
   253     Q_D(const HbIconItem);
   209     return d->mIcon;
   254     return d->mIcon;
   210 }
   255 }
   211 
   256 
   212 /*!
   257 /*!
   213  Sets the HbIcon instance associated with this HbIconItem.
   258  Sets the HbIcon instance associated with this HbIconItem.
   214 
   259 
       
   260  Calling any function on \a icon after this one may not have any effect on the
       
   261  icon displayed by the HbIconItem. Use the setters in HbIconItem instead. Of course
       
   262  the settings set on \a icon before calling setIcon() will all be taken into account.
       
   263 
       
   264  The icon-specific parameters (flags, color, mirroring mode) set via the HbIconItem
       
   265  setters before are lost as this function causes the entire underlying icon to be
       
   266  replaced with a new one.
       
   267  
   215  \param icon the HbIcon instance that this HbIconItem displays.
   268  \param icon the HbIcon instance that this HbIconItem displays.
   216 
   269 
   217  When \a takeIconSettings is false, the following settings are not
   270  \sa icon()
   218  taken (ignored) from \a icon: flags, color, mirroring mode.  Instead,
   271 */
   219  the previous values set via HbIconItem's setters are used.
   272 void HbIconItem::setIcon(const HbIcon &icon, bool reserved)
   220 
   273 {
   221  \sa icon
   274     Q_UNUSED(reserved);
   222 */
   275     Q_D(HbIconItem);
   223 void HbIconItem::setIcon(const HbIcon &icon, bool takeIconSettings)
       
   224 {
       
   225     Q_D(HbIconItem );
       
   226     if (d->mIcon != icon) {
   276     if (d->mIcon != icon) {
   227         if (takeIconSettings) {
   277         d->mIcon = icon;
   228             d->mIcon = icon;
       
   229         } else {
       
   230             // Must preserve settings like flags, colors, etc. In this case the
       
   231             // settings made previously through HbIconItem take precedence over the
       
   232             // newly set HbIcon's own settings.
       
   233             HbIcon::Flags prevFlags = d->mIcon.flags();
       
   234             QColor prevColor = d->mIcon.color();
       
   235             HbIcon::MirroringMode prevMirroringMode = d->mIcon.mirroringMode();
       
   236             d->mIcon = icon;
       
   237             d->mIcon.setFlags(prevFlags);
       
   238             d->mIcon.setColor(prevColor);
       
   239             d->mIcon.setMirroringMode(prevMirroringMode);
       
   240         }
       
   241         d->updateIconItem();
   278         d->updateIconItem();
   242     }
   279     }
   243 }
   280 }
   244 
   281 
   245 /*!
   282 /*!
   267 
   304 
   268  \sa alignment
   305  \sa alignment
   269  */
   306  */
   270 void HbIconItem::setAlignment(Qt::Alignment alignment)
   307 void HbIconItem::setAlignment(Qt::Alignment alignment)
   271 {
   308 {
   272     Q_D(HbIconItem );
   309     Q_D(HbIconItem);
       
   310     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_IconAlign, true);
   273     if (d->mAlignment != alignment) {
   311     if (d->mAlignment != alignment) {
   274         d->mAlignment = alignment;
   312         d->mAlignment = alignment;
   275         update();
   313         update();
   276     }
   314     }
   277 }
   315 }
   285 
   323 
   286  \sa aspectRatioMode
   324  \sa aspectRatioMode
   287  */
   325  */
   288 void HbIconItem::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
   326 void HbIconItem::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
   289 {
   327 {
   290     Q_D(HbIconItem );
   328     Q_D(HbIconItem);
   291     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_IconAspectRatioMode, true);
   329     d->setApiProtectionFlag(HbWidgetBasePrivate::AC_IconAspectRatioMode, true);
   292     if (d->mAspectRatioMode != aspectRatioMode) {
   330     if (d->mAspectRatioMode != aspectRatioMode) {
   293         d->mAspectRatioMode = aspectRatioMode;
   331         d->mAspectRatioMode = aspectRatioMode;
   294         update();
   332         update();
   295     }
   333     }
   298 /*!
   336 /*!
   299  Sets the QIcon mode for the icon. An icon can show different images for different modes.
   337  Sets the QIcon mode for the icon. An icon can show different images for different modes.
   300  If this method is not called, the icon uses the default mode which is QIcon::Normal.
   338  If this method is not called, the icon uses the default mode which is QIcon::Normal.
   301 
   339 
   302  \param mode the new icon mode.
   340  \param mode the new icon mode.
   303  \warning Currently this method makes use of pixmap() routine in case of NVG icons. 
   341  \warning Currently this method makes use of pixmap() routine in case of NVG icons.
   304  pixmap() slows down the hardware accelerated rendering.
   342  pixmap() slows down the hardware accelerated rendering.
   305  \sa mode
   343  \sa mode
   306  */
   344  */
   307 void HbIconItem::setMode(QIcon::Mode mode)
   345 void HbIconItem::setMode(QIcon::Mode mode)
   308 {
   346 {
   309     Q_D(HbIconItem );
   347     Q_D(HbIconItem);
   310     if (d->mMode != mode) {
   348     if (d->mMode != mode) {
   311         d->mMode = mode;
   349         d->mMode = mode;
   312         update();
   350         update();
   313     }
   351     }
   314 }
   352 }
   321 
   359 
   322  \sa state
   360  \sa state
   323  */
   361  */
   324 void HbIconItem::setState(QIcon::State state)
   362 void HbIconItem::setState(QIcon::State state)
   325 {
   363 {
   326     Q_D(HbIconItem );
   364     Q_D(HbIconItem);
   327     if (d->mState != state) {
   365     if (d->mState != state) {
   328         d->mState = state;
   366         d->mState = state;
   329         update();
   367         update();
   330     }
   368     }
   331 }
   369 }
   338  \sa HbIcon::setIconName()
   376  \sa HbIcon::setIconName()
   339  \sa iconName
   377  \sa iconName
   340  */
   378  */
   341 void HbIconItem::setIconName(const QString &iconName)
   379 void HbIconItem::setIconName(const QString &iconName)
   342 {
   380 {
   343     Q_D(HbIconItem );
   381     Q_D(HbIconItem);
   344     if (d->mIcon.iconName() != iconName) {
   382     if (d->mIcon.iconName() != iconName) {
   345         d->mIcon.setIconName(iconName);
   383         d->mIcon.setIconName(iconName);
   346         d->updateIconItem();
   384         d->updateIconItem();
   347     }
   385     }
   348 }
   386 }
   357 void HbIconItem::setFlags(HbIcon::Flags flags)
   395 void HbIconItem::setFlags(HbIcon::Flags flags)
   358 {
   396 {
   359     Q_D(HbIconItem);
   397     Q_D(HbIconItem);
   360     if (d->mIcon.flags() != flags) {
   398     if (d->mIcon.flags() != flags) {
   361         d->mIcon.setFlags(flags);
   399         d->mIcon.setFlags(flags);
   362         if (d->mIconRect.isValid())
   400         d->updateIconParams();
   363             d->mAnimator.setIcon(d->mIcon);
       
   364         update();
       
   365     }
   401     }
   366 }
   402 }
   367 
   403 
   368 /*!
   404 /*!
   369  Sets the mirroring \a mode for the icon item.
   405  Sets the mirroring \a mode for the icon item.
   376 void HbIconItem::setMirroringMode(HbIcon::MirroringMode mode)
   412 void HbIconItem::setMirroringMode(HbIcon::MirroringMode mode)
   377 {
   413 {
   378     Q_D(HbIconItem);
   414     Q_D(HbIconItem);
   379     if (d->mIcon.mirroringMode() != mode) {
   415     if (d->mIcon.mirroringMode() != mode) {
   380         d->mIcon.setMirroringMode(mode);
   416         d->mIcon.setMirroringMode(mode);
   381         if (d->mIconRect.isValid())
   417         d->updateIconParams();
   382             d->mAnimator.setIcon(d->mIcon);
       
   383         update();
       
   384     }
   418     }
   385 }
   419 }
   386 
   420 
   387 /*!
   421 /*!
   388  Sets the \a brush for the icon item.
   422  Sets the \a brush for the icon item.
   411  \sa HbIcon::setIconName()
   445  \sa HbIcon::setIconName()
   412  \sa iconName
   446  \sa iconName
   413  */
   447  */
   414 void HbIconItem::setIconName(const QString &iconName, QIcon::Mode mode, QIcon::State state)
   448 void HbIconItem::setIconName(const QString &iconName, QIcon::Mode mode, QIcon::State state)
   415 {
   449 {
   416     Q_D( HbIconItem );
   450     Q_D(HbIconItem);
   417     d->mIcon.setIconName(iconName, mode, state);
   451     d->mIcon.setIconName(iconName, mode, state);
   418     d->updateIconItem();
   452     d->updateIconItem();
   419 }
   453 }
   420 
   454 
   421 /*!
   455 /*!
   422   Sets the new icon color for the HbIconItem. Note that the color is just
   456   Sets the new icon color for the HbIconItem. Note that the color
   423   stored but not actually used if the HbIcon::Colorized flag is not set and the
   457   is just stored but not actually used if the HbIcon::Colorized flag
   424   icon is not a mono icon from the theme.
   458   is not set and the icon is not a mono icon from the theme.
   425 
   459 
   426  \param  color to be set.
   460   See HbIcon::setColor() for more information on colorization of mono
   427  \sa HbIconItem::color(), HbIcon::setColor()
   461   icons in widgets.
       
   462 
       
   463   \param  color to be set.
       
   464   \sa HbIconItem::color(), HbIcon::setColor()
   428 */
   465 */
   429 void HbIconItem::setColor(const QColor &color)
   466 void HbIconItem::setColor(const QColor &color)
   430 {
   467 {
   431     Q_D( HbIconItem );
   468     Q_D(HbIconItem);
   432     if (d->mIcon.color() != color) {
   469     if (d->mIcon.color() != color) {
   433         d->mIcon.setColor(color);
   470         d->mIcon.setColor(color);
   434         if (d->mIconRect.isValid())
   471         d->updateIconParams();
   435             d->mAnimator.setIcon(d->mIcon);
       
   436         update();
       
   437     }
   472     }
   438 }
   473 }
   439 
   474 
   440 /*!
   475 /*!
   441 * Returns the color of the HbIconItem.
   476 * Returns the color of the HbIconItem.
   442 * \sa HbIconItem::setColor()
   477 * \sa HbIconItem::setColor()
   443 */
   478 */
   444 QColor HbIconItem::color() const
   479 QColor HbIconItem::color() const
   445 {
   480 {
   446     Q_D(const  HbIconItem );
   481     Q_D(const  HbIconItem);
   447     return d->mIcon.color();
   482     return d->mIcon.color();
   448 }
   483 }
   449 
   484 
   450 /*!
   485 /*!
   451  Returns the default size of the icon.
   486  Returns the default size of the icon.
   452  
   487 
   453  For raster images this is the original size of the image.
   488  For raster images this is the original size of the image.
   454 
   489 
   455  \sa HbIcon::defaultSize()
   490  \sa HbIcon::defaultSize()
   456  */
   491  */
   457 QSizeF HbIconItem::defaultSize() const
   492 QSizeF HbIconItem::defaultSize() const
   458 {
   493 {
   459     Q_D(const HbIconItem );
   494     Q_D(const HbIconItem);
   460     return d->mIcon.defaultSize();
   495     return d->mIcon.defaultSize();
   461 }
   496 }
   462 
   497 
   463 /*!
   498 /*!
   464  \return the size of this HbIconItem
   499  \return the size of this HbIconItem
   475 
   510 
   476  \sa setAspectRatioMode
   511  \sa setAspectRatioMode
   477  */
   512  */
   478 Qt::AspectRatioMode HbIconItem::aspectRatioMode() const
   513 Qt::AspectRatioMode HbIconItem::aspectRatioMode() const
   479 {
   514 {
   480     Q_D(const HbIconItem );
   515     Q_D(const HbIconItem);
   481     return d->mAspectRatioMode;
   516     return d->mAspectRatioMode;
   482 }
   517 }
   483 
   518 
   484 /*!
   519 /*!
   485  \return the icon's alignment.
   520  \return the icon's alignment.
   486 
   521 
   487  \sa setAlignment
   522  \sa setAlignment
   488  */
   523  */
   489 Qt::Alignment HbIconItem::alignment() const
   524 Qt::Alignment HbIconItem::alignment() const
   490 {
   525 {
   491     Q_D(const HbIconItem );
   526     Q_D(const HbIconItem);
   492     return d->mAlignment;
   527     return d->mAlignment;
   493 }
   528 }
   494 
   529 
   495 /*!
   530 /*!
   496  \return the icon's mode.
   531  \return the icon's mode.
   497 
   532 
   498  \sa setMode
   533  \sa setMode
   499  */
   534  */
   500 QIcon::Mode HbIconItem::mode() const
   535 QIcon::Mode HbIconItem::mode() const
   501 {
   536 {
   502     Q_D(const HbIconItem );
   537     Q_D(const HbIconItem);
   503     return d->mMode;
   538     return d->mMode;
   504 }
   539 }
   505 
   540 
   506 /*!
   541 /*!
   507  \return the icon's state.
   542  \return the icon's state.
   508 
   543 
   509  \sa setState
   544  \sa setState
   510  */
   545  */
   511 QIcon::State HbIconItem::state() const
   546 QIcon::State HbIconItem::state() const
   512 {
   547 {
   513     Q_D(const HbIconItem );
   548     Q_D(const HbIconItem);
   514     return d->mState;
   549     return d->mState;
   515 }
   550 }
   516 
   551 
   517 /*!
   552 /*!
   518  \return the icon's name.
   553  \return the icon's name.
   520  \sa HbIcon::iconName()
   555  \sa HbIcon::iconName()
   521  \sa setIconName
   556  \sa setIconName
   522  */
   557  */
   523 QString HbIconItem::iconName() const
   558 QString HbIconItem::iconName() const
   524 {
   559 {
   525     Q_D(const HbIconItem );
   560     Q_D(const HbIconItem);
   526     return d->mIcon.iconName();
   561     return d->mIcon.iconName();
   527 }
   562 }
   528 
   563 
   529 /*!
   564 /*!
   530  \return the icon name for a specific mode and state.
   565  \return the icon name for a specific mode and state.
   534  \sa HbIcon::iconName()
   569  \sa HbIcon::iconName()
   535  \sa setIconName
   570  \sa setIconName
   536  */
   571  */
   537 QString HbIconItem::iconName(QIcon::Mode mode, QIcon::State state) const
   572 QString HbIconItem::iconName(QIcon::Mode mode, QIcon::State state) const
   538 {
   573 {
   539     Q_D(const HbIconItem );
   574     Q_D(const HbIconItem);
   540     return d->mIcon.iconName(mode, state);
   575     return d->mIcon.iconName(mode, state);
   541 }
   576 }
   542 
   577 
   543 /*!
   578 /*!
   544  \return the HbIcon flags for the icon displayed by this HbIconItem.
   579  \return the HbIcon flags for the icon displayed by this HbIconItem.
   578 /*!
   613 /*!
   579  * Refer HbIcon::isNull()
   614  * Refer HbIcon::isNull()
   580  */
   615  */
   581 bool HbIconItem::isNull() const
   616 bool HbIconItem::isNull() const
   582 {
   617 {
   583     Q_D(const HbIconItem );
   618     Q_D(const HbIconItem);
   584     return d->mIcon.isNull();
   619     return d->mIcon.isNull();
   585 }
   620 }
   586 
   621 
   587 /*!
   622 /*!
   588  Paints the graphics item.
   623  Paints the graphics item.
   592 void HbIconItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
   627 void HbIconItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
   593 {
   628 {
   594     Q_UNUSED(widget)
   629     Q_UNUSED(widget)
   595     Q_UNUSED(option)
   630     Q_UNUSED(option)
   596     Q_D(HbIconItem);
   631     Q_D(HbIconItem);
   597     const QRectF rect(boundingRect());
   632     if (d->mClearCachedRect){
   598     if(!rect.isEmpty()){
   633         d->recalculateBoundingRect();
   599         if (d->mIconRect != rect) {
   634     }
   600             d->mIconRect = rect;
   635     if (!d->mBoundingRect.isEmpty()){
       
   636         if (d->mIconRect != d->mBoundingRect) {
       
   637             d->mIconRect = d->mBoundingRect;
       
   638             if (!d->mIcon.isNull()) {
       
   639                 HbIconPrivate::d_ptr_detached(&d->mIcon)->setThemedColor(d->mThemedColor);
       
   640             }
   601             d->mIcon.setSize(d->mIconRect.size());
   641             d->mIcon.setSize(d->mIconRect.size());
   602             d->mAnimator.setIcon(d->mIcon);
   642             d->mAnimator.setIcon(d->mIcon);
   603         }
   643         }
   604         painter->fillRect(rect, d->mBrush);
   644         if (d->mBrush != Qt::NoBrush) {
   605         d->mAnimator.paint(painter, rect,
   645             painter->fillRect(d->mBoundingRect, d->mBrush);
       
   646         }
       
   647         d->mAnimator.paint(painter, d->mBoundingRect,
   606                            d->mAspectRatioMode, d->mAlignment,
   648                            d->mAspectRatioMode, d->mAlignment,
   607                            d->mMode, d->mState);
   649                            d->mMode, d->mState);
   608     }
   650     }
   609     if (HbIconItemPrivate::outlinesEnabled) {
   651     if (HbIconItemPrivate::outlinesEnabled) {
   610         painter->setBrush(QBrush(QColor(0, 255, 0, 50)));
   652         painter->setBrush(QBrush(QColor(0, 255, 0, 50)));
   611         painter->drawRect(contentsRect()); 
   653         painter->drawRect(contentsRect());
   612     }
   654     }
       
   655 }
       
   656 
       
   657 /*!
       
   658  \reimp
       
   659  */
       
   660 QRectF HbIconItem::boundingRect() const
       
   661 
       
   662 {
       
   663     Q_D(const HbIconItem);
       
   664     if (d->mClearCachedRect) {
       
   665         d->recalculateBoundingRect();
       
   666     }
       
   667     return d->mAdjustedRect;
       
   668 }
       
   669 
       
   670 /*!
       
   671  \reimp
       
   672  */
       
   673 void HbIconItem::setGeometry(const QRectF& rect)
       
   674 {
       
   675     Q_D(HbIconItem);
       
   676     d->mClearCachedRect = true;
       
   677     HbWidgetBase::setGeometry(rect);
   613 }
   678 }
   614 
   679 
   615 /*!
   680 /*!
   616     \reimp
   681     \reimp
   617  */
   682  */
   628         HbWidgetBase::changeEvent(event);
   693         HbWidgetBase::changeEvent(event);
   629         break;
   694         break;
   630     }
   695     }
   631 }
   696 }
   632 
   697 
   633  /*!
   698 /*!
   634     \reimp
   699    \reimp
   635  */
   700 */
   636 QVariant HbIconItem::itemChange(GraphicsItemChange change, const QVariant &value)
   701 QVariant HbIconItem::itemChange(GraphicsItemChange change, const QVariant &value)
   637 {
   702 {
   638     Q_D(HbIconItem);
   703     Q_D(HbIconItem);
   639     if (QGraphicsItem::ItemEnabledHasChanged==change) {
   704     if (QGraphicsItem::ItemEnabledHasChanged == change) {
   640         d->mMode = value.toBool() ? QIcon::Normal : QIcon::Disabled;
   705         d->mMode = value.toBool() ? QIcon::Normal : QIcon::Disabled;
   641     }
   706     }
   642 
   707 
   643     return HbWidgetBase::itemChange(change, value);
   708     return HbWidgetBase::itemChange(change, value);
   644 }
   709 }