telutils/dialpad/src/dialpadbuttonstyle.cpp
changeset 19 e44a8c097b15
parent 15 d7fc66ccd6fb
child 21 5c9f230baf1b
child 23 427125ac6cb8
equal deleted inserted replaced
15:d7fc66ccd6fb 19:e44a8c097b15
     1 /*!
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Custom button style
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbicon.h>
       
    19 #include <hbstyleoptionpushbutton.h>
       
    20 #include <hbframeitem.h>
       
    21 #include <hbframedrawer.h>
       
    22 #include "dialpadbuttonstyle.h"
       
    23 
       
    24 DialpadButtonStyle::DialpadButtonStyle()
       
    25     : mButtonStyle(NormalButtonStyle)
       
    26 {
       
    27 }
       
    28 
       
    29 DialpadButtonStyle::~DialpadButtonStyle()
       
    30 {
       
    31 }
       
    32 
       
    33 void DialpadButtonStyle::updatePrimitive(
       
    34     QGraphicsItem *item,
       
    35     HbStyle::Primitive primitive,
       
    36     const QStyleOption *option ) const
       
    37 {
       
    38     switch(primitive){
       
    39     case P_PushButton_background:{
       
    40         const HbStyleOptionPushButton *opt = 
       
    41             qstyleoption_cast<const HbStyleOptionPushButton *>(option);
       
    42         HbFrameItem *frameItem = qgraphicsitem_cast<HbFrameItem*>( item );
       
    43         if(!frameItem)
       
    44             return;
       
    45 
       
    46         frameItem->setZValue(-1.0);
       
    47         if(opt->backgroundFrameDrawer &&!(opt->backgroundFrameDrawer->isNull())) {
       
    48             frameItem->setFrameDrawer( (opt->backgroundFrameDrawer));
       
    49         } else {
       
    50             QString frameGraphicsName;
       
    51             QIcon::Mode mode = QIcon::Disabled;
       
    52             QIcon::State state = QIcon::Off;
       
    53             if (opt->state & QStyle::State_Enabled)
       
    54                 mode = QIcon::Normal;
       
    55             if (opt->state & QStyle::State_Active)
       
    56                 mode = QIcon::Active;
       
    57             if (opt->state & QStyle::State_Selected)
       
    58                 mode = QIcon::Selected;
       
    59             if (opt->state & QStyle::State_On)
       
    60                 state = QIcon::On;
       
    61 
       
    62             if (mode == QIcon::Disabled && state == QIcon::Off) {
       
    63                 frameGraphicsName = "qtg_fr_input_btn_function_disabled";
       
    64             } else if (mode == QIcon::Normal && state == QIcon::On) {
       
    65                 if (mButtonStyle==CallButtonStyle) {
       
    66                     frameGraphicsName = "qtg_fr_btn_green_pressed";
       
    67                 } else if (mButtonStyle==NormalButtonStyle) {
       
    68                     frameGraphicsName = "qtg_fr_input_btn_keypad_pressed";
       
    69                 } else {
       
    70                     frameGraphicsName = "qtg_fr_input_btn_function_pressed";
       
    71                 }
       
    72             } else if (mode == QIcon::Selected && state == QIcon::Off) {
       
    73                 frameGraphicsName = "qtg_fr_btn_highlight";
       
    74             } else {
       
    75                 if (mButtonStyle==CallButtonStyle) {
       
    76                     frameGraphicsName = "qtg_fr_btn_green_normal";
       
    77                 } else if (mButtonStyle==NormalButtonStyle) {
       
    78                     frameGraphicsName = "qtg_fr_input_btn_keypad_normal";
       
    79                 } else {
       
    80                     frameGraphicsName = "qtg_fr_input_btn_function_normal";
       
    81                 }
       
    82             }
       
    83 
       
    84             frameItem->frameDrawer().setFrameGraphicsName(frameGraphicsName);
       
    85             if (!opt->background.isNull()) {
       
    86                 QString customName = opt->background.iconName(mode, state);
       
    87                 frameItem->frameDrawer().setFrameGraphicsName(customName);
       
    88                 frameItem->setGeometry(opt->rect);
       
    89                 frameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
    90                 break;
       
    91             }
       
    92             frameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
    93         }
       
    94 
       
    95         frameItem->setGeometry(opt->rect);
       
    96         break;
       
    97     }
       
    98 
       
    99     default:
       
   100         HbStyle::updatePrimitive(item,primitive,option);
       
   101         break;
       
   102     } // switch
       
   103 }
       
   104 
       
   105 void DialpadButtonStyle::setButtonStyle(ButtonStyle style)
       
   106 {
       
   107     mButtonStyle = style;
       
   108 }