|
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 HbInput 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 #include <hbgridview.h> |
|
27 #include <hbview.h> |
|
28 #include <hbwidget.h> |
|
29 #include <QStandardItemModel> |
|
30 #include <QStandardItem> |
|
31 #include <QFileInfoList> |
|
32 #include <QDir> |
|
33 |
|
34 #include <HbMainWindow> |
|
35 #include <HbFrameItem> |
|
36 #include <HbFrameDrawer> |
|
37 #include <hbdialog_p.h> |
|
38 |
|
39 #include "hbinputsmileypicker.h" |
|
40 |
|
41 /// @cond |
|
42 |
|
43 class HbInputSmileyPickerPrivate: public HbDialogPrivate |
|
44 { |
|
45 Q_DECLARE_PUBLIC(HbInputSmileyPicker) |
|
46 |
|
47 public: |
|
48 HbInputSmileyPickerPrivate(int rows, int columns); |
|
49 ~HbInputSmileyPickerPrivate(); |
|
50 |
|
51 void getSmilies(const QStringList& smileys); |
|
52 void _q_activated(const QModelIndex& index); |
|
53 |
|
54 // member variables. |
|
55 HbGridView *mView; |
|
56 QStandardItemModel *mModel; |
|
57 }; |
|
58 |
|
59 HbInputSmileyPickerPrivate::HbInputSmileyPickerPrivate(int rows, int columns) |
|
60 :mView(0), mModel(0) |
|
61 { |
|
62 Q_Q(HbInputSmileyPicker); |
|
63 // we should make sure that it comes above vkb |
|
64 setPriority(HbPopupPrivate::VirtualKeyboard + 1); |
|
65 |
|
66 // create a view and set the rows and columns. |
|
67 mView = new HbGridView(q); |
|
68 mView->setRowCount(rows); |
|
69 mView->setColumnCount(columns); |
|
70 mView->setScrollDirections(Qt::Horizontal); |
|
71 mView->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
|
72 mModel = new QStandardItemModel(q); |
|
73 mView->setModel(mModel); |
|
74 } |
|
75 |
|
76 HbInputSmileyPickerPrivate::~HbInputSmileyPickerPrivate() |
|
77 { |
|
78 } |
|
79 |
|
80 void HbInputSmileyPickerPrivate::getSmilies(const QStringList& smileys) |
|
81 { |
|
82 mModel->clear(); |
|
83 QStandardItem* item = 0; |
|
84 foreach (QString smiley, smileys) { |
|
85 item = new QStandardItem(); |
|
86 item->setData(HbIcon(smiley), Qt::DecorationRole); |
|
87 mModel->appendRow(item); |
|
88 } |
|
89 } |
|
90 |
|
91 void HbInputSmileyPickerPrivate::_q_activated(const QModelIndex& index) |
|
92 { |
|
93 Q_Q(HbInputSmileyPicker); |
|
94 if (!hidingInProgress) { |
|
95 HbIcon smileyIcon = index.model()->data(index, Qt::DecorationRole).value<HbIcon>(); |
|
96 emit q->selected(smileyIcon.iconName()); |
|
97 q->hide(); |
|
98 } |
|
99 } |
|
100 |
|
101 /// @endcond |
|
102 |
|
103 /*! |
|
104 @proto |
|
105 @hbinput |
|
106 \class HbInputSmileyPicker |
|
107 \brief Smiley picker widget |
|
108 |
|
109 Smiley picker is a dialog containing a grid of emoticons in the form of icons. |
|
110 It emits selected signal with corresponding emoticon text once a smiley is clicked. |
|
111 |
|
112 \sa HbDialog |
|
113 \sa HbGridView |
|
114 */ |
|
115 HbInputSmileyPicker::HbInputSmileyPicker(int rows, int columns, QGraphicsItem *parent, QStringList smileys) |
|
116 : HbDialog(*new HbInputSmileyPickerPrivate(rows, columns), parent) |
|
117 { |
|
118 Q_D(HbInputSmileyPicker); |
|
119 |
|
120 #if QT_VERSION >= 0x040600 |
|
121 // Make sure the smiley picker never steals focus. |
|
122 setFlag(QGraphicsItem::ItemIsPanel, true); |
|
123 setActive(false); |
|
124 #endif |
|
125 |
|
126 // set dialog properties |
|
127 setFocusPolicy(Qt::ClickFocus); |
|
128 setDismissPolicy(TapAnywhere); |
|
129 setBackgroundFaded(false); |
|
130 setTimeout(NoTimeout); |
|
131 setContentWidget(d->mView); |
|
132 |
|
133 // extract smilies. |
|
134 d->getSmilies(smileys); |
|
135 |
|
136 // connect signals |
|
137 connect(d->mView, SIGNAL(activated(QModelIndex )), this, SLOT(_q_activated(QModelIndex ))); |
|
138 } |
|
139 |
|
140 /*! |
|
141 Destructs the object. |
|
142 */ |
|
143 HbInputSmileyPicker::~HbInputSmileyPicker() |
|
144 { |
|
145 } |
|
146 |
|
147 /*! |
|
148 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 |
|
150 first row and column |
|
151 */ |
|
152 void HbInputSmileyPicker::showEvent( QShowEvent * event ) |
|
153 { |
|
154 Q_D(HbInputSmileyPicker); |
|
155 QStandardItem *item = d->mModel->item(0); |
|
156 // when ever we do a show smiley picker. |
|
157 // we should scroll back to the first position. |
|
158 // otherwise we will show the smiley grid in previous state. |
|
159 if (item) { |
|
160 d->mView->scrollTo(item->index()); |
|
161 } |
|
162 HbDialog::showEvent(event); |
|
163 } |
|
164 |
|
165 #include "moc_hbinputsmileypicker.cpp" |