locationpickerservice/src/locationpickerappwindow.cpp
changeset 17 0f22fb80ebba
parent 15 13ae750350c9
child 20 cd10d5b85554
equal deleted inserted replaced
15:13ae750350c9 17:0f22fb80ebba
    14 * Description: LocationPickerAppWindow implementation
    14 * Description: LocationPickerAppWindow implementation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "locationpickerappwindow.h"
    18 #include "locationpickerappwindow.h"
    19 #include "locationpickertoolbar.h"
    19 
    20 #include "locationpickerallview.h"
    20 #include "qlocationpickeritem.h"
       
    21 
    21 #include "locationpickersearchview.h"
    22 #include "locationpickersearchview.h"
    22 #include "locationpickercollectionlistview.h"
    23 #include "locationpickerpotraitview.h"
    23 #include "locationpickerservice.h"
    24 #include "locationpickerservice.h"
    24 #include "locationpickertypes.h"
       
    25 #include "locationpickertypes.h"
       
    26 #include "locationpickerdatamanager.h"
    25 #include "locationpickerdatamanager.h"
    27  
    26 #include "locationpickerdocumentloader.h"
       
    27 #include "locationpickerlandscapeview.h"
       
    28 
    28 // ----------------------------------------------------------------------------
    29 // ----------------------------------------------------------------------------
    29 // LocationPickerAppWindow::LocationPickerAppWindow()
    30 // LocationPickerAppWindow::LocationPickerAppWindow()
    30 // ----------------------------------------------------------------------------
    31 // ----------------------------------------------------------------------------
    31 LocationPickerAppWindow::LocationPickerAppWindow(
    32 LocationPickerAppWindow::LocationPickerAppWindow(QWidget *parent, Hb::WindowFlags windowFlags)
    32         QWidget* aParent ):
    33 	:HbMainWindow(parent, windowFlags),
    33         HbMainWindow( aParent )
    34 	mLocationPickerSearchView(NULL),
       
    35     mLocationPickerDocumentLoader(NULL),
       
    36 	mLocationPickerPotraitView(NULL),
       
    37 	mLocationPickerLandscapeView(NULL),
       
    38     mService(NULL),
       
    39 	mviewType(ELocationPickerContent)
    34 {
    40 {
    35     // create the service object;
    41     // create the service object;
    36     mService = new LocationPickerService( this );
    42     mService = new LocationPickerService(this);
    37   
    43     //create document loader object
    38     LocationPickerToolBar *toolBar = new LocationPickerToolBar( this );
    44     mLocationPickerDocumentLoader = new LocationPickerDocumentLoader();
    39 
    45    
    40     // Create 'all' view, set the tool bar and add the view to main window
    46     bool ok = false;
    41     mLocationPickerAllView = new LocationPickerAllView( this ); 
    47     //load the Locationpicker portrait view
    42     if( !mLocationPickerAllView->locationsFound() )
    48     mLocationPickerDocumentLoader->load(":/locationpickerpotrait.docml", &ok);
    43     {
    49     Q_ASSERT_X(ok, "locationpickerservice", "invalid DocML file");
    44         toolBar->disableTabs();
    50     //find graphics location picker potrait view
    45     }
    51     QGraphicsWidget *locationPickerWidget = mLocationPickerDocumentLoader->findWidget("LocationPickerPotraitView");
    46     mLocationPickerAllView->setToolBar(toolBar);
    52     Q_ASSERT_X((locationPickerWidget != 0), "locationpickerservice", "invalid DocML file");
    47     addView(mLocationPickerAllView);
    53     mLocationPickerPotraitView = qobject_cast<LocationPickerPotraitView*>(locationPickerWidget);
    48     setCurrentView(mLocationPickerAllView);
    54     //initialize potrait widgets and connect to respective signals 
    49 
    55     mLocationPickerPotraitView->init(Qt::Vertical);
    50     // Create 'search' view, set the tool bar and add the view to main window
    56     connectPotraitSlots();
    51     mLocationPickerSearchView = new LocationPickerSearchView( this );
    57     addView( mLocationPickerPotraitView );
    52     mLocationPickerSearchView->setToolBar(toolBar);
    58 
    53     addView(mLocationPickerSearchView);
    59     mLocationPickerDocumentLoader->reset();
    54 
    60 
    55     // Create 'collection' view, set the tool bar and add the view to main window
    61     //load the Locationpicker landscape view
    56     mLocationPickerCollectionListView = new LocationPickerCollectionListView( this );
    62     mLocationPickerDocumentLoader->load(":/locationpickerlandscape.docml", &ok);
    57     mLocationPickerCollectionListView->setToolBar(toolBar);
    63     Q_ASSERT_X(ok, "locationpickerservice", "invalid DocML file");
    58     addView(mLocationPickerCollectionListView);
    64     //find graphics location picker landscape view
    59     
    65     locationPickerWidget = mLocationPickerDocumentLoader->findWidget("LocationPickerLandscapeView");
    60 }
    66     Q_ASSERT_X((locationPickerWidget != 0), "locationpickerservice", "invalid DocML file");
    61 
    67     mLocationPickerLandscapeView = qobject_cast<LocationPickerLandscapeView*>(locationPickerWidget);
       
    68     //initialize widgets and connect to respective signals 
       
    69     mLocationPickerLandscapeView->init(Qt::Horizontal);
       
    70     connectLandscapeSlots();
       
    71     addView(mLocationPickerLandscapeView);
       
    72     //connect to orientationChanged signal
       
    73     connect(this, SIGNAL(orientationChanged(Qt::Orientation)),this, SLOT(changeOrientation(Qt::Orientation)));
       
    74     //launch the view in current orientation
       
    75     changeOrientation(this->orientation());
       
    76 }
    62 
    77 
    63 // ----------------------------------------------------------------------------
    78 // ----------------------------------------------------------------------------
    64 // LocationPickerAppWindow::~LocationPickerAppWindow()
    79 // LocationPickerAppWindow::~LocationPickerAppWindow()
    65 // ----------------------------------------------------------------------------
    80 // ----------------------------------------------------------------------------
    66 LocationPickerAppWindow::~LocationPickerAppWindow()
    81 LocationPickerAppWindow::~LocationPickerAppWindow()
    67 {
    82 {
    68     delete mService;
    83     delete mService;
    69 }
    84     delete mLocationPickerSearchView;
    70 
    85     delete mLocationPickerDocumentLoader;
    71 
    86     delete mLocationPickerPotraitView;
    72 // ----------------------------------------------------------------------------
    87     delete mLocationPickerLandscapeView;
    73 // LocationPickerAppWindow::backButtonTriggered()
       
    74 // ----------------------------------------------------------------------------
       
    75 void LocationPickerAppWindow::backButtonTriggered()
       
    76 {
       
    77     if( currentViewIndex() > KNumberOfMainViews-1 )
       
    78     {
       
    79         //the current view is collection content view.
       
    80         //so come back to collection list view
       
    81         setCurrentView(mLocationPickerCollectionListView);
       
    82         deleteCollectionContentView();
       
    83     }
       
    84     else
       
    85     {
       
    86 		// Other views request complete with a invalid location picker item
       
    87 		QLocationPickerItem item;
       
    88 		item.mIsValid = false;
       
    89         mService->complete(item);
       
    90     }
       
    91 }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // LocationPickerAppWindow::deleteCollectionContentView()
       
    95 // ----------------------------------------------------------------------------
       
    96 void LocationPickerAppWindow::deleteCollectionContentView()
       
    97 {
       
    98 	// call collection view's deleteCollectionContentView()
       
    99     mLocationPickerCollectionListView->deleteCollectionContentView();
       
   100 }
    88 }
   101 
    89 
   102 // ----------------------------------------------------------------------------
    90 // ----------------------------------------------------------------------------
   103 // LocationPickerAppWindow::itemSelected()
    91 // LocationPickerAppWindow::itemSelected()
   104 // ----------------------------------------------------------------------------
    92 // ----------------------------------------------------------------------------
   105 void LocationPickerAppWindow::itemSelected( quint32 aLmid )
    93 void LocationPickerAppWindow::itemSelected( quint32 aLmid )
   106 {
    94 {
   107     QLocationPickerItem item;
    95     QLocationPickerItem item;
   108     
       
   109     LocationPickerDataManager dataManager;
    96     LocationPickerDataManager dataManager;
   110     dataManager.getLocationItem( aLmid, item );
    97     dataManager.getLocationItem(aLmid, item);
   111 
       
   112     // complete the request
    98     // complete the request
   113     mService->complete(item);
    99     mService->complete(item);
   114    
   100 }
   115 }
   101 
   116 
   102 void LocationPickerAppWindow::serviceComplete()
       
   103 {
       
   104     // Other views request complete with a valid location picker item
       
   105     QLocationPickerItem item;
       
   106     item.mIsValid = false;
       
   107     mService->complete(item);
       
   108 }
       
   109 // ----------------------------------------------------------------------------
       
   110 // LocationPickerAppWindow::activateSearchView()
       
   111 // ----------------------------------------------------------------------------
       
   112 void LocationPickerAppWindow::activateSearchView()
       
   113 {   
       
   114     //load the LocationPickerSearchView
       
   115     bool ok = false;
       
   116     if(!mLocationPickerSearchView)
       
   117     {
       
   118         mLocationPickerDocumentLoader->load(":/locationpickersearchview.docml", &ok);
       
   119         Q_ASSERT_X(ok, "locationpickerService", "invalid DocML file");
       
   120         //find the LocationPickerSearchView
       
   121         QGraphicsWidget *locationPickerSearchWidget = mLocationPickerDocumentLoader->findWidget("LocationPickerSearchView");
       
   122         Q_ASSERT_X((locationPickerSearchWidget != 0), "locationpickerService", "invalid DocML file");
       
   123         mLocationPickerSearchView = qobject_cast<LocationPickerSearchView*>(locationPickerSearchWidget);
       
   124         Q_ASSERT_X((mLocationPickerSearchView != 0), "mLocationPickerSearchView", 
       
   125             "qobject cast failure");
       
   126         //initialize the action items and connect to slots
       
   127         mLocationPickerSearchView->init();
       
   128         connect(mLocationPickerSearchView,SIGNAL(switchView()),this,SLOT(activateLocationPickerView()));
       
   129         connect(mLocationPickerSearchView,SIGNAL(selectItem( quint32 )),this,SLOT(itemSelected( quint32 )));
       
   130         addView(mLocationPickerSearchView);
       
   131     }
       
   132     //set LocationPickerSearchview as current view
       
   133     setCurrentView(mLocationPickerSearchView);
       
   134     mviewType = ELocationPickerSearchView;
       
   135 }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // LocationPickerAppWindow::activateLocationPickerView()
       
   139 // ----------------------------------------------------------------------------
       
   140 void LocationPickerAppWindow::activateLocationPickerView()
       
   141 { 
       
   142     mviewType = ELocationPickerContent;
       
   143     //check the orientation and load view accordingly 
       
   144     if(this->orientation() == Qt::Horizontal)
       
   145     {
       
   146         mLocationPickerLandscapeView->setViewType( ELocationPickerContent );
       
   147         mLocationPickerLandscapeView->manageGridView();
       
   148         setCurrentView(mLocationPickerLandscapeView);
       
   149     }
       
   150     else
       
   151     { 
       
   152         mLocationPickerPotraitView->setViewType( ELocationPickerContent );
       
   153         mLocationPickerPotraitView->manageListView();
       
   154         setCurrentView( mLocationPickerPotraitView );
       
   155     }
       
   156 }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // LocationPickerAppWindow::changeOrientation()
       
   160 // ----------------------------------------------------------------------------
       
   161 void LocationPickerAppWindow::changeOrientation(Qt::Orientation)
       
   162 {   
       
   163     //check the orientation and load view accordingly 
       
   164     if( orientation() == (Qt::Horizontal ))
       
   165     {
       
   166         loadLandscape();
       
   167     }
       
   168     else
       
   169     {
       
   170         loadPotrait();
       
   171     }
       
   172 }
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // LocationPickerAppWindow::loadPotrait()
       
   176 // ----------------------------------------------------------------------------
       
   177 void LocationPickerAppWindow::loadPotrait()
       
   178 {   
       
   179 	//load potrait view except for search view
       
   180     if(mviewType != ELocationPickerSearchView)
       
   181 	  {
       
   182         if(mLocationPickerLandscapeView->getViewType() == ELocationPickerContent)
       
   183         {
       
   184         mLocationPickerPotraitView->setViewType(ELocationPickerContent);
       
   185         }
       
   186     	mLocationPickerPotraitView->manageListView();
       
   187     	setCurrentView( mLocationPickerPotraitView );
       
   188     }
       
   189 }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // LocationPickerAppWindow::loadLandscape()
       
   193 // ----------------------------------------------------------------------------
       
   194 void LocationPickerAppWindow::loadLandscape()
       
   195 {   
       
   196     if(mviewType != ELocationPickerSearchView)
       
   197 	 {
       
   198          //load landscape view in current potrait content
       
   199          mLocationPickerLandscapeView->setViewType( mLocationPickerPotraitView->getViewType() );
       
   200          //load landscape for all content except collectionlistcontent
       
   201     	 if(mLocationPickerPotraitView->getViewType() != ELocationPickerCollectionListContent)
       
   202     	 {
       
   203              mLocationPickerLandscapeView->manageGridView();
       
   204     		 setCurrentView(mLocationPickerLandscapeView);
       
   205 		 }
       
   206 	 }
       
   207 }
       
   208 
       
   209 // ----------------------------------------------------------------------------
       
   210 // LocationPickerAppWindow::loadLandscape()
       
   211 // ----------------------------------------------------------------------------
       
   212 void LocationPickerAppWindow::connectPotraitSlots()
       
   213 {
       
   214      connect(mLocationPickerPotraitView,SIGNAL(switchToSearchView()),this,SLOT(activateSearchView()));
       
   215      connect(mLocationPickerPotraitView,SIGNAL(selectItem( quint32 )),this,SLOT(itemSelected( quint32 )));
       
   216      connect(mLocationPickerPotraitView,SIGNAL(completeService()),this,SLOT(serviceComplete()));
       
   217      connect(mLocationPickerPotraitView,SIGNAL(sendCategoryID( quint32 )),this,SLOT(setCategoryID( quint32 )));
       
   218      connect(mLocationPickerPotraitView,SIGNAL(handleAllList()),this,SLOT(allListHandle()));
       
   219 }
       
   220 
       
   221 // ----------------------------------------------------------------------------
       
   222 // LocationPickerAppWindow::loadLandscape()
       
   223 // ----------------------------------------------------------------------------
       
   224 void LocationPickerAppWindow::connectLandscapeSlots()
       
   225 {   
       
   226     connect(mLocationPickerLandscapeView,SIGNAL(switchToSearchView()),this,SLOT(activateSearchView()));
       
   227     connect(mLocationPickerLandscapeView,SIGNAL(selectItem( quint32 )),this,SLOT(itemSelected( quint32 )));
       
   228     connect(mLocationPickerLandscapeView,SIGNAL(completeService()),this,SLOT(serviceComplete()));
       
   229     connect(mLocationPickerLandscapeView,SIGNAL(sendCategoryID( quint32 )),this,SLOT(setCategoryID( quint32 )));
       
   230     connect(mLocationPickerLandscapeView,SIGNAL(handleCollectionList()),this,SLOT(handleCollectionList()));
       
   231 }
       
   232 
       
   233 // ----------------------------------------------------------------------------
       
   234 // LocationPickerAppWindow::setCategoryID()
       
   235 // ----------------------------------------------------------------------------
       
   236 void LocationPickerAppWindow::setCategoryID( quint32 acategoryId )
       
   237 {
       
   238     //set the same category id to both views
       
   239     mLocationPickerPotraitView->setCategoryID(acategoryId);
       
   240     mLocationPickerLandscapeView->setCategoryID(acategoryId);
       
   241     //Load the collectioncontent in appropriate orientation
       
   242     if(orientation() == Qt::Vertical)
       
   243     {
       
   244         mviewType = ELocationPickerCollectionContent;
       
   245         mLocationPickerPotraitView->manageListView();
       
   246         setCurrentView( mLocationPickerPotraitView );
       
   247     }
       
   248     else
       
   249     {   
       
   250         mviewType = ELocationPickerCollectionContent;
       
   251         loadLandscape();        
       
   252     }
       
   253 }
       
   254 
       
   255 // ----------------------------------------------------------------------------
       
   256 // LocationPickerAppWindow::handleCollectionList()
       
   257 // ----------------------------------------------------------------------------
       
   258 void LocationPickerAppWindow::handleCollectionList()
       
   259 {  
       
   260     //In collection List both view should look same(list)
       
   261     mLocationPickerPotraitView->setViewType( ELocationPickerCollectionListContent );
       
   262     mviewType = ELocationPickerCollectionListContent;
       
   263     mLocationPickerPotraitView->manageListView();
       
   264     setCurrentView( mLocationPickerPotraitView );
       
   265 }
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // LocationPickerAppWindow::allListHandle()
       
   269 // ----------------------------------------------------------------------------
       
   270 void LocationPickerAppWindow::allListHandle()
       
   271 {
       
   272     //all list after collection list in horizontal orientation
       
   273     mLocationPickerLandscapeView->setViewType( ELocationPickerContent );
       
   274     mLocationPickerLandscapeView->manageGridView();
       
   275     setCurrentView(mLocationPickerLandscapeView);
       
   276 }
   117 
   277 
   118 Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem)
   278 Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem)