src/hbcore/gui/hbtoolbutton.cpp
changeset 30 80e4d18b72f5
parent 28 b7da29130b0e
equal deleted inserted replaced
28:b7da29130b0e 30:80e4d18b72f5
    33 #include "hbcolorscheme.h"
    33 #include "hbcolorscheme.h"
    34 #include "hbtextitem.h"
    34 #include "hbtextitem.h"
    35 #include "hbiconitem.h"
    35 #include "hbiconitem.h"
    36 #include "hbview.h"
    36 #include "hbview.h"
    37 #include "hbmainwindow.h"
    37 #include "hbmainwindow.h"
       
    38 #include "hbframeitem.h"
       
    39 #include "hbevent.h"
    38 
    40 
    39 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED
    41 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED
    40 
    42 
    41 #include "hbstyle_p.h" // for iconmodes...
    43 #include "hbstyle_p.h" // for iconmodes...
    42 
    44 
   210 bool HbToolButtonPrivate::isToolBarExtension() const
   212 bool HbToolButtonPrivate::isToolBarExtension() const
   211 {
   213 {
   212     return (action != 0 && toolbarExtensionFrame);
   214     return (action != 0 && toolbarExtensionFrame);
   213 }
   215 }
   214 
   216 
   215 
       
   216 
       
   217 
       
   218 void HbToolButtonPrivate::framePrimitiveData(HbStyleFramePrimitiveData *data)
   217 void HbToolButtonPrivate::framePrimitiveData(HbStyleFramePrimitiveData *data)
   219 {
   218 {
   220 
       
   221     Q_Q(HbToolButton);
   219     Q_Q(HbToolButton);
   222 
   220 
   223     data->fillWholeRect = true;
   221     data->fillWholeRect = true;
   224    
   222 
   225     if (orientation == Qt::Vertical) {
   223     if (orientation == Qt::Vertical) {
   226         data->frameType = HbFrameDrawer::ThreePiecesHorizontal;
   224         data->frameType = HbFrameDrawer::ThreePiecesHorizontal;
   227     } else {
   225     } else {
   228         data->frameType = HbFrameDrawer::ThreePiecesVertical;
   226         data->frameType = HbFrameDrawer::ThreePiecesVertical;
   229     }
   227     }
   231     QStringList list;
   229     QStringList list;
   232     QString frameGraphicsFooter;
   230     QString frameGraphicsFooter;
   233     // data->state already set by abstractbutton's data init
   231     // data->state already set by abstractbutton's data init
   234     QIcon::Mode mode = HbStylePrivate::iconMode(data->state);
   232     QIcon::Mode mode = HbStylePrivate::iconMode(data->state);
   235     QIcon::State state = HbStylePrivate::iconState(data->state);
   233     QIcon::State state = HbStylePrivate::iconState(data->state);
   236     
   234 
   237     // custom background
   235     // custom background
   238     if (!q->background().isNull()) {
   236     if (!q->background().isNull()) {
   239         data->frameGraphicsName = customBackground.iconName(mode, state);
   237         data->frameGraphicsName = customBackground.iconName(mode, state);
   240         return;
   238         return;
   241     }
   239     }
   242 
   240 
   243     // in toolbar extension
   241     // in toolbar extension
   244     if(isToolBarExtension()) {
   242     if(isToolBarExtension()) {
   245        if (mode == QIcon::Normal && state == QIcon::On) {
   243         if (mode == QIcon::Normal && state == QIcon::On) {
   246            if(!q->isCheckable()){
   244             if(!q->isCheckable()){
   247                 data->frameGraphicsName = QLatin1String("qtg_fr_popup_grid_pressed");
   245                 data->frameGraphicsName = QLatin1String("qtg_fr_popup_grid_pressed");
   248             } else {
   246             } else {
   249                 data->frameGraphicsName = QLatin1String("qtg_fr_tb_ext");
   247                 data->frameGraphicsName = QLatin1String("qtg_fr_tb_ext");
   250             }
   248             }
   251         } else {
   249         } else {
   252             data->frameGraphicsName = QLatin1String("");
   250             data->frameGraphicsName = QLatin1String("");
   253         }
   251         }
   254     data->frameType = HbFrameDrawer::NinePieces;
   252         data->frameType = HbFrameDrawer::NinePieces;
   255     return;
   253         return;
   256     }
   254     }
   257 
   255 
   258     if (!toolBarPosition) {
   256     if (!toolBarPosition) {
   259         if (mode == QIcon::Disabled && state == QIcon::Off) {
   257         if (mode == QIcon::Disabled && state == QIcon::Off) {
   260             data->frameGraphicsName = QLatin1String("qtg_fr_btn_disabled");
   258             data->frameGraphicsName = QLatin1String("qtg_fr_btn_disabled");
   270             data->frameGraphicsName = QLatin1String("qtg_fr_btn_normal");
   268             data->frameGraphicsName = QLatin1String("qtg_fr_btn_normal");
   271         }
   269         }
   272         data->frameType = HbFrameDrawer::NinePieces;
   270         data->frameType = HbFrameDrawer::NinePieces;
   273         return;
   271         return;
   274     }
   272     }
   275 // For toolbar:
   273     // For toolbar:
   276 
   274 
   277                 QString frameGraphicsHeader;
   275     QString frameGraphicsHeader;
   278                 if (!mDialogToolBar){
   276     if (!mDialogToolBar){
   279                     if (useTransparentGraphics()) {
   277         if (useTransparentGraphics()) {
   280                         frameGraphicsHeader = orientation == Qt::Vertical ?
   278             frameGraphicsHeader = orientation == Qt::Vertical ?
   281                                               QLatin1String("qtg_fr_tb_trans_h_"):
   279                                   QLatin1String("qtg_fr_tb_trans_h_"):
   282                                               QLatin1String("qtg_fr_tb_trans_v_");
   280                                   QLatin1String("qtg_fr_tb_trans_v_");
   283                     } else {
   281         } else {
   284                         frameGraphicsHeader = orientation == Qt::Vertical ?
   282             frameGraphicsHeader = orientation == Qt::Vertical ?
   285                                               QLatin1String("qtg_fr_tb_h_"):
   283                                   QLatin1String("qtg_fr_tb_h_"):
   286                                               QLatin1String("qtg_fr_tb_v_");
   284                                   QLatin1String("qtg_fr_tb_v_");
   287                     }
   285         }
   288                 }else {
   286     } else {
   289                     frameGraphicsHeader = QLatin1String("qtg_fr_popup_sk_");
   287         frameGraphicsHeader = QLatin1String("qtg_fr_popup_sk_");
   290                     data->mirroringMode = HbIcon::LayoutDirection;
   288         data->mirroringMode = HbIcon::LayoutDirection;
   291                 }
   289     }
   292 
   290 
   293                 switch (toolBarPosition) {
   291     switch (toolBarPosition) {
   294                     case TB_OnlyOne:
   292         case TB_OnlyOne:
   295                         if (orientation == Qt::Vertical) {
   293             if (orientation == Qt::Vertical) {
   296                             list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_r");
   294                 list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_r");
   297                         } else {
   295             } else {
   298                             list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_b");
   296                 list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_b");
   299                         }
   297             }
   300                         break;
   298             break;
   301                     case TB_Beginning:
   299         case TB_Beginning:
   302                         if (orientation== Qt::Vertical) {
   300             if (orientation== Qt::Vertical) {
   303                             list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_cr");
   301                 list << QLatin1String("_l") << QLatin1String("_c") << QLatin1String("_cr");
   304                         } else {
   302             } else {
   305                             list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_cb");
   303                 list << QLatin1String("_t") << QLatin1String("_c") << QLatin1String("_cb");
   306                         }
   304             }
   307                         break;
   305             break;
   308                     case TB_Middle:
   306         case TB_Middle:
   309                         if (orientation == Qt::Vertical) {
   307             if (orientation == Qt::Vertical) {
   310                             list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_cr");
   308                 list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_cr");
   311                         } else {
   309             } else {
   312                             list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_cb");
   310                 list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_cb");
   313                         }
   311             }
   314                         break;
   312             break;
   315                     case TB_End:
   313         case TB_End:
   316                         if (orientation== Qt::Vertical) {
   314             if (orientation== Qt::Vertical) {
   317                             list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_r");
   315                 list << QLatin1String("_cl") << QLatin1String("_c") << QLatin1String("_r");
   318                         } else {
   316             } else {
   319                             list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_b");
   317                 list << QLatin1String("_ct") << QLatin1String("_c") << QLatin1String("_b");
   320                         }
   318             }
   321                         break;
   319             break;
   322 
   320 
   323                     default:
   321         default:
   324                     case TB_None:
   322         case TB_None:
   325                     break;
   323             break;
   326                 }; // switch case end
   324     } // switch case end
   327                 
   325 
   328 
   326     data->fileNameSuffixList = list;
   329 
   327     if (mode == QIcon::Disabled && state == QIcon::Off) {
   330                 data->fileNameSuffixList = list;
   328         frameGraphicsFooter = QLatin1String("disabled");
   331                 if (mode == QIcon::Disabled && state == QIcon::Off) {
   329     } else if (mode == QIcon::Normal && state == QIcon::On) {
   332                     frameGraphicsFooter = QLatin1String("disabled");
   330         if(!q->isCheckable()) {
   333                 } else if (mode == QIcon::Normal && state == QIcon::On) {
   331             frameGraphicsFooter = QLatin1String("pressed");
   334                     if(!q->isCheckable()) {
   332         } else {
   335                         frameGraphicsFooter = QLatin1String("pressed");
   333             frameGraphicsFooter = QLatin1String("latched");
   336                     } else {
   334         }
   337                         frameGraphicsFooter = QLatin1String("latched");
   335     } else if (mode == QIcon::Selected && state == QIcon::Off) {
   338                     }
   336         frameGraphicsFooter = QLatin1String("highlight");
   339                 } else if (mode == QIcon::Selected && state == QIcon::Off) {
   337     } else {
   340                     frameGraphicsFooter = QLatin1String("highlight");
   338         frameGraphicsFooter = QLatin1String("normal");
   341                 } else {
   339     }
   342                     frameGraphicsFooter = QLatin1String("normal");
   340     data->frameGraphicsName = QString ("%0%1").arg(frameGraphicsHeader).arg(frameGraphicsFooter);
   343                 }
   341     data->mirroringMode = HbIcon::LayoutDirection;
   344                 data->frameGraphicsName = QString ("%0%1").arg(frameGraphicsHeader).arg(frameGraphicsFooter);
   342 }
   345                 data->mirroringMode = HbIcon::LayoutDirection;
   343 
   346                 return;
       
   347 
       
   348 }
       
   349 void HbToolButtonPrivate::iconPrimitiveData(HbStyleIconPrimitiveData *data)
   344 void HbToolButtonPrivate::iconPrimitiveData(HbStyleIconPrimitiveData *data)
   350 {
   345 {
   351     Q_Q(HbToolButton);
   346     Q_Q(HbToolButton);
   352     if (q->action()) {
   347     if (q->action()) {
   353         data->icon = q->action()->icon();
   348         data->icon = q->action()->icon();
   354     } else if(action){
   349     } else if(action){
   355         data->icon = action->icon();
   350         data->icon = action->icon();
       
   351     } else {
       
   352         data->icon = HbIcon();
   356     }
   353     }
   357     data->iconMode = HbStylePrivate::iconMode(data->state);
   354     data->iconMode = HbStylePrivate::iconMode(data->state);
   358     data->iconState = HbStylePrivate::iconState(data->state);
   355     data->iconState = HbStylePrivate::iconState(data->state);
   359     return;
   356     return;
   360 }
   357 }
   361 void HbToolButtonPrivate::textPrimitiveData(HbStyleTextPrimitiveData *data)
   358 void HbToolButtonPrivate::textPrimitiveData(HbStyleTextPrimitiveData *data)
   362 {
   359 {
   363     if(action) {
   360     if(action) {
   364         data->text = action->text();
   361         data->text = action->text();
       
   362     } else {
       
   363         data->text = QString();
   365     }
   364     }
   366 }
   365 }
   367 
   366 
   368 QSizeF HbToolButtonPrivate::getMinimumSize()
   367 QSizeF HbToolButtonPrivate::getMinimumSize()
   369 {
   368 {
   558         HbStyleTextPrimitiveData data;
   557         HbStyleTextPrimitiveData data;
   559         initPrimitiveData(&data, d->textItem);
   558         initPrimitiveData(&data, d->textItem);
   560         bool itemHasNoContents = false;
   559         bool itemHasNoContents = false;
   561         if (data.text.isSet()) {
   560         if (data.text.isSet()) {
   562             if ( data.text.value().isEmpty() || data.text.value().isNull() ||
   561             if ( data.text.value().isEmpty() || data.text.value().isNull() ||
   563                 (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonIcon)) {
   562                  (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonIcon)) {
   564                 itemHasNoContents = true;
   563                 itemHasNoContents = true;
   565             }
   564             }
   566         }
   565         }
   567         d->textItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents);
   566         d->textItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents);
   568         if(!itemHasNoContents) {
   567         if(!itemHasNoContents) {
   569 
   568 
   570             style()->updatePrimitive(d->textItem, &data, this);
   569             style()->updatePrimitive(d->textItem, &data, this);
       
   570             /* HbDialog::setPrimaryAction deprecation action coloring - begin */
       
   571             if (d->action && d->action->property("invalid_addition").isValid() ) {
       
   572                 HbTextItem *textItem = qgraphicsitem_cast<HbTextItem*>(d->textItem);
       
   573                 textItem->setTextColor(QColor("magenta"));
       
   574             }
       
   575             /* HbDialog::setPrimaryAction deprecation action coloring - end */
   571             d->textItem->update();
   576             d->textItem->update();
   572         }
   577         }
   573     }
   578     }
   574     if (d->iconItem) {
   579     if (d->iconItem) {
   575         HbStyleIconPrimitiveData data;
   580         HbStyleIconPrimitiveData data;
   578         bool itemHasNoContents = false;
   583         bool itemHasNoContents = false;
   579         if (data.icon.isSet()) {
   584         if (data.icon.isSet()) {
   580             if (data.icon.value().isNull() || (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonText)) {
   585             if (data.icon.value().isNull() || (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonText)) {
   581                 itemHasNoContents = true;
   586                 itemHasNoContents = true;
   582             } else {
   587             } else {
   583                     style()->updatePrimitive(d->iconItem, &data, this);
   588                 style()->updatePrimitive(d->iconItem, &data, this);
   584                     d->iconItem->update();
   589                 /* HbDialog::setPrimaryAction deprecation action coloring - begin */
       
   590                 if (d->action && d->action->property("invalid_addition").isValid() ) {
       
   591                     HbIconItem *iconItem = qgraphicsitem_cast<HbIconItem*>(d->iconItem);
       
   592                     iconItem->setColor(QColor("magenta"));
       
   593                 }
       
   594                 /* HbDialog::setPrimaryAction deprecation action coloring - end */
       
   595                 d->iconItem->update();
   585             }
   596             }
   586         }
   597         }
   587         d->iconItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents);
   598         d->iconItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents);
   588     }
   599     }
   589 
       
   590 }
   600 }
   591 
   601 
   592 
   602 
   593 /*!
   603 /*!
   594     \internal
   604     \internal
   685 bool HbToolButton::event(QEvent *event)
   695 bool HbToolButton::event(QEvent *event)
   686 {
   696 {
   687     if (event->type() == QEvent::GraphicsSceneMouseRelease) {
   697     if (event->type() == QEvent::GraphicsSceneMouseRelease) {
   688         mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
   698         mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
   689         return true;
   699         return true;
       
   700     } else if(event->type() == HbEvent::ThemeChanged) {
       
   701         Q_D(HbToolButton);
       
   702         changeEvent(event);
       
   703         if (d->frameItem) {
       
   704             HbFrameItem *item = static_cast<HbFrameItem*>(d->frameItem);
       
   705             item->frameDrawer().themeChanged();
       
   706         }
   690     }
   707     }
   691 
   708 
   692     return HbAbstractButton::event(event);
   709     return HbAbstractButton::event(event);
   693 }
   710 }
   694 
   711