homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsmenuview.cpp
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
equal deleted inserted replaced
5:c743ef5928ba 35:f9ce957a272c
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Menu view.
       
    15  *
       
    16  */
       
    17 #include <QActionGroup>
       
    18 
       
    19 #include <HbAction>
       
    20 #include <HbAbstractItemView>
       
    21 #include <HbAbstractViewItem>
       
    22 #include <HbGroupBox>
       
    23 #include <HbListView>
       
    24 #include <HbMainWindow>
       
    25 #include <HbSearchPanel>
       
    26 #include <HbToolBar>
       
    27 #include <HbView>
       
    28 
       
    29 #include "hsallappsstate.h"
       
    30 #include "hsallcollectionsstate.h"
       
    31 #include "hscollectionstate.h"
       
    32 #include "hsovistorehandler.h"
       
    33 #include "hsmenuitemmodel.h"
       
    34 #include "hsmenuview.h"
       
    35 
       
    36 /*!
       
    37     \class HsMenuView
       
    38     \ingroup group_hsmenustateplugin
       
    39 
       
    40     \brief Menu View.
       
    41 
       
    42     Provides UI for Application Library states.
       
    43 
       
    44     \sa HsAppLibraryState
       
    45 */
       
    46 
       
    47 /*!
       
    48  Constructor
       
    49 
       
    50  Builds UI objects
       
    51  Sets up signals connections.
       
    52 
       
    53  \param window Main window.
       
    54  */
       
    55 HsMenuView::HsMenuView(HbMainWindow *window):
       
    56     mBuilder(),
       
    57     mWindow(window),
       
    58     mModel(NULL),
       
    59     mMenuSearch(this),
       
    60     mToolBarActionGroup(new QActionGroup(mBuilder.toolBar())),
       
    61     mMenuMode(NormalHsMenuMode)
       
    62 {
       
    63     setUpToolBar();
       
    64     connectItemViewsSignals();
       
    65 }
       
    66 
       
    67 /*!
       
    68  Destructor
       
    69 
       
    70  Disconnects signals.
       
    71  */
       
    72 HsMenuView::~HsMenuView()
       
    73 {
       
    74     disconnectItemViewsSignals();
       
    75 }
       
    76 
       
    77 /*!
       
    78  Sets model for item view.
       
    79 
       
    80  \param model Model to show by item view
       
    81  */
       
    82 void HsMenuView::setModel(HsMenuItemModel *model)
       
    83 {
       
    84     HSMENUTEST_FUNC_ENTRY("HsMenuView::setModel");
       
    85 
       
    86     if (model != mModel) {
       
    87         if (mModel != NULL) {
       
    88             disconnectModelSignals();
       
    89         }
       
    90         mModel = model; // mModel preserves information on actual model type
       
    91     }
       
    92 
       
    93     mBuilder.listView()->setModel(model);
       
    94     if (model != NULL) {
       
    95         connectModelSignals();
       
    96     }
       
    97     HSMENUTEST_FUNC_EXIT("HsMenuView::setModel");
       
    98 }
       
    99 
       
   100 /*!
       
   101  Sets model for item view.
       
   102 
       
   103  \return Model shown by item view.
       
   104  */
       
   105 const HsMenuItemModel *HsMenuView::model() const
       
   106 {
       
   107     return mModel;
       
   108 }
       
   109 
       
   110 /*!
       
   111     Sets label text to be shown when label is enabled.
       
   112     \param label Label text.
       
   113  */
       
   114 void HsMenuView::setLabel(const QString &label)
       
   115 {
       
   116     HSMENUTEST_FUNC_ENTRY("HsMenuView::setLabel");
       
   117     mBuilder.label()->setHeading(label);
       
   118     HSMENUTEST_FUNC_EXIT("HsMenuView::setLabel");
       
   119 }
       
   120 
       
   121 /*!
       
   122  Scrolls item view to requested item.
       
   123  If search panel is open it will be closed after the fuction call.
       
   124  \param index The index of the item the view is to be scrolled.
       
   125  \param hint Where the target item should be positioned in visible area
       
   126  after scroll.
       
   127  */
       
   128 void HsMenuView::scrollTo(const QModelIndex &index,
       
   129                           HbAbstractItemView::ScrollHint hint)
       
   130 {
       
   131     HSMENUTEST_FUNC_ENTRY("HsAllCollectionsState::scrollTo");
       
   132 
       
   133     if (index != QModelIndex()) {
       
   134         mBuilder.listView()->scrollTo(index, hint);
       
   135     }
       
   136     HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::scrollTo");
       
   137 }
       
   138 
       
   139 /*!
       
   140      Scrolls item view to requested item.
       
   141      Does not close search panel.
       
   142      \param index The index of the item the view is to be scrolled.
       
   143      \param hint Where the target item should be positioned in visible area
       
   144      after scroll.
       
   145  */
       
   146 void HsMenuView::scrollToWithoutHidingSearchPanel(const QModelIndex &index,
       
   147         HbAbstractItemView::ScrollHint hint)
       
   148 {
       
   149     HSMENUTEST_FUNC_ENTRY("HsMenuView::scrollToWithoutHidingSearchPanel");
       
   150     hideSearchPanelOnScrolling(false);
       
   151     scrollTo(index, hint);
       
   152     hideSearchPanelOnScrolling(true);
       
   153     HSMENUTEST_FUNC_EXIT("HsMenuView::scrollToWithoutHidingSearchPanel");
       
   154 }
       
   155 
       
   156 /*!
       
   157     Makes the UI to show or hide view label.
       
   158      \param visible When true label will be shown,
       
   159      otherwise it will be hidden.
       
   160  */
       
   161 void HsMenuView::setLabelVisible(bool visible)
       
   162 {
       
   163     HSMENUTEST_FUNC_ENTRY("HsMenuView::setLabelVisible");
       
   164     mBuilder.setLabelVisible(visible);
       
   165     HSMENUTEST_FUNC_EXIT("HsMenuView::setLabelVisible");
       
   166 }
       
   167 
       
   168 /*!
       
   169     Makes the UI to show or hide view search panel.
       
   170     When search panel is shown the view toolbar and status pane
       
   171     are hidden until search panel is hidden.
       
   172      \param visible When true search panel will be shown,
       
   173      otherwise it will be hidden.
       
   174  */
       
   175 void HsMenuView::setSearchPanelVisible(bool visible)
       
   176 {
       
   177     HSMENUTEST_FUNC_ENTRY("HsMenuView::setSearchPanelVisible");
       
   178     if (mBuilder.searchPanel()->isVisible() != visible) {
       
   179         const static Hb::SceneItems statusPaneItems(
       
   180             Hb::SecondarySoftKeyItem
       
   181             | Hb::TitlePaneItem
       
   182             | Hb::IndicatorItems);
       
   183 
       
   184         if (visible) {
       
   185             mWindow->hideItems(statusPaneItems);
       
   186             connectSearchPanelSignals();
       
   187         } else {
       
   188             mWindow->showItems(statusPaneItems);
       
   189             disconnectSearchPanelSignals();
       
   190         }
       
   191 
       
   192         mBuilder.setSearchPanelVisible(visible);
       
   193     }
       
   194     HSMENUTEST_FUNC_EXIT("HsMenuView::setSearchPanelVisible");
       
   195 }
       
   196 
       
   197 /*!
       
   198     \return Application Library UI view.
       
   199  */
       
   200 HbView *HsMenuView::view()
       
   201 {
       
   202     return mBuilder.view();
       
   203 }
       
   204 
       
   205 /*!
       
   206     Returns toolbar action group of Application Library view.
       
   207     The group contains All Applications Action and All Collections Action.
       
   208     \return Toolbar action group.
       
   209  */
       
   210 QActionGroup *HsMenuView::toolBarActionGroup()
       
   211 {
       
   212     return mToolBarActionGroup;
       
   213 }
       
   214 
       
   215 /*!
       
   216     \return All Applications Action.
       
   217  */
       
   218 HbAction *HsMenuView::allAppsAction()
       
   219 {
       
   220     return mBuilder.allAppsAction();
       
   221 }
       
   222 
       
   223 /*!
       
   224     \return All Collections Action.
       
   225  */
       
   226 HbAction *HsMenuView::allCollectionsAction()
       
   227 {
       
   228     return mBuilder.allCollectionsAction();
       
   229 }
       
   230 
       
   231 /*!
       
   232     \return Ovi Store Action.
       
   233  */
       
   234 HbAction *HsMenuView::oviStoreAction()
       
   235 {
       
   236     return mBuilder.oviStoreAction();
       
   237 }
       
   238 
       
   239 /*!
       
   240     \return Index of the first item in the item view if
       
   241     any is shown or invalid index otherwise.
       
   242  */
       
   243 QModelIndex HsMenuView::firstVisibleItemIndex()
       
   244 {
       
   245     HSMENUTEST_FUNC_ENTRY("HsMenuView::firstVisibleItemIndex");
       
   246 
       
   247     QModelIndex result;
       
   248 
       
   249     const QList<HbAbstractViewItem *> array =
       
   250         mBuilder.listView()->visibleItems();
       
   251 
       
   252     if (array.count() >= 1) {
       
   253         result = array[0]->modelIndex();
       
   254     }
       
   255     HSMENUTEST_FUNC_EXIT("HsMenuView::firstVisibleItemIndex");
       
   256 
       
   257     return result;
       
   258 }
       
   259 
       
   260 /*!
       
   261  * Makes search panel visible.
       
   262  * Equivalent to \a setSearchPanelVisible(true)
       
   263  */
       
   264 void HsMenuView::showSearchPanel()
       
   265 {
       
   266     HSMENUTEST_FUNC_ENTRY("HsMenuView::showSearchPanel");
       
   267     setSearchPanelVisible(true);
       
   268     HSMENUTEST_FUNC_EXIT("HsMenuView::showSearchPanel");
       
   269 }
       
   270 
       
   271 /*!
       
   272  * Makes search panel visible.
       
   273  * Equivalent to \a setSearchPanelVisible(false).
       
   274  */
       
   275 void HsMenuView::hideSearchPanel()
       
   276 {
       
   277     HSMENUTEST_FUNC_ENTRY("HsMenuView::hideSearchPanel");
       
   278     setSearchPanelVisible(false);
       
   279     HSMENUTEST_FUNC_EXIT("HsMenuView::hideSearchPanel");
       
   280 }
       
   281 
       
   282 /*!
       
   283  Scrolls item view to requested row.
       
   284  If search panel is open it will be closed after the fuction call.
       
   285  \param row The row which is to get on the top of item view.
       
   286  \param hint Ignored.
       
   287   */
       
   288 void HsMenuView::scrollToRow(int row, QAbstractItemView::ScrollHint hint)
       
   289 {
       
   290     // TODO: remove hint from the interface
       
   291     Q_UNUSED(hint);
       
   292     HSMENUTEST_FUNC_ENTRY("HsMenuView::scrollToRow");
       
   293     scrollTo(mModel->index(row), HbAbstractItemView::PositionAtTop);
       
   294     HSMENUTEST_FUNC_EXIT("HsMenuView::scrollToRow");
       
   295 }
       
   296 
       
   297 /*!
       
   298  Connects \a activated and \a longPressed signals coming from list
       
   299  view to trigger corresponding signal of this object.
       
   300 */
       
   301 void HsMenuView::connectItemViewsSignals()
       
   302 {
       
   303     const HbListView *const listView = mBuilder.listView();
       
   304 
       
   305     connect(listView, SIGNAL(activated(QModelIndex)),
       
   306             this, SIGNAL(activated(QModelIndex)));
       
   307     connect(listView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   308             this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)));
       
   309 
       
   310 }
       
   311 
       
   312 /*!
       
   313  Disconnects \a activated and \a longPressed signals coming from list
       
   314  view from corresponding signal of this object.
       
   315 */
       
   316 void HsMenuView::disconnectItemViewsSignals()
       
   317 {
       
   318     const HbListView *const listView = mBuilder.listView();
       
   319 
       
   320     disconnect(listView, SIGNAL(activated(QModelIndex)),
       
   321                this, SIGNAL(activated(QModelIndex)));
       
   322     disconnect(listView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   323                this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)));
       
   324 }
       
   325 
       
   326 /*!
       
   327  Connects model's \a scrollTo signal with the object \a scrollToRow slot.
       
   328 */
       
   329 void HsMenuView::connectModelSignals()
       
   330 {
       
   331     connect(mModel,SIGNAL(scrollTo(int,QAbstractItemView::ScrollHint)),
       
   332             this, SLOT(scrollToRow(int,QAbstractItemView::ScrollHint)));
       
   333 }
       
   334 
       
   335 /*!
       
   336  Disconnects model's \a scrollTo signal from the object \a scrollToRow slot.
       
   337 */
       
   338 void HsMenuView::disconnectModelSignals()
       
   339 {
       
   340     disconnect(mModel, SIGNAL(scrollTo(int,QAbstractItemView::ScrollHint)),
       
   341                this, SLOT(scrollToRow(int,QAbstractItemView::ScrollHint)));
       
   342 }
       
   343 
       
   344 /*!
       
   345  Connects signals \a exitClicked and \a criteriaChanged emitted
       
   346  by search panel with handling slots of the object or its members
       
   347 */
       
   348 void HsMenuView::connectSearchPanelSignals()
       
   349 {
       
   350     connect(mBuilder.searchPanel(), SIGNAL(exitClicked()),
       
   351             this, SLOT(hideSearchPanel()));
       
   352 
       
   353     connect(mBuilder.searchPanel(), SIGNAL(criteriaChanged(QString)),
       
   354             &mMenuSearch, SLOT(findItem(QString)));
       
   355 
       
   356     hideSearchPanelOnScrolling(true);
       
   357 }
       
   358 
       
   359 /*!
       
   360  Disconnects signals \a exitClicked and \a criteriaChanged emitted
       
   361  by search panel from handling slots of the object or its members
       
   362 */
       
   363 void HsMenuView::disconnectSearchPanelSignals()
       
   364 {
       
   365     disconnect(mBuilder.searchPanel(), SIGNAL(exitClicked()),
       
   366                this, SLOT(hideSearchPanel()));
       
   367 
       
   368     disconnect(mBuilder.searchPanel(), SIGNAL(criteriaChanged(QString)),
       
   369                &mMenuSearch, SLOT(findItem(QString)));
       
   370 
       
   371     hideSearchPanelOnScrolling(false);
       
   372 }
       
   373 
       
   374 /*!
       
   375   Connects or disconnects item views' (list) \a scrollingStarted
       
   376   signal with the object \a hideSearchPanel slot.
       
   377   \param hide When true connects the signals with the slots, otherwise
       
   378   disconnects them.
       
   379  */
       
   380 void HsMenuView::hideSearchPanelOnScrolling(bool hide)
       
   381 {
       
   382     const HbListView *const listView = mBuilder.listView();
       
   383 
       
   384     if (hide) {
       
   385         connect(listView, SIGNAL(scrollingStarted()),
       
   386                 this, SLOT(hideSearchPanel()));
       
   387     } else {
       
   388         disconnect(listView, SIGNAL(scrollingStarted()),
       
   389                    this, SLOT(hideSearchPanel()));
       
   390     }
       
   391 }
       
   392 
       
   393 /*!
       
   394  Groups All Application and All Collection actions. Connects Search Action with
       
   395  the object's \a showSearchPanel slot.
       
   396  */
       
   397 void HsMenuView::setUpToolBar()
       
   398 {
       
   399     HSMENUTEST_FUNC_ENTRY("HsMenuView::construct()");
       
   400 
       
   401     mBuilder.allAppsAction()->setActionGroup(mToolBarActionGroup);
       
   402 
       
   403     mBuilder.allCollectionsAction()->setActionGroup(mToolBarActionGroup);
       
   404 
       
   405     connect(mBuilder.searchAction(), SIGNAL(triggered()),
       
   406             this, SLOT(showSearchPanel()));
       
   407 
       
   408     HSMENUTEST_FUNC_EXIT("HsMenuView::construct()");
       
   409 }
       
   410 
       
   411 HsMenuMode HsMenuView::getHsMenuMode()
       
   412 {
       
   413     return mMenuMode;
       
   414 }
       
   415 
       
   416 void HsMenuView::setHsMenuMode(HsMenuMode menuMode)
       
   417 {
       
   418     mMenuMode = menuMode;
       
   419 }