|
1 /* |
|
2 * Copyright (c) 2010 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 |
|
19 #include "ViewController.h" |
|
20 #include <QDebug> |
|
21 |
|
22 namespace GVA { |
|
23 |
|
24 ViewController::ViewController() |
|
25 : m_viewMap() { |
|
26 m_current = m_viewMap.begin(); |
|
27 } |
|
28 |
|
29 ViewController::~ViewController() { |
|
30 foreach(ControllableViewBase *view, m_viewMap) { |
|
31 delete view; |
|
32 } |
|
33 } |
|
34 |
|
35 void ViewController::addView(ControllableViewBase *controllableView) { |
|
36 assert(controllableView); |
|
37 qDebug() << "ViewController::addView: adding " << controllableView |
|
38 << " jsObject=" << controllableView->jsObject(); |
|
39 QString key; |
|
40 // Set up parent/child link for javascript access to the view. |
|
41 if(controllableView->jsObject()) { |
|
42 // Use the view's javascript object. |
|
43 controllableView->jsObject()->setParent(this); |
|
44 key = controllableView->jsObject()->objectName(); |
|
45 } |
|
46 else { |
|
47 // Use the view itself. |
|
48 controllableView->setParent(this); |
|
49 key = controllableView->objectName(); |
|
50 } |
|
51 if(key.isNull()) { |
|
52 qWarning("ViewController::addView: missing objectName."); |
|
53 } |
|
54 m_viewMap.insert(key, controllableView); |
|
55 } |
|
56 |
|
57 QObjectList ViewController::getViews() { |
|
58 QObjectList *result = new QObjectList; |
|
59 foreach(ControllableViewBase *view, m_viewMap) { |
|
60 result->append(view); |
|
61 } |
|
62 return *result; |
|
63 } |
|
64 |
|
65 void ViewController::showCurrent() { |
|
66 qDebug() << "ViewController::showCurrent: " << m_current.value(); |
|
67 ControllableViewBase *currentView = m_current.value(); |
|
68 if(!currentView) return; |
|
69 |
|
70 if(!currentView->isActive()) { |
|
71 emit currentViewChanging(); |
|
72 // Activate the current view. |
|
73 currentView->activate(); |
|
74 currentView->show(); |
|
75 |
|
76 // Deactivate all others. |
|
77 foreach(ControllableViewBase *view, m_viewMap) { |
|
78 if(view && view->isActive() && view != currentView) { |
|
79 view->hide(); |
|
80 view->deactivate(); |
|
81 } |
|
82 } |
|
83 emit currentViewChanged(); |
|
84 } |
|
85 } |
|
86 |
|
87 void ViewController::showView(const QString &name) { |
|
88 ViewMap::iterator it = m_viewMap.find(name); |
|
89 if(it != m_viewMap.end()) { |
|
90 m_current = it; |
|
91 showCurrent(); |
|
92 } |
|
93 } |
|
94 |
|
95 void ViewController::freezeView() { |
|
96 if(!m_viewMap.isEmpty() ) { |
|
97 m_current.value()->freeze(); |
|
98 } |
|
99 } |
|
100 |
|
101 void ViewController::unfreezeView() { |
|
102 if(!m_viewMap.isEmpty() ) { |
|
103 m_current.value()->unfreeze(); |
|
104 } |
|
105 } |
|
106 |
|
107 void ViewController::dump() { |
|
108 qDebug() << "ViewController::dump:" |
|
109 << " count=" << m_viewMap.count() |
|
110 << " current=" << m_current.value(); |
|
111 foreach(ControllableViewBase *view, m_viewMap) { |
|
112 qDebug() << " " << view; |
|
113 } |
|
114 } |
|
115 |
|
116 void ViewController::viewChanged() { |
|
117 emit currentViewChanged(); |
|
118 } |
|
119 |
|
120 ControllableViewBase* ViewController::currentView() { |
|
121 if(!m_viewMap.isEmpty()) |
|
122 return m_current.value(); |
|
123 else |
|
124 return NULL; |
|
125 } |
|
126 |
|
127 } |
|
128 |