phoneuis/bubblemanager2/bubblecore/src/bubblecontainerwidget.cpp
changeset 37 ba76fc04e6c2
child 46 bc5a64e5bc3c
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     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: Bubble container.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <hbstyle.h>
       
    20 #include <hbframeitem.h>
       
    21 #include <hbframedrawer.h>
       
    22 #include "bubblecontainerwidget.h"
       
    23 
       
    24 BubbleContainerWidget::BubbleContainerWidget(QGraphicsItem* item)
       
    25     : HbWidget(item), mBackground(0)
       
    26 {
       
    27     createPrimitives();
       
    28     updatePrimitives();
       
    29     Q_ASSERT(mBackground);
       
    30 }
       
    31 
       
    32 BubbleContainerWidget::~BubbleContainerWidget()
       
    33 {
       
    34 }
       
    35 
       
    36 void BubbleContainerWidget::createPrimitives()
       
    37 {
       
    38     delete mBackground;
       
    39     mBackground = new HbFrameItem(this);
       
    40     style()->setItemName(mBackground, "background");
       
    41     mBackground->setZValue(-1.0);
       
    42     mBackground->setVisible(false); // background in drawn in paint()
       
    43 }
       
    44 
       
    45 void BubbleContainerWidget::updatePrimitives()
       
    46 {
       
    47     mBackground->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
    48     mBackground->frameDrawer().setFrameGraphicsName("qtg_fr_list_normal");
       
    49 }
       
    50 
       
    51 void BubbleContainerWidget::mousePressEvent(
       
    52     QGraphicsSceneMouseEvent * event)
       
    53 {
       
    54     if (event->button() != Qt::LeftButton) {
       
    55         event->ignore();
       
    56         return;
       
    57     }
       
    58 
       
    59     mPressed = true;
       
    60     event->accept();
       
    61 }
       
    62 
       
    63 void BubbleContainerWidget::mouseMoveEvent(
       
    64     QGraphicsSceneMouseEvent *event)
       
    65 {
       
    66     if (!(event->buttons() & Qt::LeftButton)) {
       
    67         event->ignore();
       
    68         return;
       
    69     }
       
    70 
       
    71     if ( !rect().contains(event->pos()) && mPressed ) {
       
    72         ungrabMouse();
       
    73         mPressed = false;
       
    74     }
       
    75 }
       
    76 
       
    77 void BubbleContainerWidget::mouseReleaseEvent(
       
    78     QGraphicsSceneMouseEvent *event)
       
    79 {
       
    80     if (event->button() != Qt::LeftButton) {
       
    81         event->ignore();
       
    82         return;
       
    83     }
       
    84 
       
    85     if (mPressed) {
       
    86         emit clicked();
       
    87         mPressed = false;
       
    88         event->accept();
       
    89     }
       
    90 }
       
    91 
       
    92 void BubbleContainerWidget::paint(
       
    93     QPainter *painter,
       
    94     const QStyleOptionGraphicsItem *option,
       
    95     QWidget *widget)
       
    96 {
       
    97     Q_UNUSED(widget)
       
    98     Q_UNUSED(option)
       
    99 
       
   100     mBackground->frameDrawer().paint(painter,boundingRect());
       
   101 }
       
   102 
       
   103 void BubbleContainerWidget::showEvent(QShowEvent *event)
       
   104 {
       
   105     Q_UNUSED(event)
       
   106     mPressed = false;
       
   107 }
       
   108