src/hbwidgets/widgets/hbcombobox.h
changeset 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #ifndef HBCOMBOBOX_H
       
    27 #define HBCOMBOBOX_H
       
    28 
       
    29 #include <hbwidget.h>
       
    30 
       
    31 class HbValidator;
       
    32 class HbComboBoxPrivate;
       
    33 class HbStyleOptionComboBox;
       
    34 
       
    35 class HB_WIDGETS_EXPORT HbComboBox : public HbWidget
       
    36 {
       
    37     Q_OBJECT
       
    38     Q_ENUMS(InsertPolicy)
       
    39     Q_PROPERTY( InsertPolicy insertPolicy READ insertPolicy WRITE setInsertPolicy )
       
    40     Q_PROPERTY( bool editable READ isEditable WRITE setEditable ) 
       
    41     Q_PROPERTY( int count READ count )
       
    42     Q_PROPERTY( QStringList items READ items WRITE setItems )
       
    43     Q_PROPERTY( int currentIndex READ currentIndex WRITE setCurrentIndex )
       
    44     Q_PROPERTY( QString currentText READ currentText )
       
    45 
       
    46 public:
       
    47     enum InsertPolicy {
       
    48         NoInsert,
       
    49         InsertAtTop,
       
    50         InsertAtCurrent,
       
    51         InsertAtBottom,
       
    52         InsertAfterCurrent,
       
    53         InsertBeforeCurrent,
       
    54         InsertAlphabetically
       
    55     };
       
    56 
       
    57     explicit HbComboBox( QGraphicsItem *parent = 0 );
       
    58     virtual ~HbComboBox( );
       
    59 
       
    60     enum { Type = Hb::ItemType_ComboBox };
       
    61     int type( ) const { return Type; }
       
    62 
       
    63     void addItem( const QString &text, const QVariant &userData = QVariant() );
       
    64     void addItem( const HbIcon &icon, 
       
    65                   const QString &text,
       
    66                   const QVariant &userData = QVariant() );
       
    67 
       
    68     void addItems( const QStringList &texts );
       
    69 
       
    70     void insertItem( int index, const QString &text, const QVariant &userData = QVariant() );
       
    71     void insertItem( int index,
       
    72                      const HbIcon &icon,
       
    73                      const QString &text,
       
    74                      const QVariant & userData = QVariant() );
       
    75     void insertItems( int index, const QStringList &texts );
       
    76 
       
    77     int count( ) const;
       
    78 
       
    79     void setInsertPolicy( InsertPolicy policy );
       
    80     InsertPolicy insertPolicy( ) const;
       
    81 
       
    82     void setItems( const QStringList &texts );
       
    83     QStringList items( ) const;
       
    84 
       
    85     void setItemIcon( int index, const HbIcon &icon );
       
    86     HbIcon itemIcon( int index ) const;
       
    87 
       
    88     void setItemText( int index, const QString &text );
       
    89     QString itemText( int index ) const;
       
    90             
       
    91     void setModel( QAbstractItemModel *model );
       
    92     QAbstractItemModel* model( ) const;
       
    93     
       
    94     void setEditable( bool editable );
       
    95     bool isEditable( ) const;
       
    96 
       
    97     void setItemData( int index, const QVariant &value, int role = Qt::UserRole );
       
    98     QVariant itemData( int index, int role = Qt::UserRole ) const;
       
    99 
       
   100     void setValidator( HbValidator *validator );
       
   101     const HbValidator *validator( ) const;
       
   102     
       
   103     QString currentText( ) const;
       
   104     
       
   105     int currentIndex( ) const;
       
   106     
       
   107     void removeItem( int index );
       
   108 
       
   109     inline int findText( const QString &text,
       
   110         Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive ) const
       
   111         { return findData( text, Qt::DisplayRole, flags ); }
       
   112     int findData( const QVariant &data, int role = Qt::UserRole,
       
   113         Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive ) const;
       
   114 
       
   115     QGraphicsItem* primitive( HbStyle::Primitive primitive ) const;
       
   116 
       
   117 public slots:
       
   118     void updatePrimitives( );
       
   119     void clear( );
       
   120     void clearEditText( );
       
   121     void setCurrentIndex( int index );
       
   122     void setEditText( const QString &text );
       
   123     
       
   124 
       
   125 signals:
       
   126     void currentIndexChanged( int index );
       
   127     void currentIndexChanged( const QString &text );
       
   128     void editTextChanged( const QString &text );
       
   129 
       
   130 protected:
       
   131     HbComboBox( HbComboBoxPrivate &dd, QGraphicsItem *parent = 0 );
       
   132     void initStyleOption( HbStyleOptionComboBox *option ) const;
       
   133     void resizeEvent( QGraphicsSceneResizeEvent *event );
       
   134     void keyPressEvent( QKeyEvent *event );
       
   135     void keyReleaseEvent( QKeyEvent *event );
       
   136     void changeEvent( QEvent *event );
       
   137     bool eventFilter( QObject *obj, QEvent *event );
       
   138 
       
   139 private:
       
   140     Q_DECLARE_PRIVATE_D( d_ptr, HbComboBox )
       
   141     Q_DISABLE_COPY( HbComboBox )
       
   142     Q_PRIVATE_SLOT( d_func( ), void _q_textChanged( const QModelIndex &aIndex ) )
       
   143     Q_PRIVATE_SLOT( d_func( ), void _q_textCompleted( const QModelIndex &aIndex ) )
       
   144     Q_PRIVATE_SLOT( d_func( ), void _q_textChanged( const QString &aString ) )
       
   145 };
       
   146 
       
   147 #endif // HBCOMBOBOX_H
       
   148