src/hbwidgets/widgets/hblabel.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    35 #include "hbcolorscheme.h"
    35 #include "hbcolorscheme.h"
    36 #include "hbwidget_p.h"
    36 #include "hbwidget_p.h"
    37 #include "hbstyleoptionlabel_p.h"
    37 #include "hbstyleoptionlabel_p.h"
    38 #include "hbwidgetbase.h"
    38 #include "hbwidgetbase.h"
    39 #include "hblabel.h"
    39 #include "hblabel.h"
       
    40 #include "hbstyle_p.h"
       
    41 #include "hbstyletextprimitivedata.h"
       
    42 #include "hbstylerichtextprimitivedata.h"
       
    43 #include "hbstyleiconprimitivedata.h"
    40 
    44 
    41 /*!
    45 /*!
    42     @alpha
    46     @alpha
    43     @hbcore
    47     @hbcore
    44 
    48 
    87 
    91 
    88 class HbLabelPrivate: public HbWidgetPrivate {
    92 class HbLabelPrivate: public HbWidgetPrivate {
    89     Q_DECLARE_PUBLIC(HbLabel)
    93     Q_DECLARE_PUBLIC(HbLabel)
    90 
    94 
    91 public:
    95 public:
    92             HbLabelPrivate ();
    96     HbLabelPrivate();
    93     ~HbLabelPrivate ();
    97     ~HbLabelPrivate();
       
    98 
       
    99     void init();
       
   100     void clear();
    94 
   101 
    95     void clearAll();
   102     void clearAll();
    96 
   103 
    97     void setText(const QString &text, HbStyle::Primitive primitiveId);
   104     void setText(const QString &text, HbStyle::PrimitiveType primitiveId);
    98     void setIcon(const HbIcon &icon);
   105     void setIcon(const HbIcon &icon);
    99 
   106 
   100     void updatePrimitives ();
   107     void updatePrimitives ();
   101     void createPrimitives ();
   108     void createPrimitives ();
   102 
   109 
   103     //shared between icon and text
   110     //shared between icon and text
   104     Qt::Alignment mAlignment;
   111     HbStyleValue<Qt::Alignment> mAlignment;
   105 
   112 
   106     // text section
   113     // text section
   107     QString mText;
   114     HbStyleValue<QString> mText;
   108     Qt::TextElideMode mElideMode;
   115     HbStyleValue<Qt::TextElideMode> mElideMode;
   109     Hb::TextWrapping mTextWrapping;
   116     HbStyleValue<Hb::TextWrapping> mTextWrapping;
   110     QColor mColor;
   117     HbStyleValue<QColor> mColor;
       
   118     HbStyleValue<int> mMaxLines;
   111 
   119 
   112     // icon section
   120     // icon section
   113     HbIcon mIcon;
   121     HbStyleValue<HbIcon> mIcon;
   114     Qt::AspectRatioMode mAspectRatioMode;
   122     HbStyleValue<Qt::AspectRatioMode> mAspectRatioMode;
   115 
   123 
   116     // primitive handling
   124     // primitive handling
   117     QGraphicsItem *mPrimitiveItem;
   125     QGraphicsObject *mPrimitiveItem;
   118     HbStyle::Primitive mActivePrimitive;
   126 
       
   127     HbStyle::PrimitiveType mActivePrimitive;
   119 };
   128 };
   120 
   129 
   121 HbLabelPrivate::HbLabelPrivate() :
   130 HbLabelPrivate::HbLabelPrivate() :
   122         HbWidgetPrivate(),
   131         HbWidgetPrivate(),
   123         mAlignment(Qt::AlignLeft | Qt::AlignVCenter),
       
   124         mText(QString()),
       
   125         mElideMode(Qt::ElideRight),
       
   126         mTextWrapping(Hb::TextNoWrap),
       
   127         mAspectRatioMode(Qt::KeepAspectRatio),
       
   128         mPrimitiveItem(0),
   132         mPrimitiveItem(0),
   129         mActivePrimitive(HbStyle::P_None)
   133         mActivePrimitive(HbStyle::PT_None)
   130 {
   134 {
   131 }
   135 }
       
   136 
       
   137 void HbLabelPrivate::init()
       
   138 {
       
   139     Q_Q(HbLabel);
       
   140     q->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
       
   141 }
       
   142 
       
   143 void HbLabelPrivate::clear()
       
   144 {
       
   145     // no implementation needed
       
   146 }
       
   147 
   132 
   148 
   133 void HbLabelPrivate::clearAll()
   149 void HbLabelPrivate::clearAll()
   134 {
   150 {
   135     if (mPrimitiveItem) {
   151     if (mPrimitiveItem) {
   136         delete mPrimitiveItem;
   152         delete mPrimitiveItem;
   137         mPrimitiveItem = 0;
   153         mPrimitiveItem = 0;
   138         mActivePrimitive = HbStyle::P_None;
   154         mActivePrimitive = HbStyle::PT_None;
   139     }
   155     }
   140 
   156 
   141     mText.clear();
   157     mText.clear();
   142     mIcon.clear();
   158     mIcon.clear();
   143 }
   159 }
   144 
   160 
   145 void HbLabelPrivate::setText(const QString &text, HbStyle::Primitive primitiveId)
   161 void HbLabelPrivate::setText(const QString &text, HbStyle::PrimitiveType primitiveId)
   146 {
   162 {
   147     Q_Q(HbLabel);
   163     Q_Q(HbLabel);
   148 
   164 
   149     if (text.isNull()) {
   165     if (text.isNull()) {
   150         clearAll();
   166         clearAll();
   153 
   169 
   154     if (mActivePrimitive != primitiveId) {
   170     if (mActivePrimitive != primitiveId) {
   155         clearAll();
   171         clearAll();
   156     }
   172     }
   157 
   173 
   158     if (mText != text || mText.isNull()) {
   174     if (mText!=text) {
   159         mText = text;
   175         mText = text;
   160         if (mActivePrimitive != primitiveId) {
   176         if (mActivePrimitive != primitiveId) {
   161             mActivePrimitive = primitiveId;
   177             mActivePrimitive = primitiveId;
   162             createPrimitives();
   178             createPrimitives();
   163             q->repolish(); // reconecting new primitive to HbAnchorLayout so it is really needed!
   179             q->repolish(); // reconecting new primitive to HbAnchorLayout so it is really needed!
   173     if (icon.isNull()) {
   189     if (icon.isNull()) {
   174         clearAll();
   190         clearAll();
   175         return;
   191         return;
   176     }
   192     }
   177 
   193 
   178     if (mActivePrimitive != HbStyle::P_Label_icon) {
   194     if (mActivePrimitive != HbStyle::PT_IconItem) {
   179         clearAll();
   195         clearAll();
   180     }
   196     }
   181 
   197 
   182     if (mIcon != icon) {
   198     if (mIcon != icon) {
   183         mIcon = icon;
   199         mIcon = icon;
   184 
   200 
   185         if (mActivePrimitive != HbStyle::P_Label_icon) {
   201         if (mActivePrimitive != HbStyle::PT_IconItem) {
   186             mActivePrimitive = HbStyle::P_Label_icon;
   202             mActivePrimitive = HbStyle::PT_IconItem;
   187             createPrimitives();
   203             createPrimitives();
   188             q->repolish(); // reconecting new primitive to HbAnchorLayout so it is really needed!
   204             q->repolish(); // reconecting new primitive to HbAnchorLayout so it is really needed!
   189         }
   205         }
   190         q->updatePrimitives();
   206         q->updatePrimitives();
   191     }
   207     }
   199 {
   215 {
   200     Q_Q(HbLabel);
   216     Q_Q(HbLabel);
   201 
   217 
   202     Q_ASSERT(mPrimitiveItem==0);
   218     Q_ASSERT(mPrimitiveItem==0);
   203 
   219 
   204     if (mActivePrimitive != HbStyle::P_None) {
   220     switch (mActivePrimitive) {
   205         mPrimitiveItem = q->style()->createPrimitive(mActivePrimitive, q);
   221     case HbStyle::PT_None:
       
   222         break;
       
   223 
       
   224     case HbStyle::PT_IconItem:
       
   225         mPrimitiveItem = q->style()->createPrimitive(mActivePrimitive, QString("icon"),q);
       
   226         break;
       
   227 
       
   228     case HbStyle::PT_TextItem: // no break
       
   229     case HbStyle::PT_RichTextItem:
       
   230         mPrimitiveItem = q->style()->createPrimitive(mActivePrimitive, QString("text"),q);
       
   231         break;
       
   232 
       
   233     default:
       
   234         Q_ASSERT(0);
   206     }
   235     }
   207 }
   236 }
   208 
   237 
   209 void HbLabelPrivate::updatePrimitives()
   238 void HbLabelPrivate::updatePrimitives()
   210 {
   239 {
   211     Q_Q(HbLabel);
   240     Q_Q(HbLabel);
   212 
   241 
   213     if (mActivePrimitive != HbStyle::P_None) {
   242     if (mActivePrimitive != HbStyle::PT_None) {
   214         Q_ASSERT(mActivePrimitive == HbStyle::P_Label_icon
   243         Q_ASSERT(mActivePrimitive == HbStyle::PT_IconItem
   215                  || mActivePrimitive == HbStyle::P_Label_richtext
   244                  || mActivePrimitive == HbStyle::PT_RichTextItem
   216                  || mActivePrimitive == HbStyle::P_Label_text);
   245                  || mActivePrimitive == HbStyle::PT_TextItem);
   217 
   246 
   218         HbStyleOptionLabel option;
   247         switch (mActivePrimitive) {
   219         q->initStyleOption(&option);
   248         case HbStyle::PT_IconItem: {
   220         q->style()->updatePrimitive(mPrimitiveItem, mActivePrimitive, &option);
   249                 HbStyleIconPrimitiveData data;
       
   250                 // set common data:
       
   251                 data.alignment = mAlignment;
       
   252 
       
   253                 // set icon data:
       
   254                 data.aspectRatioMode = mAspectRatioMode;
       
   255                 data.icon = mIcon;
       
   256 
       
   257                 q->style()->updatePrimitive(mPrimitiveItem,
       
   258                                             &data);
       
   259             }
       
   260             break;
       
   261         case HbStyle::PT_TextItem: {
       
   262                 HbStyleTextPrimitiveData data;
       
   263 
       
   264                 // set common data:
       
   265                 data.alignment = mAlignment;
       
   266 
       
   267                 // set text common data:
       
   268                 data.text = mText;
       
   269                 data.textColor = mColor;
       
   270                 data.textWrapping = mTextWrapping;
       
   271 
       
   272                 // plain text specyfic:
       
   273                 data.elideMode = mElideMode;
       
   274                 data.maximumLines = mMaxLines;
       
   275 
       
   276                 q->style()->updatePrimitive(mPrimitiveItem,
       
   277                                             &data);
       
   278             }
       
   279             break;
       
   280 
       
   281         case HbStyle::PT_RichTextItem: {
       
   282                 HbStyleRichTextPrimitiveData data;
       
   283 
       
   284                 // set common data:
       
   285                 data.alignment = mAlignment;
       
   286 
       
   287                 // set text common data:
       
   288                 data.text = mText;
       
   289                 data.defaultColor = mColor;
       
   290                 data.textWrappingMode = mTextWrapping;
       
   291 
       
   292                 q->style()->updatePrimitive(mPrimitiveItem,
       
   293                                             &data);
       
   294             }
       
   295             break;
       
   296 
       
   297         case 0: {
       
   298             }
       
   299             break;
       
   300 
       
   301         default:
       
   302             Q_ASSERT(0);
       
   303         }
   221     }
   304     }
   222 }
   305 }
   223 
   306 
   224 /*!
   307 /*!
   225     Constructs the label with a given \a parent.
   308     Constructs the label with a given \a parent.
   226     \param parent - the parent graphics item.
   309     \param parent - the parent graphics item.
   227  */
   310  */
   228 HbLabel::HbLabel(QGraphicsItem *parent) :
   311 HbLabel::HbLabel(QGraphicsItem *parent) :
   229         HbWidget(*new HbLabelPrivate, parent)
   312         HbWidget(*new HbLabelPrivate, parent)
   230 {
   313 {
   231     setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
   314     Q_D(HbLabel);
       
   315     d->init();
   232 }
   316 }
   233 
   317 
   234 /*!
   318 /*!
   235     \internal
   319     \internal
   236  */
   320  */
   237 HbLabel::HbLabel(HbLabelPrivate &dd, QGraphicsItem * parent) :
   321 HbLabel::HbLabel(HbLabelPrivate &dd, QGraphicsItem * parent) :
   238         HbWidget(dd, parent)
   322         HbWidget(dd, parent)
   239 {
   323 {
   240     setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
   324     Q_D(HbLabel);
       
   325     d->init();
   241 }
   326 }
   242 
   327 
   243 /*!
   328 /*!
   244     Constructs the label with a given \a text and \a parent. This constructor is a convenience for
   329     Constructs the label with a given \a text and \a parent. This constructor is a convenience for
   245     common use case to have a label with plain text content. Using this contructor you do not need
   330     common use case to have a label with plain text content. Using this contructor you do not need
   257 /*!
   342 /*!
   258     Label destructor.
   343     Label destructor.
   259  */
   344  */
   260 HbLabel::~HbLabel ()
   345 HbLabel::~HbLabel ()
   261 {
   346 {
       
   347     Q_D(HbLabel);
       
   348     d->clear();
   262 }
   349 }
   263 
   350 
   264 /*!
   351 /*!
   265     Sets the label contents to plain text containing the textual
   352     Sets the label contents to plain text containing the textual
   266     representation of integer \a num. Any previous content is cleared.
   353     representation of integer \a num. Any previous content is cleared.
   307 void HbLabel::setElideMode (Qt::TextElideMode elideMode)
   394 void HbLabel::setElideMode (Qt::TextElideMode elideMode)
   308 {
   395 {
   309     Q_D(HbLabel);
   396     Q_D(HbLabel);
   310     if (elideMode != d->mElideMode) {
   397     if (elideMode != d->mElideMode) {
   311         d->mElideMode = elideMode;
   398         d->mElideMode = elideMode;
   312         if (!d->mText.isNull()) {
   399         if (d->mText.isSet()) {
   313             updatePrimitives();
   400             updatePrimitives();
   314         }
   401         }
   315     }
   402     }
   316 }
   403 }
   317 
   404 
   318 /*!
   405 /*!
   319     Default elide mode is Qt::ElideRight.
   406     By default this method returns invalid value to indicate that
       
   407     eliding is controlled by CSS (setElideMode was not used).
       
   408     In CSS elide by default is set to Qt::ElideRight.
       
   409 
   320     \return the elide mode of the text.
   410     \return the elide mode of the text.
   321 
   411 
   322     \sa HbLabel::setElideMode()
   412     \sa HbLabel::setElideMode()
   323  */
   413  */
   324 Qt::TextElideMode HbLabel::elideMode() const
   414 Qt::TextElideMode HbLabel::elideMode() const
   325 {
   415 {
   326     Q_D(const HbLabel);
   416     Q_D(const HbLabel);
   327     return d->mElideMode;
   417     if (d->mElideMode.isSet()) {
       
   418         return d->mElideMode;
       
   419     } else {
       
   420         return (Qt::TextElideMode)-1;
       
   421     }
   328 }
   422 }
   329 
   423 
   330 /*!
   424 /*!
   331     Sets the text wrapping mode to \a mode.
   425     Sets the text wrapping mode to \a mode.
   332     \param mode - wrapping mode
   426     \param mode - wrapping mode
   336 void HbLabel::setTextWrapping(Hb::TextWrapping mode)
   430 void HbLabel::setTextWrapping(Hb::TextWrapping mode)
   337 {
   431 {
   338     Q_D(HbLabel);
   432     Q_D(HbLabel);
   339     if (d->mTextWrapping != mode) {
   433     if (d->mTextWrapping != mode) {
   340         d->mTextWrapping = mode;
   434         d->mTextWrapping = mode;
   341         if (!d->mText.isNull()) {
   435         if (d->mText.isSet()) {
   342             updatePrimitives();
   436             updatePrimitives();
   343         }
   437         }
   344     }
   438     }
   345 }
   439 }
   346 
   440 
   347 /*!
   441 /*!
   348     \return the label's current text wrapping mode.
   442     \return the label's current text wrapping mode.
   349     Default value is NoWrap.
   443     Default value is Hb::TextNoWrap.
   350 
   444 
   351     \sa setTextWrapping()
   445     \sa setTextWrapping()
   352  */
   446  */
   353 Hb::TextWrapping HbLabel::textWrapping() const
   447 Hb::TextWrapping HbLabel::textWrapping() const
   354 {
   448 {
   355     Q_D(const HbLabel);
   449     Q_D(const HbLabel);
   356     return d->mTextWrapping;
   450 
       
   451     if (d->mTextWrapping.isSet()) {
       
   452         return d->mTextWrapping;
       
   453     } else {
       
   454         return Hb::TextNoWrap;
       
   455     }
   357 }
   456 }
   358 
   457 
   359 /*!
   458 /*!
   360     Sets the icon displayed by this label.
   459     Sets the icon displayed by this label.
   361     Removes any existing text from the label.
   460     Removes any existing text from the label.
   376     \sa setIcon
   475     \sa setIcon
   377  */
   476  */
   378 HbIcon HbLabel::icon() const
   477 HbIcon HbLabel::icon() const
   379 {
   478 {
   380     Q_D(const HbLabel);
   479     Q_D(const HbLabel);
   381     return d->mIcon;
   480 
       
   481     if (d->mIcon.isSet()) {
       
   482         return d->mIcon;
       
   483     } else {
       
   484         return HbIcon();
       
   485     }
   382 }
   486 }
   383 
   487 
   384 /*!
   488 /*!
   385     Clears the content of the label. After this the label is empty.
   489     Clears the content of the label. After this the label is empty.
   386 
   490 
   401 void HbLabel::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
   505 void HbLabel::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
   402 {
   506 {
   403     Q_D(HbLabel);
   507     Q_D(HbLabel);
   404     if (d->mAspectRatioMode != aspectRatioMode) {
   508     if (d->mAspectRatioMode != aspectRatioMode) {
   405         d->mAspectRatioMode = aspectRatioMode;
   509         d->mAspectRatioMode = aspectRatioMode;
   406         if (!d->mIcon.isNull()) {
   510         if (d->mIcon.isSet()) {
   407             updatePrimitives();
   511             updatePrimitives();
   408         }
   512         }
   409     }
   513     }
   410 }
   514 }
   411 
   515 
   416     \sa setAspectRatio()
   520     \sa setAspectRatio()
   417  */
   521  */
   418 Qt::AspectRatioMode HbLabel::aspectRatioMode() const
   522 Qt::AspectRatioMode HbLabel::aspectRatioMode() const
   419 {
   523 {
   420     Q_D(const HbLabel);
   524     Q_D(const HbLabel);
   421     return d->mAspectRatioMode;
   525 
       
   526     if (d->mAspectRatioMode.isSet()) {
       
   527         return d->mAspectRatioMode;
       
   528     } else {
       
   529         return Qt::KeepAspectRatio;
       
   530     }
   422 }
   531 }
   423 
   532 
   424 /*!
   533 /*!
   425     Sets the label contents to plain text containing \a text. Any previous content is cleared.
   534     Sets the label contents to plain text containing \a text. Any previous content is cleared.
   426     Does nothing if the string representation is the same as the current contents of the label.
   535     Does nothing if the string representation is the same as the current contents of the label.
   430     \sa setIcon()
   539     \sa setIcon()
   431  */
   540  */
   432 void HbLabel::setPlainText(const QString &text)
   541 void HbLabel::setPlainText(const QString &text)
   433 {
   542 {
   434     Q_D(HbLabel);
   543     Q_D(HbLabel);
   435     d->setText(text, HbStyle::P_Label_text);
   544     d->setText(text, HbStyle::PT_TextItem);
   436 }
   545 }
   437 
   546 
   438 /*!
   547 /*!
   439     Sets the label contents to html text containing \a text. Any previous content is cleared.
   548     Sets the label contents to html text containing \a text. Any previous content is cleared.
   440     Does nothing if the string representation is the same as the current contents of the label.
   549     Does nothing if the string representation is the same as the current contents of the label.
   444     \sa setIcon()
   553     \sa setIcon()
   445  */
   554  */
   446 void HbLabel::setHtml(const QString &text)
   555 void HbLabel::setHtml(const QString &text)
   447 {
   556 {
   448     Q_D(HbLabel);
   557     Q_D(HbLabel);
   449     d->setText(text, HbStyle::P_Label_richtext);
   558     d->setText(text, HbStyle::PT_RichTextItem);
   450 }
   559 }
   451 
   560 
   452 /*!
   561 /*!
   453     Sets the \a alignment of the label.
   562     Sets the \a alignment of the label.
   454     \param alignment - the new alignment.
   563     \param alignment - the new alignment.
   458 void HbLabel::setAlignment(Qt::Alignment alignment)
   567 void HbLabel::setAlignment(Qt::Alignment alignment)
   459 {
   568 {
   460     Q_D(HbLabel);
   569     Q_D(HbLabel);
   461     if (d->mAlignment != alignment) {
   570     if (d->mAlignment != alignment) {
   462         d->mAlignment = alignment;
   571         d->mAlignment = alignment;
   463         if (d->mActivePrimitive!=HbStyle::P_None) {
   572         if (alignment == 0) {
       
   573             d->mAlignment.clear();
       
   574         }
       
   575         if (d->mActivePrimitive!=HbStyle::PT_None) {
   464             updatePrimitives();
   576             updatePrimitives();
   465         }
   577         }
   466     }
   578     }
   467 }
   579 }
   468 
   580 
   469 /*!
   581 /*!
   470     \return the alignment. Default alignment is 'Qt::AlignLeft | Qt::AlignVCenter'
   582     \return the alignment. Default alignment is '0' indicating that nothing was
       
   583     set (so CSS cotrols alignment).
   471 
   584 
   472     \sa HbLabel::setAlignment()
   585     \sa HbLabel::setAlignment()
   473  */
   586  */
   474 Qt::Alignment HbLabel::alignment() const
   587 Qt::Alignment HbLabel::alignment() const
   475 {
   588 {
   476     Q_D(const HbLabel);
   589     Q_D(const HbLabel);
   477     return d->mAlignment;
   590     if (d->mAlignment.isSet()) {
       
   591         return d->mAlignment;
       
   592     } else {
       
   593         return 0;
       
   594     }
   478 }
   595 }
   479 
   596 
   480 /*!
   597 /*!
   481     \return true if both text and icon are empty; otherwise returns false.
   598     \return true if both text and icon are empty; otherwise returns false.
   482 
   599 
   488     \sa clear()
   605     \sa clear()
   489  */
   606  */
   490 bool HbLabel::isEmpty() const
   607 bool HbLabel::isEmpty() const
   491 {
   608 {
   492     Q_D(const HbLabel);
   609     Q_D(const HbLabel);
   493     return d->mActivePrimitive == HbStyle::P_None;
   610     return d->mActivePrimitive == HbStyle::PT_None;
   494 }
   611 }
   495 
   612 
   496 /*!
   613 /*!
   497 
   614 
   498     \deprecated HbLabel::primitive(HbStyle::Primitive)
   615     \deprecated HbLabel::primitive(HbStyle::Primitive)
   499         is deprecated.
   616         is deprecated.
   500 
   617 
   501     Returns a pointer to the QGraphicsItem primitive used by this label.
   618     Returns a pointer to the QGraphicsItem primitive used by this label.
   502     \param primitive - the type of graphics primitive required.
   619     \param primitive - the type of graphics primitive required.
   503     HbLabel supports HbStyle::P_Label_text and HbStyle::P_Label_icon.
   620     HbLabel supports HbStyle::PT_TextItem and HbStyle::PT_IconItem.
   504     \return the QGraphicsItem used by the label. It is 0 if type \a primitive not currently in use.
   621     \return the QGraphicsItem used by the label. It is 0 if type \a primitive not currently in use.
   505     It is also 0 if the text or icon object is empty.
   622     It is also 0 if the text or icon object is empty.
   506 
   623 
   507     \reimp
   624     \reimp
   508 
   625 
   509     \sa isEmpty()
   626     \sa isEmpty()
   510  */
   627  */
   511 QGraphicsItem * HbLabel::primitive(HbStyle::Primitive primitive) const
   628 QGraphicsItem * HbLabel::primitive(HbStyle::Primitive primitive) const
   512 {
   629 {
   513     Q_D(const HbLabel);
   630     Q_D(const HbLabel);
   514     if (primitive == d->mActivePrimitive) {
   631     switch ((HbStylePrivate::Primitive)primitive) {
       
   632     case HbStylePrivate::P_Label_icon:
       
   633         if (d->mActivePrimitive != HbStyle::PT_IconItem) {
       
   634             break;
       
   635         }
   515         return d->mPrimitiveItem;
   636         return d->mPrimitiveItem;
   516     }
   637 
   517     return HbWidget::primitive(primitive);
   638     case HbStylePrivate::P_Label_text:
       
   639         if (d->mActivePrimitive != HbStyle::PT_TextItem) {
       
   640             break;
       
   641         }
       
   642         return d->mPrimitiveItem;
       
   643 
       
   644     case HbStylePrivate::P_Label_richtext:
       
   645         if (d->mActivePrimitive != HbStyle::PT_RichTextItem) {
       
   646             break;
       
   647         }
       
   648         return d->mPrimitiveItem;
       
   649 
       
   650     default:
       
   651         return HbWidget::primitive(primitive);
       
   652     }
       
   653     return 0;
   518 }
   654 }
   519 
   655 
   520 /*!
   656 /*!
   521     Initializes \a option with the values from this HbLabel.
   657     Initializes \a option with the values from this HbLabel.
   522     HbStyleOptionLabel is used by HbStyle to perform changes in appearance
   658     HbStyleOptionLabel is used by HbStyle to perform changes in appearance
   529 
   665 
   530     HbWidget::initStyleOption(option);
   666     HbWidget::initStyleOption(option);
   531 
   667 
   532     option->alignment = d->mAlignment;
   668     option->alignment = d->mAlignment;
   533 
   669 
   534     if (!d->mText.isNull()) {
   670     if (d->mText.isSet()) {
   535         option->text = d->mText;
   671         option->text = d->mText;
   536         option->elideMode = d->mElideMode;
   672         option->elideMode = d->mElideMode;
   537         option->textWrapMode = d->mTextWrapping;
   673         option->textWrapMode = d->mTextWrapping;
   538         option->color = d->mColor;
   674         option->color = d->mColor;
   539     }
   675         option->maximumLines = d->mMaxLines;
   540 
   676     }
   541     if (!d->mIcon.isNull()) {
   677 
       
   678     if (d->mIcon.isSet()) {
   542         option->icon = d->mIcon;
   679         option->icon = d->mIcon;
   543         option->aspectRatioMode = d->mAspectRatioMode;
   680         option->aspectRatioMode = d->mAspectRatioMode;
   544     }
   681     }
   545 }
   682 }
   546 
   683 
   547 QSizeF HbLabel::sizeHint ( Qt::SizeHint which, const QSizeF & constraint ) const
   684 QSizeF HbLabel::sizeHint ( Qt::SizeHint which, const QSizeF & constraint ) const
   548 {
   685 {
   549     if (isEmpty()) {
   686     if (isEmpty() && which!=Qt::MaximumSize) {
   550         return QSizeF(0,0);
   687         return QSizeF(0,0);
   551     }
   688     }
   552     return HbWidget::sizeHint(which,constraint);
   689     return HbWidget::sizeHint(which,constraint);
   553 }
   690 }
   554 
   691 
   574     Plain text accessor. Returns empty string if not set.
   711     Plain text accessor. Returns empty string if not set.
   575  */
   712  */
   576 QString HbLabel::plainText() const
   713 QString HbLabel::plainText() const
   577 {
   714 {
   578     Q_D(const HbLabel);
   715     Q_D(const HbLabel);
   579     if (d->mActivePrimitive == HbStyle::P_Label_text) {
   716     if (d->mActivePrimitive == HbStyle::PT_TextItem) {
   580         return d->mText;
   717         return d->mText;
   581     }
   718     }
   582     return QString();
   719     return QString();
   583 }
   720 }
   584 
   721 
   586     Rich text text accessor. Returns empty string if not set.
   723     Rich text text accessor. Returns empty string if not set.
   587  */
   724  */
   588 QString HbLabel::html() const
   725 QString HbLabel::html() const
   589 {
   726 {
   590     Q_D(const HbLabel);
   727     Q_D(const HbLabel);
   591     if (d->mActivePrimitive == HbStyle::P_Label_richtext) {
   728     if (d->mActivePrimitive == HbStyle::PT_RichTextItem) {
   592         return d->mText;
   729         return d->mText;
   593     }
   730     }
   594     return QString();
   731     return QString();
   595 }
   732 }
   596 
   733 
   600 void HbLabel::setTextColor( const QColor &textColor )
   737 void HbLabel::setTextColor( const QColor &textColor )
   601 {
   738 {
   602     Q_D(HbLabel);
   739     Q_D(HbLabel);
   603     if (d->mColor!=textColor) {
   740     if (d->mColor!=textColor) {
   604         d->mColor=textColor;
   741         d->mColor=textColor;
   605         if (!d->mText.isNull()) {
   742         if (d->mText.isSet()) {
   606             updatePrimitives();
   743             updatePrimitives();
   607         }
   744         }
   608     }
   745     }
   609 }
   746 }
   610 
   747 
   612     Returns color of text or invalid value if theme color is used.
   749     Returns color of text or invalid value if theme color is used.
   613  */
   750  */
   614 QColor HbLabel::textColor() const
   751 QColor HbLabel::textColor() const
   615 {
   752 {
   616     Q_D(const HbLabel);
   753     Q_D(const HbLabel);
   617     return d->mColor;
   754 
       
   755     if (d->mColor.isSet()) {
       
   756         return d->mColor;
       
   757     } else {
       
   758         return QColor();
       
   759     }
       
   760 }
       
   761 
       
   762 /*!
       
   763     If plain text is used (\sa setPlainText) this will set maximum number of lines
       
   764     to be visible in label.
       
   765     Zero or negative value disables the feature.
       
   766 
       
   767     \sa maximumLines()
       
   768  */
       
   769 void HbLabel::setMaximumLines(int maxLines)
       
   770 {
       
   771     Q_D(HbLabel);
       
   772 
       
   773     maxLines = qMax(maxLines, 0);
       
   774     if (d->mMaxLines != maxLines) {
       
   775         d->mMaxLines = maxLines;
       
   776         if (d->mActivePrimitive == HbStyle::PT_TextItem) {
       
   777             updatePrimitives();
       
   778         }
       
   779     }
       
   780 }
       
   781 
       
   782 /*!
       
   783     Returns maximum number of lines which can be visible in label when
       
   784     plain text is used (\sa setPlainText).
       
   785     Zero value means that there is no limitation.
       
   786 
       
   787     \sa setMaximumLines(int)
       
   788  */
       
   789 int HbLabel::maximumLines() const
       
   790 {
       
   791     Q_D(const HbLabel);
       
   792 
       
   793     if (d->mMaxLines.isSet()) {
       
   794         return d->mMaxLines;
       
   795     } else {
       
   796         return 0;
       
   797     }
   618 }
   798 }
   619 
   799 
   620 #include "moc_hblabel.cpp"
   800 #include "moc_hblabel.cpp"