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 |
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. |
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: |
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 = |
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); |
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 |
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 { |