phoneuis/bubblemanager2/bubblecore/src/bubbleexpandedhandler.cpp
changeset 21 92ab7f8d0eab
child 22 6bb1b21d2484
equal deleted inserted replaced
4:c84cf270c54f 21:92ab7f8d0eab
       
     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:  Expanded call bubble handler.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <hbaction.h>
       
    20 #include <hbpushbutton.h>
       
    21 #include <hbtextitem.h>
       
    22 
       
    23 #include "bubblemanager2.h"
       
    24 #include "bubbleexpandedhandler.h"
       
    25 #include "bubbleheader.h"
       
    26 #include "bubbleutils.h"
       
    27 #include "bubbleimagewidget.h"
       
    28 #include "bubbleheadingwidget.h"
       
    29 
       
    30 BubbleExpandedHandler::BubbleExpandedHandler(
       
    31     BubbleWidgetManager& widgetManager,
       
    32     BubbleWidgetManager::View view,
       
    33     BubbleWidgetManager::Container container,
       
    34     QObject* parent )
       
    35     : BubbleHandler(widgetManager,view,container,parent)
       
    36 {
       
    37     mHeading = qobject_cast<BubbleHeadingWidget*>(
       
    38         widget(BubbleWidgetManager::Heading));
       
    39     Q_ASSERT(mHeading);
       
    40 
       
    41     mImage = qobject_cast<BubbleImageWidget*>(
       
    42         widget(BubbleWidgetManager::Image));
       
    43     Q_ASSERT(mImage);
       
    44 
       
    45     mButtonCenter = qobject_cast<HbPushButton*>(
       
    46         widget(BubbleWidgetManager::CenterButton));
       
    47     Q_ASSERT(mButtonCenter);
       
    48     mButtonLeft = qobject_cast<HbPushButton*>(
       
    49         widget(BubbleWidgetManager::LeftButton));
       
    50     Q_ASSERT(mButtonLeft);
       
    51     mButtonRight = qobject_cast<HbPushButton*>(
       
    52         widget(BubbleWidgetManager::RightButton));
       
    53     Q_ASSERT(mButtonRight);
       
    54 
       
    55     reset();
       
    56 }
       
    57 
       
    58 BubbleExpandedHandler::~BubbleExpandedHandler()
       
    59 {
       
    60 }
       
    61 
       
    62 void BubbleExpandedHandler::reset()
       
    63 {  
       
    64     mHeader = 0;
       
    65     mButtonCenter->hide();
       
    66     mButtonCenter->setDown(false);
       
    67     mButtonCenter->disconnect();
       
    68     mButtonCenter->setText("");
       
    69     mButtonLeft->hide();
       
    70     mButtonLeft->setDown(false);
       
    71     mButtonLeft->disconnect();
       
    72     mButtonLeft->setText("");
       
    73     mButtonRight->hide();
       
    74     mButtonRight->setDown(false);
       
    75     mButtonRight->disconnect();
       
    76     mButtonRight->setText("");
       
    77     mImage->hide();
       
    78     mHeading->reset();
       
    79 }
       
    80 
       
    81 void BubbleExpandedHandler::readBubbleHeader(
       
    82     const BubbleHeader& header )
       
    83 {
       
    84     mHeader = &header;
       
    85 
       
    86     mHeading->readBubbleHeader(header);
       
    87 
       
    88     if (header.callImage().length()) {
       
    89         mImage->setImage(header.callImage());
       
    90         mImage->show();
       
    91     }
       
    92 
       
    93     setButtons(mHeader->actions());
       
    94 }
       
    95 
       
    96 void BubbleExpandedHandler::setButtons(const QList<HbAction*>& actions)
       
    97 {
       
    98     if ( actions.count()==1 && mButtonCenter ) {
       
    99         HbAction* action = actions.at(0);
       
   100         mButtonCenter->setIcon( action->icon() );
       
   101         connect(mButtonCenter, SIGNAL( clicked() ),
       
   102                 action, SLOT( trigger() ) );
       
   103         BubbleUtils::setButtonStyleForAction(*mButtonCenter,*action);
       
   104         mButtonCenter->show();
       
   105     } else  if (actions.count()==2 && mButtonLeft && mButtonRight ) {
       
   106         // Left button
       
   107         HbAction* action1 = actions.at(0);
       
   108         mButtonLeft->setIcon(action1->icon());
       
   109         connect( mButtonLeft, SIGNAL( clicked() ),
       
   110                  action1, SLOT( trigger() ) );
       
   111         BubbleUtils::setButtonStyleForAction(*mButtonLeft,*action1);
       
   112         mButtonLeft->show();
       
   113         // Right button
       
   114         HbAction* action2 = actions.at(1);
       
   115         mButtonRight->setIcon( action2->icon() );
       
   116         connect( mButtonRight, SIGNAL( clicked() ),
       
   117                  action2, SLOT( trigger() ) );
       
   118         BubbleUtils::setButtonStyleForAction(*mButtonRight,*action2);
       
   119         mButtonRight->show();
       
   120     }
       
   121 }
       
   122 
       
   123 QGraphicsWidget* BubbleExpandedHandler::graphicsWidgetForAction(
       
   124     HbAction* action ) const
       
   125 {
       
   126     if ( mButtonLeft->text() == action->text() ) {
       
   127         return mButtonLeft;
       
   128     } else if ( mButtonRight->text() == action->text() ) {
       
   129         return mButtonRight;
       
   130     } else if ( mButtonCenter->text() == action->text() ) {
       
   131         return mButtonCenter;
       
   132     } else {
       
   133         return 0;
       
   134     }
       
   135 }
       
   136 
       
   137 void BubbleExpandedHandler::updateTimerDisplayNow()
       
   138 {
       
   139     mHeading->updateTimerDisplayNow();
       
   140 }