src/hbwidgets/widgets/hbcombodropdown_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 28 b7da29130b0e
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    26 #include "hbcombodropdown_p.h"
    26 #include "hbcombodropdown_p.h"
    27 #include "hbcombobox_p.h"
    27 #include "hbcombobox_p.h"
    28 #include "hbwidget_p.h"
    28 #include "hbwidget_p.h"
    29 #include <hblistview.h>
    29 #include <hblistview.h>
    30 #include <hbwidgetfeedback.h>
    30 #include <hbwidgetfeedback.h>
       
    31 #include <hbinputvirtualkeyboard.h>
    31 
    32 
    32 #include <hbtapgesture.h>
    33 #include <hbtapgesture.h>
    33 #include <hbpangesture.h>
    34 #include <hbpangesture.h>
    34 #include <QGestureEvent>
    35 #include <QGestureEvent>
       
    36 #include <QGraphicsSceneMouseEvent>
    35 
    37 
    36 class HbComboDropDownPrivate : public HbWidgetPrivate
    38 class HbComboDropDownPrivate : public HbWidgetPrivate
    37 {
    39 {
    38 };
    40 };
    39 HbComboDropDown::HbComboDropDown( HbComboBoxPrivate *comboBoxPrivate, QGraphicsItem *parent )
    41 HbComboDropDown::HbComboDropDown( HbComboBoxPrivate *comboBoxPrivate, QGraphicsItem *parent )
    42      comboPrivate( comboBoxPrivate ),
    44      comboPrivate( comboBoxPrivate ),
    43      vkbOpened( false ),
    45      vkbOpened( false ),
    44      backgroundPressed( false )
    46      backgroundPressed( false )
    45 {
    47 {
    46     Q_D(HbComboDropDown);
    48     Q_D(HbComboDropDown);
    47     d->setBackgroundItem(HbStyle::P_ComboBoxPopup_background);
    49     d->setBackgroundItem(HbStylePrivate::P_ComboBoxPopup_background);
    48     #if QT_VERSION >= 0x040600
    50     #if QT_VERSION >= 0x040600
    49     //this is to keep the focus in the previous widget.
    51     //this is to keep the focus in the previous widget.
    50     setFlag( QGraphicsItem::ItemIsPanel, true );
    52     setFlag( QGraphicsItem::ItemIsPanel, true );
    51     setActive( false );
    53     setActive( false );
    52     #endif
    54     #endif
    53 }
    55 }
    54 
    56 
    55 HbComboDropDown::~HbComboDropDown( )
    57 HbComboDropDown::~HbComboDropDown( )
    56 {
    58 {
    57 
       
    58 }
    59 }
    59 
    60 
    60 void HbComboDropDown::createList( )
    61 void HbComboDropDown::createList( )
    61 {
    62 {
    62    mList = new HbListView( this );
    63    mList = new HbListView( this );
    83 bool HbComboDropDown::eventFilter( QObject *obj, QEvent *event )
    84 bool HbComboDropDown::eventFilter( QObject *obj, QEvent *event )
    84 {
    85 {
    85     Q_UNUSED( obj );
    86     Q_UNUSED( obj );
    86     bool accepted = false;
    87     bool accepted = false;
    87 
    88 
    88     if ( isVisible( ) && !vkbOpened ) {
    89     if ( isVisible( ) ) {
    89         switch( event->type( ) )
    90         switch( event->type( ) )
    90         {
    91         {
    91         case QEvent::GraphicsSceneMousePress:
    92         case QEvent::GraphicsSceneMousePress:
    92         case QEvent::GraphicsSceneMouseDoubleClick:
    93         case QEvent::GraphicsSceneMouseDoubleClick:
    93             {
    94             {
    94                 if( !( this->isUnderMouse( ) ) ) {
    95                 if( !vkbOpened ) {
    95                     HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed );
    96                     //if vkb is not opened and dropdown is not clicked then dismiss drop down
    96                     setVisible( false );
    97                     if( !( this->isUnderMouse( ) ) ) {
    97                     comboPrivate->q_ptr->setProperty("state","normal");
    98                         HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed );
    98                     backgroundPressed = true;
    99                         setVisible( false );
    99                     accepted = true;
   100                         comboPrivate->q_ptr->setProperty("state","normal");
       
   101                         backgroundPressed = true;
       
   102                         accepted = true;
       
   103                     }
       
   104                 } else {
       
   105                     //if vkb is opened then dismiss drop down only if click happened outside drop down and
       
   106                     //vkb area
       
   107                     if( comboPrivate->mEditable ) {
       
   108                         HbEditorInterface editorInterface( comboPrivate->q_ptr );
       
   109                         HbVkbHost *host = editorInterface.vkbHost( );
       
   110                         if( host ) {
       
   111                             //get the scene rect of vkb
       
   112                             QGraphicsWidget *vkbWidget = host->activeKeypad( )->asGraphicsWidget( );
       
   113                             QRectF tmp = host->applicationArea( );
       
   114                             QRectF vkbArea = vkbWidget->mapToScene( tmp ).boundingRect( );
       
   115                             QGraphicsSceneMouseEvent *mouseEvent = 
       
   116                                 static_cast< QGraphicsSceneMouseEvent * >( event );
       
   117                             if( !( this->isUnderMouse( ) ) &&
       
   118                                 !vkbArea.contains( mouseEvent->scenePos( ) ) ) {
       
   119                                 HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed );
       
   120                                 setVisible( false );
       
   121                                 comboPrivate->q_ptr->setProperty( "state", "normal" );
       
   122                                 backgroundPressed = true;
       
   123                                 accepted = true;
       
   124                             }
       
   125                         }
       
   126                     }
   100                 }
   127                 }
   101             }
   128             }
   102             break;
   129             break;
   103         case QEvent::Gesture:
   130         case QEvent::Gesture:
   104             {
   131             {
   122         }
   149         }
   123     }
   150     }
   124     return accepted;
   151     return accepted;
   125 }
   152 }
   126 
   153 
       
   154 QVariant HbComboDropDown::itemChange( GraphicsItemChange change, const QVariant & value )
       
   155 {
       
   156     switch( change ) {
       
   157         case QGraphicsItem::ItemVisibleHasChanged:
       
   158             if( !value.toBool( ) ) {
       
   159                 comboPrivate->resetGeometryChangeFlag( );
       
   160             }
       
   161             break;
       
   162         default:
       
   163             break;
       
   164     }
       
   165     return HbWidget::itemChange( change, value );
       
   166 }
       
   167 
   127 #include "moc_hbcombodropdown_p.cpp"
   168 #include "moc_hbcombodropdown_p.cpp"
   128 
   169