--- a/src/hbcore/style/hbstyle.cpp Wed Aug 18 10:05:37 2010 +0300
+++ b/src/hbcore/style/hbstyle.cpp Thu Sep 02 20:44:51 2010 +0300
@@ -65,6 +65,15 @@
#include "hbstyleoptionprogresssliderhandle_p.h"
#include "hbstyleoptionprogressslider_p.h"
+
+#include <hbstyleprimitivedata.h>
+#include <hbstyletextprimitivedata.h>
+#include <hbstylerichtextprimitivedata.h>
+#include <hbstyleiconprimitivedata.h>
+#include <hbstyleframeprimitivedata.h>
+#include <hbstylemarqueeprimitivedata.h>
+#include <hbstyletouchareaprimitivedata.h>
+
#include <hbicon.h>
#include <hbstyle.h>
#include <hbframedrawer.h>
@@ -100,7 +109,6 @@
#include <hbanchor.h>
#include <QGraphicsWidget>
-#include <hbwidget.h>
#include <hbwidgetbase.h>
#include "hbdeviceprofile.h"
#include "hbrepeatitem_p.h"
@@ -113,6 +121,7 @@
#include "hbfeaturemanager_r.h"
#endif
+
Q_DECLARE_METATYPE(QGraphicsLayout*)
//Uncomment next define(s) in order to get more debug prints.
@@ -147,7 +156,6 @@
*/
// TODO: margins should be defined in layout data once layout specification exists.
-static const int ItemName = 0xfffe;
static const QString STYLE_LOCATION = QLatin1String(":/themes/style/hbdefault/rules/widgets/%w/%w");
static const QString COLOR_STYLE_LOCATION = QLatin1String(":/themes/style/hbdefault/rules/widgets/%w/%w_color.css");
static const int TOUCHAREA_ZVALUE = 1000;
@@ -203,28 +211,208 @@
delete d_ptr;
}
/*!
-
- \deprecated HbStyle::createPrimitive(HbStyle::Primitive, QGraphicsItem*)
- is deprecated. This method will be made private and later replaced with new version.
+ Instantiates widget building blocks. The building blocks are called "primitives" and their main function is to perform the painting (e.g. drawing text).
+ A set of base primitives are defined in HbStyle::BasePrimitive enumeration. A widget calling this method should not cast the returned QGraphicsObject
+ to the actual primitive object. By following this rule the styling mechanism can be used to change the actual primitive instance to something else than the original one
+ instantiated by the createPrimitive() method. This enables customizing the painting of the UI without touching the widget code.
+
+ Updating of a primitive's state is done by using HbStyle::updatePrimitive() method which uses the style primitive data classes (comparable to
+ Qt styleoptions) to get the state information needed for the primitive updating.
+
+ \param primitiveType, enumeration of the base primitive
+ \param itemName, string which identifies a primitive in the widget (e.g. "background", or "text"). The item name matches with primitive names in widget's CSS file.
+ \param parent, parent for the primitive, although the default is 0 usually the widget is given as a parent for the primitive
+ \return QGraphicsObject, the returned primitive should be stored as a QGraphicsObject on the widget side
+ \sa HbStyle::updatePrimitive()
+ \sa HbStylePrimitiveData
+ \sa HbStyleTextPrimitiveData
+ \sa HbStyleFramePrimitiveData
+ \sa HbStyleIconPrimitiveData
+ \sa HbStyleRichTextPrimitiveData
+ \sa HbStyleMarqueePrimitiveData
+ \sa HbStyleTouchAreaPrimitiveData
*/
-QGraphicsItem *HbStyle::createPrimitive( HbStyle::Primitive primitive, QGraphicsItem *parent ) const
+QGraphicsObject *HbStyle::createPrimitive(HbStyle::PrimitiveType primitiveType, const QString &itemName, QGraphicsObject *parent) const
{
- Q_UNUSED(primitive);
- Q_UNUSED(parent);
- return 0;
-
+ QGraphicsObject *bp;
+
+ switch (primitiveType) {
+ case PT_TextItem:
+ bp = new HbTextItem(parent);
+ break;
+ case PT_RichTextItem:
+ bp = new HbRichTextItem(parent);
+ break;
+ case PT_FrameItem:
+ bp = new HbFrameItem(parent);
+ break;
+ case PT_IconItem:
+ bp = new HbIconItem(parent);
+ break;
+ case PT_MarqueeItem:
+ bp = new HbMarqueeItem(parent);
+ break;
+ case PT_TouchArea:
+ bp = new HbTouchArea(parent);
+ break;
+ default:
+ bp = 0;
+ }
+
+ if (bp != 0) {
+ setItemName(bp, itemName);
+ }
+
+ return bp;
}
+
/*!
-\deprecated HbStyle::updatePrimitive(QGraphicsItem*, HbStyle::Primitive, const QStyleOption*)
-is deprecated. This method will be made private and later replaced with a new version.
-
+ This method is called by Hb widgets whenever there's a widget state change that results to a change in primitive's state.
+ For example if a button's text changes the button widget needs to update the button's text primitive by calling this method.
+
+ Widgets need to use the HbStylePrimitiveData-derived classes to carry the primitive state information from the widget to the style.
+ These data classes enable the widget to set the primitives' state information without directly using the primitive APIs.
+
+ Note that the updating of the primitive attributes is optimized so that if just one value from the primitive data set is updated only that one
+ value will be updated to the primitive on the style side. The values on primitive data classes are stored by using HbStyleValue templated class
+ which keeps track of whether a primitive data value was assigned or not. On the style side before calling the primitive API the HbStyleValue's
+ isSet()-method is called first to check if the widget did assign the primitive data value.
+
+
+ \param primitive, the primitive to be updated
+ \param data, primitive data needed for updating the primitive
+ \param parent, optionally the parent can be given
+ \return bool, true if correct primitive type was found from the style, false if not.
+ \sa HbStyle::createPrimitive()
+ \sa HbStylePrimitiveData
+ \sa HbStyleTextPrimitiveData
+ \sa HbStyleFramePrimitiveData
+ \sa HbStyleIconPrimitiveData
+ \sa HbStyleRichTextPrimitiveData
+ \sa HbStyleMarqueePrimitiveData
+ \sa HbStyleTouchAreaPrimitiveData
*/
-void HbStyle::updatePrimitive( QGraphicsItem *item, HbStyle::Primitive primitive, const QStyleOption *option ) const
+bool HbStyle::updatePrimitive(QGraphicsObject *primitive, const HbStylePrimitiveData *data, QGraphicsObject *parent) const
{
- Q_UNUSED(item);
- Q_UNUSED(primitive);
- Q_UNUSED(option);
+ Q_UNUSED(parent);
+
+ if (HbTextItem *textItem = qgraphicsitem_cast<HbTextItem*>(primitive)) {
+ const HbStyleTextPrimitiveData *td = hbstyleprimitivedata_cast<const HbStyleTextPrimitiveData*>(data);
+ if (td->text.isSet())
+ textItem->setText(td->text);
+ if (td->textColor.isSet())
+ textItem->setTextColor(td->textColor);
+ if (td->alignment.isSet())
+ textItem->setAlignment(td->alignment);
+ if (td->elideMode.isSet())
+ textItem->setElideMode(td->elideMode);
+ if (td->textWrapping.isSet())
+ textItem->setTextWrapping(td->textWrapping);
+ if (td->isTextVisible.isSet())
+ textItem->setTextVisible(td->isTextVisible);
+ if (td->isTextClip.isSet())
+ textItem->setTextClip(td->isTextClip);
+ if (td->geometry.isSet())
+ textItem->setGeometry(td->geometry);
+ if (td->fadeLength.isSet())
+ textItem->setFadeLength(td->fadeLength);
+ if (td->fadeLengths.isSet())
+ textItem->setFadeLengths(td->fadeLengths);
+ return true;
+
+ } else if (HbIconItem *iconItem = qgraphicsitem_cast<HbIconItem*>(primitive)) {
+ const HbStyleIconPrimitiveData *id = hbstyleprimitivedata_cast<const HbStyleIconPrimitiveData*>(data);
+ if (id->icon.isSet())
+ iconItem->setIcon(id->icon);
+ if (id->size.isSet())
+ iconItem->setSize(id->size);
+ if (id->aspectRatioMode.isSet())
+ iconItem->setAspectRatioMode(id->aspectRatioMode);
+ if (id->alignment.isSet())
+ iconItem->setAlignment(id->alignment);
+ if (id->iconMode.isSet())
+ iconItem->setMode(id->iconMode);
+ if (id->iconState.isSet())
+ iconItem->setState(id->iconState);
+ if (id->iconName.isSet())
+ iconItem->setIconName(id->iconName);
+ if (id->iconFlags.isSet())
+ iconItem->setFlags(id->iconFlags);
+ if (id->mirroringMode.isSet())
+ iconItem->setMirroringMode(id->mirroringMode);
+ if (id->brush.isSet())
+ iconItem->setBrush(id->brush);
+ if (id->color.isSet())
+ iconItem->setColor(id->color);
+ return true;
+
+ } else if(HbFrameItem *frameItem = qgraphicsitem_cast<HbFrameItem*>(primitive)) {
+ const HbStyleFramePrimitiveData *fd = hbstyleprimitivedata_cast<const HbStyleFramePrimitiveData*>(data);
+ HbFrameDrawer *drawer = &(frameItem->frameDrawer());
+ if (fd->frameGraphicsName.isSet())
+ drawer->setFrameGraphicsName(fd->frameGraphicsName);
+ if (fd->frameType.isSet())
+ drawer->setFrameType(fd->frameType);
+ if (fd->borderWidthLeft.isSet() || fd->borderWidthRight.isSet() || fd->borderWidthBottom.isSet() || fd->borderWidthTop.isSet())
+ drawer->setBorderWidths(fd->borderWidthLeft, fd->borderWidthTop, fd->borderWidthRight, fd->borderWidthBottom);
+ if (fd->fillWholeRect.isSet())
+ drawer->setFillWholeRect(fd->fillWholeRect);
+ if (fd->mirroringMode.isSet())
+ drawer->setMirroringMode(fd->mirroringMode);
+ if (fd->fileNameSuffixList.isSet())
+ drawer->setFileNameSuffixList(fd->fileNameSuffixList);
+ if (fd->pixmapMask.isSet())
+ drawer->setMask(fd->pixmapMask);
+ if (fd->bitmapMask.isSet())
+ drawer->setMask(fd->bitmapMask);
+ frameItem->setFrameDrawer(drawer);
+ return true;
+
+ } else if (HbMarqueeItem *marqueeItem = qgraphicsitem_cast<HbMarqueeItem*>(primitive)) {
+ const HbStyleMarqueePrimitiveData *md = hbstyleprimitivedata_cast<const HbStyleMarqueePrimitiveData*>(data);
+ if (md->text.isSet())
+ marqueeItem->setText(md->text);
+ if (md->textColor.isSet())
+ marqueeItem->setTextColor(md->textColor);
+ if (md->animation.isSet()) {
+ if (md->animation)
+ marqueeItem->startAnimation();
+ else
+ marqueeItem->stopAnimation();
+ }
+ if (md->loopCount.isSet())
+ marqueeItem->setLoopCount(md->loopCount);
+ return true;
+
+ } else if (HbTouchArea *touchArea = qgraphicsitem_cast<HbTouchArea*>(primitive)) {
+ const HbStyleTouchAreaPrimitiveData *td = hbstyleprimitivedata_cast<const HbStyleTouchAreaPrimitiveData*>(data);
+ if (td->size.isSet())
+ touchArea->setSize(td->size);
+ if (td->geometry.isSet())
+ touchArea->setGeometry(td->geometry);
+ return true;
+
+ } else if (HbRichTextItem *richTextItem = qgraphicsitem_cast<HbRichTextItem*>(primitive)) {
+ const HbStyleRichTextPrimitiveData *rd = hbstyleprimitivedata_cast<const HbStyleRichTextPrimitiveData*>(data);
+ if (rd->text.isSet())
+ richTextItem->setText(rd->text);
+ if (rd->defaultColor.isSet())
+ richTextItem->setTextDefaultColor(rd->defaultColor);
+ if (rd->alignment.isSet())
+ richTextItem->setAlignment(rd->alignment);
+ if (rd->textWrappingMode.isSet())
+ richTextItem->setTextWrapping(rd->textWrappingMode);
+ if (rd->isTextVisible.isSet())
+ richTextItem->setTextVisible(rd->isTextVisible);
+ if (rd->clipping.isSet())
+ richTextItem->setTextClip(rd->clipping);
+ if (rd->geometry.isSet())
+ richTextItem->setGeometry(rd->geometry);
+ return true;
+ }
+
+return false;
}
@@ -292,6 +480,7 @@
{
HbTextItem *textItem = new HbTextItem(parent);
HbStyle::setItemName(textItem, QLatin1String("text"));
+ textItem->setTextWrapping(Hb::TextWordWrap);
return textItem;
}
case P_PushButton_text:
@@ -820,7 +1009,7 @@
HbStyle::setItemName(n, QLatin1String("icon"));
return n;
}
- case P_MessageBox_text:{ //deprecated
+ case P_MessageBox_text:{
HbTextItem *rti = new HbTextItem(parent);
return rti;
}
@@ -969,12 +1158,14 @@
case P_InputDialog_text:
{
HbTextItem *n = new HbTextItem(parent);
+ n->setTextWrapping(Hb::TextWordWrap);
HbStyle::setItemName(n, QLatin1String("label-1"));
return n;
}
case P_InputDialog_additionaltext:
{
HbTextItem *n = new HbTextItem(parent);
+ n->setTextWrapping(Hb::TextWordWrap);
HbStyle::setItemName(n, QLatin1String("label-2"));
return n;
}
@@ -1309,7 +1500,7 @@
if (mode == QIcon::Disabled ) {
frameGraphicsName = QLatin1String("qtg_fr_list_disabled");
} else {
- frameGraphicsName = QLatin1String("qtg_fr_list_parent_normal");
+ frameGraphicsName = QLatin1String("qtg_fr_list_normal");
}
frameItem->frameDrawer().setFrameGraphicsName(frameGraphicsName);
frameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
@@ -2448,13 +2639,7 @@
case P_MessageBox_text: //deprecated
if (const HbStyleOptionMessageBox *opt = static_cast<const HbStyleOptionMessageBox *>(option)) {
HbTextItem *textItem = static_cast<HbTextItem*>(item);
- textItem->setAlignment(opt->textAlignment);
-
- if (opt->textWrapping) {
- textItem->setTextWrapping(Hb::TextWrapAnywhere);
- } else {
- textItem->setTextWrapping(Hb::TextNoWrap);
- }
+ textItem->setTextWrapping(Hb::TextWordWrap);
textItem->setText(opt->text);
}
break;
@@ -2717,7 +2902,6 @@
frameItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_progslider_frame_normal"));
}
}
- frameItem->frameDrawer().setFillWholeRect(true);
//frameItem->update();
}
break;
@@ -2732,7 +2916,6 @@
else {
frameItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_progslider_loaded"));
}
- frameItem->frameDrawer().setFillWholeRect(true);
frameItem->setMaximum(opt->maximum);
frameItem->setMinimum(opt->minimum);
frameItem->setValue(opt->progressValue);
@@ -2800,14 +2983,12 @@
}
else {
- if(opt->pressedState) {
-
- repeatItem->setName(QLatin1String("qtg_graf_ratingslider_unrated_pressed"));
- }
- else {
-
- repeatItem->setName(QLatin1String("qtg_graf_ratingslider_unrated"));
- }
+ if(opt->pressedState) {
+ repeatItem->setName(QLatin1String("qtg_graf_ratingslider_unrated_pressed"));
+ }
+ else {
+ repeatItem->setName(QLatin1String("qtg_graf_ratingslider_unrated"));
+ }
}
}
repeatItem->setGeometry(opt->boundingRect);
@@ -2833,14 +3014,12 @@
}
else {
-
- if(opt->pressedState) {
-
- repeatItem->setName(QLatin1String("qtg_graf_ratingslider_rated_pressed"));
- }
- else {
- repeatItem->setName(QLatin1String("qtg_graf_ratingslider_rated"));
- }
+ if(opt->pressedState) {
+ repeatItem->setName(QLatin1String("qtg_graf_ratingslider_rated_pressed"));
+ }
+ else {
+ repeatItem->setName(QLatin1String("qtg_graf_ratingslider_rated"));
+ }
}
}
repeatItem->setGeometry(opt->boundingRect);
@@ -3115,7 +3294,6 @@
if(!item) {
return;
}
- textItem->setTextWrapping(Hb::TextWrapAnywhere);
textItem->setText(opt->text);
}
break;
@@ -3126,7 +3304,6 @@
if(!item) {
return;
}
- textItem->setTextWrapping(Hb::TextWrapAnywhere);
textItem->setText(opt->additionalText);
}
break;
@@ -4172,4 +4349,5 @@
return HbWidgetBasePrivate::d_ptr(widgetBase);
}
+
#include "moc_hbstyle.cpp"