1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
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 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
11 * |
8 * |
12 * Contributors: |
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
15 * |
19 * |
16 */ |
20 */ |
17 |
|
18 |
21 |
19 #include "ViewController.h" |
22 #include "ViewController.h" |
20 #include <QDebug> |
23 #include <QDebug> |
21 |
24 |
22 namespace GVA { |
25 namespace GVA { |
23 |
26 |
24 ViewController::ViewController() |
27 ViewController::ViewController() |
25 : m_viewMap() { |
28 : m_viewMap() { |
26 m_current = m_viewMap.begin(); |
29 m_current = m_viewMap.begin(); |
27 } |
30 } |
28 |
31 |
32 } |
35 } |
33 } |
36 } |
34 |
37 |
35 void ViewController::addView(ControllableViewBase *controllableView) { |
38 void ViewController::addView(ControllableViewBase *controllableView) { |
36 assert(controllableView); |
39 assert(controllableView); |
37 qDebug() << "ViewController::addView: adding " << controllableView |
|
38 << " jsObject=" << controllableView->jsObject(); |
|
39 QString key; |
40 QString key; |
40 // Set up parent/child link for javascript access to the view. |
41 // Set up parent/child link for javascript access to the view. |
41 if(controllableView->jsObject()) { |
42 if (controllableView->jsObject()) { |
42 // Use the view's javascript object. |
43 // Use the view's javascript object. |
43 controllableView->jsObject()->setParent(this); |
44 controllableView->jsObject()->setParent(this); |
44 key = controllableView->jsObject()->objectName(); |
45 key = controllableView->jsObject()->objectName(); |
45 } |
46 } |
46 else { |
47 else { |
47 // Use the view itself. |
48 // Use the view itself. |
48 controllableView->setParent(this); |
49 controllableView->setParent(this); |
49 key = controllableView->objectName(); |
50 key = controllableView->objectName(); |
50 } |
51 } |
51 if(key.isNull()) { |
52 if (key.isNull()) { |
52 qWarning("ViewController::addView: missing objectName."); |
53 qWarning("ViewController::addView: missing objectName."); |
53 } |
54 } |
54 m_viewMap.insert(key, controllableView); |
55 m_viewMap.insert(key, controllableView); |
|
56 // Set the only view to current view |
|
57 if (m_viewMap.size() == 1) |
|
58 m_current = m_viewMap.begin(); |
55 } |
59 } |
56 |
60 |
57 QObjectList ViewController::getViews() { |
61 QObjectList ViewController::getViews() { |
58 QObjectList *result = new QObjectList; |
62 QObjectList *result = new QObjectList; |
59 foreach(ControllableViewBase *view, m_viewMap) { |
63 foreach(ControllableViewBase *view, m_viewMap) { |
60 result->append(view); |
64 result->append(view); |
61 } |
65 } |
62 return *result; |
66 return *result; |
63 } |
67 } |
64 |
68 |
65 void ViewController::showCurrent() { |
69 void ViewController::showCurrent() { |
66 qDebug() << "ViewController::showCurrent: " << m_current.value(); |
|
67 ControllableViewBase *currentView = m_current.value(); |
70 ControllableViewBase *currentView = m_current.value(); |
68 if(!currentView) return; |
71 if (!currentView) return; |
69 |
72 |
70 if(!currentView->isActive()) { |
73 if (!currentView->isActive()) { |
71 emit currentViewChanging(); |
74 emit currentViewChanging(); |
72 // Activate the current view. |
75 // Activate the current view. |
73 currentView->activate(); |
76 currentView->activate(); |
74 currentView->show(); |
77 currentView->show(); |
75 |
78 |
76 // Deactivate all others. |
79 // Deactivate all others. |
77 foreach(ControllableViewBase *view, m_viewMap) { |
80 foreach(ControllableViewBase *view, m_viewMap) { |
78 if(view && view->isActive() && view != currentView) { |
81 if (view && view->isActive() && view != currentView) { |
79 view->hide(); |
82 //If this view has the same widget as the current view, |
80 view->deactivate(); |
83 //then don't hide this view. |
|
84 if(currentView->widget() != view->widget()) |
|
85 view->hide(); |
|
86 view->deactivate(); |
81 } |
87 } |
82 } |
88 } |
83 emit currentViewChanged(); |
89 emit currentViewChanged(); |
84 } |
90 } |
85 } |
91 } |
86 |
92 |
87 void ViewController::showView(const QString &name) { |
93 void ViewController::showView(const QString &name) { |
88 ViewMap::iterator it = m_viewMap.find(name); |
94 ViewMap::iterator it = m_viewMap.find(name); |
89 if(it != m_viewMap.end()) { |
95 if (it != m_viewMap.end()) { |
90 m_current = it; |
96 m_current = it; |
91 showCurrent(); |
97 showCurrent(); |
92 } |
98 } |
93 } |
99 } |
94 |
100 |
95 void ViewController::freezeView() { |
101 void ViewController::freezeView() { |
96 if(!m_viewMap.isEmpty() ) { |
102 if (!m_viewMap.isEmpty() ) { |
97 m_current.value()->freeze(); |
103 m_current.value()->freeze(); |
98 } |
104 } |
99 } |
105 } |
100 |
106 |
101 void ViewController::unfreezeView() { |
107 void ViewController::unfreezeView() { |
102 if(!m_viewMap.isEmpty() ) { |
108 if (!m_viewMap.isEmpty() ) { |
103 m_current.value()->unfreeze(); |
109 m_current.value()->unfreeze(); |
104 } |
110 } |
105 } |
111 } |
106 |
112 |
107 void ViewController::dump() { |
113 void ViewController::dump() { |