|
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: Implements the wizard activation and interactions. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ftuwizardactivatedstate.h" |
|
20 #include "fturuntimeservices_global.h" |
|
21 #include "ftucontentservice.h" |
|
22 #include <ftuwizard.h> |
|
23 |
|
24 #include <hbmainwindow.h> |
|
25 #include <hbdocumentloader.h> |
|
26 #include <hbview.h> |
|
27 #include <hblabel.h> |
|
28 #include <hbstackedwidget.h> |
|
29 #include <hbicon.h> |
|
30 #include <hbinstance.h> |
|
31 #include <hbaction.h> |
|
32 #include <hbgridview.h> |
|
33 #include <QStandardItemModel> |
|
34 #include <QDebug> |
|
35 #include <QGraphicsWidget> |
|
36 #include <QDir> |
|
37 |
|
38 const int gridRowCount = 1; |
|
39 |
|
40 const char *FTUSTATEPROVIDER_DOCML2 = ":/xml/ftustateprovider.docml"; |
|
41 const char *WIZARD_VIEW = "wizardView"; |
|
42 const char *WIZARD_INFOTEXT_LABEL = "wizardInfoTextLabel"; |
|
43 const char *WIZARD_STACKEDWIDGET = "wizardStackedWidget"; |
|
44 const char *WIZARD_GRID_VIEW = "wizardGridView"; |
|
45 |
|
46 /* |
|
47 #define LOG_GEOM(txt, r) logGeometry(txt, r) |
|
48 |
|
49 static void logGeometry(const char *txt, const QRectF& r) |
|
50 { |
|
51 qDebug() << "ftu:" << txt << " x: " << r.topLeft().x() << " y: " << r.topLeft().y() |
|
52 << " w: " << r.width() << " h: " << r.height(); |
|
53 } |
|
54 */ |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // FtuWizardActivatedState::FtuWizardActivatedState |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 FtuWizardActivatedState::FtuWizardActivatedState(QState *parent) : |
|
61 QState(parent), |
|
62 mMainWindow(NULL), |
|
63 mDocumentLoader(NULL), |
|
64 mPluginView(NULL), |
|
65 mActiveWizard(NULL), |
|
66 mPluginTitleLabel(NULL), |
|
67 mWizardStackedWidget(NULL), |
|
68 mBackAction(NULL), |
|
69 mMenustrip(NULL), |
|
70 mPreviousView(NULL), |
|
71 mCurrentView(NULL), |
|
72 mPluginDisplayMode(PartialScreen) |
|
73 { |
|
74 mMainWindow = hbInstance->allMainWindows().at(0); |
|
75 mDocumentLoader = new HbDocumentLoader(); |
|
76 mPluginView = new HbView(); |
|
77 |
|
78 bool ok = false; |
|
79 mDocumentLoader->load(FTUSTATEPROVIDER_DOCML2, &ok); |
|
80 QGraphicsWidget *widget = mDocumentLoader->findWidget(WIZARD_VIEW); |
|
81 Q_ASSERT_X(ok && (widget != 0), "ftustateprovider", "invalid DocML file"); |
|
82 |
|
83 mPluginView->setWidget(widget); |
|
84 mMainWindow->addView(mPluginView); |
|
85 |
|
86 mPluginView->setTitle(qtTrId("txt_ftu_title_setup")); |
|
87 |
|
88 mPluginTitleLabel = qobject_cast<HbLabel *>(mDocumentLoader->findWidget(WIZARD_INFOTEXT_LABEL)); |
|
89 |
|
90 mWizardStackedWidget = qobject_cast<HbStackedWidget *>(mDocumentLoader->findWidget(WIZARD_STACKEDWIDGET)); |
|
91 |
|
92 QString path = QDir::currentPath(); |
|
93 |
|
94 mBackAction = new HbAction(Hb::BackAction, this); |
|
95 |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // FtuWizardActivatedState::~FtuWizardActivatedState |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 FtuWizardActivatedState::~FtuWizardActivatedState() |
|
103 { |
|
104 delete mDocumentLoader; |
|
105 |
|
106 if(mBackAction) |
|
107 { |
|
108 delete mBackAction; |
|
109 } |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // FtuWizardActivatedState::onEntry |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void FtuWizardActivatedState::onEntry(QEvent *event) |
|
117 { |
|
118 qDebug() << "ftu:FtuWizardActivatedState::onEntry"; |
|
119 QState::onEntry(event); |
|
120 |
|
121 int activeIndex = content()->activeWizard(); |
|
122 mActiveWizard = content()->wizard(activeIndex); |
|
123 |
|
124 mPluginView->setNavigationAction(mBackAction); |
|
125 // Make menustrip for testing purposes. |
|
126 if(!mMenustrip) |
|
127 { |
|
128 constructGrid(); |
|
129 } |
|
130 mMenustrip->setVisible(true); |
|
131 |
|
132 connect(mBackAction, SIGNAL(triggered()), |
|
133 this, SLOT(handleBackEvent())); |
|
134 |
|
135 setActiveWizardConnections(); |
|
136 |
|
137 mActiveWizard->activateWizard(); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // FtuWizardActivatedState::onExit |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void FtuWizardActivatedState::onExit(QEvent *event) |
|
145 { |
|
146 QState::onExit(event); |
|
147 |
|
148 disconnect(mBackAction, SIGNAL(triggered()), |
|
149 this, SLOT(handleBackEvent())); |
|
150 |
|
151 disconnect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, |
|
152 QGraphicsWidget* )), |
|
153 this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*))); |
|
154 |
|
155 disconnect(mActiveWizard, SIGNAL(fullScreenModeRequested(FtuWizard *)), |
|
156 this, SLOT(enableFullScreenMode(FtuWizard*))); |
|
157 |
|
158 disconnect(mActiveWizard, SIGNAL(partialScreenModeRequested(FtuWizard * )), |
|
159 this, SLOT(enablePartialScreenMode(FtuWizard*))); |
|
160 |
|
161 disconnect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )), |
|
162 this, SLOT(updateInfoText(FtuWizard *, QString))); |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // FtuWizardActivatedState::setActiveWizardConnections |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void FtuWizardActivatedState::setActiveWizardConnections() |
|
170 { |
|
171 // first disconnect possible old connections with active wizard |
|
172 disconnect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, |
|
173 QGraphicsWidget* )), |
|
174 this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*))); |
|
175 |
|
176 disconnect(mActiveWizard, SIGNAL(fullScreenModeRequested(FtuWizard *)), |
|
177 this, SLOT(enableFullScreenMode(FtuWizard*))); |
|
178 |
|
179 disconnect(mActiveWizard, SIGNAL(partialScreenModeRequested(FtuWizard * )), |
|
180 this, SLOT(enablePartialScreenMode(FtuWizard*))); |
|
181 |
|
182 disconnect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )), |
|
183 this, SLOT(updateInfoText(FtuWizard *, QString))); |
|
184 |
|
185 // then connect new ones to active wizard |
|
186 connect(mActiveWizard, SIGNAL(viewChanged(FtuWizard *, QGraphicsWidget* )), |
|
187 this, SLOT(changeWizardView(FtuWizard*, QGraphicsWidget*))); |
|
188 |
|
189 connect(mActiveWizard, SIGNAL(fullScreenModeRequested(FtuWizard *)), |
|
190 this, SLOT(enableFullScreenMode(FtuWizard*))); |
|
191 |
|
192 connect(mActiveWizard, SIGNAL(partialScreenModeRequested(FtuWizard * )), |
|
193 this, SLOT(enablePartialScreenMode(FtuWizard*))); |
|
194 |
|
195 connect(mActiveWizard, SIGNAL(infoTextUpdated(FtuWizard *, QString )), |
|
196 this, SLOT(updateInfoText(FtuWizard *, QString))); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // FtuWizardActivatedState::content |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 FtuContentService *FtuWizardActivatedState::content() const |
|
204 { |
|
205 return property(FTU_CONTENT_SERVICE_KEY).value<FtuContentService*>(); |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // FtuWizardActivatedState::handleBackEvent |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 |
|
213 void FtuWizardActivatedState::handleBackEvent() |
|
214 { |
|
215 if(!mActiveWizard->handleBackEvent()) |
|
216 { |
|
217 emit backEventTriggered(); |
|
218 } |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // FtuWizardActivatedState::changeWizardView |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void FtuWizardActivatedState::changeWizardView(FtuWizard *caller, |
|
226 QGraphicsWidget* viewWidget) |
|
227 { |
|
228 if(caller == mActiveWizard) |
|
229 { |
|
230 if(viewWidget) |
|
231 { |
|
232 if (mWizardStackedWidget->indexOf(viewWidget) == -1) |
|
233 { |
|
234 // add wizard's widget to stacked widget if not yet there |
|
235 mWizardStackedWidget->addWidget(viewWidget); |
|
236 } |
|
237 // set wizard's widget as current widget |
|
238 mWizardStackedWidget->setCurrentWidget(viewWidget); |
|
239 |
|
240 qDebug() << "Ftu: switching view due plugin view change"; |
|
241 mainWindow()->setCurrentView(mPluginView, true); |
|
242 |
|
243 QList<FtuWizard*> wizards = content()->wizards(); |
|
244 // get index of active wizard |
|
245 int index = wizards.indexOf(mActiveWizard); |
|
246 |
|
247 // temp solution to skip edge indexes - start |
|
248 if (index == 0) { index++; } |
|
249 if (index == wizards.count()-1) { index--; } |
|
250 // temp solution to skip edge indexes - end |
|
251 |
|
252 // create model index for active wizard |
|
253 QModelIndex modelIndex = mMenustrip->model()->index(index, 0); |
|
254 // scroll to correct position in menustrip |
|
255 HbAbstractItemView::ScrollHint hint = HbAbstractItemView::PositionAtCenter; |
|
256 mMenustrip->scrollTo(modelIndex, hint); |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // FtuWizardActivatedState::enableFullScreenMode |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 void FtuWizardActivatedState::enableFullScreenMode(FtuWizard *caller) |
|
266 { |
|
267 if(caller == mActiveWizard) |
|
268 { |
|
269 mPluginDisplayMode = FullScreen; |
|
270 // Remove menustrip |
|
271 mMenustrip->setVisible(false); |
|
272 caller->resizeWizard(calculateWizardGeometry()); |
|
273 } |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // FtuWizardActivatedState::enablePartialScreenMode |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void FtuWizardActivatedState::enablePartialScreenMode(FtuWizard *caller) |
|
281 { |
|
282 if(caller == mActiveWizard) |
|
283 { |
|
284 mPluginDisplayMode = PartialScreen; |
|
285 mMenustrip->setVisible(true); |
|
286 caller->resizeWizard(calculateWizardGeometry()); |
|
287 } |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // FtuWizardActivatedState::updateInfoText |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 void FtuWizardActivatedState::updateInfoText(FtuWizard *caller, |
|
295 QString text) |
|
296 { |
|
297 if(caller == mActiveWizard) |
|
298 { |
|
299 mPluginTitleLabel->setPlainText(text); |
|
300 } |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // FtuWizardActivatedState::mainWindow |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 HbMainWindow* FtuWizardActivatedState::mainWindow() |
|
308 { |
|
309 return hbInstance->allMainWindows().at(0); |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // FtuWizardActivatedState::constructGrid |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 void FtuWizardActivatedState::constructGrid() |
|
317 { |
|
318 // fetch grid view from docml |
|
319 mMenustrip = qobject_cast<HbGridView *>(mDocumentLoader->findWidget(WIZARD_GRID_VIEW)); |
|
320 // set row amount for grid |
|
321 mMenustrip->setRowCount(gridRowCount); |
|
322 |
|
323 mMenustrip->setScrollDirections(Qt::Horizontal); |
|
324 |
|
325 FtuContentService* ftuContentService = content(); |
|
326 // get wizards |
|
327 QList<FtuWizard*> wizards = ftuContentService->wizards(); |
|
328 |
|
329 QStandardItemModel* model = new QStandardItemModel(this); |
|
330 |
|
331 for(int i = 0 ; i < wizards.size() ; ++i) |
|
332 { |
|
333 // get wizard settings |
|
334 const FtuWizardSetting& settings = wizards.at(i)->wizardSettings(); |
|
335 QStandardItem* item = new QStandardItem(); |
|
336 HbIcon icon(settings.mMenustripDefaultIcon.absoluteFilePath()); |
|
337 |
|
338 item->setBackground(QBrush(Qt::lightGray)); |
|
339 item->setData(icon, Qt::DecorationRole); |
|
340 |
|
341 QStringList data; |
|
342 data << settings.mMenustripLabel; |
|
343 |
|
344 item->setData(QVariant(data), Qt::DisplayRole); |
|
345 |
|
346 model->appendRow(item); |
|
347 } |
|
348 // set above defined model for menustrip |
|
349 mMenustrip->setModel(model); |
|
350 |
|
351 connect(mMenustrip, SIGNAL(activated(const QModelIndex)), |
|
352 this, SLOT(activateWizard(const QModelIndex))); |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // FtuWizardActivatedState::activateWizard |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 void FtuWizardActivatedState::activateWizard(const QModelIndex index) |
|
360 { |
|
361 // get index for selected wizard |
|
362 int wizardIndex = index.row(); |
|
363 if (wizardIndex != -1) |
|
364 { |
|
365 // check if other wizard than current is activated |
|
366 if (mActiveWizard != content()->wizard(wizardIndex)) |
|
367 { |
|
368 // first deactivate current active wizard |
|
369 if(mActiveWizard) |
|
370 { |
|
371 mActiveWizard->deactivateWizard(); |
|
372 } |
|
373 // set selected wizard active (precaution, as state does not change) |
|
374 content()->setActiveWizard(wizardIndex); |
|
375 // save active wizard |
|
376 mActiveWizard = content()->wizard(wizardIndex); |
|
377 // reset connections for new active wizard |
|
378 setActiveWizardConnections(); |
|
379 // set new active wizard visible |
|
380 mActiveWizard->activateWizard(); |
|
381 } |
|
382 |
|
383 // temp solution to skip edge indexes - start |
|
384 if (wizardIndex == 0) { wizardIndex++; } |
|
385 if (wizardIndex == content()->wizards().count()-1) { wizardIndex--; } |
|
386 QModelIndex modelIndex = mMenustrip->model()->index(wizardIndex, 0); |
|
387 // temp solution to skip edge indexes - end |
|
388 |
|
389 HbAbstractItemView::ScrollHint hint = HbAbstractItemView::PositionAtCenter; |
|
390 // scroll to correct position in menustrip |
|
391 mMenustrip->scrollTo(modelIndex, hint); |
|
392 } |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // FtuWizardActivatedState::calculateWizardGeometry |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 QRectF FtuWizardActivatedState::calculateWizardGeometry() |
|
400 { |
|
401 QRectF widgetRect = mWizardStackedWidget->geometry(); |
|
402 QRectF pluginRect = mPluginView->geometry(); |
|
403 if(mPluginDisplayMode == FullScreen) |
|
404 { |
|
405 pluginRect.setSize(QSizeF(widgetRect.width(), |
|
406 (widgetRect.height() + |
|
407 mMenustrip->geometry().height()))); |
|
408 } |
|
409 else |
|
410 { |
|
411 pluginRect.setSize(QSizeF(widgetRect.width(), |
|
412 widgetRect.height())); |
|
413 } |
|
414 |
|
415 return pluginRect; |
|
416 } |