ui/views/slideshowview/src/glxslideshowview.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 03 May 2010 12:31:32 +0300
changeset 26 c499df2dbb33
parent 24 99ad1390cd33
child 29 2c833fc9e98f
permissions -rw-r--r--
Revision: 201015 Kit: 201018

/*
* Copyright (c) 2009 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".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:   ?Description
*
*/


//Includes
#include <QEvent>
#include <QDebug>
#include <hbmainwindow.h>
#include <hbdocumentloader.h>


//User Includes
#include "glxuistd.h"
#include "glxviewids.h"
#include "glxmodelparm.h"
#include "glxdocloaderdefs.h"
#include "glxslideshowview.h"
#include "glxslideshowwidget.h"
#include "glxcommandhandlers.hrh" //To:Do temporary remove once orbit back problem is resolved

#include <glxtvoutwrapper.h>

#include <glxlog.h>
#include <glxtracer.h>

GlxSlideShowView::GlxSlideShowView(HbMainWindow *window,HbDocumentLoader *DocLoader) : GlxView(GLX_SLIDESHOWVIEW_ID), mModel(NULL),
                  mWindow(window), mSlideShowWidget(NULL),mTvOutWrapper(NULL)
{
    TRACER("GlxSlideShowView::GlxSlideShowView()");
    mDocLoader = DocLoader;
}

GlxSlideShowView::~GlxSlideShowView()
{
    TRACER("GlxSlideShowView::~GlxSlideShowView()");
    if(mSlideShowWidget){
        disconnect( mSlideShowWidget, SIGNAL( slideShowEvent( GlxSlideShowEvent ) ), this, SLOT( slideShowEventHandler( GlxSlideShowEvent ) ) );
        delete mSlideShowWidget;
        mSlideShowWidget = NULL;
    }

    if(mDocLoader) {
        mDocLoader->reset();
        delete mDocLoader;
        mDocLoader = NULL;
    }
}

void GlxSlideShowView::activate()
{
    //To:Do error handling
    TRACER("GlxSlideShowView::activate()");
    mWindow->setOrientation(Qt::Horizontal, false);

    //finds the widgets from the docml
    loadObjects();
    setItemVisible(Hb::AllItems, false) ;
    connect( mSlideShowWidget, SIGNAL( slideShowEvent( GlxSlideShowEvent ) ), this, SLOT( slideShowEventHandler( GlxSlideShowEvent ) ) ); 
    connect( mSlideShowWidget, SIGNAL( indexchanged() ), this, SLOT( indexchanged() ) );
    
    if (!mTvOutWrapper){
        mTvOutWrapper = new GlxTvOutWrapper();
        }
}

void GlxSlideShowView::deActivate()
{
    TRACER("GlxSlideShowView::deActivate()");
    mWindow->unsetOrientation(false);
    setItemVisible(Hb::AllItems , TRUE);
    disconnect( mSlideShowWidget, SIGNAL( slideShowEvent( GlxSlideShowEvent ) ), this, SLOT( slideShowEventHandler( GlxSlideShowEvent ) ) );
    disconnect( mSlideShowWidget, SIGNAL( indexchanged() ), this, SLOT( indexchanged() ) );
    //Delete the Items in the slide show widget
    mSlideShowWidget->cleanUp();
    mModel = NULL;
    if (mTvOutWrapper){
        delete mTvOutWrapper;
        mTvOutWrapper = NULL;
    }
}

void GlxSlideShowView::setModel(QAbstractItemModel *model)
{
    TRACER("GlxSlideShowView::setModel()");
    GLX_LOG_INFO2("GlxSlideShowView::setModel() model %u mModel %u", model, mModel);
    if ( mModel == model ) {
        return ;
    }
    mModel = model;
    mSlideShowWidget->setModel(mModel);
    if (mTvOutWrapper){
        mTvOutWrapper->setModel(mModel);
        mTvOutWrapper->setImagetoHDMI();
        }
}

void GlxSlideShowView::setModelContext()
{
    TRACER("GlxSlideShowView::setModelContext()");
    if ( mModel && mWindow ) {
        GLX_LOG_INFO1("GlxSlideShowView::setModelContext %d", mWindow->orientation() );
    
        if ( mWindow->orientation() == Qt::Horizontal ) {
            mModel->setData(QModelIndex(), (int)GlxContextLsFs, GlxContextRole );
        }
        else {
            mModel->setData(QModelIndex(), (int)GlxContextPtFs, GlxContextRole );
        }
    }
}

void GlxSlideShowView::orientationChanged(Qt::Orientation)
{
    TRACER("GlxSlideShowView::orientationChanged()");
    setModelContext();
    mSlideShowWidget->orientationChanged( screenGeometry() );
}

void GlxSlideShowView::slideShowEventHandler( GlxSlideShowEvent e) 
{
    TRACER("GlxSlideShowView::slideShowEventHandler()");
    GLX_LOG_INFO1("GlxSlideShowView::slideShowEventHandler() event %d", e);
    switch ( e ) {
        case UI_ON_EVENT :
            setItemVisible(Hb::AllItems, TRUE) ;
            break;

        case UI_OFF_EVENT :
            setItemVisible(Hb::AllItems, false) ;
            break;

        case EMPTY_DATA_EVENT :
            emit actionTriggered( EGlxCmdEmptyData );
            break;

        default :
            break;        
    }
}

void GlxSlideShowView::indexchanged()
{
    TRACER("GlxSlideShowView::indexchanged()");
    if (mTvOutWrapper){
        mTvOutWrapper->setImagetoHDMI();
    }

}

bool GlxSlideShowView::event(QEvent *event)
{
    TRACER("GlxSlideShowView::event()");
    GLX_LOG_INFO1("GlxSlideShowView::event() %d event type", event->type());
    if ( event->type() ==  QEvent::WindowActivate && mSlideShowWidget) {
        mSlideShowWidget->startSlideShow();
    }

    if ( event->type() ==  QEvent::WindowDeactivate && mSlideShowWidget) {
       mSlideShowWidget->stopSlideShow();
    }
    return HbView::event(event);
}

void GlxSlideShowView::loadObjects()
{
    TRACER("GlxSlideShowView::loadObjects");    
    //Load/Retrieve the widgets
    HbView *view     = static_cast<GlxSlideShowView*>(mDocLoader->findWidget(GLXSLIDESHOW_VIEW));
    mSlideShowWidget = static_cast<GlxSlideShowWidget*>(mDocLoader->findWidget(GLXSLIDESHOW_WIDGET));
    
    //Initialise the Slideshow widget
    mSlideShowWidget->setSlideShowWidget(mDocLoader);
    mSlideShowWidget->setItemGeometry( screenGeometry() );  
}