--- a/src/hbwidgets/widgets/hblabel.cpp Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbwidgets/widgets/hblabel.cpp Fri Sep 17 08:32:10 2010 +0300
@@ -38,6 +38,9 @@
#include "hbwidgetbase.h"
#include "hblabel.h"
#include "hbstyle_p.h"
+#include "hbstyletextprimitivedata.h"
+#include "hbstylerichtextprimitivedata.h"
+#include "hbstyleiconprimitivedata.h"
/*!
@alpha
@@ -90,46 +93,41 @@
Q_DECLARE_PUBLIC(HbLabel)
public:
- HbLabelPrivate ();
- ~HbLabelPrivate ();
+ HbLabelPrivate();
+ ~HbLabelPrivate();
void clearAll();
- void setText(const QString &text, HbStylePrivate::Primitive primitiveId);
+ void setText(const QString &text, HbStyle::PrimitiveType primitiveId);
void setIcon(const HbIcon &icon);
void updatePrimitives ();
void createPrimitives ();
//shared between icon and text
- Qt::Alignment mAlignment;
+ HbStyleValue<Qt::Alignment> mAlignment;
// text section
- QString mText;
- Qt::TextElideMode mElideMode;
- Hb::TextWrapping mTextWrapping;
- QColor mColor;
- int mMaxLines;
+ HbStyleValue<QString> mText;
+ HbStyleValue<Qt::TextElideMode> mElideMode;
+ HbStyleValue<Hb::TextWrapping> mTextWrapping;
+ HbStyleValue<QColor> mColor;
+ HbStyleValue<int> mMaxLines;
// icon section
- HbIcon mIcon;
- Qt::AspectRatioMode mAspectRatioMode;
+ HbStyleValue<HbIcon> mIcon;
+ HbStyleValue<Qt::AspectRatioMode> mAspectRatioMode;
// primitive handling
- QGraphicsItem *mPrimitiveItem;
- HbStylePrivate::Primitive mActivePrimitive;
+ QGraphicsObject *mPrimitiveItem;
+
+ HbStyle::PrimitiveType mActivePrimitive;
};
HbLabelPrivate::HbLabelPrivate() :
HbWidgetPrivate(),
- mAlignment(Qt::AlignLeft | Qt::AlignVCenter),
- mText(QString()),
- mElideMode(Qt::ElideRight),
- mTextWrapping(Hb::TextNoWrap),
- mMaxLines(0),
- mAspectRatioMode(Qt::KeepAspectRatio),
mPrimitiveItem(0),
- mActivePrimitive(HbStylePrivate::P_None)
+ mActivePrimitive(HbStyle::PT_None)
{
}
@@ -138,14 +136,14 @@
if (mPrimitiveItem) {
delete mPrimitiveItem;
mPrimitiveItem = 0;
- mActivePrimitive = HbStylePrivate::P_None;
+ mActivePrimitive = HbStyle::PT_None;
}
mText.clear();
mIcon.clear();
}
-void HbLabelPrivate::setText(const QString &text, HbStylePrivate::Primitive primitiveId)
+void HbLabelPrivate::setText(const QString &text, HbStyle::PrimitiveType primitiveId)
{
Q_Q(HbLabel);
@@ -158,7 +156,7 @@
clearAll();
}
- if (mText != text || mText.isNull()) {
+ if (mText!=text) {
mText = text;
if (mActivePrimitive != primitiveId) {
mActivePrimitive = primitiveId;
@@ -178,15 +176,15 @@
return;
}
- if (mActivePrimitive != HbStylePrivate::P_Label_icon) {
+ if (mActivePrimitive != HbStyle::PT_IconItem) {
clearAll();
}
if (mIcon != icon) {
mIcon = icon;
- if (mActivePrimitive != HbStylePrivate::P_Label_icon) {
- mActivePrimitive = HbStylePrivate::P_Label_icon;
+ if (mActivePrimitive != HbStyle::PT_IconItem) {
+ mActivePrimitive = HbStyle::PT_IconItem;
createPrimitives();
q->repolish(); // reconecting new primitive to HbAnchorLayout so it is really needed!
}
@@ -204,8 +202,21 @@
Q_ASSERT(mPrimitiveItem==0);
- if (mActivePrimitive != HbStylePrivate::P_None) {
- mPrimitiveItem = HbStylePrivate::createPrimitive(mActivePrimitive, q);
+ switch (mActivePrimitive) {
+ case HbStyle::PT_None:
+ break;
+
+ case HbStyle::PT_IconItem:
+ mPrimitiveItem = q->style()->createPrimitive(mActivePrimitive, QString("icon"),q);
+ break;
+
+ case HbStyle::PT_TextItem: // no break
+ case HbStyle::PT_RichTextItem:
+ mPrimitiveItem = q->style()->createPrimitive(mActivePrimitive, QString("text"),q);
+ break;
+
+ default:
+ Q_ASSERT(0);
}
}
@@ -213,14 +224,68 @@
{
Q_Q(HbLabel);
- if (mActivePrimitive != HbStylePrivate::P_None) {
- Q_ASSERT(mActivePrimitive == HbStylePrivate::P_Label_icon
- || mActivePrimitive == HbStylePrivate::P_Label_richtext
- || mActivePrimitive == HbStylePrivate::P_Label_text);
+ if (mActivePrimitive != HbStyle::PT_None) {
+ Q_ASSERT(mActivePrimitive == HbStyle::PT_IconItem
+ || mActivePrimitive == HbStyle::PT_RichTextItem
+ || mActivePrimitive == HbStyle::PT_TextItem);
+
+ switch (mActivePrimitive) {
+ case HbStyle::PT_IconItem: {
+ HbStyleIconPrimitiveData data;
+ // set common data:
+ data.alignment = mAlignment;
+
+ // set icon data:
+ data.aspectRatioMode = mAspectRatioMode;
+ data.icon = mIcon;
+
+ q->style()->updatePrimitive(mPrimitiveItem,
+ &data);
+ }
+ break;
+ case HbStyle::PT_TextItem: {
+ HbStyleTextPrimitiveData data;
+
+ // set common data:
+ data.alignment = mAlignment;
+
+ // set text common data:
+ data.text = mText;
+ data.textColor = mColor;
+ data.textWrapping = mTextWrapping;
- HbStyleOptionLabel option;
- q->initStyleOption(&option);
- HbStylePrivate::updatePrimitive(mPrimitiveItem, mActivePrimitive, &option);
+ // plain text specyfic:
+ data.elideMode = mElideMode;
+ data.maximumLines = mMaxLines;
+
+ q->style()->updatePrimitive(mPrimitiveItem,
+ &data);
+ }
+ break;
+
+ case HbStyle::PT_RichTextItem: {
+ HbStyleRichTextPrimitiveData data;
+
+ // set common data:
+ data.alignment = mAlignment;
+
+ // set text common data:
+ data.text = mText;
+ data.defaultColor = mColor;
+ data.textWrappingMode = mTextWrapping;
+
+ q->style()->updatePrimitive(mPrimitiveItem,
+ &data);
+ }
+ break;
+
+ case 0: {
+ }
+ break;
+
+ default:
+ Q_ASSERT(0);
+ }
}
}
@@ -312,7 +377,7 @@
Q_D(HbLabel);
if (elideMode != d->mElideMode) {
d->mElideMode = elideMode;
- if (!d->mText.isNull()) {
+ if (d->mText.isSet()) {
updatePrimitives();
}
}
@@ -327,7 +392,11 @@
Qt::TextElideMode HbLabel::elideMode() const
{
Q_D(const HbLabel);
- return d->mElideMode;
+ if (d->mElideMode.isSet()) {
+ return d->mElideMode;
+ } else {
+ return Qt::ElideRight;
+ }
}
/*!
@@ -341,7 +410,7 @@
Q_D(HbLabel);
if (d->mTextWrapping != mode) {
d->mTextWrapping = mode;
- if (!d->mText.isNull()) {
+ if (d->mText.isSet()) {
updatePrimitives();
}
}
@@ -349,14 +418,19 @@
/*!
\return the label's current text wrapping mode.
- Default value is NoWrap.
+ Default value is Hb::TextNoWrap.
\sa setTextWrapping()
*/
Hb::TextWrapping HbLabel::textWrapping() const
{
Q_D(const HbLabel);
- return d->mTextWrapping;
+
+ if (d->mTextWrapping.isSet()) {
+ return d->mTextWrapping;
+ } else {
+ return Hb::TextNoWrap;
+ }
}
/*!
@@ -381,7 +455,12 @@
HbIcon HbLabel::icon() const
{
Q_D(const HbLabel);
- return d->mIcon;
+
+ if (d->mIcon.isSet()) {
+ return d->mIcon;
+ } else {
+ return HbIcon();
+ }
}
/*!
@@ -406,7 +485,7 @@
Q_D(HbLabel);
if (d->mAspectRatioMode != aspectRatioMode) {
d->mAspectRatioMode = aspectRatioMode;
- if (!d->mIcon.isNull()) {
+ if (d->mIcon.isSet()) {
updatePrimitives();
}
}
@@ -421,7 +500,12 @@
Qt::AspectRatioMode HbLabel::aspectRatioMode() const
{
Q_D(const HbLabel);
- return d->mAspectRatioMode;
+
+ if (d->mAspectRatioMode.isSet()) {
+ return d->mAspectRatioMode;
+ } else {
+ return Qt::KeepAspectRatio;
+ }
}
/*!
@@ -435,7 +519,7 @@
void HbLabel::setPlainText(const QString &text)
{
Q_D(HbLabel);
- d->setText(text, HbStylePrivate::P_Label_text);
+ d->setText(text, HbStyle::PT_TextItem);
}
/*!
@@ -449,7 +533,7 @@
void HbLabel::setHtml(const QString &text)
{
Q_D(HbLabel);
- d->setText(text, HbStylePrivate::P_Label_richtext);
+ d->setText(text, HbStyle::PT_RichTextItem);
}
/*!
@@ -463,21 +547,29 @@
Q_D(HbLabel);
if (d->mAlignment != alignment) {
d->mAlignment = alignment;
- if (d->mActivePrimitive!=HbStylePrivate::P_None) {
+ if (alignment == 0) {
+ d->mAlignment.clear();
+ }
+ if (d->mActivePrimitive!=HbStyle::PT_None) {
updatePrimitives();
}
}
}
/*!
- \return the alignment. Default alignment is 'Qt::AlignLeft | Qt::AlignVCenter'
+ \return the alignment. Default alignment is '0' indicating that nothing was
+ set (so CSS cotrols alignment).
\sa HbLabel::setAlignment()
*/
Qt::Alignment HbLabel::alignment() const
{
Q_D(const HbLabel);
- return d->mAlignment;
+ if (d->mAlignment.isSet()) {
+ return d->mAlignment;
+ } else {
+ return 0;
+ }
}
/*!
@@ -493,7 +585,7 @@
bool HbLabel::isEmpty() const
{
Q_D(const HbLabel);
- return d->mActivePrimitive == HbStylePrivate::P_None;
+ return d->mActivePrimitive == HbStyle::PT_None;
}
/*!
@@ -503,7 +595,7 @@
Returns a pointer to the QGraphicsItem primitive used by this label.
\param primitive - the type of graphics primitive required.
- HbLabel supports HbStylePrivate::P_Label_text and HbStylePrivate::P_Label_icon.
+ HbLabel supports HbStyle::PT_TextItem and HbStyle::PT_IconItem.
\return the QGraphicsItem used by the label. It is 0 if type \a primitive not currently in use.
It is also 0 if the text or icon object is empty.
@@ -514,10 +606,29 @@
QGraphicsItem * HbLabel::primitive(HbStyle::Primitive primitive) const
{
Q_D(const HbLabel);
- if ((HbStylePrivate::Primitive)primitive == d->mActivePrimitive) {
+ switch ((HbStylePrivate::Primitive)primitive) {
+ case HbStylePrivate::P_Label_icon:
+ if (d->mActivePrimitive != HbStyle::PT_IconItem) {
+ break;
+ }
+ return d->mPrimitiveItem;
+
+ case HbStylePrivate::P_Label_text:
+ if (d->mActivePrimitive != HbStyle::PT_TextItem) {
+ break;
+ }
return d->mPrimitiveItem;
+
+ case HbStylePrivate::P_Label_richtext:
+ if (d->mActivePrimitive != HbStyle::PT_RichTextItem) {
+ break;
+ }
+ return d->mPrimitiveItem;
+
+ default:
+ return HbWidget::primitive(primitive);
}
- return HbWidget::primitive(primitive);
+ return 0;
}
/*!
@@ -534,7 +645,7 @@
option->alignment = d->mAlignment;
- if (!d->mText.isNull()) {
+ if (d->mText.isSet()) {
option->text = d->mText;
option->elideMode = d->mElideMode;
option->textWrapMode = d->mTextWrapping;
@@ -542,7 +653,7 @@
option->maximumLines = d->mMaxLines;
}
- if (!d->mIcon.isNull()) {
+ if (d->mIcon.isSet()) {
option->icon = d->mIcon;
option->aspectRatioMode = d->mAspectRatioMode;
}
@@ -580,7 +691,7 @@
QString HbLabel::plainText() const
{
Q_D(const HbLabel);
- if (d->mActivePrimitive == HbStylePrivate::P_Label_text) {
+ if (d->mActivePrimitive == HbStyle::PT_TextItem) {
return d->mText;
}
return QString();
@@ -592,7 +703,7 @@
QString HbLabel::html() const
{
Q_D(const HbLabel);
- if (d->mActivePrimitive == HbStylePrivate::P_Label_richtext) {
+ if (d->mActivePrimitive == HbStyle::PT_RichTextItem) {
return d->mText;
}
return QString();
@@ -606,7 +717,7 @@
Q_D(HbLabel);
if (d->mColor!=textColor) {
d->mColor=textColor;
- if (!d->mText.isNull()) {
+ if (d->mText.isSet()) {
updatePrimitives();
}
}
@@ -618,7 +729,12 @@
QColor HbLabel::textColor() const
{
Q_D(const HbLabel);
- return d->mColor;
+
+ if (d->mColor.isSet()) {
+ return d->mColor;
+ } else {
+ return QColor();
+ }
}
/*!
@@ -635,7 +751,7 @@
maxLines = qMax(maxLines, 0);
if (d->mMaxLines != maxLines) {
d->mMaxLines = maxLines;
- if (d->mActivePrimitive == HbStylePrivate::P_Label_text) {
+ if (d->mActivePrimitive == HbStyle::PT_TextItem) {
updatePrimitives();
}
}
@@ -650,7 +766,13 @@
*/
int HbLabel::maximumLines() const
{
- return d_func()->mMaxLines;
+ Q_D(const HbLabel);
+
+ if (d->mMaxLines.isSet()) {
+ return d->mMaxLines;
+ } else {
+ return 0;
+ }
}
#include "moc_hblabel.cpp"