src/hbwidgets/widgets/hbcombobox_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 28 b7da29130b0e
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    82 
    82 
    83     if ( !mDropDown ) {
    83     if ( !mDropDown ) {
    84         return;
    84         return;
    85     }
    85     }
    86 
    86 
    87     if ( !mDropDown->scene() || !mDropDown->scene( )->property( "destructed" ).isValid( ) ) {
    87     //if drop down is added to scene then remove it from scene so that scene does not deletes
    88         delete mDropDown;
    88     //drop down again
    89         mDropDown = 0;
    89     if( mDropDown->scene() ) {
    90     }
    90         q->scene()->removeItem(mDropDown);
       
    91     }
       
    92 
       
    93     delete mDropDown;
       
    94     mDropDown = 0;
    91 }
    95 }
    92 
    96 
    93 void HbComboBoxPrivate::init( )
    97 void HbComboBoxPrivate::init( )
    94 {
    98 {
    95     createPrimitives( );
    99     createPrimitives( );
    97 
   101 
    98 void HbComboBoxPrivate::createPrimitives( )
   102 void HbComboBoxPrivate::createPrimitives( )
    99 {
   103 {
   100     Q_Q( HbComboBox );
   104     Q_Q( HbComboBox );
   101 
   105 
   102     mTextItem = q->style( )->createPrimitive( HbStyle::P_ComboBox_text, q );
   106     mTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_ComboBox_text, q );
   103     HbStyle::setItemName( mTextItem, "combobox_labelfield" );
   107     HbStyle::setItemName( mTextItem, "combobox_labelfield" );
   104 
   108 
   105     mBackgroundItem = q->style( )->createPrimitive( HbStyle::P_ComboBox_background, q );
   109     mBackgroundItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_ComboBox_background, q );
   106     HbStyle::setItemName( mBackgroundItem, "text_background" );
   110     HbStyle::setItemName( mBackgroundItem, "text_background" );
   107 
   111 
   108     mButton = q->style( )->createPrimitive( HbStyle::P_ComboBox_button, q );
   112     mButton = HbStylePrivate::createPrimitive( HbStylePrivate::P_ComboBox_button, q );
   109     HbStyle::setItemName( mButton, "combobox_button" );
   113     HbStyle::setItemName( mButton, "combobox_button" );
   110 
   114 
   111     mButtonTouchAreaItem = q->style( )->createPrimitive( HbStyle::P_ComboBoxButton_toucharea, q );
   115     mButtonTouchAreaItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_ComboBoxButton_toucharea, q );
   112 
   116 
   113     static_cast<HbTouchArea*>( mButtonTouchAreaItem )->grabGesture( Qt::TapGesture );
   117     static_cast<HbTouchArea*>( mButtonTouchAreaItem )->grabGesture( Qt::TapGesture );
   114 }
   118 }
   115 
   119 
   116 void HbComboBoxPrivate::touchAreaPressEvent( )
   120 void HbComboBoxPrivate::touchAreaPressEvent( )
   119     if ( q->count( ) > 0 ) {
   123     if ( q->count( ) > 0 ) {
   120         HbWidgetFeedback::triggered( q, Hb::InstantPressed );
   124         HbWidgetFeedback::triggered( q, Hb::InstantPressed );
   121     }
   125     }
   122     mIsDown = true;
   126     mIsDown = true;
   123     q->updatePrimitives( );
   127     q->updatePrimitives( );
   124     q->setProperty( "state", "pressed" );
   128     //Update the state only when valid model is there
       
   129     if ( mModel && mModel->rowCount( ) ) {
       
   130         q->setProperty( "state", "pressed" );
       
   131     }
   125 }
   132 }
   126 
   133 
   127 void HbComboBoxPrivate::touchAreaReleaseEvent(  )
   134 void HbComboBoxPrivate::touchAreaReleaseEvent(  )
   128 {
   135 {
   129     Q_Q( HbComboBox );
   136     Q_Q( HbComboBox );
   236         delete temp;
   243         delete temp;
   237         temp = 0;
   244         temp = 0;
   238     }
   245     }
   239 }
   246 }
   240 
   247 
       
   248 void HbComboBoxPrivate::resetGeometryChangeFlag( )
       
   249 {
       
   250     Q_Q( HbComboBox );
       
   251     QGraphicsWidget *p = q;
       
   252     if( widgetGeometryChange.count() > 0 ) {
       
   253         while ( p->parentWidget( ) ) {
       
   254             p = p->parentWidget( );
       
   255             if ( !widgetGeometryChange.value( p ) ) {
       
   256                 //if earlier geometry change flag was disabled then disable this flag
       
   257                 p->setFlag( QGraphicsItem::ItemSendsGeometryChanges, false );
       
   258             }
       
   259         }
       
   260         widgetGeometryChange.clear();
       
   261     }
       
   262 }
       
   263 
   241 void HbComboBoxPrivate::positionDropDown( )
   264 void HbComboBoxPrivate::positionDropDown( )
   242 {
   265 {
   243     Q_Q( HbComboBox );
   266     Q_Q( HbComboBox );
   244     QRectF popupRect;
   267     QRectF popupRect;
   245     QRectF sceneRect( QPointF( ), HbDeviceProfile::profile( q ).logicalSize( ) );
   268     QRectF sceneRect( QPointF( ), HbDeviceProfile::profile( q ).logicalSize( ) );
   251 
   274 
   252     //read the maximum rows in drop down for different orientation from css
   275     //read the maximum rows in drop down for different orientation from css
   253     if( q->mainWindow( )->orientation( ) == Qt::Horizontal ) {
   276     if( q->mainWindow( )->orientation( ) == Qt::Horizontal ) {
   254         if( mDropDownRowsInLandscape == -1 ) {
   277         if( mDropDownRowsInLandscape == -1 ) {
   255             HbStyleParameters params;
   278             HbStyleParameters params;
   256             q->style( )->parameters( params );
   279             q->style()->parameters( params );
   257             params.addParameter( "max-rows-in-dropdown" );
   280             params.addParameter( "max-rows-in-dropdown" );
   258             q->polish( params );
   281             q->polish( params );
   259             mDropDownRowsInLandscape = params.value( "max-rows-in-dropdown" ).toInt( );
   282             mDropDownRowsInLandscape = params.value( "max-rows-in-dropdown" ).toInt( );
   260         }
   283         }
   261         maxPopupHeight = mDropDownRowsInLandscape * mListItemHeight;
   284         maxPopupHeight = mDropDownRowsInLandscape * mListItemHeight;
   262     } else if( q->mainWindow( )->orientation( ) == Qt::Vertical ) {
   285     } else if( q->mainWindow( )->orientation( ) == Qt::Vertical ) {
   263         if( mDropDownRowsInPortrait == -1 ) {
   286         if( mDropDownRowsInPortrait == -1 ) {
   264             HbStyleParameters params;
   287             HbStyleParameters params;
   265             q->style( )->parameters( params );
   288             q->style()->parameters( params );
   266             params.addParameter( "max-rows-in-dropdown" );
   289             params.addParameter( "max-rows-in-dropdown" );
   267             q->polish( params );
   290             q->polish( params );
   268             mDropDownRowsInPortrait = params.value( "max-rows-in-dropdown" ).toInt( );
   291             mDropDownRowsInPortrait = params.value( "max-rows-in-dropdown" ).toInt( );
   269         }
   292         }
   270         maxPopupHeight = mDropDownRowsInPortrait * mListItemHeight;
   293         maxPopupHeight = mDropDownRowsInPortrait * mListItemHeight;
   386     mDropDown->setMaximumSize( popupSize );
   409     mDropDown->setMaximumSize( popupSize );
   387     mDropDown->setPos( popupPos );
   410     mDropDown->setPos( popupPos );
   388     QGraphicsWidget *p = q;
   411     QGraphicsWidget *p = q;
   389     while ( p->parentWidget( ) ) {
   412     while ( p->parentWidget( ) ) {
   390         p = p->parentWidget( );
   413         p = p->parentWidget( );
       
   414         //cache the original geometry change flag of parent widget
       
   415         QGraphicsItem::GraphicsItemFlags itemFlags = p->flags( );
       
   416         bool geometryFlagEnabled =  itemFlags & QGraphicsItem::ItemSendsGeometryChanges;
       
   417         widgetGeometryChange.insert(p, geometryFlagEnabled);
       
   418 
       
   419         //This flag is being set since geometry change notification is required for properly
       
   420         //positioning drop down when its visible and combobox position is changed for example
       
   421         //when orientation change happens.
       
   422         p->setFlag( QGraphicsItem::ItemSendsGeometryChanges );
   391     }
   423     }
   392     mDropDown->setZValue( p->zValue( ) + 1 );
   424     mDropDown->setZValue( p->zValue( ) + 1 );
   393 }
   425 }
   394 
   426 
   395 void HbComboBoxPrivate::_q_textChanged( const QModelIndex & aIndex )
   427 void HbComboBoxPrivate::_q_textChanged( const QModelIndex & aIndex )
   401         if( mLineEdit ) {
   433         if( mLineEdit ) {
   402             mLineEdit->setText( mText );
   434             mLineEdit->setText( mText );
   403         } else {
   435         } else {
   404             HbStyleOptionComboBox comboBoxOption;
   436             HbStyleOptionComboBox comboBoxOption;
   405             q->initStyleOption( &comboBoxOption );
   437             q->initStyleOption( &comboBoxOption );
   406             q->style( )->updatePrimitive( mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   438             HbStylePrivate::updatePrimitive( mTextItem, HbStylePrivate::P_ComboBox_text, &comboBoxOption );
   407         }
   439         }
   408         mCurrentIndex = aIndex;
   440         mCurrentIndex = aIndex;
   409     } else {
   441     } else {
   410        q->disconnect( mLineEdit, SIGNAL( textChanged ( QString ) ), q,
   442        q->disconnect( mLineEdit, SIGNAL( textChanged ( QString ) ), q,
   411            SLOT( _q_textChanged( QString ) ) );
   443            SLOT( _q_textChanged( QString ) ) );
   598             if( mLineEdit ) {
   630             if( mLineEdit ) {
   599                 mLineEdit->setText( mText );
   631                 mLineEdit->setText( mText );
   600             } else {
   632             } else {
   601                 HbStyleOptionComboBox comboBoxOption;
   633                 HbStyleOptionComboBox comboBoxOption;
   602                 q->initStyleOption(&comboBoxOption);
   634                 q->initStyleOption(&comboBoxOption);
   603                 q->style( )->updatePrimitive(
   635                 HbStylePrivate::updatePrimitive(
   604                     mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   636                     mTextItem, HbStylePrivate::P_ComboBox_text, &comboBoxOption );
   605             }
   637             }
   606         }
   638         }
   607         currentIndexChanged( mCurrentIndex );
   639         currentIndexChanged( mCurrentIndex );
   608     }
   640     }
   609 }
   641 }