src/hbwidgets/widgets/hbcombobox.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    29 #include <hblistview.h>
    29 #include <hblistview.h>
    30 #include <hbtoucharea.h>
    30 #include <hbtoucharea.h>
    31 #include <hbtextitem.h>
    31 #include <hbtextitem.h>
    32 #include <hbstyleoptioncombobox_p.h>
    32 #include <hbstyleoptioncombobox_p.h>
    33 #include <hbnamespace_p.h>
    33 #include <hbnamespace_p.h>
       
    34 #include <hbmainwindow.h>
    34 #include <QStandardItemModel>
    35 #include <QStandardItemModel>
    35 #include <QGraphicsScene>
    36 #include <QGraphicsScene>
    36 #include <QDebug>
    37 #include <QDebug>
    37 
    38 
    38 #include <hbtapgesture.h>
    39 #include <hbtapgesture.h>
   159 /*!
   160 /*!
   160     @beta
   161     @beta
   161 
   162 
   162     \property HbComboBox::items
   163     \property HbComboBox::items
   163 
   164 
   164     It replaces the existing list with \a texts.
   165     It replaces the existing list with \a texts. If \a texts passed is empty then this function 
       
   166     clears the model and returns. 
       
   167 
       
   168     \sa clear()
   165 */
   169 */
   166 void HbComboBox::setItems( const QStringList &texts )
   170 void HbComboBox::setItems( const QStringList &texts )
   167 {  
   171 {  
   168     if ( texts.isEmpty( ) ) {
   172     if ( texts.isEmpty( ) ) {
       
   173         //if string list passed is empty then clear the current items in combobox
       
   174         clear();
   169         return;
   175         return;
   170     }
   176     }
   171     QStandardItemModel* model = new QStandardItemModel( this );
   177     QStandardItemModel* model = new QStandardItemModel( this );
   172     int textCount = texts.count( );
   178     int textCount = texts.count( );
   173     for( int i = 0; i < textCount; i++ )
   179     for( int i = 0; i < textCount; i++ )
   485                         d->mLineEdit->setText( QString( ) );
   491                         d->mLineEdit->setText( QString( ) );
   486                     } else {
   492                     } else {
   487                         d->mText.clear( );
   493                         d->mText.clear( );
   488                         HbStyleOptionComboBox comboBoxOption;
   494                         HbStyleOptionComboBox comboBoxOption;
   489                         initStyleOption( &comboBoxOption );
   495                         initStyleOption( &comboBoxOption );
   490                         style( )->updatePrimitive(
   496                         HbStylePrivate::updatePrimitive(
   491                             d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   497                             d->mTextItem, HbStylePrivate::P_ComboBox_text, &comboBoxOption );
   492                     }
   498                     }
   493                 }
   499                 }
   494                 d->mCurrentIndex = QModelIndex();
   500                 d->mCurrentIndex = QModelIndex();
   495                 return;
   501                 return;
   496             }
   502             }
   507                         d->mLineEdit->setText( QString( ) );
   513                         d->mLineEdit->setText( QString( ) );
   508                     } else {
   514                     } else {
   509                         d->mText = d->mModel->data( d->mCurrentIndex ).toString( );
   515                         d->mText = d->mModel->data( d->mCurrentIndex ).toString( );
   510                         HbStyleOptionComboBox comboBoxOption;
   516                         HbStyleOptionComboBox comboBoxOption;
   511                         initStyleOption( &comboBoxOption );
   517                         initStyleOption( &comboBoxOption );
   512                         style( )->updatePrimitive(
   518                         HbStylePrivate::updatePrimitive(
   513                             d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption);
   519                             d->mTextItem, HbStylePrivate::P_ComboBox_text, &comboBoxOption);
   514                     }
   520                     }
   515                 }
   521                 }
   516                 d->currentIndexChanged( d->mCurrentIndex );
   522                 d->currentIndexChanged( d->mCurrentIndex );
   517             }
   523             }
   518         }
   524         }
   577 QGraphicsItem* HbComboBox::primitive( HbStyle::Primitive primitive ) const
   583 QGraphicsItem* HbComboBox::primitive( HbStyle::Primitive primitive ) const
   578 {
   584 {
   579     Q_D( const HbComboBox );
   585     Q_D( const HbComboBox );
   580 
   586 
   581     switch( primitive ) {
   587     switch( primitive ) {
   582         case HbStyle::P_ComboBox_text:
   588         case HbStylePrivate::P_ComboBox_text:
   583             return d->mTextItem;
   589             return d->mTextItem;
   584         case HbStyle::P_ComboBox_background:
   590         case HbStylePrivate::P_ComboBox_background:
   585             return d->mBackgroundItem;
   591             return d->mBackgroundItem;
   586         case HbStyle::P_ComboBox_button:
   592         case HbStylePrivate::P_ComboBox_button:
   587             return d->mButton;
   593             return d->mButton;
   588         case HbStyle::P_ComboBoxButton_toucharea:
   594         case HbStylePrivate::P_ComboBoxButton_toucharea:
   589             return d->mButtonTouchAreaItem;
   595             return d->mButtonTouchAreaItem;
   590         default:
   596         default:
   591             return 0;
   597             return 0;
   592     }
   598     }
   593 }
   599 }
   612     HbWidget::initStyleOption( &styleOption );
   618     HbWidget::initStyleOption( &styleOption );
   613     if ( d->mIsDown ) {
   619     if ( d->mIsDown ) {
   614         styleOption.state |= QStyle::State_Sunken;
   620         styleOption.state |= QStyle::State_Sunken;
   615     }
   621     }
   616     if ( d->mBackgroundItem ) {
   622     if ( d->mBackgroundItem ) {
   617         style( )->updatePrimitive( 
   623         HbStylePrivate::updatePrimitive( 
   618             d->mBackgroundItem, HbStyle::P_ComboBox_background, &styleOption );
   624             d->mBackgroundItem, HbStylePrivate::P_ComboBox_background, &styleOption );
   619         style( )->updatePrimitive( 
   625         HbStylePrivate::updatePrimitive( 
   620             d->mButton, HbStyle::P_ComboBox_button, &styleOption );
   626             d->mButton, HbStylePrivate::P_ComboBox_button, &styleOption );
   621     }
   627     }
   622 }
   628 }
   623 
   629 
   624 /*!
   630 /*!
   625     @beta
   631     @beta
   639                 d->mLineEdit->setText( QString( ) );
   645                 d->mLineEdit->setText( QString( ) );
   640             } else {
   646             } else {
   641                 d->mText.clear( );
   647                 d->mText.clear( );
   642                 HbStyleOptionComboBox comboBoxOption;
   648                 HbStyleOptionComboBox comboBoxOption;
   643                 initStyleOption( &comboBoxOption );
   649                 initStyleOption( &comboBoxOption );
   644                 style( )->updatePrimitive( d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   650                 HbStylePrivate::updatePrimitive( d->mTextItem, HbStylePrivate::P_ComboBox_text, &comboBoxOption );
   645             }
   651             }
   646         }
   652         }
   647     }
   653     }
   648 }
   654 }
   649 
   655 
   985                         d->mLineEdit->setText( text );
   991                         d->mLineEdit->setText( text );
   986                     } else {
   992                     } else {
   987                         d->mText = text ;
   993                         d->mText = text ;
   988                         HbStyleOptionComboBox comboBoxOption;
   994                         HbStyleOptionComboBox comboBoxOption;
   989                         initStyleOption( &comboBoxOption );
   995                         initStyleOption( &comboBoxOption );
   990                         style( )->updatePrimitive(
   996                         HbStylePrivate::updatePrimitive(
   991                             d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   997                             d->mTextItem, HbStylePrivate::P_ComboBox_text, &comboBoxOption );
   992                     }
   998                     }
   993                 }
   999                 }
   994             }
  1000             }
   995         }
  1001         }
   996     }
  1002     }
  1046 }
  1052 }
  1047 
  1053 
  1048 /*!
  1054 /*!
  1049     \reimp
  1055     \reimp
  1050  */
  1056  */
       
  1057 void HbComboBox::polish( HbStyleParameters& params )
       
  1058 {
       
  1059     Q_D(HbComboBox);
       
  1060     params.addParameter( "max-rows-in-dropdown" );
       
  1061     HbWidget::polish(params);
       
  1062 
       
  1063     //read the maximum rows in drop down for different orientation from css
       
  1064     if (isVisible()) {
       
  1065         if( mainWindow( )->orientation( ) == Qt::Horizontal ) {
       
  1066             if( d->mDropDownRowsInLandscape == -1 ) {
       
  1067                 d->mDropDownRowsInLandscape = params.value( "max-rows-in-dropdown" ).toInt( );
       
  1068                 if( d->mDropDown && d->mDropDown->isVisible() ) {
       
  1069                     //if drop dow is visible in one mode and then orientation is changed then
       
  1070                     //drop down was not resized properly since positionDropDown is getting called
       
  1071                     //before polish(). Hence forcing to position drop down again.
       
  1072                     d->positionDropDown();
       
  1073                 }
       
  1074             }
       
  1075         } else if( mainWindow( )->orientation( ) == Qt::Vertical ) {
       
  1076             if( d->mDropDownRowsInPortrait == -1 ) {
       
  1077                 d->mDropDownRowsInPortrait = params.value( "max-rows-in-dropdown" ).toInt( );
       
  1078                 if( d->mDropDown && d->mDropDown->isVisible() ) {
       
  1079                     //if drop dow is visible in one mode and then orientation is changed then
       
  1080                     //drop down was not resized properly since positionDropDown is getting called
       
  1081                     //before polish(). Hence forcing to position drop down again.
       
  1082                     d->positionDropDown();
       
  1083                 }
       
  1084             }
       
  1085         }
       
  1086     }
       
  1087 }
       
  1088 
       
  1089 /*!
       
  1090     \reimp
       
  1091  */
  1051 QVariant HbComboBox::itemChange( GraphicsItemChange change, const QVariant & value )
  1092 QVariant HbComboBox::itemChange( GraphicsItemChange change, const QVariant & value )
  1052 {
  1093 {
  1053     Q_D( HbComboBox );
  1094     Q_D( HbComboBox );
  1054     switch( change ) {
  1095     switch( change ) {
  1055         case QGraphicsItem::ItemScenePositionHasChanged:
  1096         case QGraphicsItem::ItemScenePositionHasChanged:
  1076             break;
  1117             break;
  1077     }
  1118     }
  1078     HbWidget::changeEvent( event );
  1119     HbWidget::changeEvent( event );
  1079 }
  1120 }
  1080 
  1121 
  1081 
       
  1082 // End of file
  1122 // End of file
  1083 
  1123 
  1084 
  1124