locationpickerservice/src/locationpickerappwindow.cpp
changeset 17 0f22fb80ebba
parent 15 13ae750350c9
child 20 cd10d5b85554
--- a/locationpickerservice/src/locationpickerappwindow.cpp	Fri Apr 16 14:54:12 2010 +0300
+++ b/locationpickerservice/src/locationpickerappwindow.cpp	Mon May 03 12:27:22 2010 +0300
@@ -16,87 +16,75 @@
 */
 
 #include "locationpickerappwindow.h"
-#include "locationpickertoolbar.h"
-#include "locationpickerallview.h"
+
+#include "qlocationpickeritem.h"
+
 #include "locationpickersearchview.h"
-#include "locationpickercollectionlistview.h"
+#include "locationpickerpotraitview.h"
 #include "locationpickerservice.h"
-#include "locationpickertypes.h"
-#include "locationpickertypes.h"
 #include "locationpickerdatamanager.h"
- 
+#include "locationpickerdocumentloader.h"
+#include "locationpickerlandscapeview.h"
+
 // ----------------------------------------------------------------------------
 // LocationPickerAppWindow::LocationPickerAppWindow()
 // ----------------------------------------------------------------------------
-LocationPickerAppWindow::LocationPickerAppWindow(
-        QWidget* aParent ):
-        HbMainWindow( aParent )
+LocationPickerAppWindow::LocationPickerAppWindow(QWidget *parent, Hb::WindowFlags windowFlags)
+	:HbMainWindow(parent, windowFlags),
+	mLocationPickerSearchView(NULL),
+    mLocationPickerDocumentLoader(NULL),
+	mLocationPickerPotraitView(NULL),
+	mLocationPickerLandscapeView(NULL),
+    mService(NULL),
+	mviewType(ELocationPickerContent)
 {
     // create the service object;
-    mService = new LocationPickerService( this );
-  
-    LocationPickerToolBar *toolBar = new LocationPickerToolBar( this );
+    mService = new LocationPickerService(this);
+    //create document loader object
+    mLocationPickerDocumentLoader = new LocationPickerDocumentLoader();
+   
+    bool ok = false;
+    //load the Locationpicker portrait view
+    mLocationPickerDocumentLoader->load(":/locationpickerpotrait.docml", &ok);
+    Q_ASSERT_X(ok, "locationpickerservice", "invalid DocML file");
+    //find graphics location picker potrait view
+    QGraphicsWidget *locationPickerWidget = mLocationPickerDocumentLoader->findWidget("LocationPickerPotraitView");
+    Q_ASSERT_X((locationPickerWidget != 0), "locationpickerservice", "invalid DocML file");
+    mLocationPickerPotraitView = qobject_cast<LocationPickerPotraitView*>(locationPickerWidget);
+    //initialize potrait widgets and connect to respective signals 
+    mLocationPickerPotraitView->init(Qt::Vertical);
+    connectPotraitSlots();
+    addView( mLocationPickerPotraitView );
 
-    // Create 'all' view, set the tool bar and add the view to main window
-    mLocationPickerAllView = new LocationPickerAllView( this ); 
-    if( !mLocationPickerAllView->locationsFound() )
-    {
-        toolBar->disableTabs();
-    }
-    mLocationPickerAllView->setToolBar(toolBar);
-    addView(mLocationPickerAllView);
-    setCurrentView(mLocationPickerAllView);
+    mLocationPickerDocumentLoader->reset();
 
-    // Create 'search' view, set the tool bar and add the view to main window
-    mLocationPickerSearchView = new LocationPickerSearchView( this );
-    mLocationPickerSearchView->setToolBar(toolBar);
-    addView(mLocationPickerSearchView);
-
-    // Create 'collection' view, set the tool bar and add the view to main window
-    mLocationPickerCollectionListView = new LocationPickerCollectionListView( this );
-    mLocationPickerCollectionListView->setToolBar(toolBar);
-    addView(mLocationPickerCollectionListView);
-    
+    //load the Locationpicker landscape view
+    mLocationPickerDocumentLoader->load(":/locationpickerlandscape.docml", &ok);
+    Q_ASSERT_X(ok, "locationpickerservice", "invalid DocML file");
+    //find graphics location picker landscape view
+    locationPickerWidget = mLocationPickerDocumentLoader->findWidget("LocationPickerLandscapeView");
+    Q_ASSERT_X((locationPickerWidget != 0), "locationpickerservice", "invalid DocML file");
+    mLocationPickerLandscapeView = qobject_cast<LocationPickerLandscapeView*>(locationPickerWidget);
+    //initialize widgets and connect to respective signals 
+    mLocationPickerLandscapeView->init(Qt::Horizontal);
+    connectLandscapeSlots();
+    addView(mLocationPickerLandscapeView);
+    //connect to orientationChanged signal
+    connect(this, SIGNAL(orientationChanged(Qt::Orientation)),this, SLOT(changeOrientation(Qt::Orientation)));
+    //launch the view in current orientation
+    changeOrientation(this->orientation());
 }
 
-
 // ----------------------------------------------------------------------------
 // LocationPickerAppWindow::~LocationPickerAppWindow()
 // ----------------------------------------------------------------------------
 LocationPickerAppWindow::~LocationPickerAppWindow()
 {
     delete mService;
-}
-
-
-// ----------------------------------------------------------------------------
-// LocationPickerAppWindow::backButtonTriggered()
-// ----------------------------------------------------------------------------
-void LocationPickerAppWindow::backButtonTriggered()
-{
-    if( currentViewIndex() > KNumberOfMainViews-1 )
-    {
-        //the current view is collection content view.
-        //so come back to collection list view
-        setCurrentView(mLocationPickerCollectionListView);
-        deleteCollectionContentView();
-    }
-    else
-    {
-		// Other views request complete with a invalid location picker item
-		QLocationPickerItem item;
-		item.mIsValid = false;
-        mService->complete(item);
-    }
-}
-
-// ----------------------------------------------------------------------------
-// LocationPickerAppWindow::deleteCollectionContentView()
-// ----------------------------------------------------------------------------
-void LocationPickerAppWindow::deleteCollectionContentView()
-{
-	// call collection view's deleteCollectionContentView()
-    mLocationPickerCollectionListView->deleteCollectionContentView();
+    delete mLocationPickerSearchView;
+    delete mLocationPickerDocumentLoader;
+    delete mLocationPickerPotraitView;
+    delete mLocationPickerLandscapeView;
 }
 
 // ----------------------------------------------------------------------------
@@ -105,14 +93,186 @@
 void LocationPickerAppWindow::itemSelected( quint32 aLmid )
 {
     QLocationPickerItem item;
-    
     LocationPickerDataManager dataManager;
-    dataManager.getLocationItem( aLmid, item );
-
+    dataManager.getLocationItem(aLmid, item);
     // complete the request
     mService->complete(item);
-   
+}
+
+void LocationPickerAppWindow::serviceComplete()
+{
+    // Other views request complete with a valid location picker item
+    QLocationPickerItem item;
+    item.mIsValid = false;
+    mService->complete(item);
+}
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::activateSearchView()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::activateSearchView()
+{   
+    //load the LocationPickerSearchView
+    bool ok = false;
+    if(!mLocationPickerSearchView)
+    {
+        mLocationPickerDocumentLoader->load(":/locationpickersearchview.docml", &ok);
+        Q_ASSERT_X(ok, "locationpickerService", "invalid DocML file");
+        //find the LocationPickerSearchView
+        QGraphicsWidget *locationPickerSearchWidget = mLocationPickerDocumentLoader->findWidget("LocationPickerSearchView");
+        Q_ASSERT_X((locationPickerSearchWidget != 0), "locationpickerService", "invalid DocML file");
+        mLocationPickerSearchView = qobject_cast<LocationPickerSearchView*>(locationPickerSearchWidget);
+        Q_ASSERT_X((mLocationPickerSearchView != 0), "mLocationPickerSearchView", 
+            "qobject cast failure");
+        //initialize the action items and connect to slots
+        mLocationPickerSearchView->init();
+        connect(mLocationPickerSearchView,SIGNAL(switchView()),this,SLOT(activateLocationPickerView()));
+        connect(mLocationPickerSearchView,SIGNAL(selectItem( quint32 )),this,SLOT(itemSelected( quint32 )));
+        addView(mLocationPickerSearchView);
+    }
+    //set LocationPickerSearchview as current view
+    setCurrentView(mLocationPickerSearchView);
+    mviewType = ELocationPickerSearchView;
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::activateLocationPickerView()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::activateLocationPickerView()
+{ 
+    mviewType = ELocationPickerContent;
+    //check the orientation and load view accordingly 
+    if(this->orientation() == Qt::Horizontal)
+    {
+        mLocationPickerLandscapeView->setViewType( ELocationPickerContent );
+        mLocationPickerLandscapeView->manageGridView();
+        setCurrentView(mLocationPickerLandscapeView);
+    }
+    else
+    { 
+        mLocationPickerPotraitView->setViewType( ELocationPickerContent );
+        mLocationPickerPotraitView->manageListView();
+        setCurrentView( mLocationPickerPotraitView );
+    }
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::changeOrientation()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::changeOrientation(Qt::Orientation)
+{   
+    //check the orientation and load view accordingly 
+    if( orientation() == (Qt::Horizontal ))
+    {
+        loadLandscape();
+    }
+    else
+    {
+        loadPotrait();
+    }
 }
 
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::loadPotrait()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::loadPotrait()
+{   
+	//load potrait view except for search view
+    if(mviewType != ELocationPickerSearchView)
+	  {
+        if(mLocationPickerLandscapeView->getViewType() == ELocationPickerContent)
+        {
+        mLocationPickerPotraitView->setViewType(ELocationPickerContent);
+        }
+    	mLocationPickerPotraitView->manageListView();
+    	setCurrentView( mLocationPickerPotraitView );
+    }
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::loadLandscape()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::loadLandscape()
+{   
+    if(mviewType != ELocationPickerSearchView)
+	 {
+         //load landscape view in current potrait content
+         mLocationPickerLandscapeView->setViewType( mLocationPickerPotraitView->getViewType() );
+         //load landscape for all content except collectionlistcontent
+    	 if(mLocationPickerPotraitView->getViewType() != ELocationPickerCollectionListContent)
+    	 {
+             mLocationPickerLandscapeView->manageGridView();
+    		 setCurrentView(mLocationPickerLandscapeView);
+		 }
+	 }
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::loadLandscape()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::connectPotraitSlots()
+{
+     connect(mLocationPickerPotraitView,SIGNAL(switchToSearchView()),this,SLOT(activateSearchView()));
+     connect(mLocationPickerPotraitView,SIGNAL(selectItem( quint32 )),this,SLOT(itemSelected( quint32 )));
+     connect(mLocationPickerPotraitView,SIGNAL(completeService()),this,SLOT(serviceComplete()));
+     connect(mLocationPickerPotraitView,SIGNAL(sendCategoryID( quint32 )),this,SLOT(setCategoryID( quint32 )));
+     connect(mLocationPickerPotraitView,SIGNAL(handleAllList()),this,SLOT(allListHandle()));
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::loadLandscape()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::connectLandscapeSlots()
+{   
+    connect(mLocationPickerLandscapeView,SIGNAL(switchToSearchView()),this,SLOT(activateSearchView()));
+    connect(mLocationPickerLandscapeView,SIGNAL(selectItem( quint32 )),this,SLOT(itemSelected( quint32 )));
+    connect(mLocationPickerLandscapeView,SIGNAL(completeService()),this,SLOT(serviceComplete()));
+    connect(mLocationPickerLandscapeView,SIGNAL(sendCategoryID( quint32 )),this,SLOT(setCategoryID( quint32 )));
+    connect(mLocationPickerLandscapeView,SIGNAL(handleCollectionList()),this,SLOT(handleCollectionList()));
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::setCategoryID()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::setCategoryID( quint32 acategoryId )
+{
+    //set the same category id to both views
+    mLocationPickerPotraitView->setCategoryID(acategoryId);
+    mLocationPickerLandscapeView->setCategoryID(acategoryId);
+    //Load the collectioncontent in appropriate orientation
+    if(orientation() == Qt::Vertical)
+    {
+        mviewType = ELocationPickerCollectionContent;
+        mLocationPickerPotraitView->manageListView();
+        setCurrentView( mLocationPickerPotraitView );
+    }
+    else
+    {   
+        mviewType = ELocationPickerCollectionContent;
+        loadLandscape();        
+    }
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::handleCollectionList()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::handleCollectionList()
+{  
+    //In collection List both view should look same(list)
+    mLocationPickerPotraitView->setViewType( ELocationPickerCollectionListContent );
+    mviewType = ELocationPickerCollectionListContent;
+    mLocationPickerPotraitView->manageListView();
+    setCurrentView( mLocationPickerPotraitView );
+}
+
+// ----------------------------------------------------------------------------
+// LocationPickerAppWindow::allListHandle()
+// ----------------------------------------------------------------------------
+void LocationPickerAppWindow::allListHandle()
+{
+    //all list after collection list in horizontal orientation
+    mLocationPickerLandscapeView->setViewType( ELocationPickerContent );
+    mLocationPickerLandscapeView->manageGridView();
+    setCurrentView(mLocationPickerLandscapeView);
+}
 
 Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem)