36
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0""
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
55
|
14 |
* Description: View item implementation for list entry item.
|
36
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cpdataformlistentryviewitem.h"
|
40
|
19 |
|
|
20 |
#ifdef HB_EFFECTS
|
|
21 |
#include "hbeffect.h"
|
|
22 |
#endif
|
|
23 |
|
|
24 |
#ifdef HB_GESTURE_FW
|
|
25 |
#include <hbtapgesture.h>
|
|
26 |
#include <hbframeitem.h>
|
|
27 |
#endif
|
|
28 |
|
36
|
29 |
#include <hbdataformmodel.h>
|
|
30 |
#include <hbdataformmodelitem.h>
|
|
31 |
#include <hbabstractitemview.h>
|
|
32 |
#include <cpsettingformentryitemdata.h>
|
|
33 |
|
40
|
34 |
#define CP_DATAFORMLISTENTRYVIEWITEM QLatin1String("cpdataformlistentryviewitem")
|
|
35 |
|
55
|
36 |
/**
|
|
37 |
* Constructor
|
|
38 |
*/
|
36
|
39 |
CpDataFormListEntryViewItem::CpDataFormListEntryViewItem(QGraphicsItem *parent) :
|
|
40 |
HbDataFormViewItem(parent)
|
|
41 |
{
|
55
|
42 |
// Add effeect just like item in HbListView
|
40
|
43 |
#ifdef HB_EFFECTS
|
|
44 |
HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_press", "pressed");
|
|
45 |
HbEffect::add(CP_DATAFORMLISTENTRYVIEWITEM + "-focus", "listviewitem_release", "released");
|
|
46 |
#endif
|
36
|
47 |
}
|
|
48 |
|
55
|
49 |
/**
|
|
50 |
* Destructor
|
|
51 |
*/
|
36
|
52 |
CpDataFormListEntryViewItem::~CpDataFormListEntryViewItem()
|
|
53 |
{
|
|
54 |
}
|
|
55 |
|
55
|
56 |
/**
|
|
57 |
* Reimplement by CpDataFormListEntryViewItem, this function return a instance copy.
|
|
58 |
*/
|
36
|
59 |
HbAbstractViewItem* CpDataFormListEntryViewItem::createItem()
|
|
60 |
{
|
|
61 |
return new CpDataFormListEntryViewItem(*this);
|
|
62 |
}
|
|
63 |
|
55
|
64 |
/**
|
|
65 |
* Reimplement by CpDataFormListEntryViewItem, return true when the model item type is
|
|
66 |
* ListEntryItem
|
|
67 |
*/
|
36
|
68 |
bool CpDataFormListEntryViewItem::canSetModelIndex(const QModelIndex &index) const
|
|
69 |
{
|
|
70 |
HbDataFormModelItem::DataItemType itemType =
|
|
71 |
static_cast<HbDataFormModelItem::DataItemType>(
|
|
72 |
index.data(HbDataFormModelItem::ItemTypeRole).toInt());
|
|
73 |
|
|
74 |
return ( itemType == CpSettingFormEntryItemData::ListEntryItem );
|
|
75 |
}
|
|
76 |
|
55
|
77 |
/**
|
|
78 |
* Reimplement by CpDataFormListEntryViewItem
|
|
79 |
* No content widget in custom list item. So return a null pointer directly
|
|
80 |
*/
|
36
|
81 |
HbWidget* CpDataFormListEntryViewItem::createCustomWidget()
|
|
82 |
{
|
55
|
83 |
// Don't need to create any widget
|
|
84 |
return 0;
|
|
85 |
}
|
|
86 |
/**
|
|
87 |
* Reimplement by CpDataFormListEntryViewItem. Change the description property for
|
|
88 |
* custom list item.
|
|
89 |
*/
|
|
90 |
void CpDataFormListEntryViewItem::restore()
|
|
91 |
{
|
36
|
92 |
HbDataFormModelItem::DataItemType itemType =
|
55
|
93 |
static_cast<HbDataFormModelItem::DataItemType> (modelIndex().data(
|
|
94 |
HbDataFormModelItem::ItemTypeRole).toInt());
|
|
95 |
|
|
96 |
if (itemType == CpSettingFormEntryItemData::ListEntryItem) {
|
|
97 |
QModelIndex itemIndex = modelIndex();
|
|
98 |
HbDataFormModel *model = qobject_cast<HbDataFormModel*> (itemView()->model());
|
|
99 |
if (model) {
|
|
100 |
HbDataFormModelItem *modelItem = model->itemFromIndex(itemIndex);
|
|
101 |
if (modelItem->data(HbDataFormModelItem::DescriptionRole).toString().isEmpty()) {
|
|
102 |
this->setProperty("hasDescription", false);
|
|
103 |
}
|
|
104 |
else {
|
|
105 |
this->setProperty("hasDescription", true);
|
|
106 |
}
|
|
107 |
}
|
36
|
108 |
}
|
55
|
109 |
HbDataFormViewItem::restore();
|
36
|
110 |
}
|
|
111 |
|
55
|
112 |
/**
|
|
113 |
* Reimplement by CpDataFormListEntryViewItem, provide the effect when pressing list item
|
|
114 |
*/
|
40
|
115 |
void CpDataFormListEntryViewItem::pressStateChanged(bool pressed, bool animate)
|
|
116 |
{
|
|
117 |
#ifdef HB_EFFECTS
|
|
118 |
QGraphicsItem *focusItem = primitive("dataItem_Background");
|
|
119 |
bool doAnimate = animate;
|
|
120 |
|
|
121 |
if (pressed) {
|
|
122 |
if (doAnimate) {
|
|
123 |
HbEffect::cancel(this, "released");
|
|
124 |
HbEffect::cancel(focusItem, "released");
|
|
125 |
|
|
126 |
HbEffect::start(this, CP_DATAFORMLISTENTRYVIEWITEM, "pressed");
|
|
127 |
HbEffect::start(focusItem, CP_DATAFORMLISTENTRYVIEWITEM + QString("-focus"), "pressed");
|
|
128 |
}
|
|
129 |
} else {
|
|
130 |
if (doAnimate) {
|
|
131 |
HbEffect::cancel(this, "pressed");
|
|
132 |
HbEffect::cancel(focusItem, "pressed");
|
|
133 |
|
|
134 |
HbEffect::start(this, CP_DATAFORMLISTENTRYVIEWITEM, "released");
|
|
135 |
HbEffect::start(focusItem, CP_DATAFORMLISTENTRYVIEWITEM + QString("-focus"), "released");
|
|
136 |
} else {
|
|
137 |
HbEffect::cancel(this, "pressed");
|
|
138 |
HbEffect::start(this, CP_DATAFORMLISTENTRYVIEWITEM, "released");
|
|
139 |
if (focusItem) {
|
|
140 |
HbEffect::cancel(focusItem, "pressed");
|
|
141 |
HbEffect::start(focusItem, CP_DATAFORMLISTENTRYVIEWITEM + QString("-focus"), "released", this);
|
|
142 |
}
|
|
143 |
}
|
|
144 |
}
|
|
145 |
#endif
|
|
146 |
}
|
|
147 |
|
|
148 |
#ifdef HB_GESTURE_FW
|
55
|
149 |
|
|
150 |
/**
|
|
151 |
* Reimplement by CpDataFormListEntryViewItem, set different graphics for list item's gesture
|
|
152 |
*/
|
40
|
153 |
void CpDataFormListEntryViewItem::gestureEvent(QGestureEvent *event)
|
|
154 |
{
|
|
155 |
HbFrameItem *backgroundItem = static_cast<HbFrameItem*> ( primitive("dataItem_Background") );
|
|
156 |
HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
|
|
157 |
|
|
158 |
if(backgroundItem && tap) {
|
|
159 |
switch(tap->state()) {
|
|
160 |
case Qt::GestureStarted: {
|
55
|
161 |
// Set the pressed state
|
40
|
162 |
backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_pressed"));
|
|
163 |
}
|
|
164 |
break;
|
|
165 |
case Qt::GestureUpdated: {
|
|
166 |
|
|
167 |
}
|
|
168 |
break;
|
|
169 |
case Qt::GestureCanceled: {
|
55
|
170 |
// Set the normal state
|
40
|
171 |
backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
|
|
172 |
}
|
|
173 |
break;
|
|
174 |
case Qt::GestureFinished: {
|
55
|
175 |
// Set the normal state
|
40
|
176 |
backgroundItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_list_normal"));
|
|
177 |
}
|
|
178 |
break;
|
|
179 |
default:
|
|
180 |
break;
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
HbDataFormViewItem::gestureEvent( event );
|
|
185 |
}
|
|
186 |
#endif
|
|
187 |
|
|
188 |
|
36
|
189 |
//End of File
|