src/hbcore/style/hbstyle.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    85 #include <hbrichtextitem_p.h>
    85 #include <hbrichtextitem_p.h>
    86 #include <hbtoucharea.h>
    86 #include <hbtoucharea.h>
    87 #include <hbindicatorleveliconitem_p.h>
    87 #include <hbindicatorleveliconitem_p.h>
    88 
    88 
    89 #include <hbglobal.h>
    89 #include <hbglobal.h>
    90 #include <hbpluginloader_p.h>
       
    91 #include "hbstyleinterface_p.h"
       
    92 #include <hbstyleparameters.h>
    90 #include <hbstyleparameters.h>
    93 
    91 
    94 #include "hbstyleselector_p.h"
    92 #include "hbstyleselector_p.h"
    95 #include "hblayeredstyleloader_p.h"
    93 #include "hblayeredstyleloader_p.h"
    96 #include "hbwidgetstyleloader_p.h"
    94 #include "hbwidgetstyleloader_p.h"
    98 #include "hbrepeaticonitem_p.h"
    96 #include "hbrepeaticonitem_p.h"
    99 #include "hbnamespace_p.h"
    97 #include "hbnamespace_p.h"
   100 
    98 
   101 
    99 
   102 #include "hbanchorlayout.h"
   100 #include "hbanchorlayout.h"
   103 #include "hbanchorlayoutdebug_p.h"
   101 #include <hbanchor.h>
   104 #include "hbanchor_p.h"
       
   105 
   102 
   106 #include <QGraphicsWidget>
   103 #include <QGraphicsWidget>
   107 #include <hbwidget.h>
   104 #include <hbwidget.h>
   108 #include <hbwidgetbase.h>
   105 #include <hbwidgetbase.h>
   109 #include "hbdeviceprofile.h"
   106 #include "hbdeviceprofile.h"
   110 #include "hbrepeatitem_p.h"
   107 #include "hbrepeatitem_p.h"
   111 
   108 
   112 #include <QDebug>
   109 #include <QDebug>
       
   110 #include <QMetaClassInfo>
       
   111 
       
   112 Q_DECLARE_METATYPE(QGraphicsLayout*)
   113 
   113 
   114 //Uncomment next define(s) in order to get more debug prints.
   114 //Uncomment next define(s) in order to get more debug prints.
   115 //Similar define exists also in the engine side.
   115 //Similar define exists also in the engine side.
   116 //#define HBSTYLE_DEBUG
   116 //#define HBSTYLE_DEBUG
   117 
   117 
   135 
   135 
   136     Generally primitives should be updated only when a state change occurs. When a widget uses primitives to construct
   136     Generally primitives should be updated only when a state change occurs. When a widget uses primitives to construct
   137     itself it does not need a paint() method at all since primitives (widget's children) are doing the drawing. 
   137     itself it does not need a paint() method at all since primitives (widget's children) are doing the drawing. 
   138     Painting for the primitives occurs from the graphics scene.
   138     Painting for the primitives occurs from the graphics scene.
   139 
   139 
       
   140     HbStyle has some caching functionality and thus it should not be instantiated explicitly, but 
       
   141     accessed only through HbWidget::style() or HbInstance::style() APIs.
       
   142 
   140 */
   143 */
   141 
   144 
   142 /*!
   145 /*!
   143 
   146 
   144 	    \deprecated P_PushButton_icon
   147 	    \deprecated P_PushButton_icon
   791 static const QString COLOR_STYLE_LOCATION = QLatin1String(":/themes/style/hbdefault/rules/widgets/%w/%w_color");
   794 static const QString COLOR_STYLE_LOCATION = QLatin1String(":/themes/style/hbdefault/rules/widgets/%w/%w_color");
   792 static const int TOUCHAREA_ZVALUE = 1000;
   795 static const int TOUCHAREA_ZVALUE = 1000;
   793 
   796 
   794 static const QString GLOBAL_PARAMETERS_LOCATION = QLatin1String(":/themes/style/hbdefault/variables/layout/zoom/0/hbglobalparameters.css");
   797 static const QString GLOBAL_PARAMETERS_LOCATION = QLatin1String(":/themes/style/hbdefault/variables/layout/zoom/0/hbglobalparameters.css");
   795 
   798 
       
   799 static const char* LAYOUT_PTR_PROPERTY = "HbStyle_layout_ptr";
       
   800 static const char* LAYOUT_NAME_PROPERTY = "HbStyle_layout_name";
       
   801 
   796 inline void overrideSpacing( HbAnchorLayout *layout, const QString &name, Hb::Edge edge, qreal val )
   802 inline void overrideSpacing( HbAnchorLayout *layout, const QString &name, Hb::Edge edge, qreal val )
   797 {
   803 {
   798     if( name.isNull() ) {
   804     if( name.isNull() ) {
   799         return;
   805         return;
   800     }
   806     }
   801     QList<HbAnchor*> list = HbAnchorLayoutDebug::getOriginalAnchors( layout );
   807     QList<HbAnchor*> list = layout->anchors();
   802     for( int i = 0; i < list.size(); i++ ) {
   808     for( int i = 0; i < list.size(); i++ ) {
   803         HbAnchor *anchor = list.at(i);
   809         HbAnchor *anchor = list.at(i);
   804         if( ( anchor->mStartId == name ) && ( anchor->mStartEdge == edge ) ) {
   810         if( ( anchor->startNodeId() == name ) && ( anchor->startEdge() == edge ) ) {
   805             layout->setAnchor( anchor->mStartId, anchor->mStartEdge, anchor->mEndId, anchor->mEndEdge, val );
   811             anchor->setDirection( val < 0 ? HbAnchor::Negative : HbAnchor::Positive );
       
   812             anchor->setPreferredLength( qAbs(val) );
       
   813             if (anchor->anchorId().isEmpty()) {
       
   814                 // assuming it's a fixed anchor
       
   815                 anchor->setSizePolicy( QSizePolicy::Fixed );
       
   816             } else {
       
   817                 // assuming it's a "spacer" and we want to override the minimum length
       
   818                 anchor->setMinimumLength( qAbs(val) );
       
   819             }
   806         }
   820         }
   807     }
   821     }
   808 }
   822 }
   809 
   823 
   810 /*!
   824 /*!
   811 Constructor
   825 Constructor
       
   826 
       
   827 Should not be called explicitly. Use HbWidget::style() or HbInstance::style() instead.
   812 */
   828 */
   813 HbStyle::HbStyle() :
   829 HbStyle::HbStyle() :
   814     d_ptr(new HbStylePrivate)
   830     d_ptr(new HbStylePrivate)
   815 {
   831 {
   816     Q_D( HbStyle );
   832     Q_D( HbStyle );
   823 HbStyle::~HbStyle()
   839 HbStyle::~HbStyle()
   824 {
   840 {
   825     delete d_ptr;
   841     delete d_ptr;
   826 }
   842 }
   827 
   843 
   828 /*!
       
   829 
       
   830     \deprecated HbStyle::registerPlugin(const QString&)
       
   831     is deprecated. Style plugins are not supported anymore.
       
   832 
       
   833     Registers the style plugin with the Style system. This method can be called by a custom widget
       
   834     or application in order to register the style plugin that implements the custom graphics primitives.
       
   835     This method results in loading of the plugin, if the plugin is registered for the first time.
       
   836     It returns the base ID for the primitives implemented by the style plugin. The custom widget
       
   837     can use the range of integers from (BaseID) to (BaseID+count-1) to refer to the custom
       
   838     primitives, where count is the number of primitives supported by the plugin. The style
       
   839     plugin must return the correct number of primitives when the primitiveCount() method is called.
       
   840     In case of errors the method returns < 0. Note also that for each registerPlugin there must be
       
   841     a unregisterPlugin call, the last unregisterPlugin call for a plugin causes the plugin to be unloaded.
       
   842 
       
   843     If the style plugin implementation returns valid path with layout defition files (CSS+WidgetML)
       
   844     from layoutPath() method the layout definitions CSSs gets read when calling registerPlugin().
       
   845 
       
   846     \param pluginName, name of the Plugin library to be dynamically loaded
       
   847     \return int the base ID to be used for the primitives implemented by the style plugin
       
   848     \sa unregisterPlugin()
       
   849  */
       
   850 int HbStyle::registerPlugin(const QString &pluginName)
       
   851 {
       
   852     Q_D( const HbStyle );
       
   853 
       
   854     // check if the plugin is already registered
       
   855     if (d->registeredPlugins.contains(pluginName)) {
       
   856         // increase the reference count
       
   857         d->registeredPlugins.value(pluginName)->refCount++;
       
   858         // return the base ID of the primitives enumeration
       
   859         return d->registeredPlugins.value(pluginName)->primitiveBaseId;
       
   860     }
       
   861 
       
   862     // load the plugin
       
   863     HbPluginLoader* loader = new HbPluginLoader(pluginName);
       
   864     if (!loader)
       
   865         return -1;
       
   866 
       
   867     // get the instance pointer
       
   868     QObject* pluginInstance = loader->instance();
       
   869     if (!pluginInstance) {
       
   870 
       
   871         // try the additional paths
       
   872         QFileInfo fileInfo(pluginName);
       
   873         foreach (QString additionalPath, hbInstance->libraryPaths()) {
       
   874             const QDir pluginDir(additionalPath);
       
   875             loader->setPluginName(pluginDir.absoluteFilePath(fileInfo.fileName()));
       
   876             pluginInstance = loader->instance();
       
   877             if (pluginInstance) {
       
   878                 break;
       
   879             }
       
   880         }
       
   881 
       
   882         if (!pluginInstance) {
       
   883             delete loader;
       
   884             return -1;
       
   885         }
       
   886     }
       
   887 
       
   888     HbStyleInterface *stylePlugin = qobject_cast<HbStyleInterface *>(pluginInstance);
       
   889 
       
   890     int primitiveCount = stylePlugin->primitiveCount();
       
   891     if (primitiveCount <= 0) {
       
   892         delete pluginInstance;
       
   893         delete loader;
       
   894         return -1;
       
   895     }
       
   896 
       
   897     HbStyleInterfaceInfo* info = new HbStyleInterfaceInfo();
       
   898     info->loader = loader;
       
   899     info->primitiveBaseId = d->nextAvailableId;
       
   900 
       
   901     // make entries for the primitives in the hash table
       
   902     for (int i=d->nextAvailableId; i<(d->nextAvailableId+primitiveCount); i++)
       
   903     {
       
   904         d->customPrimitives.insert(i, info);
       
   905     }
       
   906 
       
   907     // make entry for the plugin in the registered plugins hash table
       
   908     HbStylePluginInfo* pluginInfo = new HbStylePluginInfo();
       
   909     pluginInfo->primitiveBaseId = d->nextAvailableId;
       
   910     pluginInfo->primitiveCount = primitiveCount;
       
   911     pluginInfo->refCount = 1;
       
   912 
       
   913     d->registeredPlugins.insert(pluginName, pluginInfo);
       
   914     d->nextAvailableId += primitiveCount;
       
   915 
       
   916     // register associated style files
       
   917     HbWidgetStyleLoader::instance()->addFilePath(
       
   918         stylePlugin->layoutPath(),
       
   919         HbLayeredStyleLoader::Concern_Layouts,
       
   920         HbLayeredStyleLoader::Priority_Core);
       
   921     d->pluginStylePaths.insert(pluginName, stylePlugin->layoutPath());
       
   922 
       
   923     return pluginInfo->primitiveBaseId;
       
   924 }
       
   925 
       
   926 
       
   927 /*!
       
   928 
       
   929     \deprecated HbStyle::unregisterPlugin(const QString&)
       
   930     is deprecated. Style plugins are not supported anymore.
       
   931 
       
   932     Un-registers the style plugin.
       
   933     If the reference count becomes zero, the plugin is unloaded and the primitive IDs are de-registered
       
   934     If a client has called registerPlugin() it must unregister the style plugin with this method.
       
   935 
       
   936     \param pluginName, name of the Plugin library
       
   937  */
       
   938 void HbStyle::unregisterPlugin(const QString &pluginName)
       
   939 {
       
   940     Q_D( const HbStyle );
       
   941     if (d->registeredPlugins.contains(pluginName)) {
       
   942         HbStylePluginInfo *info = d->registeredPlugins.value(pluginName);
       
   943         info->refCount--;
       
   944         // unload plugin and remove from list
       
   945         if (info->refCount == 0) {
       
   946             HbStyleInterfaceInfo* styleInfo = d->customPrimitives.value(info->primitiveBaseId);
       
   947             delete styleInfo->loader->instance();
       
   948             delete styleInfo->loader;
       
   949             delete styleInfo;
       
   950             for (int i=info->primitiveBaseId; i< (info->primitiveBaseId+info->primitiveCount); i++) {
       
   951                   d->customPrimitives.remove(i);
       
   952             }
       
   953             d->registeredPlugins.remove(pluginName);
       
   954 
       
   955             // unregister associated style files
       
   956             HbWidgetStyleLoader::instance()->removeFilePath(
       
   957                 d->pluginStylePaths.value(pluginName),
       
   958                 HbLayeredStyleLoader::Concern_Layouts,
       
   959                 HbLayeredStyleLoader::Priority_Core);
       
   960             d->pluginStylePaths.remove(pluginName);
       
   961 
       
   962             if( d->registeredPlugins.count() == 0 ){
       
   963                 // no plugins loaded, can reset the id counter
       
   964                 d->nextAvailableId = HbStyle::P_CustomBase;
       
   965             }
       
   966 
       
   967         }
       
   968     }
       
   969 }
       
   970 
       
   971 
   844 
   972 /*!
   845 /*!
   973 
   846 
   974   \deprecated HbStyle::createPrimitive(HbStyle::Primitive, QGraphicsItem*)
   847   \deprecated HbStyle::createPrimitive(HbStyle::Primitive, QGraphicsItem*)
   975   is deprecated. This method will be replaced with an altered version which will use new base primitive enumerations.
   848   is deprecated. This method will be replaced with an altered version which will use new base primitive enumerations.
   990   \return HbWidgetBase is returned.
   863   \return HbWidgetBase is returned.
   991 
   864 
   992  */
   865  */
   993 QGraphicsItem *HbStyle::createPrimitive( HbStyle::Primitive primitive, QGraphicsItem *parent ) const
   866 QGraphicsItem *HbStyle::createPrimitive( HbStyle::Primitive primitive, QGraphicsItem *parent ) const
   994 {
   867 {
   995 
       
   996     Q_D( const HbStyle );
       
   997 
       
   998     if (d->customPrimitives.contains(primitive)) {
       
   999         HbStyleInterfaceInfo* info = d->customPrimitives.value(primitive);
       
  1000         QObject* pluginInstance = info->loader->instance();
       
  1001         HbStyleInterface *stylePlugin = qobject_cast<HbStyleInterface *>(pluginInstance);
       
  1002         return stylePlugin->createPrimitive((HbStyle::Primitive)(primitive-info->primitiveBaseId), parent);
       
  1003     }
       
  1004 
   868 
  1005         switch (primitive){
   869         switch (primitive){
  1006             case P_MenuItem_submenuindicator:
   870             case P_MenuItem_submenuindicator:
  1007                 {
   871                 {
  1008                 HbIconItem *item = new HbIconItem(parent);
   872                 HbIconItem *item = new HbIconItem(parent);
  1115                 HbTouchArea *ta = new HbTouchArea(parent);
   979                 HbTouchArea *ta = new HbTouchArea(parent);
  1116                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
   980                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1117                 setItemName(ta, QLatin1String("toucharea"));
   981                 setItemName(ta, QLatin1String("toucharea"));
  1118                 ta->setZValue(TOUCHAREA_ZVALUE);
   982                 ta->setZValue(TOUCHAREA_ZVALUE);
  1119                 if(parent){
   983                 if(parent){
  1120                     parent->setHandlesChildEvents(true);
   984                     parent->setFiltersChildEvents(true);
  1121                 }
   985                 }
  1122                 return ta;
   986                 return ta;
  1123                 }
   987                 }
  1124 
   988 
  1125             case P_ProgressSliderHandle_icon:
   989             case P_ProgressSliderHandle_icon:
  1135                 {
   999                 {
  1136                 HbTouchArea *ta = new HbTouchArea(parent);
  1000                 HbTouchArea *ta = new HbTouchArea(parent);
  1137                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1001                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1138                 setItemName(ta, QLatin1String("toucharea"));
  1002                 setItemName(ta, QLatin1String("toucharea"));
  1139                 if(parent){
  1003                 if(parent){
  1140                     parent->setHandlesChildEvents(true);
  1004                     parent->setFiltersChildEvents(true);
  1141                 }
  1005                 }
  1142                 return ta;
  1006                 return ta;
  1143                 }
  1007                 }
  1144             case P_ScrollBar_toucharea:
  1008             case P_ScrollBar_toucharea:
  1145                 {
  1009                 {
  1155             case P_ComboBoxButton_toucharea:
  1019             case P_ComboBoxButton_toucharea:
  1156                 {
  1020                 {
  1157                 HbTouchArea *ta = new HbTouchArea(parent);
  1021                 HbTouchArea *ta = new HbTouchArea(parent);
  1158                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1022                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1159                 setItemName(ta, QLatin1String("combobox_button_toucharea"));
  1023                 setItemName(ta, QLatin1String("combobox_button_toucharea"));
  1160                 /*if(parent){
  1024                 if(parent){
  1161                     parent->setHandlesChildEvents(true);
  1025                     parent->setFiltersChildEvents(true);
  1162                 }*/
  1026                 }
  1163                 return ta;
  1027                 return ta;
  1164                 }
  1028                 }
  1165              case P_TitleBar_toucharea: {
  1029              case P_TitleBar_toucharea: 
       
  1030                 {
  1166                 HbTouchArea *ta = new HbTouchArea(parent);
  1031                 HbTouchArea *ta = new HbTouchArea(parent);
  1167                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1032                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1168                 setItemName(ta, QLatin1String("toucharea"));
  1033                 setItemName(ta, QLatin1String("toucharea"));
       
  1034                 return ta;
       
  1035                 }
       
  1036              case P_IndicatorButton_toucharea:
       
  1037              case P_TitlePane_toucharea:
       
  1038              case P_NavigationButton_toucharea:
       
  1039                 {
       
  1040                 HbTouchArea *ta = new HbTouchArea(parent);
       
  1041                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
       
  1042                 setItemName(ta, QLatin1String("toucharea"));
       
  1043                 if (parent){
       
  1044                     parent->setHandlesChildEvents(true);
       
  1045                 }
  1169                 return ta;
  1046                 return ta;
  1170                 }
  1047                 }
  1171              case P_SliderElement_touchdecrease:
  1048              case P_SliderElement_touchdecrease:
  1172              case P_SliderElement_touchincrease:
  1049              case P_SliderElement_touchincrease:
  1173              case P_SliderElement_touchgroove:
  1050              case P_SliderElement_touchgroove:
  1174                 {
  1051                 {
  1175                 HbTouchArea *ta = new HbTouchArea(parent);
  1052                 HbTouchArea *ta = new HbTouchArea(parent);
  1176                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1053                 ta->setFlag(QGraphicsItem::ItemIsFocusable);
  1177                 if(parent){
  1054                 if(parent){
  1178                     //parent->setHandlesChildEvents(true);
  1055                     parent->setFiltersChildEvents(true);
  1179                 }
  1056                 }
  1180                 return ta;
  1057                 return ta;
  1181                 }
  1058                 }
  1182             case P_SliderElement_text:
  1059             case P_SliderElement_text:
  1183             case P_ProgressBar_text:
  1060             case P_ProgressBar_text:
  1573                 return n;
  1450                 return n;
  1574             }
  1451             }
  1575 
  1452 
  1576             case P_ItemViewItem_background: {
  1453             case P_ItemViewItem_background: {
  1577                 HbIconItem *iconItem = q_check_ptr(new HbIconItem(parent));
  1454                 HbIconItem *iconItem = q_check_ptr(new HbIconItem(parent));
       
  1455                 iconItem->setZValue(-3.0);
  1578                 setItemName(iconItem, QLatin1String("background"));
  1456                 setItemName(iconItem, QLatin1String("background"));
  1579                 return iconItem;
  1457                 return iconItem;
  1580             }
  1458             }
  1581 
  1459 
  1582             case P_ListViewItem_text: {
  1460             case P_ListViewItem_text: {
  1635             case P_ComboBox_button: {
  1513             case P_ComboBox_button: {
  1636                 HbIconItem *n = new HbIconItem(QString(), parent);
  1514                 HbIconItem *n = new HbIconItem(QString(), parent);
  1637                 return n;
  1515                 return n;
  1638             }
  1516             }
  1639             case P_ItemViewItem_focus: {
  1517             case P_ItemViewItem_focus: {
  1640                 HbFrameItem *item = q_check_ptr(new HbFrameItem(parent));
  1518                 HbFrameItem *frameItem = q_check_ptr(new HbFrameItem(parent));
  1641                 //setItemName(item, QLatin1String("focus-indicator"));
  1519                 frameItem->setZValue(-1.0);
  1642                 return item;
  1520                 return frameItem;
  1643             }
  1521             }
  1644             case P_ItemHighlight_background:
  1522             case P_ItemHighlight_background:
  1645                 return new HbFrameItem(parent);
  1523                 return new HbFrameItem(parent);
  1646 
  1524 
  1647             case P_ItemViewItem_frame: {
  1525             case P_ItemViewItem_frame: {
  1648                 HbFrameItem *item = q_check_ptr(new HbFrameItem(parent));
  1526                 HbFrameItem *item = q_check_ptr(new HbFrameItem(parent));
       
  1527                 item->setZValue(-4.0);
  1649                 setItemName(item,"frame");
  1528                 setItemName(item,"frame");
  1650                 return item;
  1529                 return item;
  1651             }
  1530             }
  1652             case P_ScrollArea_continuationbottom:
  1531             case P_ScrollArea_continuationbottom:
  1653             {
  1532             {
  1743  */
  1622  */
  1744 void HbStyle::updatePrimitive( QGraphicsItem *item, HbStyle::Primitive primitive, const QStyleOption *option ) const
  1623 void HbStyle::updatePrimitive( QGraphicsItem *item, HbStyle::Primitive primitive, const QStyleOption *option ) const
  1745 {
  1624 {
  1746     Q_D( const HbStyle );
  1625     Q_D( const HbStyle );
  1747 
  1626 
  1748     if (d->customPrimitives.contains(primitive)) {
       
  1749         HbStyleInterfaceInfo* info = d->customPrimitives.value(primitive);
       
  1750         QObject* pluginInstance = info->loader->instance();
       
  1751         HbStyleInterface *stylePlugin = qobject_cast<HbStyleInterface *>(pluginInstance);
       
  1752         return stylePlugin->updatePrimitive(item, (HbStyle::Primitive)(primitive-info->primitiveBaseId), option);
       
  1753     }
       
  1754 
       
  1755     switch(primitive){
  1627     switch(primitive){
  1756             case P_PushButton_icon:
  1628             case P_PushButton_icon:
  1757                 {
  1629                 {
  1758                     if (const HbStyleOptionPushButton *opt =
  1630                     if (const HbStyleOptionPushButton *opt =
  1759                         qstyleoption_cast<const HbStyleOptionPushButton*>(option)) {
  1631                         qstyleoption_cast<const HbStyleOptionPushButton*>(option)) {
  1867                 break;
  1739                 break;
  1868             case P_PushButton_toucharea:  // Generic implementation, can add other cases here
  1740             case P_PushButton_toucharea:  // Generic implementation, can add other cases here
  1869             case P_ComboBoxButton_toucharea:
  1741             case P_ComboBoxButton_toucharea:
  1870             case P_CheckBox_toucharea:
  1742             case P_CheckBox_toucharea:
  1871             case P_TitleBar_toucharea:
  1743             case P_TitleBar_toucharea:
       
  1744             case P_IndicatorButton_toucharea:
       
  1745             case P_TitlePane_toucharea:
       
  1746             case P_NavigationButton_toucharea:
  1872             case P_SliderElement_touchdecrease:
  1747             case P_SliderElement_touchdecrease:
  1873             case P_SliderElement_touchincrease:
  1748             case P_SliderElement_touchincrease:
  1874             case P_SliderElement_touchgroove:
  1749             case P_SliderElement_touchgroove:
  1875             case P_SliderElement_touchhandle:
  1750             case P_SliderElement_touchhandle:
  1876             case P_ScrollBar_toucharea:
  1751             case P_ScrollBar_toucharea:
  2397 
  2272 
  2398                 if (opt) {
  2273                 if (opt) {
  2399                     HbMarqueeItem *marqueeItem = static_cast<HbMarqueeItem*>( item );
  2274                     HbMarqueeItem *marqueeItem = static_cast<HbMarqueeItem*>( item );
  2400                     if (marqueeItem) {
  2275                     if (marqueeItem) {
  2401                         marqueeItem->setText(opt->caption);
  2276                         marqueeItem->setText(opt->caption);
  2402                         marqueeItem->startAnimation();
       
  2403                     }
  2277                     }
  2404                 }
  2278                 }
  2405                 break;
  2279                 break;
  2406             }
  2280             }
  2407 
  2281 
  3160                 if (const HbStyleOptionNotificationDialog *opt =
  3034                 if (const HbStyleOptionNotificationDialog *opt =
  3161                         qstyleoption_cast<const HbStyleOptionNotificationDialog *>(option)) {
  3035                         qstyleoption_cast<const HbStyleOptionNotificationDialog *>(option)) {
  3162                     HbTextItem *textItem = static_cast<HbTextItem*>(item);
  3036                     HbTextItem *textItem = static_cast<HbTextItem*>(item);
  3163                     textItem->setAlignment(opt->textAlignment);
  3037                     textItem->setAlignment(opt->textAlignment);
  3164                     textItem->setFontSpec(HbFontSpec(HbFontSpec::Secondary));
  3038                     textItem->setFontSpec(HbFontSpec(HbFontSpec::Secondary));
  3165                     textItem->setTextWrapping(opt->wrappingText);
  3039                     textItem->setTextWrapping(opt->textTextWrapping);
  3166                     textItem->setText(opt->text);
  3040                     textItem->setText(opt->text);
  3167                 }
  3041                 }
  3168                 break;
  3042                 break;
  3169             case P_NotificationDialog_title:
  3043             case P_NotificationDialog_title:
  3170                 if (const HbStyleOptionNotificationDialog *opt =
  3044                 if (const HbStyleOptionNotificationDialog *opt =
  3171                         qstyleoption_cast<const HbStyleOptionNotificationDialog *>(option)) {
  3045                         qstyleoption_cast<const HbStyleOptionNotificationDialog *>(option)) {
  3172                     HbTextItem *textItem = static_cast<HbTextItem*>(item);
  3046                     HbTextItem *textItem = static_cast<HbTextItem*>(item);
  3173 
       
  3174                     textItem->setAlignment(opt->titleAlignment);
  3047                     textItem->setAlignment(opt->titleAlignment);
  3175                     textItem->setFontSpec(HbFontSpec(HbFontSpec::Primary));
  3048                     textItem->setFontSpec(HbFontSpec(HbFontSpec::Primary));
  3176                     textItem->setTextWrapping(opt->wrappingTitle);
  3049                     textItem->setTextWrapping(opt->titleTextWrapping);
       
  3050                     if (opt->titleTextWrapping == Hb::TextNoWrap) {
       
  3051                         textItem->setElideMode(Qt::ElideNone);
       
  3052                     } else {
       
  3053                         textItem->setElideMode(Qt::ElideRight);
       
  3054                     }
  3177                     textItem->setText(opt->title);
  3055                     textItem->setText(opt->title);
  3178                 }
  3056                 }
  3179                 break;
  3057                 break;
  3180             case P_NotificationDialog_icon:
  3058             case P_NotificationDialog_icon:
  3181                 if (const HbStyleOptionNotificationDialog *opt =
  3059                 if (const HbStyleOptionNotificationDialog *opt =
  3277             case P_ListViewItem_icon:
  3155             case P_ListViewItem_icon:
  3278                 if (const HbStyleOptionListViewItem *opt = qstyleoption_cast<const HbStyleOptionListViewItem *>(option)) {
  3156                 if (const HbStyleOptionListViewItem *opt = qstyleoption_cast<const HbStyleOptionListViewItem *>(option)) {
  3279                     HbIconItem *iconItem = static_cast<HbIconItem*>(item);
  3157                     HbIconItem *iconItem = static_cast<HbIconItem*>(item);
  3280 
  3158 
  3281                     setItemName(iconItem, QLatin1String("icon-") + QString::number(opt->index + 1));
  3159                     setItemName(iconItem, QLatin1String("icon-") + QString::number(opt->index + 1));
  3282                     iconItem->setZValue(opt->index + 1);
  3160                     if (iconItem->zValue() != opt->index + 1) {
       
  3161                         iconItem->setZValue(opt->index + 1);
       
  3162                     }
  3283 
  3163 
  3284                     if (opt->content.canConvert<HbIcon>()){
  3164                     if (opt->content.canConvert<HbIcon>()){
  3285                         iconItem->setIcon(opt->content.value<HbIcon>());
  3165                         iconItem->setIcon(opt->content.value<HbIcon>());
  3286                     } if (opt->content.canConvert<QIcon>()){
  3166                     } if (opt->content.canConvert<QIcon>()){
  3287                         iconItem->setIcon(opt->content.value<QIcon>());
  3167                         iconItem->setIcon(opt->content.value<QIcon>());
  3594                 }*/
  3474                 }*/
  3595                 break;
  3475                 break;
  3596             case P_ItemViewItem_background:
  3476             case P_ItemViewItem_background:
  3597                 if (const HbStyleOptionAbstractViewItem *opt = qstyleoption_cast<const HbStyleOptionAbstractViewItem *>(option)) {
  3477                 if (const HbStyleOptionAbstractViewItem *opt = qstyleoption_cast<const HbStyleOptionAbstractViewItem *>(option)) {
  3598                     HbIconItem *iconItem = static_cast<HbIconItem*>(item);
  3478                     HbIconItem *iconItem = static_cast<HbIconItem*>(item);
  3599                     iconItem->setZValue(-3.0);
       
  3600                     iconItem->setGeometry(opt->boundingRect);
  3479                     iconItem->setGeometry(opt->boundingRect);
  3601                     if (opt->background.canConvert<HbIcon>()){
  3480                     if (opt->background.canConvert<HbIcon>()){
  3602                         iconItem->setIcon(opt->background.value<HbIcon>());
  3481                         iconItem->setIcon(opt->background.value<HbIcon>());
  3603                     } else if (opt->background.canConvert<QBrush>()){
  3482                     } else if (opt->background.canConvert<QBrush>()){
  3604                         iconItem->setBrush(opt->background.value<QBrush>());
  3483                         iconItem->setBrush(opt->background.value<QBrush>());
  3607 
  3486 
  3608                 break;
  3487                 break;
  3609             case P_ItemViewItem_frame:
  3488             case P_ItemViewItem_frame:
  3610                 if (const HbStyleOptionAbstractViewItem *opt = qstyleoption_cast<const HbStyleOptionAbstractViewItem *>(option)) {
  3489                 if (const HbStyleOptionAbstractViewItem *opt = qstyleoption_cast<const HbStyleOptionAbstractViewItem *>(option)) {
  3611                     HbFrameItem *frameItem = static_cast<HbFrameItem*>(item);
  3490                     HbFrameItem *frameItem = static_cast<HbFrameItem*>(item);
  3612                     frameItem->setZValue(-4.0);
       
  3613                     frameItem->setGeometry(opt->boundingRect);
  3491                     frameItem->setGeometry(opt->boundingRect);
  3614 
  3492 
  3615                     if (opt->background.canConvert<HbFrameBackground>()) {
  3493                     if (opt->background.canConvert<HbFrameBackground>()) {
  3616                         HbFrameBackground frame = opt->background.value<HbFrameBackground>();
  3494                         HbFrameBackground frame = opt->background.value<HbFrameBackground>();
  3617                         frameItem->frameDrawer().setFrameType(frame.frameType());
  3495                         frameItem->frameDrawer().setFrameType(frame.frameType());
  3651                 }
  3529                 }
  3652                 break;
  3530                 break;
  3653             case P_ItemViewItem_focus:
  3531             case P_ItemViewItem_focus:
  3654                 if (const HbStyleOptionAbstractViewItem *opt = qstyleoption_cast<const HbStyleOptionAbstractViewItem *>(option)) {
  3532                 if (const HbStyleOptionAbstractViewItem *opt = qstyleoption_cast<const HbStyleOptionAbstractViewItem *>(option)) {
  3655                     HbFrameItem *frameItem = static_cast<HbFrameItem*>(item);
  3533                     HbFrameItem *frameItem = static_cast<HbFrameItem*>(item);
  3656                     frameItem->setZValue(-1.0);
       
  3657                     frameItem->setGeometry(opt->boundingRect);
  3534                     frameItem->setGeometry(opt->boundingRect);
  3658 
  3535 
  3659                     if (opt->viewItemType == Hb::ItemType_TreeViewItem
  3536                     if (opt->viewItemType == Hb::ItemType_TreeViewItem
  3660                         || opt->viewItemType == Hb::ItemType_ListViewItem
  3537                         || opt->viewItemType == Hb::ItemType_ListViewItem
  3661                         || opt->viewItemType == Hb::ItemType_RadioButtonListViewItem) {
  3538                         || opt->viewItemType == Hb::ItemType_RadioButtonListViewItem) {
  3721                 break;
  3598                 break;
  3722 
  3599 
  3723             case P_TumbleView_background:
  3600             case P_TumbleView_background:
  3724                 if (const HbStyleOption *opt = qstyleoption_cast<const HbStyleOption*>(option)) {
  3601                 if (const HbStyleOption *opt = qstyleoption_cast<const HbStyleOption*>(option)) {
  3725                     if(HbFrameItem *frameItem = qgraphicsitem_cast<HbFrameItem*>(item)) {
  3602                     if(HbFrameItem *frameItem = qgraphicsitem_cast<HbFrameItem*>(item)) {
  3726                         frameItem->frameDrawer().setFrameGraphicsName("qtg_fr_tumbler_bg");
  3603 
       
  3604                         //Temporary source to avoid introducing new style primitive for selection dialog mark widget background item.
       
  3605                         QGraphicsItem *parent = frameItem->parentItem();
       
  3606                         const QMetaObject *obj = parent->toGraphicsObject()->metaObject();
       
  3607 
       
  3608                         QString className;
       
  3609                         if(obj){
       
  3610                             className = obj->className();
       
  3611                         }
       
  3612                         ///////////////////////////////////////////////////////////
       
  3613                         
       
  3614                         if( !className.compare("HbTumbleView") ){
       
  3615                             frameItem->frameDrawer().setFrameGraphicsName("qtg_fr_tumbler_bg");
       
  3616                         }
       
  3617                         else if( !className.compare("HbSelectionDialogMarkWidget") )
       
  3618                         {
       
  3619                             frameItem->frameDrawer().setFrameGraphicsName("qtg_fr_groupbox");
       
  3620                         }
  3727                         frameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
  3621                         frameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
  3728                         frameItem->setZValue(-5);
  3622                         frameItem->setZValue(-5);
  3729                         //TODO:temp fix, issue with css rule picking in derived class
  3623                         //TODO:temp fix, issue with css rule picking in derived class
  3730                         //frameItem->setGeometry(opt->boundingRect);
  3624                         //frameItem->setGeometry(opt->boundingRect);
  3731                         Q_UNUSED(opt);
  3625                         Q_UNUSED(opt);
  3833                     }
  3727                     }
  3834                     textItem->setTextWrapping(Hb::TextWrapAnywhere);
  3728                     textItem->setTextWrapping(Hb::TextWrapAnywhere);
  3835                     textItem->setText(opt->additionalText);
  3729                     textItem->setText(opt->additionalText);
  3836                 }
  3730                 }
  3837                 break;
  3731                 break;
       
  3732 
  3838              default:
  3733              default:
  3839                 return;
  3734                 return;
  3840     };
  3735     };
  3841 }
  3736 }
  3842 
  3737 
  3893   used by the polish() method
  3788   used by the polish() method
  3894   \internal
  3789   \internal
  3895 */
  3790 */
  3896 void HbStylePrivate::polishItem(
  3791 void HbStylePrivate::polishItem(
  3897     const HbVector<HbCss::StyleRule> &styleRules,
  3792     const HbVector<HbCss::StyleRule> &styleRules,
  3898     HbWidget* widget,
  3793     HbWidget *widget,
  3899     QGraphicsItem *item,
  3794     QGraphicsItem *item,
  3900     const QString &name,
  3795     const QString &name,
       
  3796     HbDeviceProfile &profile,
  3901     bool layoutDefined) const
  3797     bool layoutDefined) const
  3902 {
  3798 {
  3903     if (name.isEmpty() && widget != item) {
  3799     if (name.isEmpty() && widget != item) {
  3904         return;
  3800         return;
  3905     }
  3801     }
  3913     } else {
  3809     } else {
  3914         qDebug() << "HbStyle::polishItem : -- item name: " << name << "(missing item)";
  3810         qDebug() << "HbStyle::polishItem : -- item name: " << name << "(missing item)";
  3915     }
  3811     }
  3916 #endif
  3812 #endif
  3917 
  3813 
  3918     QGraphicsLayoutItem* lItem = (item && item->isWidget()) ? (QGraphicsLayoutItem*)static_cast<QGraphicsWidget*>(item) : 0;
       
  3919     if ( !lItem ) {
       
  3920         lItem = widget->layoutPrimitive(name);
       
  3921         if ( lItem && !lItem->graphicsItem() ) {
       
  3922             // assume it is spacer
       
  3923             static_cast<HbAnchorLayout*>(widget->layout())->setMapping( lItem, name );
       
  3924         }
       
  3925     }
       
  3926 
       
  3927     HbDeviceProfile profile(HbDeviceProfile::profile(widget));
       
  3928 
       
  3929     const HbVector<HbCss::Declaration> decl = declarations(styleRules, name, widget, profile);
  3814     const HbVector<HbCss::Declaration> decl = declarations(styleRules, name, widget, profile);
  3930 #ifdef HBSTYLE_DEBUG
  3815 #ifdef HBSTYLE_DEBUG
  3931     qDebug() << "HbStyle::polishItem : -- Number of matching CSS declarations: " << decl.count();
  3816     qDebug() << "HbStyle::polishItem : -- Number of matching CSS declarations: " << decl.count();
  3932 #endif
  3817 #endif
  3933     HbCss::ValueExtractor extractor(decl, layoutParameters, profile);
  3818     HbCss::ValueExtractor extractor(decl, layoutParameters, profile);
  4102                 hbWidget_p->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMax, false);
  3987                 hbWidget_p->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextLinesMax, false);
  4103             }
  3988             }
  4104         }
  3989         }
  4105     }
  3990     }
  4106 
  3991 
       
  3992     QGraphicsLayoutItem* lItem = (item && item->isWidget())
       
  3993         ? (QGraphicsLayoutItem*)static_cast<QGraphicsWidget*>(item)
       
  3994         : 0;
  4107     if ( lItem ) {
  3995     if ( lItem ) {
  4108         if ( prop.mFlags & HbCss::ExtractedMinW ) {
  3996         if ( prop.mFlags & HbCss::ExtractedMinW ) {
  4109 #ifdef HBSTYLE_DEBUG
  3997 #ifdef HBSTYLE_DEBUG
  4110             qDebug() << "HbStyle::polishItem : -- Setting minimum width: " << prop.mMinW;
  3998             qDebug() << "HbStyle::polishItem : -- Setting minimum width: " << prop.mMinW;
  4111 #endif
  3999 #endif
  4197                 overrideSpacing(layout, name, Hb::CenterVEdge, prop.mCenterV);
  4085                 overrideSpacing(layout, name, Hb::CenterVEdge, prop.mCenterV);
  4198             }
  4086             }
  4199         }
  4087         }
  4200     }
  4088     }
  4201 }
  4089 }
       
  4090 
       
  4091 void HbStylePrivate::polishAnchor(
       
  4092     const HbVector<HbCss::StyleRule> &styleRules,
       
  4093     HbWidget *widget,
       
  4094     HbAnchor *anchor,
       
  4095     HbDeviceProfile &profile) const
       
  4096 {
       
  4097 #ifdef HBSTYLE_DEBUG
       
  4098     qDebug() << "HbStyle::polish : -- --";
       
  4099     qDebug() << "HbStyle::polishAnchor : -- anchor id: " << anchor->anchorId();
       
  4100 #endif
       
  4101 
       
  4102     const HbVector<HbCss::Declaration> decl = declarations(styleRules, anchor->anchorId(), widget, profile);
       
  4103 #ifdef HBSTYLE_DEBUG
       
  4104     qDebug() << "HbStyle::polishAnchor : -- Number of matching CSS declarations: " << decl.count();
       
  4105 #endif
       
  4106     HbCss::ValueExtractor extractor(decl, layoutParameters, profile);
       
  4107     HbCss::KnownProperties prop;
       
  4108 
       
  4109     if ( !extractor.extractKnownProperties(prop) ) {
       
  4110 #ifdef HBSTYLE_DEBUG
       
  4111         qDebug() << "HbStyle::polishAnchor : -- No polish overrides found";
       
  4112 #endif
       
  4113         return;
       
  4114     }
       
  4115 
       
  4116 
       
  4117     if ( prop.mFlags & HbCss::ExtractedMinH || prop.mFlags & HbCss::ExtractedMinW ) {
       
  4118         qreal minLength = prop.mFlags & HbCss::ExtractedMinH ? prop.mMinH : prop.mMinW;
       
  4119 #ifdef HBSTYLE_DEBUG
       
  4120         qDebug() << "HbStyle::polishAnchor : -- Setting minimum length: " << minLength;
       
  4121 #endif
       
  4122         anchor->setMinimumLength( minLength );
       
  4123     }
       
  4124     if ( prop.mFlags & HbCss::ExtractedPrefH || prop.mFlags & HbCss::ExtractedPrefW ) {
       
  4125         qreal prefLength = prop.mFlags & HbCss::ExtractedPrefH ? prop.mPrefH : prop.mPrefW;
       
  4126 #ifdef HBSTYLE_DEBUG
       
  4127         qDebug() << "HbStyle::polishAnchor : -- Setting preferred length: " << prefLength;
       
  4128 #endif
       
  4129         anchor->setPreferredLength( prefLength );
       
  4130     }
       
  4131     if ( prop.mFlags & HbCss::ExtractedMaxH || prop.mFlags & HbCss::ExtractedMaxW ) {
       
  4132         qreal maxLength = prop.mFlags & HbCss::ExtractedMaxH ? prop.mMaxH : prop.mMaxW;
       
  4133 #ifdef HBSTYLE_DEBUG
       
  4134         qDebug() << "HbStyle::polishAnchor : -- Setting maximum length: " << maxLength;
       
  4135 #endif
       
  4136         anchor->setMaximumLength( maxLength );
       
  4137     }
       
  4138     if ( prop.mFlags & HbCss::ExtractedPolVer || prop.mFlags & HbCss::ExtractedPolHor ) {
       
  4139         QSizePolicy::Policy policy = prop.mFlags & HbCss::ExtractedPolVer
       
  4140             ? prop.mSizePolicy.verticalPolicy() : prop.mSizePolicy.horizontalPolicy();
       
  4141 #ifdef HBSTYLE_DEBUG
       
  4142         qDebug() << "HbStyle::polishAnchor : -- Setting size policy: " << policy;
       
  4143 #endif
       
  4144         anchor->setSizePolicy( policy );
       
  4145     }
       
  4146     if ( prop.mFlags & HbCss::ExtractedAnchorDir ) {
       
  4147 #ifdef HBSTYLE_DEBUG
       
  4148         qDebug() << "HbStyle::polishAnchor : -- Setting anchor direction: " << prop.mAnchorDir;
       
  4149 #endif
       
  4150         anchor->setDirection( prop.mAnchorDir );
       
  4151     }
       
  4152 }
       
  4153 
  4202 
  4154 
  4203 
  4155 
  4204 #define NODEPTR_N(x) HbCss::StyleSelector::NodePtr n = {n.ptr = (void *)x};
  4156 #define NODEPTR_N(x) HbCss::StyleSelector::NodePtr n = {n.ptr = (void *)x};
  4205 /*!
  4157 /*!
  4206     Polishes the appearance of the given \a widget.
  4158     Polishes the appearance of the given \a widget.
  4287     } else {
  4239     } else {
  4288         qDebug() << "HbStyle::polish : Layout name: " << layoutName;
  4240         qDebug() << "HbStyle::polish : Layout name: " << layoutName;
  4289     }
  4241     }
  4290 #endif
  4242 #endif
  4291 
  4243 
  4292     QStringList meshIds;
  4244     QStringList nodeIds;
  4293     HbAnchorLayout *meshLayout(0);
  4245     HbAnchorLayout *anchorLayout(0);
  4294     if (layoutDefined) {
  4246     if (layoutDefined) {
  4295 
  4247 
  4296         QString cachedLayoutName = widgetLayoutNames[widget];
  4248         // check that we do not override the user defined layout
  4297         bool cached = (cachedLayoutName == layoutName );
  4249         const QVariant layoutPtrByStyleV = widget->property( LAYOUT_PTR_PROPERTY );
  4298         if ( !cached ) {
  4250         const QGraphicsLayout *layoutPtrByStyle = layoutPtrByStyleV.isValid() ? layoutPtrByStyleV.value<QGraphicsLayout*>() : 0;
  4299 #ifdef HBSTYLE_DEBUG
  4251         const QGraphicsLayout *existingLayoutPtr = widget->layout();
  4300             qDebug() << "LayoutName cache miss.";
  4252 
  4301 #endif
  4253         if ( existingLayoutPtr && (existingLayoutPtr!=layoutPtrByStyle) ) {
  4302             HbWidgetStyleLoader *loader = HbWidgetStyleLoader::instance();
  4254             // widget has a layout, but it is not created by the style -> we cannot override.
  4303             if ( !loader->loadWidgetML(widget, layoutName, sectionName)) {
  4255 #ifdef HBSTYLE_DEBUG
  4304 #ifdef HBSTYLE_DEBUG
  4256             qDebug() << "HbStyle::polish : layout overridden by user";
  4305                 qDebug() << "HbStyle::polish : Failed to load WidgetML";
  4257 #endif // HBSTYLE_DEBUG
  4306 #endif
  4258         } else {
  4307                 return;
  4259             const QVariant existingLayoutNameV = widget->property( LAYOUT_NAME_PROPERTY );
  4308             }
  4260             const QString existingLayoutName = existingLayoutNameV.isValid() ? existingLayoutNameV.toString() : QString();
  4309             widgetLayoutNames[widget] = layoutName;
  4261             const bool cached = (existingLayoutName == layoutName );
  4310             if (cachedLayoutName.isNull()) {
  4262             if ( !cached ) {
  4311                 // Cached for the first time. Connect to destroyed signal.
  4263 #ifdef HBSTYLE_DEBUG
  4312                 QObject::connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*)));
  4264                 qDebug() << "LayoutName cache miss.";
  4313 #ifdef HBSTYLE_DEBUG
  4265 #endif
  4314                 qDebug() << "Cached first time. Connected to destroy signal.";
  4266                 HbWidgetStyleLoader *loader = HbWidgetStyleLoader::instance();
  4315             } else {
  4267                 if ( !loader->loadWidgetML(widget, layoutName, sectionName)) {
  4316                 qDebug() << "Cached nth time.";
  4268 #ifdef HBSTYLE_DEBUG
  4317 #endif
  4269                     qDebug() << "HbStyle::polish : Failed to load WidgetML";
  4318             }
  4270 #endif
       
  4271                     return;
       
  4272                 }
       
  4273                 const QVariant ptrVariant = QVariant::fromValue( widget->layout() );
       
  4274                 widget->setProperty( LAYOUT_PTR_PROPERTY, ptrVariant );
       
  4275                 widget->setProperty( LAYOUT_NAME_PROPERTY, QVariant( layoutName ) );
       
  4276             }
       
  4277 
       
  4278             anchorLayout = static_cast<HbAnchorLayout*>(widget->layout());
       
  4279             if (cached) {
       
  4280 #ifdef HBSTYLE_DEBUG
       
  4281                 qDebug() << "LayoutName cache hit.";
       
  4282 #endif
       
  4283                 anchorLayout->removeMappings();
       
  4284             }
       
  4285 
       
  4286             anchorLayout->setMapping(anchorLayout, "");
       
  4287             nodeIds = anchorLayout->nodeIds();
  4319         }
  4288         }
  4320         meshLayout = static_cast<HbAnchorLayout*>(widget->layout());
       
  4321         if (cached) {
       
  4322 #ifdef HBSTYLE_DEBUG
       
  4323             qDebug() << "LayoutName cache hit.";
       
  4324 #endif
       
  4325             meshLayout->removeMappings();
       
  4326         }
       
  4327 
       
  4328         meshLayout->setMapping(meshLayout, "");
       
  4329         meshIds = meshLayout->nodeIds();
       
  4330 
       
  4331     }
  4289     }
  4332 
  4290 
  4333     // polish widget and subitems
  4291     // polish widget and subitems
  4334     d->polishItem(styleRules, widget, widget, "", false);
  4292     d->polishItem(styleRules, widget, widget, "", profile, false);
  4335     QList<QGraphicsItem*> list = widget->childItems();
  4293     QList<QGraphicsItem*> list = widget->childItems();
  4336     foreach (QGraphicsItem* item, list) {
  4294     foreach (QGraphicsItem* item, list) {
  4337         QString name = HbStyle::itemName(item);
  4295         QString name = HbStyle::itemName(item);
  4338         if ( meshLayout && !name.isEmpty() ) {
  4296         if ( anchorLayout && !name.isEmpty() ) {
  4339             // Assuming that all items with "itemName" are widgets.
  4297             // Assuming that all items with "itemName" are widgets.
  4340             meshLayout->setMapping(static_cast<QGraphicsWidget*>(item), name);
  4298             anchorLayout->setMapping(static_cast<QGraphicsWidget*>(item), name);
  4341             // Remove from "meshIds" so that we don't call polishItem
  4299             // Remove from "nodeIds" so that we don't call polishItem
  4342             // twice for this item.
  4300             // twice for this item.
  4343             meshIds.removeAll(name);
  4301             nodeIds.removeAll(name);
  4344         }
  4302         }
  4345         d->polishItem(styleRules, widget, item, name, layoutDefined);
  4303         d->polishItem(styleRules, widget, item, name, profile, layoutDefined);
  4346     }
  4304     }
  4347     foreach (QString meshId, meshIds) {
  4305     foreach (QString nodeId, nodeIds) {
  4348         // These are the "missing" mesh items. Need to call polishItem
  4306         // These are the "missing" anchor items. Need to call polishItem
  4349         // for them, too, for getting the mesh anchor spacings right.
  4307         // for them, too, for getting the anchor spacings right.
  4350         // if there are mesh ids, layoutDefined is always true.
  4308         // if there are anchor node ids, layoutDefined is always true.
  4351         if ( !meshId.isEmpty() ) {
  4309         if ( !nodeId.isEmpty() ) {
  4352             d->polishItem(styleRules, widget, 0, meshId, true);
  4310             d->polishItem(styleRules, widget, 0, nodeId, profile, true);
       
  4311         }
       
  4312     }
       
  4313     if ( anchorLayout ) {
       
  4314         QList<HbAnchor*> anchors = anchorLayout->anchors();
       
  4315         foreach (HbAnchor* anchor, anchors) {
       
  4316             if ( !anchor->anchorId().isEmpty() ) {
       
  4317                 d->polishAnchor(styleRules, widget, anchor, profile);
       
  4318             }
  4353         }
  4319         }
  4354     }
  4320     }
  4355 }
  4321 }
  4356 
  4322 
  4357 /*!
  4323 /*!
  4360     \param styleRules, style-rules of the widget
  4326     \param styleRules, style-rules of the widget
  4361     \param variableRules, variable-rules of the widget
  4327     \param variableRules, variable-rules of the widget
  4362     \param widget, widget whose themed parameters are supposed to be updated
  4328     \param widget, widget whose themed parameters are supposed to be updated
  4363     \param item, graphics item whose themed parameters are supposed to be updated
  4329     \param item, graphics item whose themed parameters are supposed to be updated
  4364 */
  4330 */
  4365 void HbStylePrivate::updateThemedItems( const HbVector<HbCss::StyleRule> &styleRules,
  4331 void HbStylePrivate::updateThemedItems(
  4366     QGraphicsItem *item ) const
  4332     const HbVector<HbCss::StyleRule> &styleRules,
       
  4333     QGraphicsItem *item,
       
  4334     HbDeviceProfile &profile) const
  4367 {
  4335 {
  4368 
  4336 
  4369     QString name = HbStyle::itemName(item);
  4337     QString name = HbStyle::itemName(item);
  4370     if (name.isEmpty() ) {
  4338     if (name.isEmpty() ) {
  4371         return;
  4339         return;
  4372     }
  4340     }
  4373 
  4341 
  4374     HbTextItem* text = qgraphicsitem_cast<HbTextItem*>( item );
  4342     HbTextItem* text = qgraphicsitem_cast<HbTextItem*>( item );
       
  4343     HbRichTextItem* richtext = qgraphicsitem_cast<HbRichTextItem*>( item );
  4375     HbIconItem* iconItem = qgraphicsitem_cast<HbIconItem*>( item );
  4344     HbIconItem* iconItem = qgraphicsitem_cast<HbIconItem*>( item );
  4376     HbMarqueeItem* marqueeItem = qgraphicsitem_cast<HbMarqueeItem*>( item );
  4345     HbMarqueeItem* marqueeItem = qgraphicsitem_cast<HbMarqueeItem*>( item );
  4377     if(! (text || iconItem || marqueeItem ) ){
  4346     if(! (text || richtext || iconItem || marqueeItem ) ){
  4378         return;
  4347         return;
  4379     }
  4348     }
  4380 
  4349 
  4381     HbDeviceProfile profile;
       
  4382     const HbVector<HbCss::Declaration> decl = declarations(styleRules, name, 0, profile);
  4350     const HbVector<HbCss::Declaration> decl = declarations(styleRules, name, 0, profile);
  4383 
  4351 
  4384 #ifdef HBSTYLE_DEBUG
  4352 #ifdef HBSTYLE_DEBUG
  4385    qDebug() << "HbStyle::updateThemedItems : -- Number of matching CSS declarations: " << decl.count();
  4353    qDebug() << "HbStyle::updateThemedItems : -- Number of matching CSS declarations: " << decl.count();
  4386 #endif
  4354 #endif
  4403         if ( !HbWidgetBasePrivate::d_ptr(text)->testApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor ) ){
  4371         if ( !HbWidgetBasePrivate::d_ptr(text)->testApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor ) ){
  4404             text->setTextColor(col);
  4372             text->setTextColor(col);
  4405             HbWidgetBasePrivate::d_ptr(text)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor, false);
  4373             HbWidgetBasePrivate::d_ptr(text)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor, false);
  4406         }
  4374         }
  4407     }
  4375     }
       
  4376 
       
  4377     if(richtext) {
       
  4378 #ifdef HBSTYLE_DEBUG
       
  4379         if ( !extracted ) {
       
  4380             qDebug() << "HbStyle::getColor : -- No color information found";
       
  4381         }
       
  4382 #endif
       
  4383         if ( !HbWidgetBasePrivate::d_ptr(richtext)->testApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor ) ){
       
  4384             richtext->setTextDefaultColor(col);
       
  4385             HbWidgetBasePrivate::d_ptr(richtext)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor, false);
       
  4386         }
       
  4387     }
       
  4388 
  4408     if (iconItem) {
  4389     if (iconItem) {
  4409         // Applying color to mono-colorised icons from theme. Using setColor()
  4390         // Applying color to mono-colorised icons from theme. Using setColor()
  4410         // here would be wrong. It would lead to loosing the user-supplied color
  4391         // here would be wrong. It would lead to loosing the user-supplied color
  4411         // in some cases so use the special setThemedColor() instead.
  4392         // in some cases so use the special setThemedColor() instead.
  4412         HbIconItemPrivate::d_ptr(iconItem)->setThemedColor( col );
  4393         HbIconItemPrivate::d_ptr(iconItem)->setThemedColor( col );
  4461     }
  4442     }
  4462 
  4443 
  4463     // update themed items
  4444     // update themed items
  4464     QList<QGraphicsItem*> list = widget->childItems();
  4445     QList<QGraphicsItem*> list = widget->childItems();
  4465     foreach (QGraphicsItem* item, list) {
  4446     foreach (QGraphicsItem* item, list) {
  4466         d->updateThemedItems(styleRules, item);
  4447         d->updateThemedItems(styleRules, item, profile);
  4467     }
  4448     }
  4468 }
  4449 }
  4469 
  4450 
  4470 /*!
  4451 /*!
  4471     Checkes whether given widget has orienation specific style
  4452     Checkes whether given widget has orienation specific style
  4482 /*!
  4463 /*!
  4483     For clearing caches.
  4464     For clearing caches.
  4484 */
  4465 */
  4485 void HbStyle::widgetDestroyed(QObject* obj)
  4466 void HbStyle::widgetDestroyed(QObject* obj)
  4486 {
  4467 {
  4487     widgetLayoutNames.remove((const QGraphicsWidget *)obj);
  4468     Q_UNUSED( obj );
  4488 }
  4469 }
  4489 
  4470 
  4490 /*!
  4471 /*!
  4491 
  4472 
  4492     Sets the item name of a graphics item. Item name is not the same as object name.
  4473     Sets the item name of a graphics item. Item name is not the same as object name.
  4509         item->setData( ItemName, name );
  4490         item->setData( ItemName, name );
  4510         QGraphicsItem* parent = item->parentItem();
  4491         QGraphicsItem* parent = item->parentItem();
  4511         QGraphicsLayoutItem* lItem = (item->isWidget()) ? (QGraphicsLayoutItem*)static_cast<QGraphicsWidget*>(item) : 0;
  4492         QGraphicsLayoutItem* lItem = (item->isWidget()) ? (QGraphicsLayoutItem*)static_cast<QGraphicsWidget*>(item) : 0;
  4512         if (lItem && parent && parent->isWidget()) {
  4493         if (lItem && parent && parent->isWidget()) {
  4513             QGraphicsWidget* parentW = static_cast<QGraphicsWidget*>(parent);
  4494             QGraphicsWidget* parentW = static_cast<QGraphicsWidget*>(parent);
  4514             if ( parentW->layout() && widgetLayoutNames.contains(parentW) ) {
  4495             const QVariant layoutPtrByStyleV = parentW->property( LAYOUT_PTR_PROPERTY );
       
  4496             const QGraphicsLayout *layoutPtrByStyle = layoutPtrByStyleV.isValid() ? layoutPtrByStyleV.value<QGraphicsLayout*>() : 0;
       
  4497             if ( parentW->layout() && (parentW->layout()==layoutPtrByStyle)) {
  4515                 HbAnchorLayout* layout = static_cast<HbAnchorLayout*>(parentW->layout());
  4498                 HbAnchorLayout* layout = static_cast<HbAnchorLayout*>(parentW->layout());
  4516                 if ( layout->indexOf(lItem) != -1 ) {
  4499                 if ( layout->indexOf(lItem) != -1 ) {
  4517                     if( name.isEmpty() ) {
  4500                     if( name.isEmpty() ) {
  4518                         layout->removeMapping(originalName);
  4501                         layout->removeMapping(originalName);
  4519                     } else {
  4502                     } else {
  4672 /*!
  4655 /*!
  4673 \internal
  4656 \internal
  4674 */
  4657 */
  4675 HbStylePrivate::HbStylePrivate()
  4658 HbStylePrivate::HbStylePrivate()
  4676 {
  4659 {
  4677     nextAvailableId = HbStyle::P_CustomBase;
       
  4678     HbWidgetStyleLoader *loader = HbWidgetStyleLoader::instance();
  4660     HbWidgetStyleLoader *loader = HbWidgetStyleLoader::instance();
  4679     if(loader){
  4661     if(loader){
  4680         loader->addFilePath(STYLE_LOCATION, HbLayeredStyleLoader::Concern_Layouts,
  4662         loader->addFilePath(STYLE_LOCATION, HbLayeredStyleLoader::Concern_Layouts,
  4681                 HbLayeredStyleLoader::Priority_Core);
  4663                 HbLayeredStyleLoader::Priority_Core);
  4682         loader->addFilePath(COLOR_STYLE_LOCATION, HbLayeredStyleLoader::Concern_Colors,
  4664         loader->addFilePath(COLOR_STYLE_LOCATION, HbLayeredStyleLoader::Concern_Colors,
  4766     if (state & QStyle::State_On)
  4748     if (state & QStyle::State_On)
  4767         icon = QIcon::On;
  4749         icon = QIcon::On;
  4768     return icon;
  4750     return icon;
  4769 }
  4751 }
  4770 
  4752 
  4771 /*!
       
  4772 \internal
       
  4773 */
       
  4774 HbStyleInterface *HbStylePrivate::stylePluginInterface( HbStyle::Primitive primitive ) const
       
  4775 {
       
  4776 
       
  4777     if (customPrimitives.contains(primitive)) {
       
  4778         HbStyleInterfaceInfo* info = customPrimitives.value(primitive);
       
  4779         QObject* pluginInstance = info->loader->instance();
       
  4780         HbStyleInterface *stylePlugin = qobject_cast<HbStyleInterface *>(pluginInstance);
       
  4781         return stylePlugin;
       
  4782     }
       
  4783     return 0;
       
  4784 }
       
  4785 
  4753 
  4786 /*!
  4754 /*!
  4787 \internal
  4755 \internal
  4788 */
  4756 */
  4789 void HbStylePrivate::ensureLayoutParameters(const HbDeviceProfile &profile) const
  4757 void HbStylePrivate::ensureLayoutParameters(const HbDeviceProfile &profile) const
  4853 /*!
  4821 /*!
  4854 \internal
  4822 \internal
  4855 */
  4823 */
  4856 void HbStylePrivate::clearStyleSheetCaches()
  4824 void HbStylePrivate::clearStyleSheetCaches()
  4857 {
  4825 {
  4858     widgetLayoutNames.clear();
       
  4859     styleRulesCache.clear();
  4826     styleRulesCache.clear();
  4860 }
  4827 }
  4861 
  4828 
  4862 HbWidgetBasePrivate *HbStylePrivate::widgetBasePrivate(HbWidgetBase *widgetBase) const
  4829 HbWidgetBasePrivate *HbStylePrivate::widgetBasePrivate(HbWidgetBase *widgetBase) const
  4863 {
  4830 {
  4864     return HbWidgetBasePrivate::d_ptr(widgetBase);
  4831     return HbWidgetBasePrivate::d_ptr(widgetBase);
  4865 }
  4832 }
  4866 
  4833 
  4867 
       
  4868 #include "moc_hbstyle.cpp"
  4834 #include "moc_hbstyle.cpp"