telutils/dialpad/src/dialpadbutton.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     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
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <hbevent.h>
       
    20 #include <hbframeitem.h>
       
    21 
       
    22 #include "dialpadbutton.h"
       
    23 
       
    24 DialpadButton::DialpadButton(QGraphicsItem *parent)
       
    25     : HbPushButton(parent), mButtonType(FunctionButton)
       
    26 {
       
    27 }
       
    28 
       
    29 DialpadButton::~DialpadButton()
       
    30 {
       
    31 }
       
    32 
       
    33 DialpadButton::DialpadButtonType DialpadButton::buttonType() const
       
    34 {
       
    35     return mButtonType;
       
    36 }
       
    37 
       
    38 void DialpadButton::setButtonType(DialpadButtonType type)
       
    39 {
       
    40     mButtonType = type;
       
    41 }
       
    42 
       
    43 bool DialpadButton::sceneEvent(QEvent *event)
       
    44 {
       
    45     bool result = HbPushButton::sceneEvent(event);
       
    46 
       
    47     if (event->type() == QEvent::UngrabMouse) {
       
    48         if (isVisible() && isDown()) {
       
    49             // this is needed in situation, where
       
    50             // longpress launches a dialog (vmbx)
       
    51             // and button release event goes to
       
    52             // dialog (HbPopup grabs mouse).
       
    53             setDown(false);
       
    54             emit clicked();
       
    55             emit released();
       
    56         }
       
    57     }
       
    58 
       
    59     return result;
       
    60 }
       
    61 
       
    62 void DialpadButton::polish(HbStyleParameters& params)
       
    63 {
       
    64     // HbPushButton::polish() prevents layouting
       
    65     // text and additional-text horizontally.
       
    66     HbAbstractButton::polish( params );
       
    67 }
       
    68 
       
    69 void DialpadButton::updatePrimitives()
       
    70 {
       
    71     HbPushButton::updatePrimitives();
       
    72 
       
    73     HbFrameItem* frame =
       
    74         qgraphicsitem_cast<HbFrameItem*>(HbWidget::primitive(QLatin1String("background")));
       
    75 
       
    76     if (!frame) {
       
    77         return;
       
    78     }
       
    79 
       
    80     QString graphicsName;
       
    81 
       
    82     if (!isEnabled()) {
       
    83         graphicsName = QLatin1String("qtg_fr_input_btn_function_disabled");
       
    84     } else if (isDown()) {
       
    85         if (buttonType()==CallButton) {
       
    86             graphicsName = QLatin1String("qtg_fr_btn_green_pressed");
       
    87         } else {
       
    88             graphicsName = QLatin1String("qtg_fr_input_btn_function_pressed");
       
    89         }
       
    90     } else {
       
    91         if (buttonType()==CallButton) {
       
    92             graphicsName = QLatin1String("qtg_fr_btn_green_normal");
       
    93         } else {
       
    94             graphicsName = QLatin1String("qtg_fr_input_btn_function_normal");
       
    95         }
       
    96     }
       
    97 
       
    98     frame->frameDrawer().setFrameGraphicsName(graphicsName);
       
    99 }