--- a/ginebra2/ViewController.cpp Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/ViewController.cpp Tue Jun 29 00:46:29 2010 -0400
@@ -1,26 +1,29 @@
/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
*
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
*
-* Description:
+* Description:
*
*/
-
#include "ViewController.h"
#include <QDebug>
namespace GVA {
-
+
ViewController::ViewController()
: m_viewMap() {
m_current = m_viewMap.begin();
@@ -34,11 +37,9 @@
void ViewController::addView(ControllableViewBase *controllableView) {
assert(controllableView);
- qDebug() << "ViewController::addView: adding " << controllableView
- << " jsObject=" << controllableView->jsObject();
QString key;
// Set up parent/child link for javascript access to the view.
- if(controllableView->jsObject()) {
+ if (controllableView->jsObject()) {
// Use the view's javascript object.
controllableView->jsObject()->setParent(this);
key = controllableView->jsObject()->objectName();
@@ -48,10 +49,13 @@
controllableView->setParent(this);
key = controllableView->objectName();
}
- if(key.isNull()) {
+ if (key.isNull()) {
qWarning("ViewController::addView: missing objectName.");
}
m_viewMap.insert(key, controllableView);
+ // Set the only view to current view
+ if (m_viewMap.size() == 1)
+ m_current = m_viewMap.begin();
}
QObjectList ViewController::getViews() {
@@ -61,13 +65,12 @@
}
return *result;
}
-
+
void ViewController::showCurrent() {
- qDebug() << "ViewController::showCurrent: " << m_current.value();
ControllableViewBase *currentView = m_current.value();
- if(!currentView) return;
+ if (!currentView) return;
- if(!currentView->isActive()) {
+ if (!currentView->isActive()) {
emit currentViewChanging();
// Activate the current view.
currentView->activate();
@@ -75,31 +78,34 @@
// Deactivate all others.
foreach(ControllableViewBase *view, m_viewMap) {
- if(view && view->isActive() && view != currentView) {
- view->hide();
- view->deactivate();
+ if (view && view->isActive() && view != currentView) {
+ //If this view has the same widget as the current view,
+ //then don't hide this view.
+ if(currentView->widget() != view->widget())
+ view->hide();
+ view->deactivate();
}
}
emit currentViewChanged();
}
}
-
+
void ViewController::showView(const QString &name) {
ViewMap::iterator it = m_viewMap.find(name);
- if(it != m_viewMap.end()) {
+ if (it != m_viewMap.end()) {
m_current = it;
showCurrent();
}
}
-
+
void ViewController::freezeView() {
- if(!m_viewMap.isEmpty() ) {
+ if (!m_viewMap.isEmpty() ) {
m_current.value()->freeze();
}
}
-
+
void ViewController::unfreezeView() {
- if(!m_viewMap.isEmpty() ) {
+ if (!m_viewMap.isEmpty() ) {
m_current.value()->unfreeze();
}
}
@@ -116,9 +122,9 @@
void ViewController::viewChanged() {
emit currentViewChanged();
}
-
+
ControllableViewBase* ViewController::currentView() {
- if(!m_viewMap.isEmpty())
+ if (!m_viewMap.isEmpty())
return m_current.value();
else
return NULL;