locationpickerservice/src/locationpickerpotraitview.cpp
changeset 30 96df3ab41000
parent 26 f3533f6eae3f
equal deleted inserted replaced
26:f3533f6eae3f 30:96df3ab41000
    20 #include <HbMainWindow>
    20 #include <HbMainWindow>
    21 #include <qstandarditemmodel.h>
    21 #include <qstandarditemmodel.h>
    22 #include <HbListView>
    22 #include <HbListView>
    23 #include <HbListViewItem>
    23 #include <HbListViewItem>
    24 #include <HbAction>
    24 #include <HbAction>
    25 #include <QTimer>
    25 #include <HbMenu>
    26 #include <HbToolBar>
    26 #include <HbToolBar>
       
    27 #include <QGraphicsLinearLayout>
    27 
    28 
    28 #include "locationpickerproxymodel.h"
    29 #include "locationpickerproxymodel.h"
    29 #include "locationpickerdatamanager.h"
    30 #include "locationpickerdatamanager.h"
    30 #include "locationpickercontent.h" 
    31 #include "locationpickercontent.h" 
    31 #include "locationpickercollectionlistcontent.h"
    32 #include "locationpickercollectionlistcontent.h"
    45     mSearchAction(NULL),
    46     mSearchAction(NULL),
    46     mAscendingAction(NULL),
    47     mAscendingAction(NULL),
    47     mDescendingAction(NULL),
    48     mDescendingAction(NULL),
    48     mListView(NULL),
    49     mListView(NULL),
    49     mCollectionContent(NULL),
    50     mCollectionContent(NULL),
    50     mViewType(ELocationPickerContent)
    51     mViewType(ELocationPickerContent),
       
    52     mLinerLayout(NULL),
       
    53     mColllabel(NULL),
       
    54     mLongPressMenu(NULL)
    51 {   
    55 {   
    52     // create back action
    56     // create back action
    53     mPotraitBackAction = new HbAction(Hb::BackNaviAction);
    57     mPotraitBackAction = new HbAction(Hb::BackNaviAction);
    54     // add back key action
    58     // add back key action
    55     setNavigationAction(mPotraitBackAction);
    59     setNavigationAction(mPotraitBackAction);
    71     delete mAllAction;
    75     delete mAllAction;
    72     delete mCollectionAction;
    76     delete mCollectionAction;
    73     delete mAscendingAction;
    77     delete mAscendingAction;
    74     delete mDescendingAction;
    78     delete mDescendingAction;
    75     delete mListView;
    79     delete mListView;
       
    80     delete mLongPressMenu;
    76 }
    81 }
    77 
    82 
    78 // ----------------------------------------------------------------------------
    83 // ----------------------------------------------------------------------------
    79 // LocationPickerPotraitView::backButtonTriggered()
    84 // LocationPickerPotraitView::backButtonTriggered()
    80 // ----------------------------------------------------------------------------
    85 // ----------------------------------------------------------------------------
    89     else
    94     else
    90     {
    95     {
    91         //complete the service
    96         //complete the service
    92         emit completeService();
    97         emit completeService();
    93     } 
    98     } 
       
    99     if (mLinerLayout && mColllabel)
       
   100        {
       
   101             mColllabel->setPlainText("");
       
   102            mLinerLayout->removeItem(mColllabel);
       
   103            mLinerLayout->updateGeometry();           
       
   104            update();
       
   105        }
    94 }
   106 }
    95 
   107 
    96 
   108 
    97 // ----------------------------------------------------
   109 // ----------------------------------------------------
    98 // LocationPickerPotraitView::init()
   110 // LocationPickerPotraitView::init()
   138             QString("descendingAction")));
   150             QString("descendingAction")));
   139     if( !mAllAction || !mCollectionAction || !mSearchAction || !mAscendingAction || !mDescendingAction || !mListView)
   151     if( !mAllAction || !mCollectionAction || !mSearchAction || !mAscendingAction || !mDescendingAction || !mListView)
   140     {
   152     {
   141         qFatal("Error Reading Docml");
   153         qFatal("Error Reading Docml");
   142     }
   154     }
       
   155 
       
   156     mColllabel =  new HbLabel();
   143       
   157       
   144     //connect to slots
   158     //connect to slots
   145     connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
   159     connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
   146     connect(mDescendingAction, SIGNAL(triggered()), this,
   160     connect(mDescendingAction, SIGNAL(triggered()), this,
   147             SLOT(sortDescending()));
   161             SLOT(sortDescending()));
   150     connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered()));
   164     connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered()));
   151     connect(mSearchAction, SIGNAL(triggered()), this,
   165     connect(mSearchAction, SIGNAL(triggered()), this,
   152             SLOT(searchTabTriggered()));
   166             SLOT(searchTabTriggered()));
   153     // connect the signal of the list activated to a slot.
   167     // connect the signal of the list activated to a slot.
   154     connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
   168     connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
   155 }
   169     connect(mListView,SIGNAL(longPressed(HbAbstractViewItem*, const QPointF &)),this,
   156 
   170             SLOT(launchPopUpMenu(HbAbstractViewItem*, const QPointF &)));
       
   171 }
       
   172 
       
   173 // ----------------------------------------------------
       
   174 // LocationPickerPotraitView::manageListView()
       
   175 // ----------------------------------------------------
   157 void LocationPickerPotraitView::manageListView()
   176 void LocationPickerPotraitView::manageListView()
   158 {   
   177 {   
   159     //set the appropriate model
   178     //set the appropriate model
   160     switch(mViewType)
   179     switch(mViewType)
   161     {
   180     {
   172         {
   191         {
   173             mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
   192             mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
   174             mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
   193             mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
   175             mCollectionAction->setChecked(true);
   194             mCollectionAction->setChecked(true);
   176             mAllAction->setChecked(false);
   195             mAllAction->setChecked(false);
       
   196             if(mAscendingAction->isEnabled())
       
   197             {
       
   198                 mAscendingAction->setDisabled(true);
       
   199                 mDescendingAction->setDisabled(true);
       
   200             }
   177             mViewType = ELocationPickerCollectionListContent;
   201             mViewType = ELocationPickerCollectionListContent;
   178         }
   202         }
   179         break;
   203         break;
   180         case ELocationPickerCollectionContent:
   204         case ELocationPickerCollectionContent:
   181         {
   205         {
   188         default:
   212         default:
   189             break;
   213             break;
   190     }
   214     }
   191 }
   215 }
   192 
   216 
   193 
   217 // -----------------------------------------------------------------------------
       
   218 // LocationPickerPotraitView::disableTabs()
       
   219 // -----------------------------------------------------------------------------
   194 void LocationPickerPotraitView::disableTabs( QStandardItemModel *aModel )
   220 void LocationPickerPotraitView::disableTabs( QStandardItemModel *aModel )
   195 {
   221 {
   196     //if no location entries present
   222     //if no location entries present
   197     mListView->setModel(aModel,mListItem);
   223     mListView->setModel(aModel,mListItem);
   198     mAllAction->setDisabled(true);
   224     mAllAction->setDisabled(true);
   201     mAscendingAction->setDisabled(true);
   227     mAscendingAction->setDisabled(true);
   202     mDescendingAction->setDisabled(true);
   228     mDescendingAction->setDisabled(true);
   203 }
   229 }
   204 
   230 
   205 // -----------------------------------------------------------------------------
   231 // -----------------------------------------------------------------------------
   206 // LocationPickerView::handleActivated()
   232 // LocationPickerPotraitView::handleActivated()
   207 // -----------------------------------------------------------------------------
   233 // -----------------------------------------------------------------------------
   208 void LocationPickerPotraitView::handleActivated(const QModelIndex &aIndex)
   234 void LocationPickerPotraitView::handleActivated(const QModelIndex &aIndex)
   209 {
   235 {
   210     mIndex = aIndex;
       
   211     QTimer::singleShot(0, this, SLOT(changeModel()));
       
   212 }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // LocationPickerPotraitView::changeModel()
       
   216 // -----------------------------------------------------------------------------
       
   217 void LocationPickerPotraitView::changeModel()
       
   218 {   
       
   219     //handle the activated signal according to model set
   236     //handle the activated signal according to model set
   220     switch(mViewType)
   237     switch(mViewType)
   221     {
   238     {
   222         case ELocationPickerContent:
   239         case ELocationPickerContent:
   223         {   
   240         {   
   224             if(!mProxyModel)
   241             if(!mProxyModel)
   225             {
   242             {
   226             break;
   243             break;
   227             }
   244             }
   228             QModelIndex   index = mProxyModel->mapToSource(
   245             QModelIndex   index = mProxyModel->mapToSource(
   229                     mIndex);
   246                     aIndex);
   230             quint32 lm = 0;
   247             quint32 lm = 0;
   231             QStandardItem* item = mModel->item( index.row(), index.column() );
   248             QStandardItem* item = mModel->item( index.row(), index.column() );
   232             QVariant var = item->data( Qt::UserRole );
   249             QVariant var = item->data( Qt::UserRole );
   233             lm = var.toUInt();
   250             lm = var.toUInt();
   234             //item selected, complete request
   251             //item selected, complete request
   236         }
   253         }
   237             break;
   254             break;
   238         case ELocationPickerCollectionListContent:
   255         case ELocationPickerCollectionListContent:
   239         {
   256         {
   240             mLocationPickerCollectionListContent->getData(
   257             mLocationPickerCollectionListContent->getData(
   241                     mIndex, mCategoryId );
   258                     aIndex, mCategoryId );
   242             mViewType = ELocationPickerCollectionContent;
   259             mViewType = ELocationPickerCollectionContent;
   243             //send categoryID to set the collection content
   260             //send categoryID to set the collection content
   244             emit sendCategoryID(mCategoryId);
   261             emit sendCategoryID(mCategoryId);
   245         }
   262         }
   246             break;
   263             break;
   249             if(!mCollectionContent->getProxyModel())
   266             if(!mCollectionContent->getProxyModel())
   250             {
   267             {
   251                 break;
   268                 break;
   252             }
   269             }
   253             QModelIndex  index = mCollectionContent->getProxyModel()->mapToSource(
   270             QModelIndex  index = mCollectionContent->getProxyModel()->mapToSource(
   254                     mIndex);
   271                     aIndex);
   255             quint32 lm = 0;
   272             quint32 lm = 0;
   256             mCollectionContent->getData(index, lm);
   273             mCollectionContent->getData(index, lm);
   257             //item selected, complete request
   274             //item selected, complete request
   258             emit selectItem(lm);
   275             emit selectItem(lm);
   259         }
   276         }
   298 // -----------------------------------------------------------------------------
   315 // -----------------------------------------------------------------------------
   299 // LocationPickerPotraitView::handleAllTab()
   316 // LocationPickerPotraitView::handleAllTab()
   300 // -----------------------------------------------------------------------------
   317 // -----------------------------------------------------------------------------
   301 void LocationPickerPotraitView::allTabTriggered()
   318 void LocationPickerPotraitView::allTabTriggered()
   302 {
   319 {
       
   320     if (mLinerLayout && mColllabel)
       
   321         {
       
   322             mColllabel->setPlainText("");
       
   323             mLinerLayout->removeItem(mColllabel);
       
   324             mLinerLayout->updateGeometry();
       
   325             update();
       
   326         }
   303     //execute only if tab is not pressed
   327     //execute only if tab is not pressed
   304     if (mAllAction->isChecked())
   328     if (mAllAction->isChecked())
   305     {    
   329     {    
   306         mViewType = ELocationPickerContent;
   330         mViewType = ELocationPickerContent;
   307         if(this->mainWindow()->orientation() == Qt::Horizontal)
   331         if(this->mainWindow()->orientation() == Qt::Horizontal)
   335 // -----------------------------------------------------------------------------
   359 // -----------------------------------------------------------------------------
   336 // LocationPickerPotraitView::handleCollectionTab()
   360 // LocationPickerPotraitView::handleCollectionTab()
   337 // -----------------------------------------------------------------------------
   361 // -----------------------------------------------------------------------------
   338 void LocationPickerPotraitView::colectionTabTriggered()
   362 void LocationPickerPotraitView::colectionTabTriggered()
   339 {
   363 {
       
   364     if (mLinerLayout  && (mViewType != ELocationPickerCollectionContent) && mColllabel )
       
   365     {
       
   366         mColllabel->setPlainText("");
       
   367         mLinerLayout->removeItem(mColllabel);
       
   368         mLinerLayout->updateGeometry();
       
   369         update();
       
   370     }
   340     //execute only if tab is not pressed
   371     //execute only if tab is not pressed
   341     if (mCollectionAction->isChecked())
   372     if (mCollectionAction->isChecked())
   342     {   
   373     {   
   343         mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
   374         mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
   344         mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
   375         mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
   365 // -----------------------------------------------------------------------------
   396 // -----------------------------------------------------------------------------
   366 // LocationPickerPotraitView::setCollectionData()
   397 // LocationPickerPotraitView::setCollectionData()
   367 // -----------------------------------------------------------------------------
   398 // -----------------------------------------------------------------------------
   368 void LocationPickerPotraitView::setCollectionData( quint32 acategoryId )
   399 void LocationPickerPotraitView::setCollectionData( quint32 acategoryId )
   369 {
   400 {
       
   401     QString categoryname;
   370     
   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         }
   371     if(!mCollectionContent)
   414     if(!mCollectionContent)
   372     {
   415     {
   373         mCollectionContent
   416         mCollectionContent
   374         = new LocationPickerCollectionContent(Qt::Vertical , acategoryId);
   417         = new LocationPickerCollectionContent(Qt::Vertical , acategoryId);
   375     }
   418     }
   386         mListView->setModel(mCollectionContent->getStandardModel(),mListItem);
   429         mListView->setModel(mCollectionContent->getStandardModel(),mListItem);
   387     }
   430     }
   388     mViewType = ELocationPickerCollectionContent;
   431     mViewType = ELocationPickerCollectionContent;
   389     
   432     
   390     mCollectionAction->setChecked(true);
   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      }
   391 }
   443 }
   392 
   444 
   393 // -----------------------------------------------------------------------------
   445 // -----------------------------------------------------------------------------
   394 // LocationPickerPotraitView::setCategoryID()
   446 // LocationPickerPotraitView::setCategoryID()
   395 // -----------------------------------------------------------------------------
   447 // -----------------------------------------------------------------------------
   425     delete mCollectionContent;
   477     delete mCollectionContent;
   426     mCollectionContent = NULL;
   478     mCollectionContent = NULL;
   427     }
   479     }
   428 }
   480 }
   429 
   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 }