106 // text section |
107 // text section |
107 QString mText; |
108 QString mText; |
108 Qt::TextElideMode mElideMode; |
109 Qt::TextElideMode mElideMode; |
109 Hb::TextWrapping mTextWrapping; |
110 Hb::TextWrapping mTextWrapping; |
110 QColor mColor; |
111 QColor mColor; |
|
112 int mMaxLines; |
111 |
113 |
112 // icon section |
114 // icon section |
113 HbIcon mIcon; |
115 HbIcon mIcon; |
114 Qt::AspectRatioMode mAspectRatioMode; |
116 Qt::AspectRatioMode mAspectRatioMode; |
115 |
117 |
116 // primitive handling |
118 // primitive handling |
117 QGraphicsItem *mPrimitiveItem; |
119 QGraphicsItem *mPrimitiveItem; |
118 HbStyle::Primitive mActivePrimitive; |
120 HbStylePrivate::Primitive mActivePrimitive; |
119 }; |
121 }; |
120 |
122 |
121 HbLabelPrivate::HbLabelPrivate() : |
123 HbLabelPrivate::HbLabelPrivate() : |
122 HbWidgetPrivate(), |
124 HbWidgetPrivate(), |
123 mAlignment(Qt::AlignLeft | Qt::AlignVCenter), |
125 mAlignment(Qt::AlignLeft | Qt::AlignVCenter), |
124 mText(QString()), |
126 mText(QString()), |
125 mElideMode(Qt::ElideRight), |
127 mElideMode(Qt::ElideRight), |
126 mTextWrapping(Hb::TextNoWrap), |
128 mTextWrapping(Hb::TextNoWrap), |
|
129 mMaxLines(0), |
127 mAspectRatioMode(Qt::KeepAspectRatio), |
130 mAspectRatioMode(Qt::KeepAspectRatio), |
128 mPrimitiveItem(0), |
131 mPrimitiveItem(0), |
129 mActivePrimitive(HbStyle::P_None) |
132 mActivePrimitive(HbStylePrivate::P_None) |
130 { |
133 { |
131 } |
134 } |
132 |
135 |
133 void HbLabelPrivate::clearAll() |
136 void HbLabelPrivate::clearAll() |
134 { |
137 { |
135 if (mPrimitiveItem) { |
138 if (mPrimitiveItem) { |
136 delete mPrimitiveItem; |
139 delete mPrimitiveItem; |
137 mPrimitiveItem = 0; |
140 mPrimitiveItem = 0; |
138 mActivePrimitive = HbStyle::P_None; |
141 mActivePrimitive = HbStylePrivate::P_None; |
139 } |
142 } |
140 |
143 |
141 mText.clear(); |
144 mText.clear(); |
142 mIcon.clear(); |
145 mIcon.clear(); |
143 } |
146 } |
144 |
147 |
145 void HbLabelPrivate::setText(const QString &text, HbStyle::Primitive primitiveId) |
148 void HbLabelPrivate::setText(const QString &text, HbStylePrivate::Primitive primitiveId) |
146 { |
149 { |
147 Q_Q(HbLabel); |
150 Q_Q(HbLabel); |
148 |
151 |
149 if (text.isNull()) { |
152 if (text.isNull()) { |
150 clearAll(); |
153 clearAll(); |
173 if (icon.isNull()) { |
176 if (icon.isNull()) { |
174 clearAll(); |
177 clearAll(); |
175 return; |
178 return; |
176 } |
179 } |
177 |
180 |
178 if (mActivePrimitive != HbStyle::P_Label_icon) { |
181 if (mActivePrimitive != HbStylePrivate::P_Label_icon) { |
179 clearAll(); |
182 clearAll(); |
180 } |
183 } |
181 |
184 |
182 if (mIcon != icon) { |
185 if (mIcon != icon) { |
183 mIcon = icon; |
186 mIcon = icon; |
184 |
187 |
185 if (mActivePrimitive != HbStyle::P_Label_icon) { |
188 if (mActivePrimitive != HbStylePrivate::P_Label_icon) { |
186 mActivePrimitive = HbStyle::P_Label_icon; |
189 mActivePrimitive = HbStylePrivate::P_Label_icon; |
187 createPrimitives(); |
190 createPrimitives(); |
188 q->repolish(); // reconecting new primitive to HbAnchorLayout so it is really needed! |
191 q->repolish(); // reconecting new primitive to HbAnchorLayout so it is really needed! |
189 } |
192 } |
190 q->updatePrimitives(); |
193 q->updatePrimitives(); |
191 } |
194 } |
199 { |
202 { |
200 Q_Q(HbLabel); |
203 Q_Q(HbLabel); |
201 |
204 |
202 Q_ASSERT(mPrimitiveItem==0); |
205 Q_ASSERT(mPrimitiveItem==0); |
203 |
206 |
204 if (mActivePrimitive != HbStyle::P_None) { |
207 if (mActivePrimitive != HbStylePrivate::P_None) { |
205 mPrimitiveItem = q->style()->createPrimitive(mActivePrimitive, q); |
208 mPrimitiveItem = HbStylePrivate::createPrimitive(mActivePrimitive, q); |
206 } |
209 } |
207 } |
210 } |
208 |
211 |
209 void HbLabelPrivate::updatePrimitives() |
212 void HbLabelPrivate::updatePrimitives() |
210 { |
213 { |
211 Q_Q(HbLabel); |
214 Q_Q(HbLabel); |
212 |
215 |
213 if (mActivePrimitive != HbStyle::P_None) { |
216 if (mActivePrimitive != HbStylePrivate::P_None) { |
214 Q_ASSERT(mActivePrimitive == HbStyle::P_Label_icon |
217 Q_ASSERT(mActivePrimitive == HbStylePrivate::P_Label_icon |
215 || mActivePrimitive == HbStyle::P_Label_richtext |
218 || mActivePrimitive == HbStylePrivate::P_Label_richtext |
216 || mActivePrimitive == HbStyle::P_Label_text); |
219 || mActivePrimitive == HbStylePrivate::P_Label_text); |
217 |
220 |
218 HbStyleOptionLabel option; |
221 HbStyleOptionLabel option; |
219 q->initStyleOption(&option); |
222 q->initStyleOption(&option); |
220 q->style()->updatePrimitive(mPrimitiveItem, mActivePrimitive, &option); |
223 HbStylePrivate::updatePrimitive(mPrimitiveItem, mActivePrimitive, &option); |
221 } |
224 } |
222 } |
225 } |
223 |
226 |
224 /*! |
227 /*! |
225 Constructs the label with a given \a parent. |
228 Constructs the label with a given \a parent. |
430 \sa setIcon() |
433 \sa setIcon() |
431 */ |
434 */ |
432 void HbLabel::setPlainText(const QString &text) |
435 void HbLabel::setPlainText(const QString &text) |
433 { |
436 { |
434 Q_D(HbLabel); |
437 Q_D(HbLabel); |
435 d->setText(text, HbStyle::P_Label_text); |
438 d->setText(text, HbStylePrivate::P_Label_text); |
436 } |
439 } |
437 |
440 |
438 /*! |
441 /*! |
439 Sets the label contents to html text containing \a text. Any previous content is cleared. |
442 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. |
443 Does nothing if the string representation is the same as the current contents of the label. |
488 \sa clear() |
491 \sa clear() |
489 */ |
492 */ |
490 bool HbLabel::isEmpty() const |
493 bool HbLabel::isEmpty() const |
491 { |
494 { |
492 Q_D(const HbLabel); |
495 Q_D(const HbLabel); |
493 return d->mActivePrimitive == HbStyle::P_None; |
496 return d->mActivePrimitive == HbStylePrivate::P_None; |
494 } |
497 } |
495 |
498 |
496 /*! |
499 /*! |
497 |
500 |
498 \deprecated HbLabel::primitive(HbStyle::Primitive) |
501 \deprecated HbLabel::primitive(HbStyle::Primitive) |
499 is deprecated. |
502 is deprecated. |
500 |
503 |
501 Returns a pointer to the QGraphicsItem primitive used by this label. |
504 Returns a pointer to the QGraphicsItem primitive used by this label. |
502 \param primitive - the type of graphics primitive required. |
505 \param primitive - the type of graphics primitive required. |
503 HbLabel supports HbStyle::P_Label_text and HbStyle::P_Label_icon. |
506 HbLabel supports HbStylePrivate::P_Label_text and HbStylePrivate::P_Label_icon. |
504 \return the QGraphicsItem used by the label. It is 0 if type \a primitive not currently in use. |
507 \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. |
508 It is also 0 if the text or icon object is empty. |
506 |
509 |
507 \reimp |
510 \reimp |
508 |
511 |
509 \sa isEmpty() |
512 \sa isEmpty() |
510 */ |
513 */ |
511 QGraphicsItem * HbLabel::primitive(HbStyle::Primitive primitive) const |
514 QGraphicsItem * HbLabel::primitive(HbStyle::Primitive primitive) const |
512 { |
515 { |
513 Q_D(const HbLabel); |
516 Q_D(const HbLabel); |
514 if (primitive == d->mActivePrimitive) { |
517 if ((HbStylePrivate::Primitive)primitive == d->mActivePrimitive) { |
515 return d->mPrimitiveItem; |
518 return d->mPrimitiveItem; |
516 } |
519 } |
517 return HbWidget::primitive(primitive); |
520 return HbWidget::primitive(primitive); |
518 } |
521 } |
519 |
522 |
534 if (!d->mText.isNull()) { |
537 if (!d->mText.isNull()) { |
535 option->text = d->mText; |
538 option->text = d->mText; |
536 option->elideMode = d->mElideMode; |
539 option->elideMode = d->mElideMode; |
537 option->textWrapMode = d->mTextWrapping; |
540 option->textWrapMode = d->mTextWrapping; |
538 option->color = d->mColor; |
541 option->color = d->mColor; |
|
542 option->maximumLines = d->mMaxLines; |
539 } |
543 } |
540 |
544 |
541 if (!d->mIcon.isNull()) { |
545 if (!d->mIcon.isNull()) { |
542 option->icon = d->mIcon; |
546 option->icon = d->mIcon; |
543 option->aspectRatioMode = d->mAspectRatioMode; |
547 option->aspectRatioMode = d->mAspectRatioMode; |
615 { |
619 { |
616 Q_D(const HbLabel); |
620 Q_D(const HbLabel); |
617 return d->mColor; |
621 return d->mColor; |
618 } |
622 } |
619 |
623 |
|
624 /*! |
|
625 If plain text is used (\sa setPlainText) this will set maximum number of lines |
|
626 to be visible in label. |
|
627 Zero or negative value disables the feature. |
|
628 |
|
629 \sa maximumLines() |
|
630 */ |
|
631 void HbLabel::setMaximumLines(int maxLines) |
|
632 { |
|
633 Q_D(HbLabel); |
|
634 |
|
635 maxLines = qMax(maxLines, 0); |
|
636 if (d->mMaxLines != maxLines) { |
|
637 d->mMaxLines = maxLines; |
|
638 if (d->mActivePrimitive == HbStylePrivate::P_Label_text) { |
|
639 updatePrimitives(); |
|
640 } |
|
641 } |
|
642 } |
|
643 |
|
644 /*! |
|
645 Returns maximum number of lines which can be visible in label when |
|
646 plain text is used (\sa setPlainText). |
|
647 Zero value means that there is no limitation. |
|
648 |
|
649 \sa setMaximumLines(int) |
|
650 */ |
|
651 int HbLabel::maximumLines() const |
|
652 { |
|
653 return d_func()->mMaxLines; |
|
654 } |
|
655 |
620 #include "moc_hblabel.cpp" |
656 #include "moc_hblabel.cpp" |