locationpickerservice/src/locationpickerpotraitview.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: LocationPickerView implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "locationpickerpotraitview.h"
       
    19 
       
    20 #include <HbMainWindow>
       
    21 #include <qstandarditemmodel.h>
       
    22 #include <HbListView>
       
    23 #include <HbListViewItem>
       
    24 #include <HbAction>
       
    25 #include <HbMenu>
       
    26 #include <HbToolBar>
       
    27 #include <QGraphicsLinearLayout>
       
    28 
       
    29 #include "locationpickerproxymodel.h"
       
    30 #include "locationpickerdatamanager.h"
       
    31 #include "locationpickercontent.h" 
       
    32 #include "locationpickercollectionlistcontent.h"
       
    33 #include "locationpickercollectioncontent.h"
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // ----------------------------------------------------
       
    38 // LocationPickerPotraitView::LocationPickerView()
       
    39 // ----------------------------------------------------
       
    40 LocationPickerPotraitView::LocationPickerPotraitView( HbDocumentLoader* aLoader )
       
    41     :mDocumentLoader(aLoader),
       
    42     mLocationPickerCollectionListContent(NULL),
       
    43     mProxyModel(NULL),
       
    44     mAllAction(NULL),
       
    45     mCollectionAction(NULL),
       
    46     mSearchAction(NULL),
       
    47     mAscendingAction(NULL),
       
    48     mDescendingAction(NULL),
       
    49     mListView(NULL),
       
    50     mCollectionContent(NULL),
       
    51     mViewType(ELocationPickerContent),
       
    52     mLinerLayout(NULL),
       
    53     mColllabel(NULL),
       
    54     mLongPressMenu(NULL)
       
    55 {   
       
    56     // create back action
       
    57     mPotraitBackAction = new HbAction(Hb::BackNaviAction);
       
    58     // add back key action
       
    59     setNavigationAction(mPotraitBackAction);
       
    60     //connect to slots
       
    61      connect(mPotraitBackAction, SIGNAL(triggered()), this,
       
    62             SLOT(backTriggered()));     
       
    63     //create list item  
       
    64     mListItem = new HbListViewItem();
       
    65     //set the graphics size
       
    66     mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
    67 }
       
    68 // ----------------------------------------------------
       
    69 // LocationPickerPotraitView::~LocationPickerView()
       
    70 // ----------------------------------------------------
       
    71 LocationPickerPotraitView::~LocationPickerPotraitView()
       
    72 {
       
    73     delete mCollectionContent;
       
    74     delete mLocationPickerCollectionListContent;
       
    75     delete mAllAction;
       
    76     delete mCollectionAction;
       
    77     delete mAscendingAction;
       
    78     delete mDescendingAction;
       
    79     delete mListView;
       
    80     delete mLongPressMenu;
       
    81 }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // LocationPickerPotraitView::backButtonTriggered()
       
    85 // ----------------------------------------------------------------------------
       
    86 void LocationPickerPotraitView::backTriggered()
       
    87 {
       
    88     //if current model is collection content, go back to collectionlist content  
       
    89     if(mViewType == ELocationPickerCollectionContent)
       
    90     {
       
    91         colectionTabTriggered();
       
    92         emit collectionContentExited(); 
       
    93     }
       
    94     else
       
    95     {
       
    96         //complete the service
       
    97         emit completeService();
       
    98     } 
       
    99     if (mLinerLayout && mColllabel)
       
   100        {
       
   101             mColllabel->setPlainText("");
       
   102            mLinerLayout->removeItem(mColllabel);
       
   103            mLinerLayout->updateGeometry();           
       
   104            update();
       
   105        }
       
   106 }
       
   107 
       
   108 
       
   109 // ----------------------------------------------------
       
   110 // LocationPickerPotraitView::init()
       
   111 // ----------------------------------------------------
       
   112 void LocationPickerPotraitView::init( bool aPopulated, Qt::Orientation aOrientation, QStandardItemModel *aModel )
       
   113 {   
       
   114     mModel = aModel;
       
   115     if(aPopulated)
       
   116     {
       
   117     // Create Collection List Content
       
   118     mLocationPickerCollectionListContent = new LocationPickerCollectionListContent(aOrientation);
       
   119     //create proxy model
       
   120     mProxyModel = new LocationPickerProxyModel( aOrientation , this  );
       
   121     mProxyModel->setSourceModel(aModel);
       
   122     // set sort properties
       
   123     mProxyModel->setDynamicSortFilter(TRUE);
       
   124     mProxyModel->setSortRole(Qt::DisplayRole);
       
   125     mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
       
   126     // sort in ascending order
       
   127     mProxyModel->sort(0, Qt::AscendingOrder); 
       
   128     }
       
   129     //Get HbAction items
       
   130     mListView = qobject_cast<HbListView*> (mDocumentLoader->findObject(QString(
       
   131                    "ListView")));
       
   132     HbToolBar* toolbar = new HbToolBar();
       
   133     //Create Action Items
       
   134     mAllAction = new HbAction();
       
   135     mAllAction->setIcon(QString("qtg_mono_location"));
       
   136     mAllAction->setCheckable(true);
       
   137     mCollectionAction =new HbAction();
       
   138     mCollectionAction->setIcon(QString("qtg_mono_location_collection"));
       
   139     mCollectionAction->setCheckable(true);
       
   140     mSearchAction = new HbAction();
       
   141     mSearchAction->setIcon(QString("qtg_mono_search"));
       
   142     
       
   143     toolbar->addAction(mAllAction);
       
   144     toolbar->addAction(mCollectionAction);
       
   145     toolbar->addAction(mSearchAction);
       
   146     this->setToolBar(toolbar);
       
   147     mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   148             QString("ascendingAction")));
       
   149     mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   150             QString("descendingAction")));
       
   151     if( !mAllAction || !mCollectionAction || !mSearchAction || !mAscendingAction || !mDescendingAction || !mListView)
       
   152     {
       
   153         qFatal("Error Reading Docml");
       
   154     }
       
   155 
       
   156     mColllabel =  new HbLabel();
       
   157       
       
   158     //connect to slots
       
   159     connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
       
   160     connect(mDescendingAction, SIGNAL(triggered()), this,
       
   161             SLOT(sortDescending()));
       
   162     //connect all action Items to respective slots
       
   163     connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered()));
       
   164     connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered()));
       
   165     connect(mSearchAction, SIGNAL(triggered()), this,
       
   166             SLOT(searchTabTriggered()));
       
   167     // connect the signal of the list activated to a slot.
       
   168     connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
       
   169     connect(mListView,SIGNAL(longPressed(HbAbstractViewItem*, const QPointF &)),this,
       
   170             SLOT(launchPopUpMenu(HbAbstractViewItem*, const QPointF &)));
       
   171 }
       
   172 
       
   173 // ----------------------------------------------------
       
   174 // LocationPickerPotraitView::manageListView()
       
   175 // ----------------------------------------------------
       
   176 void LocationPickerPotraitView::manageListView()
       
   177 {   
       
   178     //set the appropriate model
       
   179     switch(mViewType)
       
   180     {
       
   181         case ELocationPickerContent:
       
   182         {   
       
   183             mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   184             mListView->setModel(mProxyModel,mListItem);
       
   185             mAllAction->setChecked(true);
       
   186             mCollectionAction->setChecked(false);
       
   187             mViewType = ELocationPickerContent;
       
   188         }
       
   189         break;
       
   190         case ELocationPickerCollectionListContent:
       
   191         {
       
   192             mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
       
   193             mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
       
   194             mCollectionAction->setChecked(true);
       
   195             mAllAction->setChecked(false);
       
   196             if(mAscendingAction->isEnabled())
       
   197             {
       
   198                 mAscendingAction->setDisabled(true);
       
   199                 mDescendingAction->setDisabled(true);
       
   200             }
       
   201             mViewType = ELocationPickerCollectionListContent;
       
   202         }
       
   203         break;
       
   204         case ELocationPickerCollectionContent:
       
   205         {
       
   206             setCollectionData(mCategoryId);
       
   207             mCollectionAction->setChecked(true);
       
   208             mAllAction->setChecked(false);
       
   209             mViewType = ELocationPickerCollectionContent;
       
   210         }
       
   211         break;
       
   212         default:
       
   213             break;
       
   214     }
       
   215 }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // LocationPickerPotraitView::disableTabs()
       
   219 // -----------------------------------------------------------------------------
       
   220 void LocationPickerPotraitView::disableTabs( QStandardItemModel *aModel )
       
   221 {
       
   222     //if no location entries present
       
   223     mListView->setModel(aModel,mListItem);
       
   224     mAllAction->setDisabled(true);
       
   225     mCollectionAction->setDisabled(true);
       
   226     mSearchAction->setDisabled(true);
       
   227     mAscendingAction->setDisabled(true);
       
   228     mDescendingAction->setDisabled(true);
       
   229 }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // LocationPickerPotraitView::handleActivated()
       
   233 // -----------------------------------------------------------------------------
       
   234 void LocationPickerPotraitView::handleActivated(const QModelIndex &aIndex)
       
   235 {
       
   236     //handle the activated signal according to model set
       
   237     switch(mViewType)
       
   238     {
       
   239         case ELocationPickerContent:
       
   240         {   
       
   241             if(!mProxyModel)
       
   242             {
       
   243             break;
       
   244             }
       
   245             QModelIndex   index = mProxyModel->mapToSource(
       
   246                     aIndex);
       
   247             quint32 lm = 0;
       
   248             QStandardItem* item = mModel->item( index.row(), index.column() );
       
   249             QVariant var = item->data( Qt::UserRole );
       
   250             lm = var.toUInt();
       
   251             //item selected, complete request
       
   252             emit selectItem( lm );
       
   253         }
       
   254             break;
       
   255         case ELocationPickerCollectionListContent:
       
   256         {
       
   257             mLocationPickerCollectionListContent->getData(
       
   258                     aIndex, mCategoryId );
       
   259             mViewType = ELocationPickerCollectionContent;
       
   260             //send categoryID to set the collection content
       
   261             emit sendCategoryID(mCategoryId);
       
   262         }
       
   263             break;
       
   264         case ELocationPickerCollectionContent:
       
   265         {
       
   266             if(!mCollectionContent->getProxyModel())
       
   267             {
       
   268                 break;
       
   269             }
       
   270             QModelIndex  index = mCollectionContent->getProxyModel()->mapToSource(
       
   271                     aIndex);
       
   272             quint32 lm = 0;
       
   273             mCollectionContent->getData(index, lm);
       
   274             //item selected, complete request
       
   275             emit selectItem(lm);
       
   276         }
       
   277             break;
       
   278         default:
       
   279             break;
       
   280     }
       
   281 }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // LocationPickerPotraitView::sortAscending()
       
   285 // -----------------------------------------------------------------------------
       
   286 void LocationPickerPotraitView::sortAscending()
       
   287 {   
       
   288     //check the model set and do sorting accordingly
       
   289     if (mViewType == ELocationPickerContent)
       
   290     {
       
   291         mProxyModel->sort(0, Qt::AscendingOrder);
       
   292     }
       
   293     else
       
   294     {
       
   295         mCollectionContent->getProxyModel()->sort(0, Qt::AscendingOrder);
       
   296     }
       
   297 }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // LocationPickerPotraitView::sortDescending()
       
   301 // -----------------------------------------------------------------------------
       
   302 void LocationPickerPotraitView::sortDescending()
       
   303 {
       
   304     //check the model set and do sorting accordingly
       
   305     if (mViewType == ELocationPickerContent)
       
   306     {
       
   307         mProxyModel->sort(0, Qt::DescendingOrder);
       
   308     }
       
   309     else
       
   310     {
       
   311         mCollectionContent->getProxyModel()->sort(0, Qt::DescendingOrder);
       
   312     }
       
   313 }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // LocationPickerPotraitView::handleAllTab()
       
   317 // -----------------------------------------------------------------------------
       
   318 void LocationPickerPotraitView::allTabTriggered()
       
   319 {
       
   320     if (mLinerLayout && mColllabel)
       
   321         {
       
   322             mColllabel->setPlainText("");
       
   323             mLinerLayout->removeItem(mColllabel);
       
   324             mLinerLayout->updateGeometry();
       
   325             update();
       
   326         }
       
   327     //execute only if tab is not pressed
       
   328     if (mAllAction->isChecked())
       
   329     {    
       
   330         mViewType = ELocationPickerContent;
       
   331         if(this->mainWindow()->orientation() == Qt::Horizontal)
       
   332         {
       
   333             //if in landscape send signal to launch grid view
       
   334             emit handleAllList();
       
   335         }
       
   336         else
       
   337         {
       
   338             mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   339             mListView->setModel(mProxyModel,mListItem);
       
   340             mCollectionAction->setChecked(false);
       
   341         }
       
   342         mAscendingAction->setEnabled(true);
       
   343         mDescendingAction->setEnabled(true);
       
   344         //delete mCollectionContent if coming back from collectioncontent
       
   345         if (mCollectionContent)
       
   346         {
       
   347             delete mCollectionContent;
       
   348             mCollectionContent = NULL;
       
   349         }
       
   350     }
       
   351     else
       
   352     {
       
   353         //Keep the tab pressed
       
   354         mAllAction->setChecked(true);
       
   355     }
       
   356     
       
   357 }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // LocationPickerPotraitView::handleCollectionTab()
       
   361 // -----------------------------------------------------------------------------
       
   362 void LocationPickerPotraitView::colectionTabTriggered()
       
   363 {
       
   364     if (mLinerLayout  && (mViewType != ELocationPickerCollectionContent) && mColllabel )
       
   365     {
       
   366         mColllabel->setPlainText("");
       
   367         mLinerLayout->removeItem(mColllabel);
       
   368         mLinerLayout->updateGeometry();
       
   369         update();
       
   370     }
       
   371     //execute only if tab is not pressed
       
   372     if (mCollectionAction->isChecked())
       
   373     {   
       
   374         mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
       
   375         mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
       
   376         mAscendingAction->setDisabled(true);
       
   377         mDescendingAction->setDisabled(true);
       
   378         mAllAction->setChecked(false);
       
   379         mViewType = ELocationPickerCollectionListContent;
       
   380     }
       
   381     else
       
   382     {
       
   383         //Keep the tab pressed
       
   384         mCollectionAction->setChecked(true);
       
   385     }
       
   386 }
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // LocationPickerPotraitView::searchTabTriggered()
       
   390 // -----------------------------------------------------------------------------
       
   391 void LocationPickerPotraitView::searchTabTriggered()
       
   392 {
       
   393     emit switchToSearchView();
       
   394 }
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // LocationPickerPotraitView::setCollectionData()
       
   398 // -----------------------------------------------------------------------------
       
   399 void LocationPickerPotraitView::setCollectionData( quint32 acategoryId )
       
   400 {
       
   401     QString categoryname;
       
   402     
       
   403     switch(acategoryId)
       
   404         {
       
   405         
       
   406         case 1: categoryname = "Landmarks";
       
   407                 break;
       
   408         case 8: categoryname = "Contacts";     
       
   409                 break;
       
   410         case 9: categoryname = "Calender";
       
   411                break;
       
   412 			   
       
   413         }
       
   414     if(!mCollectionContent)
       
   415     {
       
   416         mCollectionContent
       
   417         = new LocationPickerCollectionContent(Qt::Vertical , acategoryId);
       
   418     }
       
   419     mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   420     if(mCollectionContent->locationFound())
       
   421     {
       
   422         mListView->setModel(mCollectionContent->getProxyModel(),mListItem);
       
   423         //Enable the options
       
   424         mAscendingAction->setEnabled(true);
       
   425         mDescendingAction->setEnabled(true);
       
   426     }
       
   427     else
       
   428     {
       
   429         mListView->setModel(mCollectionContent->getStandardModel(),mListItem);
       
   430     }
       
   431     mViewType = ELocationPickerCollectionContent;
       
   432     
       
   433     mCollectionAction->setChecked(true);
       
   434     mLinerLayout = static_cast<QGraphicsLinearLayout*>(widget()->layout());
       
   435 
       
   436     if(mColllabel)
       
   437     {
       
   438         mLinerLayout->insertItem(0,mColllabel);
       
   439         mColllabel->setPlainText(categoryname);   
       
   440         mLinerLayout->updateGeometry();
       
   441         update();
       
   442      }
       
   443 }
       
   444 
       
   445 // -----------------------------------------------------------------------------
       
   446 // LocationPickerPotraitView::setCategoryID()
       
   447 // -----------------------------------------------------------------------------
       
   448 void LocationPickerPotraitView::setCategoryID( quint32 aCategoryId  )
       
   449 {
       
   450     mCategoryId = aCategoryId;
       
   451 }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // LocationPickerPotraitView::getViewType()
       
   455 // -----------------------------------------------------------------------------
       
   456 TViewType LocationPickerPotraitView::getViewType()
       
   457 {
       
   458     return mViewType;
       
   459 }
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // LocationPickerPotraitView::setViewType()
       
   463 // -----------------------------------------------------------------------------
       
   464 void LocationPickerPotraitView::setViewType(TViewType aViewType)
       
   465 {
       
   466     mViewType = aViewType;
       
   467 }
       
   468 
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // LocationPickerPotraitView::clearContentModel()
       
   472 // -----------------------------------------------------------------------------
       
   473 void LocationPickerPotraitView::clearContentModel()
       
   474 {
       
   475     if(mCollectionContent)
       
   476     {
       
   477     delete mCollectionContent;
       
   478     mCollectionContent = NULL;
       
   479     }
       
   480 }
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // LocationPickerPotraitView::launchPopUpMenu()
       
   484 // -----------------------------------------------------------------------------
       
   485 void LocationPickerPotraitView::launchPopUpMenu(HbAbstractViewItem *aItem, const QPointF &aPoint)
       
   486 {
       
   487     mLongPressMenu = new HbMenu();
       
   488     mLongPressMenu->setTimeout(HbMenu::NoTimeout);
       
   489     HbAction* selectAction  = mLongPressMenu->addAction(hbTrId("Select"));
       
   490     mIndex = aItem->modelIndex();
       
   491     connect(selectAction, SIGNAL(triggered()), this, SLOT(handleLongPress()));
       
   492     mLongPressMenu->setPreferredPos(aPoint);
       
   493     mLongPressMenu->open();
       
   494 }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // LocationPickerPotraitView::handleLongPress()
       
   498 // -----------------------------------------------------------------------------
       
   499 void LocationPickerPotraitView::handleLongPress()
       
   500 {
       
   501     handleActivated(mIndex);
       
   502 }