|
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 #include <hbgridviewitem.h> |
|
27 #include <hbgridviewitem_p.h> |
|
28 |
|
29 #include <hbeffect.h> |
|
30 |
|
31 #include "hbgridview_p.h" |
|
32 |
|
33 HbGridViewItemPrivate::HbGridViewItemPrivate(HbAbstractViewItem *prototype) : |
|
34 HbAbstractViewItemPrivate(prototype), |
|
35 mIconItem(0), |
|
36 mTextItem(0), |
|
37 mTextValid(false), |
|
38 mIconValid(false) |
|
39 { |
|
40 } |
|
41 |
|
42 HbGridViewItemPrivate::~HbGridViewItemPrivate() |
|
43 { |
|
44 } |
|
45 |
|
46 void HbGridViewItemPrivate::init() |
|
47 { |
|
48 if (isPrototype()) { |
|
49 HbEffect::add("gridviewitem-focus", "gridviewitem_press", "pressed"); |
|
50 HbEffect::add("gridviewitem-focus", "gridviewitem_release", "released"); |
|
51 mSharedData->mItemType = "gridviewitem"; |
|
52 |
|
53 HbEffect::add("gridviewitem", "gridviewitem_appear", "appear"); |
|
54 HbEffect::add("gridviewitem", "gridviewitem_disappear", "disappear"); |
|
55 } |
|
56 mContentChangedSupported = true; |
|
57 mItemsChanged = false; |
|
58 } |
|
59 |
|
60 bool HbGridViewItemPrivate::isTextValid(const QVariant& text) const |
|
61 { |
|
62 return text.canConvert<QString> (); |
|
63 }; |
|
64 |
|
65 bool HbGridViewItemPrivate::isIconValid(const QVariant& icon) const |
|
66 { |
|
67 return (icon.canConvert<QIcon>() || icon.canConvert<HbIcon>()) ? |
|
68 true : false; |
|
69 }; |
|
70 |
|
71 QString HbGridViewItemPrivate::text(const QVariant& text) const |
|
72 { |
|
73 return text.toString(); |
|
74 }; |
|
75 |
|
76 HbIcon HbGridViewItemPrivate::icon(const QVariant& icon) const |
|
77 { |
|
78 if (icon.canConvert<QIcon> ()) { |
|
79 return HbIcon(icon.value<QIcon>()); |
|
80 } |
|
81 else { |
|
82 return icon.value<HbIcon>(); |
|
83 } |
|
84 } |
|
85 |
|
86 void HbGridViewItemPrivate::updateTextItem(const HbGridViewPrivate &viewPrivate) |
|
87 { |
|
88 Q_Q(HbGridViewItem); |
|
89 QVariant textVariant = mIndex.data(Qt::DisplayRole); |
|
90 bool newTextValid = isTextValid(textVariant); |
|
91 QString newText; |
|
92 if (newTextValid) newText = textVariant.toString(); |
|
93 |
|
94 if (viewPrivate.mTextVisible) { |
|
95 if (newTextValid != mTextValid |
|
96 || mText != newText) { |
|
97 // change in content |
|
98 mText = newText; |
|
99 mTextValid = newTextValid; |
|
100 } // else - no text change |
|
101 } else { |
|
102 mTextValid = false; |
|
103 mText.clear(); |
|
104 } |
|
105 |
|
106 if ( mTextValid |
|
107 && !mTextItem) { |
|
108 mItemsChanged = true; |
|
109 mTextItem = q->style()->createPrimitive(HbStyle::P_GridViewItem_text, q); |
|
110 } |
|
111 else if ( !mTextValid |
|
112 && mTextItem) { |
|
113 mItemsChanged = true; |
|
114 delete mTextItem; |
|
115 mTextItem = 0; |
|
116 } |
|
117 } |
|
118 |
|
119 void HbGridViewItemPrivate::updateIconItem(const HbGridViewPrivate &viewPrivate) |
|
120 { |
|
121 Q_Q(HbGridViewItem); |
|
122 // icon item creation, if needed |
|
123 QVariant iconVariant = mIndex.data(Qt::DecorationRole); |
|
124 bool newIconValid = isIconValid(iconVariant); |
|
125 HbIcon newIcon; |
|
126 if (newIconValid) newIcon = icon(iconVariant); |
|
127 |
|
128 if (viewPrivate.mIconVisible) { |
|
129 if (newIconValid != mIconValid |
|
130 || mIcon != newIcon) { |
|
131 // change in content |
|
132 mIcon = newIcon; |
|
133 mIconValid = newIconValid; |
|
134 } |
|
135 } else { |
|
136 mIconValid = false; |
|
137 mIcon = HbIcon(); |
|
138 } |
|
139 |
|
140 if ( mIconValid |
|
141 && !mIconItem) { |
|
142 mItemsChanged = true; |
|
143 mIconItem = q->style()->createPrimitive(HbStyle::P_GridViewItem_icon, q); |
|
144 } |
|
145 else if ( !mIconValid |
|
146 && mIconItem) { |
|
147 mItemsChanged = true; |
|
148 delete mIconItem; |
|
149 mIconItem = 0; |
|
150 } |
|
151 } |
|
152 |