ui/views/slideshowview/src/glxslideshowview.cpp
changeset 23 74c9f037fd5d
child 24 99ad1390cd33
equal deleted inserted replaced
5:f7f0874bfe7d 23:74c9f037fd5d
       
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //Includes
       
    20 #include <QEvent>
       
    21 #include <QDebug>
       
    22 #include <hbmainwindow.h>
       
    23 #include <hbdocumentloader.h>
       
    24 
       
    25 
       
    26 //User Includes
       
    27 #include "glxuistd.h"
       
    28 #include "glxviewids.h"
       
    29 #include "glxmodelparm.h"
       
    30 #include "glxdocloaderdefs.h"
       
    31 #include "glxslideshowview.h"
       
    32 #include "glxslideshowwidget.h"
       
    33 #include "glxcommandhandlers.hrh" //To:Do temporary remove once orbit back problem is resolved
       
    34 
       
    35 #include <glxhdmicontroller.h>
       
    36 #include <glxlog.h>
       
    37 #include <glxtracer.h>
       
    38 
       
    39 GlxSlideShowView::GlxSlideShowView(HbMainWindow *window,HbDocumentLoader *DocLoader) : GlxView(GLX_SLIDESHOWVIEW_ID), mModel(NULL),
       
    40                   mWindow(window), mSlideShowWidget(NULL),iHdmiController(NULL)
       
    41     {
       
    42     TRACER("GlxSlideShowView::GlxSlideShowView()");
       
    43     mDocLoader = DocLoader;
       
    44     }
       
    45 
       
    46 GlxSlideShowView::~GlxSlideShowView()
       
    47     {
       
    48     TRACER("GlxSlideShowView::~GlxSlideShowView()");
       
    49     if(mSlideShowWidget){
       
    50         disconnect( mSlideShowWidget, SIGNAL( slideShowEvent( GlxSlideShowEvent ) ), this, SLOT( slideShowEventHandler( GlxSlideShowEvent ) ) );
       
    51         delete mSlideShowWidget;
       
    52         mSlideShowWidget = NULL;
       
    53         }
       
    54 
       
    55     if(mDocLoader) {
       
    56         mDocLoader->reset();
       
    57         delete mDocLoader;
       
    58         mDocLoader = NULL;
       
    59         }
       
    60     }
       
    61 
       
    62 void GlxSlideShowView::activate()
       
    63     {
       
    64     //To:Do error handling
       
    65     TRACER("GlxSlideShowView::activate()");
       
    66 
       
    67     //finds the widgets from the docml
       
    68     loadObjects();
       
    69     mWindow->setItemVisible(Hb::AllItems, false) ;
       
    70     connect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation)));
       
    71     connect( mSlideShowWidget, SIGNAL( slideShowEvent( GlxSlideShowEvent ) ), this, SLOT( slideShowEventHandler( GlxSlideShowEvent ) ) ); 
       
    72     connect( mSlideShowWidget, SIGNAL( indexchanged() ), this, SLOT( indexchanged() ) );
       
    73     if (!iHdmiController) {
       
    74         GLX_LOG_INFO("GlxSlideShowView::activate() - CGlxHdmi" );
       
    75         iHdmiController = CGlxHdmiController::NewL();
       
    76         }   
       
    77     }
       
    78 
       
    79 void GlxSlideShowView::deActivate()
       
    80     {
       
    81     TRACER("GlxSlideShowView::deActivate()");
       
    82     mWindow->setItemVisible(Hb::AllItems , TRUE);
       
    83     disconnect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation)));
       
    84     disconnect( mSlideShowWidget, SIGNAL( slideShowEvent( GlxSlideShowEvent ) ), this, SLOT( slideShowEventHandler( GlxSlideShowEvent ) ) );
       
    85     disconnect( mSlideShowWidget, SIGNAL( indexchanged() ), this, SLOT( indexchanged() ) );
       
    86     //Delete the Items in the slide show widget
       
    87     mSlideShowWidget->cleanUp();
       
    88     mModel = NULL;
       
    89     if (iHdmiController) {
       
    90         GLX_LOG_INFO("GlxSlideShowView() deActivate delete iHdmiController " );
       
    91         delete iHdmiController;
       
    92         iHdmiController = NULL;
       
    93         }
       
    94     }
       
    95 
       
    96 void GlxSlideShowView::setModel(QAbstractItemModel *model)
       
    97     {
       
    98     TRACER("GlxSlideShowView::setModel()");
       
    99     GLX_LOG_INFO2("GlxSlideShowView::setModel() model %u mModel %u", model, mModel);
       
   100     if ( mModel == model ) {
       
   101     return ;
       
   102     }
       
   103     mModel = model;
       
   104     mSlideShowWidget->setModel(mModel);
       
   105     SetImageToHdmiL();
       
   106     }
       
   107 
       
   108 void GlxSlideShowView::setModelContext()
       
   109     {
       
   110     TRACER("GlxSlideShowView::setModelContext()");
       
   111     if ( mModel && mWindow ) {
       
   112     GLX_LOG_INFO1("GlxSlideShowView::setModelContext %d", mWindow->orientation() );
       
   113 
       
   114     if ( mWindow->orientation() == Qt::Horizontal ) {
       
   115     mModel->setData(QModelIndex(), (int)GlxContextLsFs, GlxContextRole );
       
   116     }
       
   117     else {
       
   118     mModel->setData(QModelIndex(), (int)GlxContextPtFs, GlxContextRole );
       
   119     }
       
   120     }
       
   121     }
       
   122 
       
   123 void GlxSlideShowView::orientationChanged(Qt::Orientation)
       
   124     {
       
   125     TRACER("GlxSlideShowView::orientationChanged()");
       
   126     QRect screenRect = mWindow->geometry(); 
       
   127     setModelContext();
       
   128     mSlideShowWidget->orientationChanged(screenRect);
       
   129     }
       
   130 
       
   131 void GlxSlideShowView::slideShowEventHandler( GlxSlideShowEvent e) 
       
   132     {
       
   133     TRACER("GlxSlideShowView::slideShowEventHandler()");
       
   134     GLX_LOG_INFO1("GlxSlideShowView::slideShowEventHandler() event %d", e);
       
   135     switch ( e ) {
       
   136         case UI_ON_EVENT :
       
   137             mWindow->setItemVisible(Hb::AllItems, TRUE) ;
       
   138             break;
       
   139 
       
   140         case UI_OFF_EVENT :
       
   141             mWindow->setItemVisible(Hb::AllItems, false) ;
       
   142             break;
       
   143 
       
   144         case EMPTY_DATA_EVENT :
       
   145             emit actionTriggered( EGlxCmdEmptyData );
       
   146             break;
       
   147 
       
   148         default :
       
   149             break;        
       
   150     }
       
   151     }
       
   152 
       
   153 void GlxSlideShowView::indexchanged()
       
   154     {
       
   155     TRACER("GlxSlideShowView::indexchanged()");
       
   156     SetImageToHdmiL();
       
   157     }
       
   158 
       
   159 bool GlxSlideShowView::event(QEvent *event)
       
   160     {
       
   161     TRACER("GlxSlideShowView::event()");
       
   162     GLX_LOG_INFO1("GlxSlideShowView::event() %d event type", event->type());
       
   163     if ( event->type() ==  QEvent::WindowActivate && mSlideShowWidget) {
       
   164     mSlideShowWidget->startSlideShow();
       
   165     }
       
   166 
       
   167     if ( event->type() ==  QEvent::WindowDeactivate && mSlideShowWidget) {
       
   168     mSlideShowWidget->stopSlideShow();
       
   169     }
       
   170     return HbView::event(event);
       
   171     }
       
   172 
       
   173 void GlxSlideShowView::loadObjects()
       
   174     {
       
   175     TRACER("GlxSlideShowView::loadObjects");    
       
   176     //Load/Retrieve the widgets
       
   177     HbView *view     = static_cast<GlxSlideShowView*>(mDocLoader->findWidget(GLXSLIDESHOW_VIEW));
       
   178     mSlideShowWidget = static_cast<GlxSlideShowWidget*>(mDocLoader->findWidget(GLXSLIDESHOW_WIDGET));
       
   179     
       
   180     //Initialise the Slideshow widget
       
   181     mSlideShowWidget->setSlideShowWidget(mDocLoader);
       
   182     mSlideShowWidget->setItemGeometry(mWindow->geometry());  
       
   183     }
       
   184 
       
   185 void GlxSlideShowView::SetImageToHdmiL()
       
   186     {
       
   187     TRACER("GlxSlideShowView::SetImageToHdmiL() - CGlxHdmi 1" );
       
   188     if (iHdmiController)
       
   189         {
       
   190         GLX_LOG_INFO("GlxSlideShowView::SetImageToHdmiL() - CGlxHdmi 2" );
       
   191         // Get the image uri
       
   192         QString imagePath = (mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0),GlxUriRole)).value<QString>();
       
   193         if(imagePath.isNull())
       
   194             {
       
   195             GLX_LOG_INFO("GlxSlideShowView::SetImageToHdmiL() path is null" );
       
   196             }
       
   197         qDebug() << "GlxSlideShowView::SetImageToHdmiL() imagePath= " << imagePath;
       
   198         TPtrC aPtr = reinterpret_cast<const TUint16*>(imagePath.utf16());
       
   199 
       
   200         // Get the image Dimensions
       
   201         QSize imageDimension = (mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0),GlxDimensionsRole)).value<QSize>();
       
   202         TSize imageSize(imageDimension.width(),imageDimension.height());
       
   203         
       
   204         iHdmiController->SetImageL(aPtr,imageSize );
       
   205         }
       
   206     }