logsui/logsapp/src/logsbaseview.cpp
changeset 11 64a47b97e1e1
parent 10 b04270301d3b
child 14 f27aebe284bb
--- a/logsui/logsapp/src/logsbaseview.cpp	Wed Jun 23 18:13:05 2010 +0300
+++ b/logsui/logsapp/src/logsbaseview.cpp	Tue Jul 06 14:16:36 2010 +0300
@@ -43,7 +43,8 @@
 #include <QGraphicsLinearLayout>
 #include <hbpushbutton.h>
 #include <hbactivitymanager.h>
-
+#include <hbmodeliterator.h>
+#include <hbscrollbar.h>
 
 Q_DECLARE_METATYPE(LogsCall*)
 Q_DECLARE_METATYPE(LogsMessage*)
@@ -70,7 +71,8 @@
       mMessage(0),
       mContact(0),
       mDetailsModel(0),
-      mCallTypeMapper(0)
+      mCallTypeMapper(0),
+      mOptionsMenu(0)
 {
     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::LogsBaseView()" );
 
@@ -96,6 +98,7 @@
     delete mContact;
     delete mDetailsModel;    
     delete mCallTypeMapper;
+    delete mOptionsMenu;
 
     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::~LogsBaseView()" );
 }
@@ -278,8 +281,6 @@
     mInitialized = true;
     initFilterMenu();
     addActionNamesToMap();
-    connect(menu(), SIGNAL(aboutToShow()), this, 
-            SLOT(closeEmptyMenu()), Qt::QueuedConnection);
 }
 
 // -----------------------------------------------------------------------------
@@ -336,7 +337,7 @@
         listView()->scrollTo( topIndex );
         listView()->setCurrentIndex( topIndex, QItemSelectionModel::Select );
         initiateCallback(topIndex); 
-    }  
+    }
     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::callKeyPressed()" );
 }
 
@@ -366,32 +367,17 @@
 }
 
 // -----------------------------------------------------------------------------
-// LogsBaseView::closeEmptyMenu()
-// -----------------------------------------------------------------------------
-//
-void LogsBaseView::closeEmptyMenu()
-{
-    bool visibleActionsExist = false;
-    foreach (QAction* action, menu()->actions()) {
-        if  (action->isVisible()) {
-            visibleActionsExist = true ;
-        }
-    }
-    
-    if (!visibleActionsExist) {
-        menu()->close();
-    }
-}
-// -----------------------------------------------------------------------------
 //
 // -----------------------------------------------------------------------------
 //
 void LogsBaseView::openDialpad()
 {
     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openDialpad()" );
+   
     updateCallButton();
     setDialpadPosition();
     mDialpad->openDialpad();
+    
     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openDialpad()" );
 }
 
@@ -402,16 +388,12 @@
 void LogsBaseView::openContactsApp()
 {
     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openContactsApp()" );
-    
-    // Need to do request in async manner, otherwise new phonebook ui process
-    // will be started due bug(?) in highway.
-    XQServiceRequest snd("com.nokia.services.phonebookappservices.Launch","launch()", false);
+    XQServiceRequest snd("com.nokia.services.phonebookappservices.Launch","launch()");
     XQRequestInfo info;
     info.setForeground(true);
     snd.setInfo(info);
     int retValue;
     snd.send(retValue);
-    
     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openContactsApp()" );
 }
 
@@ -1034,7 +1016,7 @@
 // Loads appropriate section from *.docml to resize list widget
 // -----------------------------------------------------------------------------
 //
-void LogsBaseView::updateListSize()
+void LogsBaseView::updateListSize( HbListView& list )
 {
     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::updateListSize()" );
     QString newSection( logsViewDefaultSection );
@@ -1050,10 +1032,13 @@
         newSection = QString( logsViewDefaultSection );
     }
     
-    if (newSection != mLayoutSectionName) {
-        mLayoutSectionName = newSection;
-        LOGS_QDEBUG_2( "logs [UI]  loading new section: ", newSection );
-        mRepository.loadSection( viewId(), newSection );
+    bool sectionChanged( mLayoutSectionName != newSection );
+    mLayoutSectionName = newSection;
+    LOGS_QDEBUG_2( "logs [UI]  loading new section: ", newSection );
+    mRepository.loadSection( viewId(), newSection );
+    
+    if ( sectionChanged ){
+        ensureListPositioning( list );
     }
     
     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::updateListSize()" );
@@ -1202,3 +1187,87 @@
     return ( mDialpad->isOpen() && !mDialpad->editor().text().isEmpty() );
 }
 
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+void LogsBaseView::ensureListPositioning( HbListView& list )
+{
+    LOGS_QDEBUG( "logs [UI] -> LogsBaseView::ensureListPositioning()" );
+
+    HbWidget* content = 
+        qobject_cast<HbWidget*>( mRepository.findWidget( logsContentId ) );
+    QList<HbAbstractViewItem *> visibleItems = list.visibleItems();
+    if ( content && visibleItems.count() > 0 ){
+        LOGS_QDEBUG_2( "logs [UI]   contentsRect:", content->contentsRect() );
+        QRectF rect = content->contentsRect();
+        rect.adjust( 0, list.pos().y(), 0, -list.pos().y() );
+        LOGS_QDEBUG_2( "logs [UI]   listRect:", rect );
+        list.setGeometry(rect);
+        
+        HbScrollArea::ScrollBarPolicy prevPolicy = list.verticalScrollBarPolicy();
+        list.setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
+        list.setVerticalScrollBarPolicy(prevPolicy);
+        
+        qreal itemHeight = visibleItems.at(0)->size().height();
+        HbModelIterator* modelIt = list.modelIterator();
+        if ( modelIt && itemHeight > 0 ) {
+            int maxVisibleItems = rect.height() / itemHeight;
+            LOGS_QDEBUG_2( "logs [UI]   max visible items:", maxVisibleItems );
+            if ( modelIt->indexCount() <= maxVisibleItems ){
+                // All items can fit the rect reserved for the list, force them to fit
+                list.ensureVisible(QPointF(0,0));
+            } else if ( visibleItems.count() < maxVisibleItems ) {
+                // All items cannot fit the rect reserved, force to reserve whole
+                // area so that current index is tried to be centered
+                list.scrollTo(list.currentIndex(), HbAbstractItemView::PositionAtCenter);
+            }
+        }
+    }
+    LOGS_QDEBUG( "logs [UI] <- LogsBaseView::ensureListPositioning()" );
+}
+
+// -----------------------------------------------------------------------------
+// LogsBaseView::scrollToTopItem
+// -----------------------------------------------------------------------------
+//
+void LogsBaseView::scrollToTopItem( HbListView* list )
+{
+    LOGS_QDEBUG( "logs [UI] -> LogsBaseView::scrollToTopItem()" );
+    
+    if ( list && list->verticalScrollBar() ){
+        list->verticalScrollBar()->setValue(0.0);
+    }
+    
+    LOGS_QDEBUG( "logs [UI] <- LogsBaseView::scrollToTopItem()" );
+}
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+void LogsBaseView::updateMenuVisibility()
+{
+   bool visibleActionsExist = false;
+   HbMenu* optionsMenu = mOptionsMenu ? mOptionsMenu : menu();
+   foreach (QAction* action, optionsMenu->actions()) {
+       if  (action->isVisible()) {
+           visibleActionsExist = true;
+       }
+   }
+   setMenuVisible(visibleActionsExist);
+}
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+void LogsBaseView::setMenuVisible(bool visible)
+{
+    if (!visible && !mOptionsMenu) {
+        mOptionsMenu = takeMenu();
+    } else if (visible && mOptionsMenu) {
+        setMenu(mOptionsMenu);
+        mOptionsMenu = 0;
+    }
+}