logsui/logsapp/src/logsbaseview.cpp
changeset 19 e4c884866116
parent 16 c5af8598d22c
child 20 6a40edd41841
equal deleted inserted replaced
16:c5af8598d22c 19:e4c884866116
   129 // -----------------------------------------------------------------------------
   129 // -----------------------------------------------------------------------------
   130 //
   130 //
   131 void LogsBaseView::resetView()
   131 void LogsBaseView::resetView()
   132 {
   132 {
   133     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::resetView()" );
   133     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::resetView()" );
   134     mDialpad->editor().setText(QString());
   134     
   135     if ( mDialpad->isOpen() ){
   135     scrollToTopItem(listView());
   136         mDialpad->closeDialpad();
   136     
   137     }
       
   138     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::resetView()" );
   137     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::resetView()" );
   139 }
   138 }
   140 
   139 
   141 // -----------------------------------------------------------------------------
   140 // -----------------------------------------------------------------------------
   142 //
   141 //
   635         if (mContact->allowedRequestType() ==
   634         if (mContact->allowedRequestType() ==
   636                 LogsContact::TypeLogsContactOpen) {
   635                 LogsContact::TypeLogsContactOpen) {
   637             contactAction->setText(hbTrId("txt_dialer_ui_menu_open_contact"));
   636             contactAction->setText(hbTrId("txt_dialer_ui_menu_open_contact"));
   638             QObject::connect( contactAction, SIGNAL(triggered()), 
   637             QObject::connect( contactAction, SIGNAL(triggered()), 
   639                               mContact, SLOT(open()) );
   638                               mContact, SLOT(open()) );
       
   639         } else if (mContact->allowedRequestType() ==
       
   640                 LogsContact::TypeLogsContactOpenGroup) {
       
   641             contactAction->setText(hbTrId("txt_dialer_menu_open_group"));
       
   642             QObject::connect( contactAction, SIGNAL(triggered()), 
       
   643                               mContact, SLOT(open()) );
   640         }
   644         }
   641         else {
   645         else {
   642             contactAction->setText(hbTrId("txt_common_menu_add_to_contacts"));
   646             contactAction->setText(hbTrId("txt_common_menu_add_to_contacts"));
   643             QObject::connect( contactAction, SIGNAL(triggered()), 
   647             QObject::connect( contactAction, SIGNAL(triggered()), 
   644                               this, SLOT(saveContact()) );
   648                               this, SLOT(saveContact()) );
   981                 hbTrId("txt_dialer_info_call_event_will_be_removed_from"),
   985                 hbTrId("txt_dialer_info_call_event_will_be_removed_from"),
   982                 this,
   986                 this,
   983                 SLOT(deleteEventAnswer(int)),
   987                 SLOT(deleteEventAnswer(int)),
   984                 HbMessageBox::Ok | HbMessageBox::Cancel,
   988                 HbMessageBox::Ok | HbMessageBox::Cancel,
   985                 new HbLabel(hbTrId("txt_dialer_ui_title_delete_event")));
   989                 new HbLabel(hbTrId("txt_dialer_ui_title_delete_event")));
   986     }
   990     }    
   987     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::deleteEvent()" );
   991     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::deleteEvent()" );
   988 }
   992 }
   989 
   993 
   990 // -----------------------------------------------------------------------------
   994 // -----------------------------------------------------------------------------
   991 //
   995 //
  1094     mLayoutSectionName = newSection;
  1098     mLayoutSectionName = newSection;
  1095     LOGS_QDEBUG_2( "logs [UI]  loading new section: ", newSection );
  1099     LOGS_QDEBUG_2( "logs [UI]  loading new section: ", newSection );
  1096     mRepository.loadSection( viewId(), newSection );
  1100     mRepository.loadSection( viewId(), newSection );
  1097     
  1101     
  1098     if ( sectionChanged ){
  1102     if ( sectionChanged ){
  1099         ensureListPositioning( list );
  1103         bool listSizeDecreased(mDialpad->isOpen());
       
  1104         ensureListPositioning( list, listSizeDecreased );
  1100     }
  1105     }
  1101     
  1106     
  1102     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::updateListSize()" );
  1107     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::updateListSize()" );
  1103 }
  1108 }
  1104 
  1109 
  1216 
  1221 
  1217 // -----------------------------------------------------------------------------
  1222 // -----------------------------------------------------------------------------
  1218 //
  1223 //
  1219 // -----------------------------------------------------------------------------
  1224 // -----------------------------------------------------------------------------
  1220 //
  1225 //
  1221 void LogsBaseView::ensureListPositioning( HbListView& list )
  1226 void LogsBaseView::ensureListPositioning(HbListView& list, bool listSizeDecreased)
  1222 {
  1227 {
  1223     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::ensureListPositioning()" );
  1228     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::ensureListPositioning()" );
  1224 
  1229     
  1225     HbWidget* content = 
  1230     HbWidget* content = 
  1226         qobject_cast<HbWidget*>( mRepository.findWidget( logsContentId ) );
  1231         qobject_cast<HbWidget*>( mRepository.findWidget( logsContentId ) );
  1227     QList<HbAbstractViewItem *> visibleItems = list.visibleItems();
  1232     QList<HbAbstractViewItem *> visibleItems = list.visibleItems();
  1228     if ( content && visibleItems.count() > 0 ){
  1233     if ( content && visibleItems.count() > 0 ){
  1229         LOGS_QDEBUG_2( "logs [UI]   contentsRect:", content->contentsRect() );
       
  1230         QRectF rect = content->contentsRect();
  1234         QRectF rect = content->contentsRect();
  1231         rect.adjust( 0, list.pos().y(), 0, -list.pos().y() );
  1235         LOGS_QDEBUG_2( "logs [UI]   contentsRect:", rect );
  1232         LOGS_QDEBUG_2( "logs [UI]   listRect:", rect );
       
  1233         list.setGeometry(rect);
       
  1234         
  1236         
  1235         HbScrollArea::ScrollBarPolicy prevPolicy = list.verticalScrollBarPolicy();
  1237         // Important to force geometry as otherwise in dialpad opening case,
  1236         list.setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
  1238         // list is not scrollable if having few items (e.g. 4), find out current
  1237         list.setVerticalScrollBarPolicy(prevPolicy);
  1239         // fully visible item before geometry change so that list can be positioned
       
  1240         // correctly  
       
  1241         HbAbstractViewItem* firstFullyVisibleItem = visibleItems.at(0);
       
  1242         qreal itemHeight = firstFullyVisibleItem->size().height();
  1238         
  1243         
  1239         qreal itemHeight = visibleItems.at(0)->size().height();
  1244         // If at least 3/4 of the item is visible, it is considered as first fully visible
       
  1245         bool fullyVisible = ( firstFullyVisibleItem->mapRectToItem(
       
  1246             &list, firstFullyVisibleItem->boundingRect()).y() + itemHeight / 4 >= 0 );
       
  1247         if ( !fullyVisible && visibleItems.count() > 1 ){
       
  1248             firstFullyVisibleItem = visibleItems.at(1);
       
  1249         }
       
  1250         QRectF listRect = rect;
       
  1251         listRect.adjust(0, list.pos().y(), 0, 0);
       
  1252         LOGS_QDEBUG_2( "logs [UI]   listRect:", listRect );
       
  1253         list.setGeometry(listRect);
       
  1254         
  1240         HbModelIterator* modelIt = list.modelIterator();
  1255         HbModelIterator* modelIt = list.modelIterator();
       
  1256         bool allItemsFitToReservedRect = true;
  1241         if ( modelIt && itemHeight > 0 ) {
  1257         if ( modelIt && itemHeight > 0 ) {
  1242             int maxVisibleItems = rect.height() / itemHeight;
  1258             int maxVisibleItems = rect.height() / itemHeight;
  1243             LOGS_QDEBUG_2( "logs [UI]   max visible items:", maxVisibleItems );
  1259             LOGS_QDEBUG_2( "logs [UI]   max visible items:", maxVisibleItems );
  1244             if ( modelIt->indexCount() <= maxVisibleItems ){
  1260             allItemsFitToReservedRect = ( modelIt->indexCount() <= maxVisibleItems );
       
  1261             if ( allItemsFitToReservedRect ){
  1245                 // All items can fit the rect reserved for the list, force them to fit
  1262                 // All items can fit the rect reserved for the list, force them to fit
  1246                 list.ensureVisible(QPointF(0,0));
  1263                 list.ensureVisible(QPointF(0,0));
  1247             } else if ( visibleItems.count() < maxVisibleItems ) {
  1264             } else {
  1248                 // All items cannot fit the rect reserved, force to reserve whole
  1265                 // All items cannot fit the rect reserved, force to reserve whole
  1249                 // area so that current index is tried to be centered
  1266                 // area so that current fully visible item is tried to be set to top
  1250                 list.scrollTo(list.currentIndex(), HbAbstractItemView::PositionAtCenter);
  1267                 list.scrollTo(firstFullyVisibleItem->modelIndex(), 
       
  1268                               HbAbstractItemView::PositionAtTop);
       
  1269                
  1251             }
  1270             }
  1252         }
  1271         }
  1253     }
  1272         if ( listSizeDecreased && !allItemsFitToReservedRect ){
       
  1273             // Make sure that user understands that list is scrollable after geometry
       
  1274             // changed to smaller
       
  1275             HbScrollArea::ScrollBarPolicy prevPolicy = list.verticalScrollBarPolicy();
       
  1276             list.setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
  1277             list.setVerticalScrollBarPolicy(prevPolicy);
       
  1278         }
       
  1279     }   
  1254     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::ensureListPositioning()" );
  1280     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::ensureListPositioning()" );
  1255 }
  1281 }
  1256 
  1282 
  1257 // -----------------------------------------------------------------------------
  1283 // -----------------------------------------------------------------------------
  1258 // LogsBaseView::scrollToTopItem
  1284 // LogsBaseView::scrollToTopItem
  1259 // -----------------------------------------------------------------------------
  1285 // -----------------------------------------------------------------------------
  1260 //
  1286 //
  1261 void LogsBaseView::scrollToTopItem( HbListView* list )
  1287 void LogsBaseView::scrollToTopItem( HbListView* list )
  1262 {
  1288 {
  1263     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::scrollToTopItem()" );
  1289     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::scrollToTopItem()" );
  1264     
  1290 
  1265     if ( list && list->verticalScrollBar() ){
  1291     if ( list ){
  1266         list->verticalScrollBar()->setValue(0.0);
  1292         if ( model() && model()->hasIndex(0,0) ) {
       
  1293             QModelIndex topIndex = model()->index(0,0);
       
  1294             list->scrollTo( topIndex );
       
  1295         }
       
  1296         // Force also scrollbar to show itself correctly
       
  1297         if ( list->verticalScrollBar() ){
       
  1298             list->verticalScrollBar()->setValue(0.0);
       
  1299         }
  1267     }
  1300     }
  1268     
  1301     
  1269     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::scrollToTopItem()" );
  1302     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::scrollToTopItem()" );
  1270 }
  1303 }
  1271 
  1304