33 |
34 |
34 #include <HbMainWindow> |
35 #include <HbMainWindow> |
35 #include <HbFrameItem> |
36 #include <HbFrameItem> |
36 #include <HbFrameDrawer> |
37 #include <HbFrameDrawer> |
37 #include <hbdialog_p.h> |
38 #include <hbdialog_p.h> |
|
39 #include <hbinputregioncollector_p.h> |
38 |
40 |
39 #include "hbinputsmileypicker.h" |
41 const int HbLandscapeRows = 3; |
|
42 const int HbLandscapeColumns = 7; |
|
43 const int HbPortraitRows = 4; |
|
44 const int HbPortraitColumns = 5; |
40 |
45 |
41 /// @cond |
46 /// @cond |
42 |
47 |
43 class HbInputSmileyPickerPrivate: public HbDialogPrivate |
48 class HbInputSmileyPickerPrivate: public HbDialogPrivate |
44 { |
49 { |
46 |
51 |
47 public: |
52 public: |
48 HbInputSmileyPickerPrivate(int rows, int columns); |
53 HbInputSmileyPickerPrivate(int rows, int columns); |
49 ~HbInputSmileyPickerPrivate(); |
54 ~HbInputSmileyPickerPrivate(); |
50 |
55 |
51 void getSmilies(const QStringList& smileys); |
56 void getSmilies(const QStringList &smileys); |
52 void _q_activated(const QModelIndex& index); |
57 void _q_activated(const QModelIndex &index); |
53 |
58 |
54 // member variables. |
59 // member variables. |
55 HbGridView *mView; |
60 HbGridView *mView; |
56 QStandardItemModel *mModel; |
61 QStandardItemModel *mModel; |
57 }; |
62 }; |
58 |
63 |
59 HbInputSmileyPickerPrivate::HbInputSmileyPickerPrivate(int rows, int columns) |
64 HbInputSmileyPickerPrivate::HbInputSmileyPickerPrivate(int rows, int columns) |
60 :mView(0), mModel(0) |
65 : mView(0), mModel(0) |
61 { |
66 { |
|
67 Q_UNUSED(rows); |
|
68 Q_UNUSED(columns); |
62 Q_Q(HbInputSmileyPicker); |
69 Q_Q(HbInputSmileyPicker); |
63 // we should make sure that it comes above vkb |
70 // we should make sure that it comes above vkb |
64 setPriority(HbPopupPrivate::VirtualKeyboard + 1); |
71 setPriority(HbPopupPrivate::VirtualKeyboard + 1); |
65 |
72 |
66 // create a view and set the rows and columns. |
73 // create a view and set the rows and columns. |
67 mView = new HbGridView(q); |
74 mView = new HbGridView(q); |
68 mView->setRowCount(rows); |
|
69 mView->setColumnCount(columns); |
|
70 mView->setScrollDirections(Qt::Horizontal); |
75 mView->setScrollDirections(Qt::Horizontal); |
71 mView->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
76 mView->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
72 mModel = new QStandardItemModel(q); |
77 mModel = new QStandardItemModel(q); |
73 mView->setModel(mModel); |
78 mView->setModel(mModel); |
74 } |
79 } |
75 |
80 |
76 HbInputSmileyPickerPrivate::~HbInputSmileyPickerPrivate() |
81 HbInputSmileyPickerPrivate::~HbInputSmileyPickerPrivate() |
77 { |
82 { |
78 } |
83 } |
79 |
84 |
80 void HbInputSmileyPickerPrivate::getSmilies(const QStringList& smileys) |
85 void HbInputSmileyPickerPrivate::getSmilies(const QStringList &smileys) |
81 { |
86 { |
82 mModel->clear(); |
87 mModel->clear(); |
83 QStandardItem* item = 0; |
88 QStandardItem *item = 0; |
84 foreach (QString smiley, smileys) { |
89 foreach(const QString &smiley, smileys) { |
85 item = new QStandardItem(); |
90 item = new QStandardItem(); |
86 item->setData(HbIcon(smiley), Qt::DecorationRole); |
91 item->setData(HbIcon(smiley), Qt::DecorationRole); |
87 mModel->appendRow(item); |
92 mModel->appendRow(item); |
88 } |
93 } |
89 } |
94 } |
90 |
95 |
91 void HbInputSmileyPickerPrivate::_q_activated(const QModelIndex& index) |
96 void HbInputSmileyPickerPrivate::_q_activated(const QModelIndex &index) |
92 { |
97 { |
93 Q_Q(HbInputSmileyPicker); |
98 Q_Q(HbInputSmileyPicker); |
94 if (!hidingInProgress) { |
99 if (!hidingInProgress) { |
95 HbIcon smileyIcon = index.model()->data(index, Qt::DecorationRole).value<HbIcon>(); |
100 HbIcon smileyIcon = index.model()->data(index, Qt::DecorationRole).value<HbIcon>(); |
96 emit q->selected(smileyIcon.iconName()); |
101 emit q->selected(smileyIcon.iconName()); |
97 q->hide(); |
102 q->close(); |
98 } |
103 } |
99 } |
104 } |
100 |
105 |
101 /// @endcond |
106 /// @endcond |
102 |
107 |
114 */ |
119 */ |
115 HbInputSmileyPicker::HbInputSmileyPicker(int rows, int columns, QGraphicsItem *parent, QStringList smileys) |
120 HbInputSmileyPicker::HbInputSmileyPicker(int rows, int columns, QGraphicsItem *parent, QStringList smileys) |
116 : HbDialog(*new HbInputSmileyPickerPrivate(rows, columns), parent) |
121 : HbDialog(*new HbInputSmileyPickerPrivate(rows, columns), parent) |
117 { |
122 { |
118 Q_D(HbInputSmileyPicker); |
123 Q_D(HbInputSmileyPicker); |
|
124 HbInputRegionCollector::instance()->attach(this); |
119 |
125 |
120 #if QT_VERSION >= 0x040600 |
|
121 // Make sure the smiley picker never steals focus. |
126 // Make sure the smiley picker never steals focus. |
122 setFlag(QGraphicsItem::ItemIsPanel, true); |
127 setFlag(QGraphicsItem::ItemIsPanel, true); |
123 setActive(false); |
128 setActive(false); |
124 #endif |
129 |
|
130 if (!rows || !columns) { |
|
131 if (mainWindow()->orientation() == Qt::Horizontal) { |
|
132 rows = HbLandscapeRows; |
|
133 columns = HbLandscapeColumns; |
|
134 } else { |
|
135 rows = HbPortraitRows; |
|
136 columns = HbPortraitColumns; |
|
137 } |
|
138 } |
|
139 d->mView->setRowCount(rows); |
|
140 d->mView->setColumnCount(columns); |
125 |
141 |
126 // set dialog properties |
142 // set dialog properties |
127 setFocusPolicy(Qt::ClickFocus); |
143 setFocusPolicy(Qt::ClickFocus); |
128 setDismissPolicy(TapAnywhere); |
144 setDismissPolicy(TapAnywhere); |
129 setBackgroundFaded(false); |
145 setBackgroundFaded(false); |
130 setTimeout(NoTimeout); |
146 setTimeout(NoTimeout); |
131 setContentWidget(d->mView); |
147 setContentWidget(d->mView); |
|
148 d->mView->setLongPressEnabled(false); |
132 |
149 |
133 // extract smilies. |
150 // extract smilies. |
134 d->getSmilies(smileys); |
151 d->getSmilies(smileys); |
135 |
152 |
136 // connect signals |
153 // connect signals |
137 connect(d->mView, SIGNAL(activated(QModelIndex )), this, SLOT(_q_activated(QModelIndex ))); |
154 connect(d->mView, SIGNAL(activated(QModelIndex)), this, SLOT(_q_activated(QModelIndex))); |
138 } |
155 } |
139 |
156 |
140 /*! |
157 /*! |
141 Destructs the object. |
158 Destructs the object. |
142 */ |
159 */ |
143 HbInputSmileyPicker::~HbInputSmileyPicker() |
160 HbInputSmileyPicker::~HbInputSmileyPicker() |
144 { |
161 { |
145 } |
162 } |
146 |
163 |
147 /*! |
164 /*! |
148 This a virtual functions in QGraphicsWidget. It is called whenever the smiley picker widgets is shown. |
165 This a virtual functions in QGraphicsWidget. It is called whenever the smiley picker widgets is shown. |
149 Here in this function we are are scrolling to a position where we can see |
166 Here in this function we are are scrolling to a position where we can see |
150 first row and column |
167 first row and column |
151 */ |
168 */ |
152 void HbInputSmileyPicker::showEvent( QShowEvent * event ) |
169 void HbInputSmileyPicker::showEvent(QShowEvent *event) |
153 { |
170 { |
154 Q_D(HbInputSmileyPicker); |
171 Q_D(HbInputSmileyPicker); |
155 QStandardItem *item = d->mModel->item(0); |
172 QStandardItem *item = d->mModel->item(0); |
156 // when ever we do a show smiley picker. |
173 // when ever we do a show smiley picker. |
157 // we should scroll back to the first position. |
174 // we should scroll back to the first position. |