src/hbinput/inputwidgets/hbinputsmileypicker.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    20 **
    20 **
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
       
    25 #include "hbinputsmileypicker.h"
    25 
    26 
    26 #include <hbgridview.h>
    27 #include <hbgridview.h>
    27 #include <hbview.h>
    28 #include <hbview.h>
    28 #include <hbwidget.h>
    29 #include <hbwidget.h>
    29 #include <QStandardItemModel>
    30 #include <QStandardItemModel>
    35 #include <HbFrameItem>
    36 #include <HbFrameItem>
    36 #include <HbFrameDrawer>
    37 #include <HbFrameDrawer>
    37 #include <hbdialog_p.h>
    38 #include <hbdialog_p.h>
    38 #include <hbinputregioncollector_p.h>
    39 #include <hbinputregioncollector_p.h>
    39 
    40 
    40 #include "hbinputsmileypicker.h"
       
    41 
       
    42 /// @cond
    41 /// @cond
    43 
    42 
    44 class HbInputSmileyPickerPrivate: public HbDialogPrivate
    43 class HbInputSmileyPickerPrivate: public HbDialogPrivate
    45 {
    44 {
    46     Q_DECLARE_PUBLIC(HbInputSmileyPicker)
    45     Q_DECLARE_PUBLIC(HbInputSmileyPicker)
    47 
    46 
    48 public:
    47 public:
    49     HbInputSmileyPickerPrivate(int rows, int columns);
    48     HbInputSmileyPickerPrivate(int rows, int columns);
    50     ~HbInputSmileyPickerPrivate();
    49     ~HbInputSmileyPickerPrivate();
    51 
    50 
    52     void getSmilies(const QStringList& smileys);
    51     void getSmilies(const QStringList &smileys);
    53     void _q_activated(const QModelIndex& index);
    52     void _q_activated(const QModelIndex &index);
    54 
    53 
    55     // member variables.
    54     // member variables.
    56     HbGridView *mView;
    55     HbGridView *mView;
    57     QStandardItemModel *mModel;
    56     QStandardItemModel *mModel;
    58 };
    57 };
    59 
    58 
    60 HbInputSmileyPickerPrivate::HbInputSmileyPickerPrivate(int rows, int columns)
    59 HbInputSmileyPickerPrivate::HbInputSmileyPickerPrivate(int rows, int columns)
    61 :mView(0), mModel(0)
    60     : mView(0), mModel(0)
    62 {
    61 {
    63     Q_Q(HbInputSmileyPicker);
    62     Q_Q(HbInputSmileyPicker);
    64     // we should make sure that it comes above vkb
    63     // we should make sure that it comes above vkb
    65     setPriority(HbPopupPrivate::VirtualKeyboard + 1);
    64     setPriority(HbPopupPrivate::VirtualKeyboard + 1);
    66 
    65 
    76 
    75 
    77 HbInputSmileyPickerPrivate::~HbInputSmileyPickerPrivate()
    76 HbInputSmileyPickerPrivate::~HbInputSmileyPickerPrivate()
    78 {
    77 {
    79 }
    78 }
    80 
    79 
    81 void HbInputSmileyPickerPrivate::getSmilies(const QStringList& smileys)
    80 void HbInputSmileyPickerPrivate::getSmilies(const QStringList &smileys)
    82 {
    81 {
    83     mModel->clear();
    82     mModel->clear();
    84     QStandardItem* item = 0;
    83     QStandardItem *item = 0;
    85     foreach (QString smiley, smileys) {
    84     foreach(const QString &smiley, smileys) {
    86         item = new QStandardItem();
    85         item = new QStandardItem();
    87         item->setData(HbIcon(smiley), Qt::DecorationRole);
    86         item->setData(HbIcon(smiley), Qt::DecorationRole);
    88         mModel->appendRow(item);
    87         mModel->appendRow(item);
    89     }
    88     }
    90 }
    89 }
    91 
    90 
    92 void HbInputSmileyPickerPrivate::_q_activated(const QModelIndex& index)
    91 void HbInputSmileyPickerPrivate::_q_activated(const QModelIndex &index)
    93 {
    92 {
    94     Q_Q(HbInputSmileyPicker);
    93     Q_Q(HbInputSmileyPicker);
    95     if (!hidingInProgress) {
    94     if (!hidingInProgress) {
    96         HbIcon smileyIcon = index.model()->data(index, Qt::DecorationRole).value<HbIcon>();
    95         HbIcon smileyIcon = index.model()->data(index, Qt::DecorationRole).value<HbIcon>();
    97         emit q->selected(smileyIcon.iconName());
    96         emit q->selected(smileyIcon.iconName());
   116 HbInputSmileyPicker::HbInputSmileyPicker(int rows, int columns, QGraphicsItem *parent, QStringList smileys)
   115 HbInputSmileyPicker::HbInputSmileyPicker(int rows, int columns, QGraphicsItem *parent, QStringList smileys)
   117     : HbDialog(*new HbInputSmileyPickerPrivate(rows, columns), parent)
   116     : HbDialog(*new HbInputSmileyPickerPrivate(rows, columns), parent)
   118 {
   117 {
   119     Q_D(HbInputSmileyPicker);
   118     Q_D(HbInputSmileyPicker);
   120     HbInputRegionCollector::instance()->attach(this);
   119     HbInputRegionCollector::instance()->attach(this);
   121 #if QT_VERSION >= 0x040600
   120 
   122     // Make sure the smiley picker never steals focus.
   121     // Make sure the smiley picker never steals focus.
   123     setFlag(QGraphicsItem::ItemIsPanel, true);
   122     setFlag(QGraphicsItem::ItemIsPanel, true);
   124     setActive(false);
   123     setActive(false);
   125 #endif
       
   126 
   124 
   127     // set dialog properties
   125     // set dialog properties
   128     setFocusPolicy(Qt::ClickFocus);
   126     setFocusPolicy(Qt::ClickFocus);
   129     setDismissPolicy(TapAnywhere);
   127     setDismissPolicy(TapAnywhere);
   130     setBackgroundFaded(false);
   128     setBackgroundFaded(false);
   134 
   132 
   135     // extract smilies.
   133     // extract smilies.
   136     d->getSmilies(smileys);
   134     d->getSmilies(smileys);
   137 
   135 
   138     // connect signals
   136     // connect signals
   139     connect(d->mView, SIGNAL(activated(QModelIndex )), this, SLOT(_q_activated(QModelIndex )));
   137     connect(d->mView, SIGNAL(activated(QModelIndex)), this, SLOT(_q_activated(QModelIndex)));
   140 }
   138 }
   141 
   139 
   142 /*!
   140 /*!
   143 Destructs the object.
   141 Destructs the object.
   144 */
   142 */
   145 HbInputSmileyPicker::~HbInputSmileyPicker()
   143 HbInputSmileyPicker::~HbInputSmileyPicker()
   146 {
   144 {
   147 }
   145 }
   148 
   146 
   149 /*!
   147 /*!
   150 This a virtual functions in QGraphicsWidget. It is called whenever the smiley picker widgets is shown. 
   148 This a virtual functions in QGraphicsWidget. It is called whenever the smiley picker widgets is shown.
   151 Here in this function we are are scrolling to a position where we can see 
   149 Here in this function we are are scrolling to a position where we can see
   152 first row and column
   150 first row and column
   153 */
   151 */
   154 void HbInputSmileyPicker::showEvent( QShowEvent * event )
   152 void HbInputSmileyPicker::showEvent(QShowEvent *event)
   155 {
   153 {
   156     Q_D(HbInputSmileyPicker);
   154     Q_D(HbInputSmileyPicker);
   157     QStandardItem *item = d->mModel->item(0);
   155     QStandardItem *item = d->mModel->item(0);
   158     // when ever we do a show smiley picker.
   156     // when ever we do a show smiley picker.
   159     // we should scroll back to the first position.
   157     // we should scroll back to the first position.