locationpickerservice/src/locationpickerlandscapeview.cpp
changeset 31 8db05346071b
parent 30 96df3ab41000
child 32 9bd2e0ffe298
child 35 59575560d1e6
equal deleted inserted replaced
30:96df3ab41000 31:8db05346071b
     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: LocationPickerLandscapeView implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "locationpickerlandscapeview.h"
       
    19 
       
    20 #include <qstandarditemmodel.h>
       
    21 #include <HbMainWindow>
       
    22 #include <HbStyleLoader>
       
    23 #include <HbAction>
       
    24 #include <HbMenu>
       
    25 #include <HbToolBar>
       
    26 #include <QGraphicsLinearLayout>
       
    27 #include <HbLabel>
       
    28 #include <HbTextItem>
       
    29 #include <hgwidgets/hgmediawall.h>
       
    30 
       
    31 #include "hgwidgetdatamodel.h"
       
    32 #include "locationpickerproxymodel.h"
       
    33 #include "locationpickerdatamanager.h"
       
    34 #include "locationpickercollectionlistcontent.h"
       
    35 #include "locationpickercollectioncontent.h"
       
    36 
       
    37 
       
    38 
       
    39 // ----------------------------------------------------
       
    40 // LocationPickerLandscapeView::LocationPickerLandscapeView()
       
    41 // ----------------------------------------------------
       
    42 LocationPickerLandscapeView::LocationPickerLandscapeView(HbDocumentLoader* aLoader)
       
    43     :mDocumentLoader(aLoader),
       
    44     mAllAction(NULL),
       
    45     mCollectionAction(NULL),
       
    46     mSearchAction(NULL),
       
    47     mAscendingAction(NULL),
       
    48     mDescendingAction(NULL),
       
    49     mCollectionContent(NULL),
       
    50     mViewType(ELocationPickerContent),
       
    51     mModel(NULL),
       
    52     mWidget(NULL),
       
    53     mLayout(NULL),
       
    54     mEmptyLabel(NULL),
       
    55 	mLongPressMenu(NULL)
       
    56 {       
       
    57     // create back action
       
    58     mLandscapeBackAction = new HbAction(Hb::BackNaviAction);
       
    59     setNavigationAction(mLandscapeBackAction);
       
    60     connect(mLandscapeBackAction, SIGNAL(triggered()), this,
       
    61             SLOT(backButtonTriggered()));
       
    62     
       
    63 
       
    64 }
       
    65 // ----------------------------------------------------
       
    66 // LocationPickerLandscapeView::~LocationPickerLandscapeView()
       
    67 // ----------------------------------------------------
       
    68 LocationPickerLandscapeView::~LocationPickerLandscapeView()
       
    69 {
       
    70     delete mCollectionContent;
       
    71     delete mAllAction;
       
    72     delete mCollectionAction;
       
    73     delete mAscendingAction;
       
    74     delete mDescendingAction;
       
    75     delete mWidget;
       
    76     delete mModel;
       
    77     delete mLongPressMenu;
       
    78 }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // LocationPickerLandscapeView::backButtonTriggered()
       
    82 // ----------------------------------------------------------------------------
       
    83 void LocationPickerLandscapeView::backButtonTriggered()
       
    84 {
       
    85     //if current model is collection content, go back to collectionlist content  
       
    86     if(mViewType == ELocationPickerCollectionContent)
       
    87     {
       
    88         colectionTabTriggered();
       
    89         emit collectionContentExited(); 
       
    90     }
       
    91     else
       
    92     {
       
    93         //complete the service
       
    94         emit completeService();
       
    95     } 
       
    96 }
       
    97 
       
    98 
       
    99 // ----------------------------------------------------
       
   100 // LocationPickerLandscapeView::init()
       
   101 // ----------------------------------------------------
       
   102 void LocationPickerLandscapeView::init(Qt::Orientation aOrientation, QStandardItemModel *aModel )
       
   103 {   
       
   104       mStandardModel = aModel;      
       
   105       //create proxy model
       
   106       mProxyModel = new LocationPickerProxyModel( aOrientation , this  );
       
   107       mProxyModel->setSourceModel(aModel);
       
   108       // set sort properties
       
   109       mProxyModel->setDynamicSortFilter(TRUE);
       
   110       mProxyModel->setSortRole(Qt::DisplayRole);
       
   111       mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
       
   112       // sort in ascending order
       
   113       mProxyModel->sort(0, Qt::AscendingOrder);    
       
   114       
       
   115      //Get HbAction items
       
   116 	 HbToolBar* toolbar = new HbToolBar();
       
   117 	//Create Action Items
       
   118 	 mAllAction = new HbAction();
       
   119 	 mAllAction->setIcon(QString("qtg_mono_location"));
       
   120 	 mAllAction->setCheckable(true);
       
   121 	 mCollectionAction =new HbAction();
       
   122 	 mCollectionAction->setIcon(QString("qtg_mono_location_collection"));
       
   123 	 mCollectionAction->setCheckable(true);
       
   124 	 mSearchAction = new HbAction();
       
   125 	 mSearchAction->setIcon(QString("qtg_mono_search"));
       
   126 
       
   127 	 toolbar->addAction(mAllAction);
       
   128 	 toolbar->addAction(mCollectionAction);
       
   129 	 toolbar->addAction(mSearchAction);
       
   130 	 this->setToolBar(toolbar);
       
   131 	 
       
   132       mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   133               QString("ascendingAction")));
       
   134       mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   135               QString("descendingAction")));
       
   136       if( !mAllAction || !mCollectionAction || !mSearchAction || !mAscendingAction || !mDescendingAction)
       
   137       {
       
   138           qFatal("Error Reading Docml");
       
   139       }
       
   140 
       
   141       //connect to slots
       
   142       connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
       
   143       connect(mDescendingAction, SIGNAL(triggered()), this,
       
   144               SLOT(sortDescending()));
       
   145       //connect all action Items to respective slots
       
   146       connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered()));
       
   147       connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered()));
       
   148       connect(mSearchAction, SIGNAL(triggered()), this,
       
   149               SLOT(searchTabTriggered()));
       
   150       
       
   151       //hurrriganes widget
       
   152       QGraphicsWidget *widget = NULL;
       
   153       widget = mDocumentLoader->findWidget(QString("vertical"));
       
   154       mLayout =  static_cast<QGraphicsLinearLayout*>(widget->layout());
       
   155       
       
   156       mModel = new HgWidgetDataModel( mProxyModel, this );
       
   157       mModel->setImageDataType(HgWidgetDataModel::ETypeQImage);
       
   158       //create MediaWall Object
       
   159       mWidget = new HgMediawall();
       
   160       HbIcon defaultIcon(KDummyImage);
       
   161       QImage defaultImage = defaultIcon.pixmap().toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
       
   162       mWidget->setDefaultImage(defaultImage);
       
   163       mWidget->setObjectName("location");
       
   164       HbStyleLoader::registerFilePath(":/location.hgmediawall.widgetml");
       
   165       HbStyleLoader::registerFilePath(":/location.hgmediawall.css");
       
   166       mWidget->enableReflections(false);
       
   167       mWidget->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   168       mWidget->setItemSize(QSize(4.6,2));
       
   169       connect(this->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),mWidget,
       
   170 	   SLOT(orientationChanged(Qt::Orientation)));
       
   171       
       
   172       mWidget->setAcceptTouchEvents(true);
       
   173       connect(mWidget, SIGNAL(activated(const QModelIndex &)),this, SLOT(handleActivated(const QModelIndex &)));
       
   174       connect(mWidget, SIGNAL(longPressed(const QModelIndex &, const QPointF &)),this, 
       
   175               SLOT(launchPopUpMenu(const QModelIndex &, const QPointF &)));
       
   176       mLayout->addItem(mWidget);
       
   177       mWidget->setModel(mModel);
       
   178       mWidget->setLongPressEnabled(true);
       
   179       mWidget->scrollTo(mWidget->currentIndex());
       
   180 }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // LocationPickerLandscapeView::manageHgWidget()
       
   184 // -----------------------------------------------------------------------------
       
   185 void LocationPickerLandscapeView::manageHgWidget()
       
   186 {
       
   187     //set the appropriate model
       
   188     switch(mViewType)
       
   189     {
       
   190         case ELocationPickerContent:
       
   191         {  
       
   192             mModel->resetModel(mProxyModel);
       
   193             mAllAction->setChecked(true);
       
   194             mCollectionAction->setChecked(false);
       
   195         }
       
   196         break;
       
   197         case ELocationPickerCollectionContent:
       
   198         {
       
   199             setCollectionData(mCategoryId);
       
   200             mCollectionAction->setChecked(true);
       
   201             mAllAction->setChecked(false);
       
   202         }
       
   203         break;
       
   204     }
       
   205 }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // LocationPickerLandscapeView::handleActivated()
       
   209 // -----------------------------------------------------------------------------
       
   210 void LocationPickerLandscapeView::handleActivated(const QModelIndex &aIndex)
       
   211 {   
       
   212     //handle the activated signal according to model set
       
   213     int row= aIndex.row();
       
   214     int col = aIndex.column();
       
   215     switch(mViewType)
       
   216     { 
       
   217         case ELocationPickerContent:
       
   218         {
       
   219             QModelIndex proxyModelIndex = mProxyModel->index(row,col);
       
   220             QModelIndex  index = mProxyModel->mapToSource(
       
   221                     proxyModelIndex);
       
   222             quint32 lm = 0;
       
   223             QStandardItem* item = mStandardModel->item( index.row(), index.column() );
       
   224             QVariant var = item->data( Qt::UserRole );
       
   225             lm = var.toUInt();
       
   226             //item selected, complete request
       
   227             emit selectItem( lm );
       
   228         }
       
   229         break;
       
   230         case ELocationPickerCollectionContent:
       
   231         {
       
   232             if(!mCollectionContent->getProxyModel())
       
   233             {
       
   234                 break;
       
   235             }
       
   236             QModelIndex proxyModelIndex = mCollectionContent->getProxyModel()->index(row,col);
       
   237             QModelIndex   index = mCollectionContent->getProxyModel()->mapToSource(
       
   238                     proxyModelIndex);
       
   239             quint32 lm = 0;
       
   240             mCollectionContent->getData(index, lm);
       
   241             emit selectItem(lm);
       
   242         }
       
   243         break;
       
   244         default:
       
   245             break;
       
   246     }
       
   247 }
       
   248 
       
   249 
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // LocationPickerLandscapeView::sortAscending()
       
   253 // -----------------------------------------------------------------------------
       
   254 void LocationPickerLandscapeView::sortAscending()
       
   255 {   
       
   256     //check the model set and do sorting accordingly
       
   257     if (mViewType == ELocationPickerContent)
       
   258     {
       
   259         mProxyModel->sort(0,Qt::AscendingOrder);
       
   260         mModel->resetModel(mProxyModel);
       
   261     }
       
   262     else
       
   263     {
       
   264         mCollectionContent->getProxyModel()->sort(0,Qt::AscendingOrder);
       
   265         mModel->resetModel(mCollectionContent->getProxyModel());
       
   266     }
       
   267 
       
   268 }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // LocationPickerLandscapeView::sortDescending()
       
   272 // -----------------------------------------------------------------------------
       
   273 void LocationPickerLandscapeView::sortDescending()
       
   274 {   
       
   275     //check the model set and do sorting accordingly
       
   276     if (mViewType == ELocationPickerContent)
       
   277     {
       
   278         mProxyModel->sort(0,Qt::DescendingOrder);
       
   279         mModel->resetModel(mProxyModel);
       
   280     }
       
   281     else
       
   282     {
       
   283         mCollectionContent->getProxyModel()->sort(0,Qt::DescendingOrder);
       
   284         mModel->resetModel(mCollectionContent->getProxyModel());
       
   285     }
       
   286 }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // LocationPickerLandscapeView::handleAllTab()
       
   290 // -----------------------------------------------------------------------------
       
   291 void LocationPickerLandscapeView::allTabTriggered()
       
   292 {
       
   293     //execute only if tab is not pressed
       
   294     if (mAllAction->isChecked())
       
   295     {   
       
   296         if(mEmptyLabel)
       
   297         {
       
   298             mLayout->removeItem(mEmptyLabel);
       
   299             mEmptyLabel->hide();
       
   300             mLayout->insertItem(0,mWidget);
       
   301             mWidget->setVisible(true);
       
   302             delete mEmptyLabel;
       
   303             mEmptyLabel = NULL;
       
   304         }
       
   305         mModel->resetModel(mProxyModel);
       
   306     }
       
   307     mAscendingAction->setEnabled(true);
       
   308     mDescendingAction->setEnabled(true);
       
   309     mCollectionAction->setChecked(false);
       
   310     mViewType = ELocationPickerContent;
       
   311     //delete mCollectionContent if coming back from collectioncontent
       
   312     if (mCollectionContent)
       
   313     {
       
   314         delete mCollectionContent;
       
   315         mCollectionContent = NULL;
       
   316     }
       
   317     else
       
   318     {
       
   319         //Keep the tab pressed
       
   320         mAllAction->setChecked(true);
       
   321     }
       
   322 
       
   323 }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // LocationPickerLandscapeView::handleCollectionTab()
       
   327 // -----------------------------------------------------------------------------
       
   328 void LocationPickerLandscapeView::colectionTabTriggered()
       
   329 {
       
   330     //execute only if tab is not pressed
       
   331     if (mCollectionAction->isChecked())
       
   332     {   
       
   333         mAscendingAction->setDisabled(true);
       
   334         mDescendingAction->setDisabled(true);
       
   335         mViewType = ELocationPickerCollectionListContent;
       
   336     	emit handleCollectionList();
       
   337     }
       
   338     else
       
   339     {
       
   340 	    //Keep the tab pressed
       
   341         mCollectionAction->setChecked(true);
       
   342     }
       
   343 }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // LocationPickerLandscapeView::searchTabTriggered()
       
   347 // -----------------------------------------------------------------------------
       
   348 void LocationPickerLandscapeView::searchTabTriggered()
       
   349 {
       
   350     emit switchToSearchView();
       
   351 }
       
   352 
       
   353 void LocationPickerLandscapeView::setCollectionData( quint32 aCategoryId )
       
   354 {   
       
   355     if(mEmptyLabel)
       
   356     {   
       
   357         mLayout->removeItem(mEmptyLabel);
       
   358         mEmptyLabel->hide();
       
   359         mLayout->insertItem(0,mWidget);
       
   360         mWidget->show();
       
   361         delete mEmptyLabel;
       
   362         mEmptyLabel = NULL;
       
   363     }
       
   364     if(!mCollectionContent)
       
   365     {
       
   366         mCollectionContent = new LocationPickerCollectionContent(Qt::Horizontal , aCategoryId);
       
   367     }
       
   368     if(mCollectionContent->locationFound())
       
   369     {
       
   370         mModel->resetModel(mCollectionContent->getProxyModel());
       
   371         //Enable the options
       
   372         mAscendingAction->setEnabled(true);
       
   373         mDescendingAction->setEnabled(true);
       
   374     }
       
   375     else
       
   376     {
       
   377     if(!mEmptyLabel)
       
   378     {
       
   379         mEmptyLabel =  new HbTextItem(hbTrId("txt_lint_list_no_location_entries_present"));
       
   380     }
       
   381     mEmptyLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
       
   382     mEmptyLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   383     mLayout->removeItem(mWidget);
       
   384     mWidget->setVisible(false);
       
   385     mLayout->insertItem(0, mEmptyLabel);
       
   386     }
       
   387 
       
   388     mViewType = ELocationPickerCollectionContent;
       
   389     
       
   390     mCollectionAction->setChecked(true);
       
   391 }
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // LocationPickerLandscapeView::setCategoryID()
       
   395 // -----------------------------------------------------------------------------
       
   396 void LocationPickerLandscapeView::setCategoryID( quint32 aCategoryId  )
       
   397 {
       
   398     mCategoryId = aCategoryId;
       
   399 }
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // LocationPickerLandscapeView::getViewType()
       
   403 // -----------------------------------------------------------------------------
       
   404 TViewType LocationPickerLandscapeView::getViewType()
       
   405 {
       
   406     return mViewType;
       
   407 }
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // LocationPickerLandscapeView::setViewType()
       
   411 // -----------------------------------------------------------------------------
       
   412 void LocationPickerLandscapeView::setViewType(TViewType aViewType)
       
   413 {
       
   414     mViewType = aViewType;
       
   415 }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // LocationPickerLandscapeView::clearContentModel()
       
   419 // -----------------------------------------------------------------------------
       
   420 void LocationPickerLandscapeView::clearContentModel()
       
   421 {
       
   422    if(mCollectionContent)
       
   423    {
       
   424    delete mCollectionContent;
       
   425    mCollectionContent = NULL;
       
   426    }
       
   427 }
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // LocationPickerLandscapeView::launchPopUpMenu()
       
   431 // -----------------------------------------------------------------------------
       
   432 void LocationPickerLandscapeView::launchPopUpMenu(const QModelIndex &aIndex, const QPointF &aPoint)
       
   433 {
       
   434     mLongPressMenu = new HbMenu();
       
   435     mLongPressMenu->setTimeout(HbMenu::NoTimeout);
       
   436     HbAction* selectAction  = mLongPressMenu->addAction(hbTrId("Select"));
       
   437     mIndex = aIndex;
       
   438     connect(selectAction, SIGNAL(triggered()), this, SLOT(handleLongPress()));
       
   439     mLongPressMenu->setPreferredPos(aPoint);
       
   440     mLongPressMenu->open();
       
   441 }
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 // LocationPickerLandscapeView::handleLongPress()
       
   445 // -----------------------------------------------------------------------------
       
   446 void LocationPickerLandscapeView::handleLongPress()
       
   447 {
       
   448     handleActivated(mIndex);
       
   449 }