camerauis/cameraxui/cxui/src/cxuisettingbuttoncontainer.cpp
changeset 28 3075d9b614e6
parent 19 d9aefe59d544
child 30 7680ea4bbfe7
child 38 0f0b4c1d7744
child 43 0e652f8f1fbd
equal deleted inserted replaced
19:d9aefe59d544 28:3075d9b614e6
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QGraphicsSceneMouseEvent>
       
    19 #include <QCoreApplication>
       
    20 
       
    21 #include <hbfeedbackmanager.h>
       
    22 #include "cxuisettingbutton.h"
       
    23 #include "cxuisettingbuttoncontainer.h"
       
    24 #include "cxutils.h"
       
    25 
       
    26 
       
    27 CxuiSettingButtonContainer::CxuiSettingButtonContainer(QGraphicsItem *parent)
       
    28 : HbWidget(parent), mListCreated(false), mPressedDownButton(NULL), mPreviouslyPressedDownButton(NULL)
       
    29 {
       
    30 
       
    31 }
       
    32 
       
    33 void CxuiSettingButtonContainer::handleButtonPress()
       
    34 {
       
    35     CX_DEBUG_ENTER_FUNCTION();
       
    36     grabMouse();
       
    37 
       
    38     if (!mListCreated){
       
    39         QList<QGraphicsItem*> buttons = this->childItems();
       
    40         CxuiSettingButton *button;
       
    41         foreach(QGraphicsItem *item, buttons){
       
    42             button = static_cast<CxuiSettingButton*>(item);
       
    43             mButtons.append(button);
       
    44         }
       
    45         mListCreated = true;
       
    46     }
       
    47 
       
    48 
       
    49     // find the pressed item
       
    50     foreach (CxuiSettingButton* button , mButtons) {
       
    51 
       
    52         if (button->isDown()) {
       
    53             mPressedDownButton = button;
       
    54             break;
       
    55         }
       
    56     }
       
    57     CX_DEBUG_EXIT_FUNCTION();
       
    58 }
       
    59 
       
    60 void CxuiSettingButtonContainer::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
       
    61 {
       
    62 
       
    63     if (boundingRect().contains(event->pos())) {
       
    64         // moving inside the tool bar
       
    65         if (!mPressedDownButton || !mPressedDownButton->geometry().contains(event->pos())) {
       
    66             if (mPressedDownButton) {
       
    67                 // lift it up and try to find some other button
       
    68                 mPressedDownButton->setDown(false);
       
    69                 mPreviouslyPressedDownButton = mPressedDownButton;
       
    70                 mPressedDownButton = 0;
       
    71             }
       
    72 
       
    73             // Find the pressed button
       
    74             foreach (CxuiSettingButton* button, mButtons) {
       
    75                 if (button->geometry().contains(event->pos())) {
       
    76                     mPressedDownButton = button;
       
    77                     button->setDown(true);
       
    78                     button->setSetting();
       
    79                     HbFeedbackManager* feedback = HbFeedbackManager::instance();
       
    80                     CX_ASSERT_ALWAYS(feedback != NULL);
       
    81                     feedback->triggered(button, Hb::InstantDraggedOver);
       
    82 
       
    83                     break;
       
    84                 }
       
    85             }
       
    86         }
       
    87     } else {
       
    88         // moving outside the tool bar
       
    89 
       
    90         // if a button is pressed down, lift it.
       
    91         if (mPressedDownButton) {
       
    92             mPressedDownButton->setDown(false);
       
    93             mPressedDownButton = 0;
       
    94             mPreviouslyPressedDownButton = mPressedDownButton;
       
    95         }
       
    96     }
       
    97 }
       
    98 
       
    99 void CxuiSettingButtonContainer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   100 {
       
   101     Q_UNUSED(event);
       
   102     ungrabMouse();
       
   103 
       
   104     if (mPressedDownButton
       
   105         && !mPreviouslyPressedDownButton) {
       
   106         // Convert event's scene position to item's coordinate system.
       
   107         event->setPos(mPressedDownButton->mapFromScene(event->scenePos()));
       
   108         QCoreApplication::sendEvent(mPressedDownButton, event);
       
   109         mPressedDownButton = 0;
       
   110         emit buttonReleased();
       
   111     } else if (mPressedDownButton) {
       
   112         mPressedDownButton->setDown(false);
       
   113         emit buttonReleased();
       
   114     } else
       
   115     mPreviouslyPressedDownButton = 0;
       
   116 }
       
   117 
       
   118