|
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 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QGraphicsSceneMouseEvent> |
|
19 #include <hbdeviceprofile.h> //HbDeviceProfile |
|
20 |
|
21 #include <hbeffect.h> |
|
22 #include <hbdialog.h> |
|
23 |
|
24 #include "cxuisettingbutton.h" |
|
25 #include "cxutils.h" |
|
26 #include "cxuidocumentloader.h" |
|
27 #include "cxeengine.h" |
|
28 #include "cxesettings.h" |
|
29 |
|
30 |
|
31 CxuiSettingButton::CxuiSettingButton(QGraphicsItem *parent, CxeEngine *engine) |
|
32 : HbPushButton(parent), mSettingId(), mSettingValue(0), mSettingPopupXml(), mEngine(engine) |
|
33 { |
|
34 connect(this, SIGNAL(pressed()), this, SLOT(handleClicked())); |
|
35 |
|
36 } |
|
37 |
|
38 CxuiSettingButton::~CxuiSettingButton() |
|
39 { |
|
40 CX_DEBUG_ENTER_FUNCTION(); |
|
41 CX_DEBUG_EXIT_FUNCTION(); |
|
42 } |
|
43 |
|
44 void CxuiSettingButton::updateIcon(const QString& key, QVariant newValue) |
|
45 { |
|
46 CX_DEBUG_ENTER_FUNCTION(); |
|
47 // we're only interested in the setting changes that match our id |
|
48 if (key == mSettingId){ |
|
49 int value = newValue.toInt(); |
|
50 // so we wont overindex |
|
51 if (value < mIcons.size()){ |
|
52 // for this to work the icons need to be in the correct order in the XML |
|
53 QString newIcon = mIcons.at(value); |
|
54 |
|
55 // to make sure that for some reason there isn't an empty string |
|
56 if (!newIcon.isEmpty()){ |
|
57 CX_DEBUG(("setting icon to: %s",newIcon.toAscii().constData())); |
|
58 setIcon(HbIcon(newIcon)); |
|
59 setBackground(HbIcon(newIcon)); |
|
60 }else{ |
|
61 CX_DEBUG(("empty string")); |
|
62 } |
|
63 |
|
64 }else{ |
|
65 CX_DEBUG((("index %d is out of bounds"), value)); |
|
66 } |
|
67 |
|
68 |
|
69 } |
|
70 CX_DEBUG_EXIT_FUNCTION(); |
|
71 } |
|
72 |
|
73 QString CxuiSettingButton::settingId() const |
|
74 { |
|
75 return mSettingId; |
|
76 } |
|
77 |
|
78 void CxuiSettingButton::setSettingId(const QString &id) |
|
79 { |
|
80 mSettingId = id; |
|
81 } |
|
82 |
|
83 QString CxuiSettingButton::scenemodeId() const |
|
84 { |
|
85 return mScenemode; |
|
86 } |
|
87 |
|
88 void CxuiSettingButton::setScenemodeId(const QString &scenemode) |
|
89 { |
|
90 mScenemode = scenemode; |
|
91 } |
|
92 |
|
93 |
|
94 int CxuiSettingButton::settingValue() const |
|
95 { |
|
96 return mSettingValue; |
|
97 } |
|
98 |
|
99 void CxuiSettingButton::setSettingValue(int value) |
|
100 { |
|
101 mSettingValue = value; |
|
102 } |
|
103 |
|
104 void CxuiSettingButton::setIconList(const QString &iconList) |
|
105 { |
|
106 CX_DEBUG_ENTER_FUNCTION(); |
|
107 mIconList = iconList; |
|
108 CX_DEBUG(("%s", mIconList.toAscii().data())); |
|
109 mIcons = mIconList.split("+"); |
|
110 CX_DEBUG((("%d"), mIcons.size())); |
|
111 |
|
112 // we connect the signal to update the button |
|
113 // this is done here so that only those buttons that have an iconlist are connected |
|
114 // to the signal |
|
115 QObject::connect(&(mEngine->settings()), SIGNAL(settingValueChanged(const QString&,QVariant)), |
|
116 this, SLOT(updateIcon(const QString&, QVariant))); |
|
117 |
|
118 |
|
119 CX_DEBUG_EXIT_FUNCTION(); |
|
120 } |
|
121 |
|
122 QString CxuiSettingButton::iconList() const |
|
123 { |
|
124 return mIconList; |
|
125 } |
|
126 |
|
127 QString CxuiSettingButton::settingPopupXml() const |
|
128 { |
|
129 return mSettingPopupXml; |
|
130 } |
|
131 |
|
132 void CxuiSettingButton::setSettingPopupXml(const QString &popupXml) |
|
133 { |
|
134 mSettingPopupXml = popupXml; |
|
135 } |
|
136 |
|
137 void CxuiSettingButton::handleClicked() |
|
138 { |
|
139 CX_DEBUG_ENTER_FUNCTION(); |
|
140 |
|
141 if (!mSettingPopupXml.isEmpty()) { |
|
142 // If a settings popup XML reference is given, launch popup |
|
143 |
|
144 CX_DEBUG(("CxuiSettingButton::handleClicked() - launching popup %s", mSettingPopupXml.toAscii().constData())); |
|
145 |
|
146 CxuiDocumentLoader* documentLoader = new CxuiDocumentLoader(mEngine); |
|
147 bool ok = false; |
|
148 |
|
149 // Use document loader to create popup |
|
150 QObjectList objects = documentLoader->load(mSettingPopupXml, &ok); |
|
151 |
|
152 CX_DEBUG(("load ok=%d", ok)); |
|
153 |
|
154 // Set parameters for all loaded popups (almost always only one match, though) |
|
155 foreach(QObject* o, objects) { |
|
156 HbDialog* popup = qobject_cast<HbDialog*>(o); |
|
157 if (popup) { |
|
158 popup->setTimeout(HbDialog::NoTimeout); |
|
159 popup->setBackgroundFaded(false); |
|
160 popup->setAttribute(Qt::WA_DeleteOnClose, true); |
|
161 |
|
162 // set the popup place to be at the bottom of the screen |
|
163 QRectF popupRect = popup->boundingRect(); |
|
164 QSizeF screenSize = HbDeviceProfile::profile(popup).logicalSize(); |
|
165 QRectF screenRect = QRectF(QPointF(0,0), screenSize); |
|
166 |
|
167 popupRect.moveBottom(screenRect.bottom()); |
|
168 popup->setPos(popupRect.topLeft()); |
|
169 |
|
170 popup->show(); |
|
171 |
|
172 } |
|
173 } |
|
174 |
|
175 delete documentLoader; |
|
176 documentLoader = NULL; |
|
177 TInt trash; |
|
178 TInt heapSize; |
|
179 User::Heap().Compress(); |
|
180 heapSize = User::Available( trash ); |
|
181 RDebug::Print( _L( "showHeapSize <=> heapSize: %d" ),heapSize); |
|
182 |
|
183 } else { |
|
184 // Set the setting value directly to the engine |
|
185 CxeSettings *settings = NULL; |
|
186 if (mEngine) { |
|
187 settings = &mEngine->settings(); |
|
188 } |
|
189 |
|
190 CX_DEBUG_ASSERT(settings); |
|
191 CX_DEBUG_ASSERT(!mSettingId.isEmpty()); |
|
192 |
|
193 if (settings && !mSettingId.isEmpty()) { |
|
194 CX_DEBUG(("CxuiSettingButton::handleClicked() - setting %s to %d", mSettingId.toAscii().constData(), mSettingValue)); |
|
195 settings->set(mSettingId, mSettingValue); |
|
196 } |
|
197 } |
|
198 emit clickHandled(); |
|
199 |
|
200 |
|
201 CX_DEBUG_EXIT_FUNCTION(); |
|
202 } |
|
203 |
|
204 void CxuiSettingButton::setSetting() |
|
205 { |
|
206 CxeSettings *settings = NULL; |
|
207 if (mEngine) { |
|
208 settings = &mEngine->settings(); |
|
209 } |
|
210 |
|
211 CX_DEBUG_ASSERT(settings); |
|
212 CX_DEBUG_ASSERT(!mSettingId.isEmpty()); |
|
213 |
|
214 if (settings && !mSettingId.isEmpty()) { |
|
215 CX_DEBUG(("CxuiSettingButton::handleClicked() - setting %s to %d", mSettingId.toAscii().constData(), mSettingValue)); |
|
216 settings->set(mSettingId, mSettingValue); |
|
217 } |
|
218 |
|
219 } |
|
220 |
|
221 |
|
222 |
|
223 /* |
|
224 void CxuiSettingButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
225 { |
|
226 CX_DEBUG_ENTER_FUNCTION(); |
|
227 CX_DEBUG(("CxuiSettingButton::mouseMoveEvent() - %s to %d", mSettingId.toAscii().constData(), mSettingValue)); |
|
228 QPointF pos = event->pos(); |
|
229 QPoint pos2 = pos.toPoint(); |
|
230 CX_DEBUG(("itemPos: %d %d", pos2.x(), pos2.y())); |
|
231 if (!hitButton(pos)){ |
|
232 CX_DEBUG(("Left the button area")); |
|
233 this->clearFocus(); |
|
234 |
|
235 } |
|
236 |
|
237 |
|
238 |
|
239 CX_DEBUG_EXIT_FUNCTION(); |
|
240 } |
|
241 |
|
242 |
|
243 */ |