src/hbcore/style/hbstyle.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 5 627c4a0fd0e7
equal deleted inserted replaced
2:06ff229162e9 3:11d3954df52a
  3320                          else {
  3320                          else {
  3321                                frameItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_progslider_frame_normal"));
  3321                                frameItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_progslider_frame_normal"));
  3322                          }
  3322                          }
  3323 					}
  3323 					}
  3324                     frameItem->frameDrawer().setFillWholeRect(true);       
  3324                     frameItem->frameDrawer().setFillWholeRect(true);       
  3325                     frameItem->update();
  3325                     //frameItem->update();
  3326                     }
  3326                     }
  3327                     break;
  3327                     break;
  3328             case P_ProgressSlider_track: // The ProgressValue Mask
  3328             case P_ProgressSlider_track: // The ProgressValue Mask
  3329                 if (const HbStyleOptionProgressSlider *opt = qstyleoption_cast<const HbStyleOptionProgressSlider *>(option)) {
  3329                 if (const HbStyleOptionProgressSlider *opt = qstyleoption_cast<const HbStyleOptionProgressSlider *>(option)) {
  3330                     HbProgressTrackItem* frameItem = static_cast<HbProgressTrackItem*>(item);
  3330                     HbProgressTrackItem* frameItem = static_cast<HbProgressTrackItem*>(item);
  3349                     frameItem->setMaximum(opt->maximum);
  3349                     frameItem->setMaximum(opt->maximum);
  3350                     frameItem->setMinimum(opt->minimum);
  3350                     frameItem->setMinimum(opt->minimum);
  3351                     frameItem->setValue(opt->progressSliderValue);
  3351                     frameItem->setValue(opt->progressSliderValue);
  3352                     frameItem->setInverted(opt->inverted);
  3352                     frameItem->setInverted(opt->inverted);
  3353                     frameItem->setOrientation(opt->orientation);
  3353                     frameItem->setOrientation(opt->orientation);
  3354                     frameItem->update();
  3354                     //frameItem->update();
  3355                     } 
  3355                     } 
  3356                     break;
  3356                     break;
  3357             case P_ProgressBar_mintext: {
  3357             case P_ProgressBar_mintext: {
  3358                  if (const HbStyleOptionProgressBar *opt = 
  3358                  if (const HbStyleOptionProgressBar *opt = 
  3359                         qstyleoption_cast<const HbStyleOptionProgressBar*>(option)) {
  3359                         qstyleoption_cast<const HbStyleOptionProgressBar*>(option)) {
  4289         if ( !HbWidgetBasePrivate::d_ptr(text)->testApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor ) ){
  4289         if ( !HbWidgetBasePrivate::d_ptr(text)->testApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor ) ){
  4290             text->setTextColor(col);
  4290             text->setTextColor(col);
  4291             HbWidgetBasePrivate::d_ptr(text)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor, false);
  4291             HbWidgetBasePrivate::d_ptr(text)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor, false);
  4292         }
  4292         }
  4293     }   
  4293     }   
  4294     if(iconItem){
  4294     if (iconItem) {
  4295         //applying color to mono-colorised icons from theme
  4295         // Applying color to mono-colorised icons from theme. Using setColor()
  4296         iconItem->setColor( col );
  4296         // here would be wrong. It would lead to loosing the user-supplied color
       
  4297         // in some cases so use the special setThemedColor() instead.
       
  4298         HbIconItemPrivate::d_ptr(iconItem)->setThemedColor( col );
  4297     }
  4299     }
  4298     if(marqueeItem){
  4300     if(marqueeItem){
  4299         //applying color to the marquee-item from theme
  4301         //applying color to the marquee-item from theme
  4300         if(!HbWidgetBasePrivate::d_ptr(marqueeItem)->testApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor)) {
  4302         if(!HbWidgetBasePrivate::d_ptr(marqueeItem)->testApiProtectionFlag(HbWidgetBasePrivate::AC_TextColor)) {
  4301             marqueeItem->setTextColor( col ); 
  4303             marqueeItem->setTextColor( col ); 
  4423     Returns a value of a global style parameter. The value is returned in pixels. 
  4425     Returns a value of a global style parameter. The value is returned in pixels. 
  4424 
  4426 
  4425     Available parameters can be found from hbglobalparameters.css. By using these
  4427     Available parameters can be found from hbglobalparameters.css. By using these
  4426     parameters applications get consistent look.
  4428     parameters applications get consistent look.
  4427 
  4429 
  4428     \param variable Name of the global parameter.
  4430     \param param Name of the global parameter.
  4429     \param value Returns value of the global parameter.
  4431     \param value Returns value of the global parameter.
  4430     \param profile Device profile of the used HbMainWindow. Primary display's.
  4432     \param profile Device profile of the used HbMainWindow. Primary display's.
  4431             device profile HbDeviceProfile::current() is used if the value is omitted.
  4433             device profile HbDeviceProfile::current() is used if the value is omitted.
  4432     \return true if the variable were found.
  4434     \return true if the variable was found.
  4433 */
  4435 */
  4434 bool HbStyle::parameter(const QString& parameter, qreal& value, const HbDeviceProfile &profile) const
  4436 bool HbStyle::parameter(const QString& param, qreal& value, const HbDeviceProfile &profile) const
  4435 {
  4437 {
  4436     HbDeviceProfile effectiveProfile = profile;
  4438     HbDeviceProfile effectiveProfile = profile;
  4437     if ( effectiveProfile.isNull() ) {
  4439     if ( effectiveProfile.isNull() ) {
  4438         effectiveProfile = HbDeviceProfile::current();
  4440         effectiveProfile = HbDeviceProfile::current();
  4439     }
  4441     }
  4440     Q_D( const HbStyle );
  4442     Q_D( const HbStyle );
  4441     d->ensureLayoutParameters(effectiveProfile);
  4443     d->ensureLayoutParameters(effectiveProfile);
  4442     HbCss::ValueExtractor valueExtractor(d->layoutParameters, true, effectiveProfile);
  4444     HbCss::ValueExtractor valueExtractor(d->layoutParameters, true, effectiveProfile);
  4443     // todo: parsing variable/expression is done here so that there is no need to change API
  4445     // todo: parsing variable/expression is done here so that there is no need to change API
  4444     // also parameters method not changed (this change is done for docml/widgetml parsing)
  4446     // also parameters method not changed (this change is done for docml/widgetml parsing)
  4445     if (parameter.startsWith("var(") && parameter.endsWith(")")) {
  4447     if (param.startsWith("var(") && param.endsWith(")")) {
  4446         return valueExtractor.extractValue(parameter.mid(4,parameter.length()-5), value);
  4448         return valueExtractor.extractValue(param.mid(4,param.length()-5), value);
  4447     } else if (parameter.startsWith("-var(") && parameter.endsWith(")")) {
  4449     } else if (param.startsWith("-var(") && param.endsWith(")")) {
  4448         bool retVal = valueExtractor.extractValue(parameter.mid(5,parameter.length()-6), value);
  4450         bool retVal = valueExtractor.extractValue(param.mid(5,param.length()-6), value);
  4449         value = -value;
  4451         value = -value;
  4450         return retVal;
  4452         return retVal;
  4451     } else if (parameter.startsWith("expr(") && parameter.endsWith(")")) {
  4453     } else if (param.startsWith("expr(") && param.endsWith(")")) {
  4452         QString expressionString = parameter.mid(5,parameter.length()-6);
  4454         QString expressionString = param.mid(5,param.length()-6);
  4453         return valueExtractor.extractExpressionValue(expressionString, value);
  4455         return valueExtractor.extractExpressionValue(expressionString, value);
  4454     } else if (parameter.startsWith("-expr(") && parameter.endsWith(")")) {
  4456     } else if (param.startsWith("-expr(") && param.endsWith(")")) {
  4455         QString expressionString = parameter.mid(6,parameter.length()-7);
  4457         QString expressionString = param.mid(6,param.length()-7);
  4456         bool retVal = valueExtractor.extractExpressionValue(expressionString, value);
  4458         bool retVal = valueExtractor.extractExpressionValue(expressionString, value);
  4457         value = -value;
  4459         value = -value;
  4458         return retVal;
  4460         return retVal;
  4459     }
  4461     }
  4460 
  4462 
  4461     return valueExtractor.extractValue(parameter, value);    
  4463     return valueExtractor.extractValue(param, value);    
  4462 }
  4464 }
  4463 
  4465 
  4464 /*!
  4466 /*!
  4465     Returns copy of all global style parameters. Both names and values 
  4467     Returns copy of all global style parameters. Both names and values 
  4466     of the parameters are returned. The values are returned in pixels.
  4468     of the parameters are returned. The values are returned in pixels.
  4467 
  4469 
  4468     Available parameters can be found from hbglobalparameters.css. By using these
  4470     Available parameters can be found from hbglobalparameters.css. By using these
  4469     parameters applications get consistent look. Usage of this API (instead of parameter)
  4471     parameters applications get consistent look. Usage of this API (instead of parameter)
  4470     is recommended if an application needs to fetch several parameters in one place.
  4472     is recommended if an application needs to fetch several parameters in one place.
  4471 
  4473 
  4472     \param parameters Contains names and values of all global style parameters.
  4474     \param params Contains names and values of all global style parameters.
  4473     \param profile Device profile of the used HbMainWindow. Primary display's
  4475     \param profile Device profile of the used HbMainWindow. Primary display's
  4474             device profile HbDeviceProfile::current() is used if the value is omitted.
  4476             device profile HbDeviceProfile::current() is used if the value is omitted.
  4475 */
  4477 */
  4476 
  4478 
  4477 void HbStyle::parameters(HbStyleParameters &parameters, const HbDeviceProfile &profile) const
  4479 void HbStyle::parameters(HbStyleParameters &params, const HbDeviceProfile &profile) const
  4478 {
  4480 {
  4479     HbDeviceProfile effectiveProfile = profile;
  4481     HbDeviceProfile effectiveProfile = profile;
  4480     if ( effectiveProfile.isNull() ) {
  4482     if ( effectiveProfile.isNull() ) {
  4481         effectiveProfile = HbDeviceProfile::current();
  4483         effectiveProfile = HbDeviceProfile::current();
  4482     }
  4484     }
  4486     HbCss::ValueExtractor valueExtractor(d->layoutParameters, true, effectiveProfile);
  4488     HbCss::ValueExtractor valueExtractor(d->layoutParameters, true, effectiveProfile);
  4487     qreal value = 0;
  4489     qreal value = 0;
  4488     QHash<QString, HbCss::Declaration>::const_iterator i = d->layoutParameters.constBegin();
  4490     QHash<QString, HbCss::Declaration>::const_iterator i = d->layoutParameters.constBegin();
  4489     while (i != d->layoutParameters.constEnd()) {
  4491     while (i != d->layoutParameters.constEnd()) {
  4490         if (valueExtractor.extractValue(i.key(), value)) {
  4492         if (valueExtractor.extractValue(i.key(), value)) {
  4491             parameters.addParameter(i.key(), value);
  4493             params.addParameter(i.key(), value);
  4492         }
  4494         }
  4493         ++i;
  4495         ++i;
  4494     }
  4496     }
       
  4497 }
       
  4498 
       
  4499 /*!
       
  4500     Returns values for widget specific style parameters. The names of the parameters
       
  4501     are passed in with \a params. 
       
  4502 
       
  4503     This method should be used only if you need to access widget specific parameters out
       
  4504     of the polish loop. It is more efficient to use HbWidget::polish(HbStyleParameters &params)
       
  4505     if you don't need to access the parameters before the (first) polish event.
       
  4506 
       
  4507     \param parameters, style parameters to be returned to the caller
       
  4508     \param widget, HbWidget to be polished
       
  4509     \sa HbStyle::polish, HbStyle::parameters and HbWidget::polish
       
  4510 */
       
  4511 void HbStyle::widgetParameters(HbStyleParameters &params, HbWidget* widget) const
       
  4512 {
       
  4513     Q_D( const HbStyle );
       
  4514     if( !widget || !params.count() ) {
       
  4515         return;
       
  4516     }
       
  4517 #ifdef HBSTYLE_DEBUG
       
  4518     qDebug() << "HbStyle::widgetParameters : Parameters for" << widget->metaObject()->className();
       
  4519 #endif
       
  4520 
       
  4521     HbLayeredStyleLoader *styleLoader = HbLayeredStyleLoader::getStack(HbLayeredStyleLoader::Concern_Layouts);
       
  4522     if(!styleLoader){
       
  4523 #ifdef HBSTYLE_DEBUG
       
  4524         qDebug() << "HbStyle::widgetParameters : HbLayeredStyleLoader returned a null pointer.";
       
  4525 #endif
       
  4526         return;
       
  4527     }
       
  4528     HbDeviceProfile profile(HbDeviceProfile::profile(widget));
       
  4529     NODEPTR_N(widget);
       
  4530 
       
  4531     HbVector<HbCss::StyleRule> styleRules = styleLoader->styleRulesForNode(n, profile.orientation());
       
  4532 
       
  4533 #ifdef HBSTYLE_DEBUG
       
  4534     qDebug() << "HbStyle::widgetParameters : Number of style rules:" << styleRules.count();
       
  4535 #endif
       
  4536     if (!styleRules.count()) {
       
  4537         return;
       
  4538     }
       
  4539     const HbVector<HbCss::Declaration> decl = declarations(styleRules, "", widget, profile);
       
  4540 #ifdef HBSTYLE_DEBUG
       
  4541     qDebug() << "HbStyle::widgetParameters : Number of maching CSS declarations: " << decl.count();
       
  4542 #endif
       
  4543     d->ensureLayoutParameters(profile);
       
  4544 
       
  4545     HbCss::ValueExtractor extractor(decl, d->layoutParameters, profile);
       
  4546     extractor.extractParameters( params.params(), params.values() );
  4495 }
  4547 }
  4496 
  4548 
  4497 
  4549 
  4498 /*!
  4550 /*!
  4499 \internal
  4551 \internal
  4535 /*!
  4587 /*!
  4536 \internal
  4588 \internal
  4537 */
  4589 */
  4538 QString HbStylePrivate::logicalName(HbStyle::Primitive primitive, const QStyleOption *option) const
  4590 QString HbStylePrivate::logicalName(HbStyle::Primitive primitive, const QStyleOption *option) const
  4539 {
  4591 {
  4540     switch(primitive){
  4592     switch (primitive) {
  4541     case HbStyle::P_Slider_thumb:{
  4593 
       
  4594     case HbStyle::P_Slider_thumb: {
  4542         const HbStyleOptionSlider *opt = qstyleoption_cast<const HbStyleOptionSlider *>(option);
  4595         const HbStyleOptionSlider *opt = qstyleoption_cast<const HbStyleOptionSlider *>(option);
  4543         QString iconPath;
  4596         if (opt) {
  4544 
  4597             QString iconPath;
  4545                 switch (opt->orientation){
  4598             switch (opt->orientation) {
  4546                 case Qt::Horizontal:{
  4599 
  4547                         if( opt->state&QStyle::State_Sunken)
  4600             case Qt::Horizontal:
  4548                             iconPath= "qtg_graf_slider_h_handle_pressed";
  4601                 if (opt->state & QStyle::State_Sunken)
  4549                         else
  4602                     iconPath = "qtg_graf_slider_h_handle_pressed";
  4550                             iconPath= "qtg_graf_slider_h_handle_normal";
  4603                 else
  4551                         return (iconPath);
  4604                     iconPath = "qtg_graf_slider_h_handle_normal";
  4552                 }
  4605                 return iconPath;
  4553                 case Qt::Vertical:{
  4606 
  4554                         if( opt->state&QStyle::State_Sunken)
  4607             case Qt::Vertical:
  4555                             iconPath= "qtg_graf_slider_v_handle_pressed";
  4608                 if (opt->state & QStyle::State_Sunken)
  4556                         else
  4609                     iconPath = "qtg_graf_slider_v_handle_pressed";
  4557                             iconPath= "qtg_graf_slider_v_handle_normal";
  4610                 else
  4558                         return (iconPath);
  4611                     iconPath = "qtg_graf_slider_v_handle_normal";
  4559                 }
  4612                 return iconPath;
  4560                 default: break;
  4613 
       
  4614             default:
       
  4615                 break;
       
  4616 
       
  4617             }
  4561         }
  4618         }
  4562     }
  4619     }
  4563         default: break;
  4620 
  4564     }
  4621     default:
  4565 
  4622         break;
  4566 return QString();
  4623         
       
  4624     }
       
  4625 
       
  4626     return QString();
  4567 }
  4627 }
  4568 
  4628 
  4569 /*!
  4629 /*!
  4570 \internal
  4630 \internal
  4571 */
  4631 */