telutils/dialpad/src/dialpadbuttonstyle.cpp
changeset 15 d7fc66ccd6fb
parent 13 e32024264ebb
equal deleted inserted replaced
13:e32024264ebb 15:d7fc66ccd6fb
    17 
    17 
    18 #include <hbicon.h>
    18 #include <hbicon.h>
    19 #include <hbstyleoptionpushbutton.h>
    19 #include <hbstyleoptionpushbutton.h>
    20 #include <hbframeitem.h>
    20 #include <hbframeitem.h>
    21 #include <hbframedrawer.h>
    21 #include <hbframedrawer.h>
    22 #include <hbiconitem.h>
       
    23 #include <hbtextitem.h>
       
    24 #include <hbcolorscheme.h>
       
    25 #include "dialpadbuttonstyle.h"
    22 #include "dialpadbuttonstyle.h"
    26 
    23 
    27 DialpadButtonStyle::DialpadButtonStyle()
    24 DialpadButtonStyle::DialpadButtonStyle()
    28     : mButtonStyle(NormalButtonStyle)
    25     : mButtonStyle(NormalButtonStyle)
    29 {
    26 {
    61                 mode = QIcon::Selected;
    58                 mode = QIcon::Selected;
    62             if (opt->state & QStyle::State_On)
    59             if (opt->state & QStyle::State_On)
    63                 state = QIcon::On;
    60                 state = QIcon::On;
    64 
    61 
    65             if (mode == QIcon::Disabled && state == QIcon::Off) {
    62             if (mode == QIcon::Disabled && state == QIcon::Off) {
    66                 frameGraphicsName = "qtg_fr_btn_disabled";
    63                 frameGraphicsName = "qtg_fr_input_btn_function_disabled";
    67             } else if (mode == QIcon::Normal && state == QIcon::On) {
    64             } else if (mode == QIcon::Normal && state == QIcon::On) {
    68                 if (mButtonStyle==CallButtonStyle) {
    65                 if (mButtonStyle==CallButtonStyle) {
    69                     frameGraphicsName = "qtg_fr_btn_green_pressed";
    66                     frameGraphicsName = "qtg_fr_btn_green_pressed";
    70                 } else if (mButtonStyle==NormalButtonStyle) {
    67                 } else if (mButtonStyle==NormalButtonStyle) {
    71                     frameGraphicsName = "qtg_fr_input_btn_keypad_pressed";
    68                     frameGraphicsName = "qtg_fr_input_btn_keypad_pressed";
    97 
    94 
    98         frameItem->setGeometry(opt->rect);
    95         frameItem->setGeometry(opt->rect);
    99         break;
    96         break;
   100     }
    97     }
   101 
    98 
   102     case P_PushButton_icon: {
       
   103         HbStyle::updatePrimitive(item,primitive,option);
       
   104 
       
   105         // override color (todo: via css, when supported by fw)
       
   106         const HbStyleOptionPushButton *opt =
       
   107             qstyleoption_cast<const HbStyleOptionPushButton *>(option);
       
   108         QIcon::Mode mode = QIcon::Disabled;
       
   109         QIcon::State state = QIcon::Off;
       
   110         if (opt->state & QStyle::State_Enabled)
       
   111             mode = QIcon::Normal;
       
   112         if (opt->state & QStyle::State_On)
       
   113             state = QIcon::On;
       
   114 
       
   115         if (mButtonStyle==CallButtonStyle &&
       
   116             mode == QIcon::Normal) {
       
   117             if (state==QIcon::On) {
       
   118                 QColor color(HbColorScheme::color("qtc_callhandling_answer_pressed"));
       
   119                 setIconColor(item,color);
       
   120             } else {
       
   121                 QColor color(HbColorScheme::color("qtc_callhandling_answer_normal"));
       
   122                 setIconColor(item,color);
       
   123             }
       
   124         } else if (mButtonStyle==NormalButtonStyle) {
       
   125             QColor color;
       
   126             color = HbColorScheme::color("qtc_input_button_normal");
       
   127             setIconColor(item,color);
       
   128         } else { // function button
       
   129             QColor color;
       
   130             color = HbColorScheme::color("qtc_input_function_normal");
       
   131             setIconColor(item,color);
       
   132         }
       
   133         break;
       
   134     }
       
   135 
       
   136     case P_PushButton_text: {
       
   137         HbStyle::updatePrimitive(item,primitive,option);
       
   138         // override color (todo: via css, when supported by fw)
       
   139         setTextColor(item);
       
   140         break;
       
   141     }
       
   142 
       
   143     case P_PushButton_additionaltext: {
       
   144         HbStyle::updatePrimitive(item,primitive,option);
       
   145         // override color (todo: via css, when supported by fw)
       
   146         setTextColor(item);
       
   147         break;
       
   148     }
       
   149 
       
   150     default:
    99     default:
   151         HbStyle::updatePrimitive(item,primitive,option);
   100         HbStyle::updatePrimitive(item,primitive,option);
   152         break;
   101         break;
   153     } // switch
   102     } // switch
   154 }
   103 }
   155 
   104 
   156 void DialpadButtonStyle::setButtonStyle(ButtonStyle style)
   105 void DialpadButtonStyle::setButtonStyle(ButtonStyle style)
   157 {
   106 {
   158     mButtonStyle = style;
   107     mButtonStyle = style;
   159 }
   108 }
   160 
       
   161 void DialpadButtonStyle::setTextColor(QGraphicsItem *item) const
       
   162 {
       
   163     HbTextItem *textPrim = qgraphicsitem_cast<HbTextItem*>(item);
       
   164     if (textPrim) {
       
   165         QColor color;
       
   166         color = HbColorScheme::color("qtc_input_button_normal");
       
   167         if (color.isValid()) {
       
   168             textPrim->setTextColor(color);
       
   169         } else {
       
   170             textPrim->setTextColor(Qt::black);
       
   171         }
       
   172     }
       
   173 }
       
   174 
       
   175 void DialpadButtonStyle::setIconColor(
       
   176     QGraphicsItem *item,
       
   177     const QColor &color ) const
       
   178 {
       
   179     HbIconItem *iconItem = qgraphicsitem_cast<HbIconItem*>(item);
       
   180 
       
   181     if (iconItem) {
       
   182         if (color.isValid()) {
       
   183             iconItem->setColor(color);
       
   184         } else {
       
   185             iconItem->setColor(Qt::black);
       
   186         }
       
   187     }
       
   188 }