logsui/logsapp/src/logsbaseview.cpp
changeset 8 6c9acdc6adc0
parent 6 41c0a814d878
child 9 68f3171a5819
equal deleted inserted replaced
6:41c0a814d878 8:6c9acdc6adc0
    41 #include <hblabel.h>
    41 #include <hblabel.h>
    42 #include <hblistview.h>
    42 #include <hblistview.h>
    43 #include <QGraphicsLinearLayout>
    43 #include <QGraphicsLinearLayout>
    44 #include <hbpushbutton.h>
    44 #include <hbpushbutton.h>
    45 #include <hbactivitymanager.h>
    45 #include <hbactivitymanager.h>
    46 
    46 #include <hbmodeliterator.h>
       
    47 #include <hbscrollbar.h>
    47 
    48 
    48 Q_DECLARE_METATYPE(LogsCall*)
    49 Q_DECLARE_METATYPE(LogsCall*)
    49 Q_DECLARE_METATYPE(LogsMessage*)
    50 Q_DECLARE_METATYPE(LogsMessage*)
    50 Q_DECLARE_METATYPE(LogsContact*)
    51 Q_DECLARE_METATYPE(LogsContact*)
    51 Q_DECLARE_METATYPE(LogsDetailsModel*)
    52 Q_DECLARE_METATYPE(LogsDetailsModel*)
    68       mInitialized(false),
    69       mInitialized(false),
    69       mCall(0),
    70       mCall(0),
    70       mMessage(0),
    71       mMessage(0),
    71       mContact(0),
    72       mContact(0),
    72       mDetailsModel(0),
    73       mDetailsModel(0),
    73       mCallTypeMapper(0)
    74       mCallTypeMapper(0),
       
    75       mOptionsMenu(0)
    74 {
    76 {
    75     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::LogsBaseView()" );
    77     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::LogsBaseView()" );
    76 
    78 
    77     setNavigationAction(new HbAction(Hb::BackNaviAction, this));
    79     setNavigationAction(new HbAction(Hb::BackNaviAction, this));
    78     connect(navigationAction(), SIGNAL(triggered()), this, 
    80     connect(navigationAction(), SIGNAL(triggered()), this, 
    94     delete mCall;
    96     delete mCall;
    95     delete mMessage;
    97     delete mMessage;
    96     delete mContact;
    98     delete mContact;
    97     delete mDetailsModel;    
    99     delete mDetailsModel;    
    98     delete mCallTypeMapper;
   100     delete mCallTypeMapper;
       
   101     delete mOptionsMenu;
    99 
   102 
   100     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::~LogsBaseView()" );
   103     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::~LogsBaseView()" );
   101 }
   104 }
   102 
   105 
   103 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   276 {   
   279 {   
   277     Q_ASSERT_X( !mInitialized, "logs [UI] ", "view is already initialized!!" );
   280     Q_ASSERT_X( !mInitialized, "logs [UI] ", "view is already initialized!!" );
   278     mInitialized = true;
   281     mInitialized = true;
   279     initFilterMenu();
   282     initFilterMenu();
   280     addActionNamesToMap();
   283     addActionNamesToMap();
   281     connect(menu(), SIGNAL(aboutToShow()), this, 
       
   282             SLOT(closeEmptyMenu()), Qt::QueuedConnection);
       
   283 }
   284 }
   284 
   285 
   285 // -----------------------------------------------------------------------------
   286 // -----------------------------------------------------------------------------
   286 //
   287 //
   287 // -----------------------------------------------------------------------------
   288 // -----------------------------------------------------------------------------
   334         LOGS_QDEBUG( "logs [UI]     Call to topmost item in list" ); 
   335         LOGS_QDEBUG( "logs [UI]     Call to topmost item in list" ); 
   335         QModelIndex topIndex = model()->index(0,0);
   336         QModelIndex topIndex = model()->index(0,0);
   336         listView()->scrollTo( topIndex );
   337         listView()->scrollTo( topIndex );
   337         listView()->setCurrentIndex( topIndex, QItemSelectionModel::Select );
   338         listView()->setCurrentIndex( topIndex, QItemSelectionModel::Select );
   338         initiateCallback(topIndex); 
   339         initiateCallback(topIndex); 
   339     }  
   340     }
   340     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::callKeyPressed()" );
   341     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::callKeyPressed()" );
   341 }
   342 }
   342 
   343 
   343 // -----------------------------------------------------------------------------
   344 // -----------------------------------------------------------------------------
   344 //
   345 //
   364     }
   365     }
   365     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::showFilterMenu()" );
   366     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::showFilterMenu()" );
   366 }
   367 }
   367 
   368 
   368 // -----------------------------------------------------------------------------
   369 // -----------------------------------------------------------------------------
   369 // LogsBaseView::closeEmptyMenu()
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 void LogsBaseView::closeEmptyMenu()
       
   373 {
       
   374     bool visibleActionsExist = false;
       
   375     foreach (QAction* action, menu()->actions()) {
       
   376         if  (action->isVisible()) {
       
   377             visibleActionsExist = true ;
       
   378         }
       
   379     }
       
   380     
       
   381     if (!visibleActionsExist) {
       
   382         menu()->close();
       
   383     }
       
   384 }
       
   385 // -----------------------------------------------------------------------------
       
   386 //
   370 //
   387 // -----------------------------------------------------------------------------
   371 // -----------------------------------------------------------------------------
   388 //
   372 //
   389 void LogsBaseView::openDialpad()
   373 void LogsBaseView::openDialpad()
   390 {
   374 {
   391     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openDialpad()" );
   375     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openDialpad()" );
       
   376    
   392     updateCallButton();
   377     updateCallButton();
   393     setDialpadPosition();
   378     setDialpadPosition();
   394     mDialpad->openDialpad();
   379     mDialpad->openDialpad();
       
   380     
   395     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openDialpad()" );
   381     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openDialpad()" );
   396 }
   382 }
   397 
   383 
   398 // -----------------------------------------------------------------------------
   384 // -----------------------------------------------------------------------------
   399 //
   385 //
   400 // -----------------------------------------------------------------------------
   386 // -----------------------------------------------------------------------------
   401 //
   387 //
   402 void LogsBaseView::openContactsApp()
   388 void LogsBaseView::openContactsApp()
   403 {
   389 {
   404     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openContactsApp()" );
   390     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::openContactsApp()" );
   405     
   391     XQServiceRequest snd("com.nokia.services.phonebookappservices.Launch","launch()");
   406     // Need to do request in async manner, otherwise new phonebook ui process
       
   407     // will be started due bug(?) in highway.
       
   408     XQServiceRequest snd("com.nokia.services.phonebookappservices.Launch","launch()", false);
       
   409     XQRequestInfo info;
   392     XQRequestInfo info;
   410     info.setForeground(true);
   393     info.setForeground(true);
   411     snd.setInfo(info);
   394     snd.setInfo(info);
   412     int retValue;
   395     int retValue;
   413     snd.send(retValue);
   396     snd.send(retValue);
   414     
       
   415     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openContactsApp()" );
   397     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::openContactsApp()" );
   416 }
   398 }
   417 
   399 
   418 // -----------------------------------------------------------------------------
   400 // -----------------------------------------------------------------------------
   419 //
   401 //
   742         popup->setHeadingWidget(
   724         popup->setHeadingWidget(
   743                 new HbLabel(hbTrId("txt_dial_title_add_to_contacts"), popup));
   725                 new HbLabel(hbTrId("txt_dial_title_add_to_contacts"), popup));
   744         popup->setAttribute(Qt::WA_DeleteOnClose);
   726         popup->setAttribute(Qt::WA_DeleteOnClose);
   745         popup->setTimeout( HbPopup::NoTimeout );
   727         popup->setTimeout( HbPopup::NoTimeout );
   746         popup->addAction(
   728         popup->addAction(
   747                 new HbAction(hbTrId("txt_dial_button_cancel"), popup));
   729                 new HbAction(hbTrId("txt_common_button_cancel"), popup));
   748 
   730 
   749         HbWidget* buttonWidget = new HbWidget(popup);
   731         HbWidget* buttonWidget = new HbWidget(popup);
   750         QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
   732         QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
   751         
   733         
   752         HbPushButton* addButton = new HbPushButton(buttonWidget);
   734         HbPushButton* addButton = new HbPushButton(buttonWidget);
   753         addButton->setStretched(true);
   735         addButton->setStretched(true);
   754         addButton->setText(hbTrId("txt_dial_list_save_as_a_new_contact"));
   736         addButton->setText(hbTrId("txt_dial_button_save_as_a_new_contact"));
   755         HbIcon plusIcon("qtg_mono_plus");
   737         HbIcon plusIcon("qtg_mono_plus");
   756         addButton->setIcon(plusIcon);
   738         addButton->setIcon(plusIcon);
   757         connect(addButton, SIGNAL(clicked()), popup, SLOT(close()));
   739         connect(addButton, SIGNAL(clicked()), popup, SLOT(close()));
   758         connect(addButton, SIGNAL(clicked()), mContact, SLOT(addNew()));
   740         connect(addButton, SIGNAL(clicked()), mContact, SLOT(addNew()));
   759         
   741         
   760         HbPushButton* updateButton = new HbPushButton(buttonWidget);
   742         HbPushButton* updateButton = new HbPushButton(buttonWidget);
   761         updateButton->setStretched(true);
   743         updateButton->setStretched(true);
   762         updateButton->setText(hbTrId("txt_dial_list_update_existing_contact"));
   744         updateButton->setText(hbTrId("txt_dial_button_update_existing_contact"));
   763         updateButton->setIcon(plusIcon);
   745         updateButton->setIcon(plusIcon);
   764         connect(updateButton, SIGNAL(clicked()), popup, SLOT(close()));
   746         connect(updateButton, SIGNAL(clicked()), popup, SLOT(close()));
   765         connect(updateButton, SIGNAL(clicked()),
   747         connect(updateButton, SIGNAL(clicked()),
   766                 mContact, SLOT(updateExisting()));
   748                 mContact, SLOT(updateExisting()));
   767         
   749         
  1032 
  1014 
  1033 // -----------------------------------------------------------------------------
  1015 // -----------------------------------------------------------------------------
  1034 // Loads appropriate section from *.docml to resize list widget
  1016 // Loads appropriate section from *.docml to resize list widget
  1035 // -----------------------------------------------------------------------------
  1017 // -----------------------------------------------------------------------------
  1036 //
  1018 //
  1037 void LogsBaseView::updateListSize()
  1019 void LogsBaseView::updateListSize( HbListView& list )
  1038 {
  1020 {
  1039     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::updateListSize()" );
  1021     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::updateListSize()" );
  1040     QString newSection( logsViewDefaultSection );
  1022     QString newSection( logsViewDefaultSection );
  1041     Qt::Orientation orientation = mViewManager.mainWindow().orientation();
  1023     Qt::Orientation orientation = mViewManager.mainWindow().orientation();
  1042 
  1024 
  1048         }
  1030         }
  1049     } else {
  1031     } else {
  1050         newSection = QString( logsViewDefaultSection );
  1032         newSection = QString( logsViewDefaultSection );
  1051     }
  1033     }
  1052     
  1034     
  1053     if (newSection != mLayoutSectionName) {
  1035     bool sectionChanged( mLayoutSectionName != newSection );
  1054         mLayoutSectionName = newSection;
  1036     mLayoutSectionName = newSection;
  1055         LOGS_QDEBUG_2( "logs [UI]  loading new section: ", newSection );
  1037     LOGS_QDEBUG_2( "logs [UI]  loading new section: ", newSection );
  1056         mRepository.loadSection( viewId(), newSection );
  1038     mRepository.loadSection( viewId(), newSection );
       
  1039     
       
  1040     if ( sectionChanged ){
       
  1041         ensureListPositioning( list );
  1057     }
  1042     }
  1058     
  1043     
  1059     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::updateListSize()" );
  1044     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::updateListSize()" );
  1060 }
  1045 }
  1061 
  1046 
  1200 bool LogsBaseView::isDialpadInput() const 
  1185 bool LogsBaseView::isDialpadInput() const 
  1201 {
  1186 {
  1202     return ( mDialpad->isOpen() && !mDialpad->editor().text().isEmpty() );
  1187     return ( mDialpad->isOpen() && !mDialpad->editor().text().isEmpty() );
  1203 }
  1188 }
  1204 
  1189 
       
  1190 // -----------------------------------------------------------------------------
       
  1191 //
       
  1192 // -----------------------------------------------------------------------------
       
  1193 //
       
  1194 void LogsBaseView::ensureListPositioning( HbListView& list )
       
  1195 {
       
  1196     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::ensureListPositioning()" );
       
  1197 
       
  1198     HbWidget* content = 
       
  1199         qobject_cast<HbWidget*>( mRepository.findWidget( logsContentId ) );
       
  1200     QList<HbAbstractViewItem *> visibleItems = list.visibleItems();
       
  1201     if ( content && visibleItems.count() > 0 ){
       
  1202         LOGS_QDEBUG_2( "logs [UI]   contentsRect:", content->contentsRect() );
       
  1203         QRectF rect = content->contentsRect();
       
  1204         rect.adjust( 0, list.pos().y(), 0, -list.pos().y() );
       
  1205         LOGS_QDEBUG_2( "logs [UI]   listRect:", rect );
       
  1206         list.setGeometry(rect);
       
  1207         
       
  1208         HbScrollArea::ScrollBarPolicy prevPolicy = list.verticalScrollBarPolicy();
       
  1209         list.setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
  1210         list.setVerticalScrollBarPolicy(prevPolicy);
       
  1211         
       
  1212         qreal itemHeight = visibleItems.at(0)->size().height();
       
  1213         HbModelIterator* modelIt = list.modelIterator();
       
  1214         if ( modelIt && itemHeight > 0 ) {
       
  1215             int maxVisibleItems = rect.height() / itemHeight;
       
  1216             LOGS_QDEBUG_2( "logs [UI]   max visible items:", maxVisibleItems );
       
  1217             if ( modelIt->indexCount() <= maxVisibleItems ){
       
  1218                 // All items can fit the rect reserved for the list, force them to fit
       
  1219                 list.ensureVisible(QPointF(0,0));
       
  1220             } else if ( visibleItems.count() < maxVisibleItems ) {
       
  1221                 // All items cannot fit the rect reserved, force to reserve whole
       
  1222                 // area so that current index is tried to be centered
       
  1223                 list.scrollTo(list.currentIndex(), HbAbstractItemView::PositionAtCenter);
       
  1224             }
       
  1225         }
       
  1226     }
       
  1227     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::ensureListPositioning()" );
       
  1228 }
       
  1229 
       
  1230 // -----------------------------------------------------------------------------
       
  1231 // LogsBaseView::scrollToTopItem
       
  1232 // -----------------------------------------------------------------------------
       
  1233 //
       
  1234 void LogsBaseView::scrollToTopItem( HbListView* list )
       
  1235 {
       
  1236     LOGS_QDEBUG( "logs [UI] -> LogsBaseView::scrollToTopItem()" );
       
  1237     
       
  1238     if ( list && list->verticalScrollBar() ){
       
  1239         list->verticalScrollBar()->setValue(0.0);
       
  1240     }
       
  1241     
       
  1242     LOGS_QDEBUG( "logs [UI] <- LogsBaseView::scrollToTopItem()" );
       
  1243 }
       
  1244 
       
  1245 // -----------------------------------------------------------------------------
       
  1246 //
       
  1247 // -----------------------------------------------------------------------------
       
  1248 //
       
  1249 void LogsBaseView::updateMenuVisibility()
       
  1250 {
       
  1251    bool visibleActionsExist = false;
       
  1252    HbMenu* optionsMenu = mOptionsMenu ? mOptionsMenu : menu();
       
  1253    foreach (QAction* action, optionsMenu->actions()) {
       
  1254        if  (action->isVisible()) {
       
  1255            visibleActionsExist = true;
       
  1256        }
       
  1257    }
       
  1258    setMenuVisible(visibleActionsExist);
       
  1259 }
       
  1260 
       
  1261 // -----------------------------------------------------------------------------
       
  1262 //
       
  1263 // -----------------------------------------------------------------------------
       
  1264 //
       
  1265 void LogsBaseView::setMenuVisible(bool visible)
       
  1266 {
       
  1267     if (!visible && !mOptionsMenu) {
       
  1268         mOptionsMenu = takeMenu();
       
  1269     } else if (visible && mOptionsMenu) {
       
  1270         setMenu(mOptionsMenu);
       
  1271         mOptionsMenu = 0;
       
  1272     }
       
  1273 }