src/hbwidgets/itemviews/hbabstractitemview.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbabstractitemview_p.h"
       
    27 #include "hbabstractitemcontainer_p.h"
       
    28 
       
    29 #include <hbabstractitemview.h>
       
    30 #include <hbabstractviewitem.h>
       
    31 #include <hbgesturefilter.h>
       
    32 #include <hbevent.h>
       
    33 #include <hbabstractitemcontainer.h>
       
    34 #include <hbwidgetfeedback.h>
       
    35 #include <hbinstance.h>
       
    36 #include <hbscrollbar.h>
       
    37 #include <hbmodeliterator.h>
       
    38 
       
    39 #include <QGraphicsSceneMouseEvent>
       
    40 #include <QGraphicsScene>
       
    41 #include <QDebug>
       
    42 
       
    43 /*!
       
    44     @alpha
       
    45     @hbwidgets
       
    46     \class HbAbstractItemView
       
    47     \brief HbAbstractItemView provides basic functionality for item View Classes.  
       
    48     
       
    49     HbAbstractItemView is an abstract class and cannot itself be instantiated.
       
    50     HbAbstractItemView class can be used as the base class for every standard view that uses QAbstractItemModel.
       
    51     It provides a standard interface for interoperating with models(QAbstractItemModel and QItemSelectionModel)
       
    52     through signals and slots mechanism, enabling subclasses to be kept up-to-date with changes to their models.
       
    53     This class provides a default selection Model to work with. Application can set its own selection Model.
       
    54     There are several functions concerned with selection control like clearSelection(), selectAll(), setSelectionMode().
       
    55     HbAbstractItemView provides standard support for mouse navigation and scrolling of items,
       
    56     selections.
       
    57 
       
    58     \b Subclassing
       
    59     HbAbstractItemView can be subclassed for customization purposes. Derived class must provide
       
    60     implementation of scrollTo(). 
       
    61 
       
    62     Each view item is represented by an instance of HbAbstractViewItem. HbAbstractViewItem
       
    63     can be subclassed for customization purposes.
       
    64 
       
    65     HbAbstractItemView can use item recycling. This means that only visible items
       
    66     plus a small buffer of items above and below the visible area are instantiated at a time. 
       
    67     When the view is scrolled view items are recycled so that buffer size above and below the 
       
    68     visible area is kept constant.By default this feature is disabled. 
       
    69 */
       
    70 
       
    71 /*!
       
    72     \fn void HbAbstractItemView::pressed(const QModelIndex &index)
       
    73 
       
    74     This signal is emitted when a touch down event is received within
       
    75     Abstract view item that is representing \a index.
       
    76 
       
    77     See also released() and activated().
       
    78 */
       
    79 
       
    80 /*!
       
    81   \fn void HbAbstractItemView::released(const QModelIndex &index)
       
    82 
       
    83     This signal is emitted when a touch release event is received within
       
    84     Abstract view item that is representing \a index.
       
    85 
       
    86     See also pressed() and activated().
       
    87 */
       
    88 
       
    89 /*!
       
    90     \fn void HbAbstractItemView::activated(const QModelIndex &index)
       
    91 
       
    92     This signal is emitted when the item specified by \a index is activated by the user.
       
    93     How to activate items depends on the input method; e.g., with mouse by clicking the item
       
    94     or with touch input by tapping the item.
       
    95 
       
    96     See also pressed() and released().
       
    97 */
       
    98 
       
    99 /*!
       
   100     \fn void HbAbstractItemView::longPressed(HbAbstractViewItem *item, const QPointF &coords)
       
   101 
       
   102     This signal is emitted when long press event is received within
       
   103     Abstract view item \a viewItem. \a coords is scene position where the long press event happened.
       
   104 */
       
   105 
       
   106 /*!
       
   107     \enum HbAbstractItemView::SelectionMode
       
   108 
       
   109     selection types supported by HbAbstractItemView.
       
   110 
       
   111     This enum describes different selection types available in LibHb.
       
   112 */
       
   113 
       
   114 /*!
       
   115     \var HbAbstractItemView::NoSelection
       
   116 
       
   117     Items cannot be selected. This is the default value.
       
   118 */
       
   119 
       
   120 
       
   121 /*!
       
   122     \var HbAbstractItemView::SingleSelection
       
   123 
       
   124     When the user selects an item, any already-selected item becomes unselected, and the user cannot
       
   125     unselect the selected item. 
       
   126 */
       
   127 
       
   128 /*!
       
   129     \var HbAbstractItemView::MultiSelection
       
   130 
       
   131     When the user selects an item in the usual way, the selection state of that item
       
   132     is toggled and the other items are left alone. 
       
   133 */
       
   134 
       
   135 /*!
       
   136     \var HbAbstractItemView::ContiguousSelection
       
   137     \deprecated HbAbstractItemView::ContiguousSelection
       
   138        is deprecated.
       
   139 
       
   140      When the user selects an item in the usual way, the selection is cleared and the new item selected.
       
   141      However, if the user presses an item, moves the selection and releases it, all the items between
       
   142      are selected or unselected, depending on the state of the first item.
       
   143 */
       
   144 
       
   145 /*!
       
   146     \enum HbAbstractItemView::ItemAnimation
       
   147 
       
   148     animations in HbAbstractItemView that can be disabled. By default all animations are enabled.
       
   149 */
       
   150 
       
   151 /*!
       
   152     \var HbAbstractItemView::Appear
       
   153 
       
   154     Animation related to item appearance. Disable this animation in cases you expect many model items to appear,
       
   155 	for example in case like insertion of a new data source, and you do not wish to see animations.
       
   156 	
       
   157 	Note that the item appearance animations are not used directly after a setModel call to force non-animated model change. 
       
   158 */
       
   159 
       
   160 /*!
       
   161     \var HbAbstractItemView::Disappear
       
   162 
       
   163     Animation related to item removal. Disable this animation in cases you expect many model items to disappear,
       
   164 	for example in cases like filtering or removal of a data source, and you do not wish to see animations.
       
   165 */
       
   166 
       
   167 /*!
       
   168     \var HbAbstractItemView::TouchDown
       
   169 
       
   170     Animation related to item press and release.
       
   171 */
       
   172 
       
   173 /*!
       
   174     Here are the main properties of the class:
       
   175 
       
   176     \li HbAbstractItemView::itemRecycling: ItemRecycling.
       
   177     \li HbAbstractItemView::SelectionMode: Different selection types supported by view.
       
   178     \li HbAbstractItemView::bufferSize   : Buffer Size used for item recycling.
       
   179     \li HbAbstractItemView::uniformItemSizes : This property holds whether all items in the item view have the same size.
       
   180 */
       
   181 
       
   182 
       
   183 /*!
       
   184     \fn void HbAbstractItemView::scrollTo(const QModelIndex &index,
       
   185         HbAbstractItemView::ScrollHint hint = EnsureVisible)
       
   186 
       
   187     Scrolls the view if necessary to ensure that the item at \a index is visible
       
   188     according to hint. Default value just guarantees, that item will be fully visible. 
       
   189 */
       
   190 
       
   191 
       
   192 /*!
       
   193     See also HbAbstractItemManager, HbAbstractViewItem, HbAbstractItemContainer.
       
   194 
       
   195 */
       
   196 
       
   197 /*!
       
   198     \deprecated HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &, HbAbstractItemContainer *, QGraphicsItem *)
       
   199         is deprecated. Use \a HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &, HbAbstractItemContainer *, HbModelIterator *, QGraphicsItem *).
       
   200 
       
   201     Constructs a new HbAbstractItemView with \a parent.
       
   202 */
       
   203 HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &dd,
       
   204                                        HbAbstractItemContainer *container,
       
   205                                        QGraphicsItem *parent)
       
   206     : HbScrollArea(dd, parent)
       
   207 {
       
   208     qWarning("HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &, HbAbstractItemContainer *, QGraphicsItem *) is deprecated! Use HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &, HbAbstractItemContainer *, HbModelIterator *, QGraphicsItem *).");
       
   209     Q_D(HbAbstractItemView);
       
   210     Q_ASSERT_X(container, "HbAbstractItemView constructor", "Container is null");
       
   211 
       
   212     d->q_ptr = this;
       
   213     d->init(container, new HbModelIterator());
       
   214 }
       
   215 
       
   216 /*!
       
   217     Constructs a new HbAbstractItemView with \a parent.
       
   218 */
       
   219 HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &dd, 
       
   220                                        HbAbstractItemContainer *container,
       
   221                                        HbModelIterator *modelIterator,
       
   222                                        QGraphicsItem *parent)
       
   223     : HbScrollArea(dd, parent)
       
   224 {
       
   225     Q_D(HbAbstractItemView);
       
   226     Q_ASSERT_X(container, "HbAbstractItemView constructor", "Container is null");
       
   227 
       
   228     d->q_ptr = this;
       
   229     d->init(container, modelIterator);
       
   230 }
       
   231 
       
   232 /*!
       
   233     Destructs the abstract item view.
       
   234  */
       
   235 HbAbstractItemView::~HbAbstractItemView()
       
   236 {
       
   237 
       
   238 }
       
   239 
       
   240 /*!
       
   241     Returns model that view is currently presenting.
       
   242 */
       
   243 QAbstractItemModel *HbAbstractItemView::model() const
       
   244 {
       
   245     Q_D(const HbAbstractItemView);
       
   246     return d->mModelIterator->model();
       
   247 }
       
   248 
       
   249 /*!
       
   250     Sets the model to \a model and replaces current item prototype with \a prototype.
       
   251     Ownership of the model is not taken. Ownership of the prototype is taken. 
       
   252     If no prototype has been passed, default prototype is used.
       
   253 
       
   254     Note! Itemview may create view items asynchronously.
       
   255  */
       
   256 void HbAbstractItemView::setModel(QAbstractItemModel *model, HbAbstractViewItem *prototype)
       
   257 {
       
   258     Q_D(HbAbstractItemView);
       
   259     if(prototype) {
       
   260         setItemPrototype(prototype);
       
   261     }
       
   262     d->setModel(model);
       
   263 }
       
   264 
       
   265 /*!
       
   266     Returns the list of item prototypes.
       
   267 */
       
   268 QList<HbAbstractViewItem *> HbAbstractItemView::itemPrototypes() const
       
   269 {
       
   270     Q_D(const HbAbstractItemView);
       
   271     return d->mContainer->itemPrototypes();
       
   272 }
       
   273 
       
   274 /*!
       
   275     Replaces current item prototypes with \a prototype. Ownership is taken.
       
   276     
       
   277     Concrete item views provided by library have view specific view item prototype set by default.
       
   278     
       
   279     Note! This function may cause that view items are recreated. They may be created asynchronously.
       
   280 
       
   281 */
       
   282 void HbAbstractItemView::setItemPrototype(HbAbstractViewItem *prototype)
       
   283 {
       
   284     Q_D(HbAbstractItemView);
       
   285     if (prototype && d->mContainer->setItemPrototype(prototype))  {
       
   286         d->resetContainer();
       
   287     }
       
   288 }
       
   289 
       
   290 /*!
       
   291     To support multiple Abstractview items within single AbstractItemview.
       
   292     Replace current item prototypes with list of \a prototypeList. Ownership is taken.
       
   293     Setting more than one prototype will disable item recycling feature.
       
   294 
       
   295     When list view item is being created, HbAbstractViewItem::canSetModelIndex()
       
   296     is called for every item until item is found, which can create an item for
       
   297     a model index. The prototype list is gone through from end to the beginning. 
       
   298     
       
   299     Thus specialized prototypes should be in the end of the list and 
       
   300     'default' prototype first one. The specialized prototypes usually can create
       
   301     only certain types of list view items. The default prototype usually return always true,
       
   302     meaning that it can create any type of list view item. 
       
   303 
       
   304     Concrete item views provided by library have view specific view item prototype set.
       
   305 
       
   306     Note! This function may cause that view items are recreated. They may be created asynchronously.
       
   307 
       
   308     \sa HbAbstractViewItem::canSetModelIndex()
       
   309 */
       
   310 void HbAbstractItemView::setItemPrototypes(const QList<HbAbstractViewItem *> &prototypes)
       
   311 {
       
   312     Q_D(HbAbstractItemView);
       
   313     if(prototypes.count() > 0) {
       
   314         if (d->mContainer->setItemPrototypes(prototypes)) {
       
   315             d->resetContainer();
       
   316         }
       
   317     }
       
   318     
       
   319 }
       
   320 
       
   321 /*!
       
   322     Returns the current selection model.
       
   323 */
       
   324 QItemSelectionModel *HbAbstractItemView::selectionModel() const
       
   325 {
       
   326     Q_D(const HbAbstractItemView);
       
   327     return d->mSelectionModel;
       
   328 }
       
   329 
       
   330 /*!
       
   331     Sets the current selection model to \a selectionModel.
       
   332     Note: If setModel() is called after this function, the given selectionModel will be
       
   333     replaced by default selection model of the view.
       
   334  */
       
   335 void HbAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel)
       
   336 {
       
   337     Q_D(HbAbstractItemView);
       
   338     if (selectionModel 
       
   339         &&  d->mSelectionModel != selectionModel) {
       
   340         d->setSelectionModel(selectionModel);
       
   341     }
       
   342 }
       
   343 
       
   344 /*!
       
   345     \deprecated HbAbstractItemView::setSelectionMode(HbAbstractItemView::SelectionMode, bool)
       
   346         is deprecated. Use \a HbAbstractItemView::setSelectionMode(HbAbstractItemView::SelectionMode newMode)
       
   347 
       
   348     If \a newMode is not same as current selection mode of view,
       
   349     updates selection mode and all viewitems.
       
   350     If \a resetSelection is true, it clears all existing selections. By default this value is true.
       
   351  */
       
   352 void HbAbstractItemView::setSelectionMode(SelectionMode newMode, bool resetSelection)
       
   353 {
       
   354     qWarning("HbAbstractItemView::setSelectionMode(HbAbstractItemView::SelectionMode, bool) is deprecated! Use HbAbstractItemView::setSelectionMode(HbAbstractItemView::SelectionMode).");
       
   355 
       
   356     Q_D(HbAbstractItemView);
       
   357     if (d->mSelectionMode != newMode) {
       
   358         d->mSelectionMode = newMode;
       
   359 
       
   360         if (resetSelection) {
       
   361             clearSelection();
       
   362         }
       
   363 
       
   364         d->updateItems();
       
   365     }
       
   366 }
       
   367 
       
   368 /*!
       
   369     If \a newMode is not same as current selection mode of view,
       
   370     updates selection mode, all viewitems and clears all existing selections.
       
   371  */
       
   372 void HbAbstractItemView::setSelectionMode(SelectionMode newMode)
       
   373 {
       
   374     Q_D(HbAbstractItemView);
       
   375     if (d->mSelectionMode != newMode) {
       
   376         d->mSelectionMode = newMode;
       
   377 
       
   378         clearSelection();
       
   379 
       
   380         d->updateItems();
       
   381     }
       
   382 }
       
   383 
       
   384 /*!
       
   385     Selects all items in the view.
       
   386  */
       
   387 void HbAbstractItemView::selectAll()
       
   388 {
       
   389     Q_D(HbAbstractItemView);
       
   390     if (d->mModelIterator->model()
       
   391         && d->mSelectionModel 
       
   392         && (d->mSelectionMode == MultiSelection 
       
   393         ||  d->mSelectionMode == ContiguousSelection)) {
       
   394         QModelIndex firstIndex = d->mModelIterator->nextIndex(QModelIndex());
       
   395         QModelIndex lastIndex = d->mModelIterator->previousIndex(QModelIndex());
       
   396         d->mSelectionModel->select(QItemSelection(firstIndex, lastIndex), QItemSelectionModel::Select);
       
   397     }
       
   398 }
       
   399 
       
   400 /*!
       
   401     Deselects all selected items. The current index will not be changed.
       
   402  */
       
   403 void HbAbstractItemView::clearSelection()
       
   404 {
       
   405     Q_D(HbAbstractItemView);
       
   406     if (d->mSelectionModel) {
       
   407         d->mClearingSelection = true;
       
   408         d->mSelectionModel->clearSelection();
       
   409         d->mClearingSelection = false;
       
   410     }
       
   411 }
       
   412 
       
   413 /*!
       
   414     Returns current selection mode used by view.
       
   415  */
       
   416 HbAbstractItemView::SelectionMode HbAbstractItemView::selectionMode() const
       
   417 {
       
   418     Q_D(const HbAbstractItemView);
       
   419     return d->mSelectionMode;
       
   420 }
       
   421 
       
   422 /*!
       
   423     Returns index of current item.
       
   424  */
       
   425 QModelIndex HbAbstractItemView::currentIndex() const
       
   426 {
       
   427     Q_D(const HbAbstractItemView);
       
   428     return d->mCurrentIndex;
       
   429 }
       
   430 
       
   431 /*!
       
   432    Sets Currentindex to \a index. The item is selected depending on the \a selectionFlag.
       
   433    By default item is not selected. If current selection mode is NoSelection,
       
   434    item is not selected irrespective of the selection flag.
       
   435  */
       
   436 void HbAbstractItemView::setCurrentIndex(const QModelIndex &index, 
       
   437                                          QItemSelectionModel::SelectionFlags selectionFlag)
       
   438 {
       
   439     Q_D(HbAbstractItemView);
       
   440     if (d->mSelectionModel) {
       
   441         if (d->mSelectionMode == NoSelection) {
       
   442             selectionFlag = QItemSelectionModel::NoUpdate;
       
   443         } else if (d->mSelectionMode == SingleSelection
       
   444             && selectionFlag & QItemSelectionModel::Select) {
       
   445             selectionFlag |= QItemSelectionModel::Clear;
       
   446         }
       
   447 
       
   448         d->mSelectionModel->setCurrentIndex(index, selectionFlag);
       
   449     }
       
   450 }
       
   451 
       
   452 
       
   453 /*!
       
   454     Returns model index of the model's root item. 
       
   455     The root item is parent item to view's top level items.
       
   456     The root can be invalid.
       
   457  */
       
   458 QModelIndex HbAbstractItemView::rootIndex() const
       
   459 {
       
   460     Q_D(const HbAbstractItemView);
       
   461     return d->mModelIterator->rootIndex();
       
   462 }
       
   463 
       
   464 /*!
       
   465     Sets root index to \a index.
       
   466     All view items are deleted and recreated
       
   467 
       
   468     Note! View items may be created asynchronously.
       
   469  */
       
   470 void HbAbstractItemView::setRootIndex(const QModelIndex &index)
       
   471 {
       
   472     Q_D(HbAbstractItemView);
       
   473     if (d->mModelIterator->rootIndex() != index ) {
       
   474         d->mModelIterator->setRootIndex(index);
       
   475         d->resetContainer();
       
   476 
       
   477         setCurrentIndex(QModelIndex(), QItemSelectionModel::NoUpdate);
       
   478     }
       
   479 }
       
   480 
       
   481 /*!
       
   482     Resets Item view.
       
   483  */
       
   484 void HbAbstractItemView::reset()
       
   485 {
       
   486     Q_D(HbAbstractItemView);    
       
   487 
       
   488     d->mModelIterator->setRootIndex(QPersistentModelIndex());
       
   489     d->resetContainer();
       
   490 
       
   491     setCurrentIndex(QModelIndex(), QItemSelectionModel::NoUpdate);
       
   492 }
       
   493 
       
   494 /*!
       
   495     \reimp
       
   496     It should be allways called by child class if overriden.
       
   497 */
       
   498 bool HbAbstractItemView::event(QEvent *e)
       
   499 {
       
   500     Q_D(HbAbstractItemView);
       
   501 
       
   502     bool result = false;
       
   503 
       
   504     if (e->type() == HbEvent::ChildFocusOut) {
       
   505         d->mWasScrolling = isScrolling();
       
   506         result = true;
       
   507     }
       
   508 
       
   509     result |= HbScrollArea::event(e);
       
   510 
       
   511     // The two above statements have to be executed before these
       
   512     if (e->type() == HbEvent::ChildFocusIn) {
       
   513         HbAbstractViewItem *item = 0;
       
   514         QList<HbAbstractViewItem *> items = d->mContainer->items();
       
   515 
       
   516         for (QGraphicsItem *currentItem = scene()->focusItem(); currentItem != 0; currentItem = currentItem->parentItem()) {
       
   517             item = d->viewItem(currentItem);
       
   518             if (item) {
       
   519                 if (items.indexOf(item) == -1) {
       
   520                     item = 0;
       
   521                 } else {
       
   522                     break;
       
   523                 }
       
   524             }
       
   525         }
       
   526         if (item && item->modelIndex() != d->mCurrentIndex) {
       
   527             setCurrentIndex(item->modelIndex());
       
   528         }
       
   529         result = true;
       
   530     } else if (e->type() == QEvent::LayoutRequest) {
       
   531         d->refreshContainerGeometry();
       
   532         if (d->mPostponedScrollIndex.isValid()) { 
       
   533            d->scrollTo(d->mPostponedScrollIndex, d->mPostponedScrollHint);
       
   534         } 
       
   535         result = true;
       
   536     }
       
   537 
       
   538     return result;
       
   539 }
       
   540 
       
   541 /*!
       
   542     \reimp
       
   543 */
       
   544 void HbAbstractItemView::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   545 {
       
   546     Q_D(HbAbstractItemView);
       
   547     d->mPostponedScrollIndex = QPersistentModelIndex();
       
   548     d->mPreviousSelectedIndex = QModelIndex();
       
   549     d->mPreviousSelectedCommand = QItemSelectionModel::NoUpdate;
       
   550     d->mInstantClickedModifiers = 0;
       
   551 
       
   552     d->mHitItem = d->itemAt(event->scenePos());
       
   553 
       
   554     if (d->mHitItem && d->mHitItem->modelIndex().isValid()) {
       
   555         QGraphicsItem::GraphicsItemFlags flags = d->mHitItem->flags();
       
   556         if (!flags.testFlag(QGraphicsItem::ItemIsFocusable)){
       
   557             d->mHitItem = 0;
       
   558         }
       
   559     }
       
   560 
       
   561     if (d->mHitItem) {
       
   562         if (d->mHitItem->modelIndex().isValid()) {
       
   563             Hb::InteractionModifiers modifiers = 0;
       
   564             if (d->mWasScrolling) {
       
   565                 modifiers |= Hb::ModifierScrolling;
       
   566             }
       
   567             HbWidgetFeedback::triggered(d->mHitItem, Hb::InstantPressed, modifiers);
       
   568 
       
   569             if (!d->mWasScrolling) {
       
   570                 d->mHitItem->setPressed(true);
       
   571             }
       
   572         }
       
   573     }
       
   574 
       
   575     if (isScrolling()) {
       
   576         // Needed when focus does not change. Otherwise mWasScrolling updating is done on 
       
   577         // focusOutEvent or event function.
       
   578         d->mWasScrolling = true;
       
   579     }
       
   580 
       
   581     HbScrollArea::mousePressEvent(event);
       
   582     
       
   583     if (d->mHitItem) {
       
   584         emitPressed(d->mHitItem->modelIndex());
       
   585         if (d->mSelectionModel) {
       
   586             QItemSelectionModel::SelectionFlags flags = selectionCommand(d->mHitItem, event);
       
   587             d->mSelectionModel->select(d->mHitItem->modelIndex(), flags);
       
   588         }
       
   589     } else if (d->mGestureFilter) {
       
   590         d->mGestureFilter->setLongpressAnimation(false);
       
   591     }
       
   592 
       
   593     event->accept();
       
   594 }
       
   595 
       
   596 /*!
       
   597     \reimp
       
   598 */
       
   599 void HbAbstractItemView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   600 {
       
   601     Q_D(HbAbstractItemView);
       
   602 
       
   603     HbScrollArea::mouseReleaseEvent(event);
       
   604 
       
   605     if (d->mGestureFilter) {
       
   606         d->mGestureFilter->setLongpressAnimation(true);
       
   607     }
       
   608 
       
   609     HbAbstractViewItem* hitItem = d->itemAt(event->scenePos());
       
   610     if (hitItem) {
       
   611         QGraphicsItem::GraphicsItemFlags flags = hitItem->flags();
       
   612         if (!flags.testFlag(QGraphicsItem::ItemIsFocusable)){
       
   613             hitItem = 0;
       
   614         }
       
   615     }
       
   616 
       
   617     if (d->mHitItem) {
       
   618         d->mHitItem->setPressed(false);
       
   619     }
       
   620 
       
   621     if (hitItem) {
       
   622         if (hitItem->modelIndex().isValid()) {
       
   623             Hb::InteractionModifiers modifiers = 0;
       
   624             if (d->mWasScrolling) {
       
   625                 modifiers |= Hb::ModifierScrolling;
       
   626             }
       
   627             HbWidgetFeedback::triggered(hitItem, Hb::InstantReleased, modifiers);
       
   628         }
       
   629         emitReleased(hitItem->modelIndex());
       
   630     }
       
   631 
       
   632     if (d->mWasScrolling || d->mOptions.testFlag(HbAbstractItemViewPrivate::PanningActive)) {
       
   633         d->mOptions &= ~HbAbstractItemViewPrivate::PanningActive;
       
   634         if (d->mSelectionSettings.testFlag(HbAbstractItemViewPrivate::Selection)) {
       
   635             d->mSelectionSettings &= ~HbAbstractItemViewPrivate::Selection;
       
   636             d->mContSelectionAction = QItemSelectionModel::NoUpdate;
       
   637         }
       
   638     } else if (hitItem) {
       
   639         if (d->mSelectionModel) {
       
   640             d->mSelectionModel->setCurrentIndex(hitItem->modelIndex(), QItemSelectionModel::NoUpdate);
       
   641 
       
   642             QItemSelectionModel::SelectionFlags flags = selectionCommand(hitItem, event);
       
   643             d->mSelectionModel->select(hitItem->modelIndex(), flags);
       
   644         }
       
   645 
       
   646         if (    d->mHitItem == hitItem
       
   647             &&  hitItem->modelIndex().isValid()){
       
   648             HbWidgetFeedback::triggered(hitItem, Hb::InstantClicked, d->mInstantClickedModifiers);
       
   649             emitActivated(hitItem->modelIndex());
       
   650         }
       
   651 
       
   652         HbAbstractViewItem *item = d->currentItem();
       
   653         if (item) {
       
   654             d->revealItem(item, EnsureVisible);
       
   655         }
       
   656     } 
       
   657     d->mWasScrolling = false;
       
   658     event->accept(); 
       
   659 }
       
   660 
       
   661 /*!
       
   662     \reimp
       
   663 */
       
   664 void HbAbstractItemView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
       
   665 {
       
   666     HbScrollArea::mouseMoveEvent( event );
       
   667 
       
   668     Q_D(HbAbstractItemView);
       
   669 
       
   670     // contiguous selection handling.
       
   671     if (d->mSelectionSettings.testFlag(HbAbstractItemViewPrivate::Selection)
       
   672         && d->mSelectionModel
       
   673         && d->mSelectionMode == HbAbstractItemView::ContiguousSelection
       
   674         && geometry().contains(event->pos())) {
       
   675 
       
   676         QModelIndex firstIndex;
       
   677         QModelIndex lastIndex;
       
   678         d->mContainer->firstAndLastVisibleModelIndex(firstIndex, lastIndex);
       
   679         qreal scenePosY = event->scenePos().y();
       
   680         qreal lastScenePosY = event->lastScenePos().y();
       
   681         QPolygonF polygon;
       
   682         polygon << event->lastScenePos() << event->scenePos();
       
   683 
       
   684         QList<QGraphicsItem *> items = scene()->items(polygon);
       
   685         int itemCount = items.count();
       
   686 
       
   687         // loop through the items in the scene
       
   688         for (int current = 0; current < itemCount ; ++current) {
       
   689             HbAbstractViewItem *item = d->viewItem(items.at(current));
       
   690             if (item) {
       
   691                 if (d->mHitItem && item != d->mHitItem) {
       
   692                     d->mHitItem->setPressed(false);
       
   693                 }
       
   694 
       
   695                 QModelIndex itemIndex(item->modelIndex());
       
   696                 QItemSelectionModel::SelectionFlags command = selectionCommand(item, event);
       
   697                 if (    itemIndex != d->mPreviousSelectedIndex
       
   698                     ||  command != d->mPreviousSelectedCommand) {
       
   699                     d->mPreviousSelectedIndex = itemIndex;
       
   700                     d->mPreviousSelectedCommand = command;
       
   701                     d->mSelectionModel->select(itemIndex, command);
       
   702 
       
   703                     // Scroll up/down when needed
       
   704                     HbAbstractViewItem *scrollItem = 0;
       
   705                     if (itemIndex == firstIndex
       
   706                         && lastScenePosY > scenePosY) {
       
   707                         scrollItem = d->mContainer->itemByIndex(d->mModelIterator->previousIndex(itemIndex));
       
   708                     } else if (itemIndex == lastIndex
       
   709                         && lastScenePosY < scenePosY) {
       
   710                         scrollItem = d->mContainer->itemByIndex(d->mModelIterator->nextIndex(itemIndex));
       
   711                     }
       
   712 
       
   713                     if (scrollItem) {
       
   714                         QPointF delta = d->pixelsToScroll(scrollItem, EnsureVisible);
       
   715                         d->scrollByAmount(delta);
       
   716                     }
       
   717                     break;
       
   718                 }
       
   719             }
       
   720         }
       
   721     }
       
   722 
       
   723     event->accept();
       
   724 }
       
   725 
       
   726 /*!
       
   727     This slot is called when orientation is changed.
       
   728     \a newOrientation has the currentOrientation mode.
       
   729     Note: Currently platform dependent orientation support is not available
       
   730 */
       
   731 void HbAbstractItemView::orientationChanged(Qt::Orientation newOrientation)
       
   732 {
       
   733     Q_UNUSED(newOrientation);
       
   734 
       
   735     Q_D(HbAbstractItemView);
       
   736 
       
   737     //Setting the uniform ites sizes to container again resets size caches.
       
   738     d->mContainer->setUniformItemSizes(d->mContainer->uniformItemSizes());
       
   739     d->mContainer->setPos(0,0);
       
   740     d->refreshContainerGeometry();
       
   741 
       
   742     d->updateScrollMetrics();
       
   743 
       
   744     scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtTop);
       
   745 
       
   746     d->mVisibleIndex = QModelIndex();
       
   747 }
       
   748 
       
   749 /*!
       
   750     This slot is called just before orientation is to be changed.
       
   751     Note: Currently platform dependent orientation support is not available
       
   752 */
       
   753 void HbAbstractItemView::orientationAboutToBeChanged()
       
   754 {
       
   755     Q_D(HbAbstractItemView);
       
   756     d->saveIndexMadeVisibleAfterMetricsChange();
       
   757 }
       
   758 
       
   759 /*!
       
   760     Sets item recycling to \a enabled.
       
   761     By default recycling is off.
       
   762  */
       
   763 void HbAbstractItemView::setItemRecycling(bool enabled)
       
   764 {
       
   765     Q_D(HbAbstractItemView);
       
   766     d->mContainer->setItemRecycling(enabled);
       
   767 }
       
   768 
       
   769 /*!
       
   770     Returns whether item recycling feature is in use.
       
   771  */
       
   772 bool HbAbstractItemView::itemRecycling() const
       
   773 {
       
   774     Q_D(const HbAbstractItemView);
       
   775     return d->mContainer->itemRecycling();
       
   776 }
       
   777 
       
   778 /*!
       
   779     Returns view item representing current model index. This can be NULL if
       
   780     index has no view item representing it.
       
   781 */
       
   782 HbAbstractViewItem *HbAbstractItemView::currentViewItem() const
       
   783 {
       
   784     Q_D(const HbAbstractItemView);
       
   785     return d->currentItem();
       
   786 }
       
   787 
       
   788 
       
   789 /*!
       
   790     Returns view item representing given model \a index. This can be NULL if
       
   791     index has no view item representing it.
       
   792 */
       
   793 HbAbstractViewItem *HbAbstractItemView::itemByIndex(const QModelIndex &index) const
       
   794 {
       
   795     Q_D(const HbAbstractItemView);
       
   796     return d->mContainer->itemByIndex(index);
       
   797 }
       
   798 
       
   799 /*!
       
   800    Returns true if item with model index is fully or partially visible in view.
       
   801  */
       
   802 bool HbAbstractItemView::isVisible(const QModelIndex & index) const
       
   803 {
       
   804     Q_D( const HbAbstractItemView );
       
   805     return d->visible(d->mContainer->itemByIndex(index), false);
       
   806 }
       
   807 
       
   808 /*!
       
   809     \deprecated HbAbstractItemView::isVisible(HbAbstractViewItem*) const
       
   810         is deprecated. Use isVisible \a HbAbstractItemView::isVisible(const QModelIndex&) const.
       
   811 
       
   812     This is an overloaded member function, provided for convenience.
       
   813     Returns true if item is fully or partially visible in view.
       
   814  */
       
   815 bool HbAbstractItemView::isVisible(HbAbstractViewItem *item) const
       
   816 {
       
   817     qWarning("HbAbstractItemView::isVisible(HbAbstractViewItem*) const is deprecated! Use isVisible \a HbAbstractItemView::isVisible(const QModelIndex&) const");
       
   818 
       
   819     Q_D(const HbAbstractItemView);
       
   820     return d->visible(item, false);
       
   821 }
       
   822 
       
   823 /*!
       
   824     Base class implemmentation. Take care about scrollTo when it was
       
   825     called before view was visible (first scrollTo can be done after
       
   826     first layoutRequest).
       
   827     It should be always called by child class if overriden.
       
   828 
       
   829     Note! If item recycling is enabled, view item may not have reached its final 
       
   830     position, when this function returns. Then its position is fine tuned asynchronously. 
       
   831 
       
   832     \sa HbAbstractItemView::itemRecycling()
       
   833 */
       
   834 void HbAbstractItemView::scrollTo(const QModelIndex &index, ScrollHint hint)
       
   835 {
       
   836     Q_D(HbAbstractItemView);
       
   837     if (    index.isValid()
       
   838         &&  d->mModelIterator->model() == index.model()) {
       
   839         d->mPostponedScrollIndex = QPersistentModelIndex();
       
   840         d->scrollTo(index, hint);
       
   841         d->mPostponedScrollIndex = index;
       
   842         d->mPostponedScrollHint = hint;
       
   843         if (    d->mContainer->itemRecycling()
       
   844             &&  !d->mContainer->items().count()) {
       
   845             // settings index from which loading viewitems start when itemview is 
       
   846             // empty or reset by setModel()
       
   847             d->mContainer->d_func()->mFirstItemIndex = index;
       
   848         }
       
   849         QCoreApplication::postEvent(this, new QEvent(QEvent::LayoutRequest));
       
   850     }
       
   851 }
       
   852 
       
   853 /*!
       
   854     Returns list of currently visible view items.
       
   855  */
       
   856 QList<HbAbstractViewItem *> HbAbstractItemView::visibleItems() const
       
   857 {
       
   858     Q_D(const HbAbstractItemView);
       
   859     QList<HbAbstractViewItem *> visibleItems;
       
   860 
       
   861     const int count(d->mContainer->items().count());
       
   862     for (int i = 0; i < count; ++i) {
       
   863         if(d->visible(d->mContainer->items().at(i), false))
       
   864             visibleItems.append(d->mContainer->items().at(i));
       
   865     }
       
   866     return visibleItems;
       
   867 }
       
   868 
       
   869 /*!
       
   870     \deprecated HbAbstractItemView::itemAtPosition(const QPointF&) const
       
   871         is deprecated.
       
   872 
       
   873     Returns a pointer to item at the coordinates.
       
   874  */
       
   875 HbAbstractViewItem *HbAbstractItemView::itemAtPosition(const QPointF& position) const
       
   876 {
       
   877     qWarning("HbAbstractItemView::itemAtPosition(const QPointF&) const is deprecated!");
       
   878 
       
   879     Q_D(const HbAbstractItemView);
       
   880     return d->itemAt(position);
       
   881 }
       
   882 
       
   883 /*!
       
   884     Returns SelectionFlags to be used when updating selection of a item.
       
   885     The event is a user input event, such as a mouse or keyboard event.
       
   886     contiguousArea is true, if selectiontype is not single or no selection and
       
   887     user has pressed on contiguousArea of viewItemi.e CheckBox.
       
   888     By default this is false.
       
   889     Subclasses should overide this function to define their own selection behavior.
       
   890 
       
   891     \sa HbAbstractViewItem::selectionAreaContains(const QPointF &scenePosition) const
       
   892 */
       
   893 QItemSelectionModel::SelectionFlags HbAbstractItemView::selectionCommand(const HbAbstractViewItem *item,
       
   894                                                                          const QEvent *event)
       
   895 { 
       
   896     Q_D(HbAbstractItemView);
       
   897     // When the parameter contiguousArea is removed, copy paste 'd ->selectionFlags()' into here.
       
   898     return d->selectionFlags(item, event);
       
   899 }
       
   900 
       
   901 /*!
       
   902     This slot is called when items are changed in model. 
       
   903     The changed items are those from \a topLeft to \a bottomRight inclusive.
       
   904     If just one item is changed topLeft == bottomRight.
       
   905 */
       
   906 void  HbAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
       
   907 {
       
   908     Q_D(HbAbstractItemView);
       
   909 
       
   910     QList<HbAbstractViewItem *> items = d->mContainer->items();
       
   911     int itemCount = items.count();
       
   912 
       
   913     if (itemCount != 0
       
   914         && topLeft.isValid() 
       
   915         && bottomRight.isValid()
       
   916         && topLeft.parent() == bottomRight.parent()) {
       
   917         HbAbstractViewItem *startItem = itemByIndex(topLeft);
       
   918         if (topLeft != bottomRight) {
       
   919             // Multiple indexes have changed.
       
   920             int start = 0;
       
   921             if (startItem) {
       
   922                 start = items.indexOf(startItem);
       
   923             }
       
   924 
       
   925             int end = itemCount-1;
       
   926             
       
   927             HbAbstractViewItem *endItem = itemByIndex(bottomRight);
       
   928             if (endItem) {
       
   929                 end = items.indexOf(endItem, start+1);
       
   930             }
       
   931 
       
   932             for (int current = start; current <= end; current++) {
       
   933                 HbAbstractViewItem *item = items.at(current);
       
   934                 QModelIndex index = item->modelIndex();
       
   935                 int currentRow = index.row();
       
   936                 int currentColumn = index.column();
       
   937 
       
   938                 if (index.parent() == topLeft.parent()
       
   939                     && currentRow >= topLeft.row()
       
   940                     && currentRow <= bottomRight.row()
       
   941                     && currentColumn >= topLeft.column()
       
   942                     && currentColumn <= bottomRight.column()) {
       
   943                     item->updateChildItems();
       
   944                 }
       
   945             }
       
   946         } else {
       
   947             // Single index has changed.
       
   948             if (startItem) {
       
   949                 startItem->updateChildItems();
       
   950             }
       
   951         }
       
   952     }
       
   953 }
       
   954 
       
   955 /*!
       
   956     This slot is called when current index is changed in selection model.
       
   957     current is the changed or current index and previous in the old current index.
       
   958     current index may not be selected.
       
   959 */
       
   960 void HbAbstractItemView::currentIndexChanged(const QModelIndex &current, const QModelIndex &previous)
       
   961 {
       
   962     Q_D(HbAbstractItemView);
       
   963 
       
   964     if (current != d->mCurrentIndex) {
       
   965         d->mCurrentIndex = current;
       
   966 
       
   967         HbAbstractViewItem* oldItem = d->mContainer->itemByIndex(previous);
       
   968         HbAbstractViewItem* newItem = d->mContainer->itemByIndex(current);
       
   969        
       
   970         if (oldItem) {
       
   971             oldItem->lostFocus();
       
   972         } 
       
   973         
       
   974         if (previous.isValid()) {
       
   975             d->mContainer->setItemStateValue(previous, HbAbstractViewItem::FocusKey, false);
       
   976         }
       
   977 
       
   978         if (newItem) {
       
   979             newItem->receivedFocus();
       
   980         } 
       
   981         
       
   982         if (d->mCurrentIndex.isValid()) {
       
   983             d->mContainer->setItemStateValue(d->mCurrentIndex, HbAbstractViewItem::FocusKey, true);
       
   984         }
       
   985 
       
   986     }
       
   987 }
       
   988 
       
   989 /*!
       
   990     This slot is called when selection of items has changed.
       
   991     selected contains all selected items, deselected contains
       
   992     all deselected items.
       
   993 */
       
   994 void HbAbstractItemView::currentSelectionChanged(const QItemSelection &selected, 
       
   995                                                  const QItemSelection &deselected)
       
   996 {
       
   997     Q_D(HbAbstractItemView);
       
   998     QModelIndexList selectedIndexes(selected.indexes());
       
   999     int count = selectedIndexes.count();
       
  1000     for (int i = 0; i < count; ++i) {
       
  1001         HbAbstractViewItem *item = d->mContainer->itemByIndex(selectedIndexes.at(i));
       
  1002         if (item) {
       
  1003             item->setCheckState(Qt::Checked);
       
  1004             if (!d->mClearingSelection) {
       
  1005                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged);
       
  1006             }
       
  1007         } 
       
  1008         d->mContainer->setItemStateValue(selectedIndexes.at(i),
       
  1009                                          HbAbstractViewItem::CheckStateKey,
       
  1010                                          Qt::Checked);
       
  1011     }
       
  1012 
       
  1013     QModelIndexList deselectedIndexes(deselected.indexes());
       
  1014     count = deselectedIndexes.count();
       
  1015     for (int i = 0; i < count; ++i) {
       
  1016         HbAbstractViewItem *item = d->mContainer->itemByIndex(deselectedIndexes.at(i));
       
  1017         if (item) {
       
  1018             item->setCheckState(Qt::Unchecked);
       
  1019             if (!d->mClearingSelection) {
       
  1020                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged);
       
  1021             }
       
  1022         } 
       
  1023         d->mContainer->setItemStateValue(deselectedIndexes.at(i),
       
  1024                                          HbAbstractViewItem::CheckStateKey,
       
  1025                                          Qt::Unchecked);
       
  1026     }
       
  1027 }
       
  1028 
       
  1029 /*!
       
  1030     This slot is called when rows are inserted. 
       
  1031     The new rows are those under the given parent from start to end inclusive
       
  1032 */
       
  1033 void HbAbstractItemView::rowsInserted(const QModelIndex &parent, int start, int end)
       
  1034 {
       
  1035     Q_D(HbAbstractItemView);
       
  1036 
       
  1037     if (d->mModelIterator->model()->columnCount(parent) == 0) {
       
  1038         return;
       
  1039     }
       
  1040 
       
  1041     for (int current = start; current <= end; current++) {
       
  1042         QModelIndex index = model()->index(current, 0, parent);
       
  1043         bool animate = d->mEnabledAnimations & HbAbstractItemView::Appear ? d->mAnimateItems : false;
       
  1044         d->mContainer->addItem(index, animate);
       
  1045     }
       
  1046     
       
  1047 
       
  1048     if (!d->mCurrentIndex.isValid() && d->mSelectionModel) {
       
  1049         d->mSelectionModel->setCurrentIndex(d->mModelIterator->nextIndex(QModelIndex()), QItemSelectionModel::NoUpdate);
       
  1050     }
       
  1051 }
       
  1052 
       
  1053 /*!
       
  1054     This slot is called after rows have been removed from the model.
       
  1055     The removed items are those between start and end inclusive, under the given parent item.
       
  1056 */
       
  1057 void HbAbstractItemView::rowsRemoved(const QModelIndex &parent,int start,int end)
       
  1058 {
       
  1059     Q_D(HbAbstractItemView);
       
  1060     d->rowsRemoved(parent, start, end);
       
  1061 }
       
  1062 
       
  1063 /*!
       
  1064     This slot is called just before rows are removed from the model.
       
  1065     The items that will be removed are those between \a start and \a end inclusive, under the given \a parent item.
       
  1066     Default implementation is empty
       
  1067 */
       
  1068 void HbAbstractItemView::rowsAboutToBeRemoved(const QModelIndex &index, int start, int end)
       
  1069 {
       
  1070     Q_UNUSED(index);
       
  1071     Q_UNUSED(start);
       
  1072     Q_UNUSED(end);
       
  1073 }
       
  1074 
       
  1075 /*!
       
  1076     This slot is called just before rows are inserted into the model.
       
  1077     The items that will be inserted are those between \a start and \a end inclusive, under the given \a parent item.
       
  1078     Default implementation is empty.
       
  1079 */
       
  1080 void HbAbstractItemView::rowsAboutToBeInserted(const QModelIndex &index, int start, int end)
       
  1081 {
       
  1082     Q_UNUSED(index);
       
  1083     Q_UNUSED(start);
       
  1084     Q_UNUSED(end);
       
  1085 }
       
  1086 
       
  1087 /*!
       
  1088     This slot is called when columns are inserted. 
       
  1089     The new rows are those under the given parent from start to end inclusive
       
  1090 */
       
  1091 void HbAbstractItemView::columnsInserted(const QModelIndex &parent, int start, int end)
       
  1092 {
       
  1093     Q_UNUSED(end)
       
  1094     Q_UNUSED(start)
       
  1095 
       
  1096     Q_D(HbAbstractItemView);
       
  1097 
       
  1098     if (parent == d->mModelIterator->rootIndex()) {
       
  1099         // ??????? why columns
       
  1100         if (d->mModelIterator->model()->columnCount(parent) == 1) {
       
  1101             rowsInserted(parent, 0, d->mModelIterator->model()->rowCount(parent));
       
  1102         }
       
  1103     }
       
  1104 }
       
  1105 
       
  1106 /*!
       
  1107     This slot is called after columns have been removed from the model.
       
  1108     The removed items are those between start and end inclusive, under the given parent item.
       
  1109 */
       
  1110 void HbAbstractItemView::columnsRemoved(const QModelIndex &parent, int start, int end)
       
  1111 {
       
  1112     Q_UNUSED(end)
       
  1113     Q_UNUSED(start)
       
  1114 
       
  1115     Q_D(HbAbstractItemView);
       
  1116 
       
  1117     if (parent == d->mModelIterator->rootIndex()) {
       
  1118         // ??????? why columns
       
  1119         if (d->mModelIterator->model()->columnCount(parent) == 0){
       
  1120             rowsRemoved(parent, 0, d->mModelIterator->model()->rowCount(parent));
       
  1121         }
       
  1122     }
       
  1123 
       
  1124 }
       
  1125 
       
  1126 /*!
       
  1127     This slot is called just before columns are removed from the model.
       
  1128     The items that will be removed are those between \a start and \a end inclusive, under the given \a parent item.
       
  1129     Default implementation is empty
       
  1130 */
       
  1131 void HbAbstractItemView::columnsAboutToBeRemoved(const QModelIndex &index, int start, int end)
       
  1132 {
       
  1133     Q_UNUSED(index);
       
  1134     Q_UNUSED(start);
       
  1135     Q_UNUSED(end);
       
  1136 }
       
  1137 
       
  1138 /*!
       
  1139     This slot is called just before columns are inserted into the model.
       
  1140     The items that will be inserted are those between \a start and \a end inclusive, under the given \a parent item.
       
  1141     Default implementation is empty.
       
  1142 */
       
  1143 void HbAbstractItemView::columnsAboutToBeInserted(const QModelIndex &index, int start, int end)
       
  1144 {
       
  1145     Q_UNUSED(index);
       
  1146     Q_UNUSED(start);
       
  1147     Q_UNUSED(end);
       
  1148 }
       
  1149 
       
  1150 
       
  1151 /*!
       
  1152     \reimp
       
  1153 */
       
  1154 void HbAbstractItemView::panGesture(const QPointF &point)
       
  1155 {
       
  1156     Q_D( HbAbstractItemView );
       
  1157     d->mPostponedScrollIndex = QPersistentModelIndex();
       
  1158     d->mOptions |= d->PanningActive;
       
  1159     
       
  1160     if (d->mHitItem) {
       
  1161         d->mHitItem->setPressed(false, false);
       
  1162     }
       
  1163 
       
  1164     HbScrollArea::panGesture(point);
       
  1165     
       
  1166 }
       
  1167 
       
  1168 /*!
       
  1169     \reimp
       
  1170 */
       
  1171 void HbAbstractItemView::longPressGesture(const QPointF &point)
       
  1172 {
       
  1173     Q_D( HbAbstractItemView );
       
  1174     d->mPostponedScrollIndex = QPersistentModelIndex();
       
  1175     HbScrollArea::longPressGesture(point);
       
  1176 
       
  1177     if (d->mHitItem) {
       
  1178         if (d->mHitItem->modelIndex().isValid()) {
       
  1179             HbWidgetFeedback::triggered(d->mHitItem, Hb::InstantLongPressed);
       
  1180         }
       
  1181         if (d->mHitItem) {
       
  1182             d->mHitItem->setPressed(false);
       
  1183         }
       
  1184         emit longPressed(d->mHitItem, point);
       
  1185     }
       
  1186 }
       
  1187 
       
  1188 /*!
       
  1189     \reimp
       
  1190 */
       
  1191 void HbAbstractItemView::focusOutEvent(QFocusEvent *event)
       
  1192 {
       
  1193     HbScrollArea::focusOutEvent(event);
       
  1194 
       
  1195     Q_D( HbAbstractItemView );
       
  1196 
       
  1197     d->mWasScrolling = isScrolling();
       
  1198     d->stopScrolling();
       
  1199 }
       
  1200 
       
  1201 /*!
       
  1202     Emits the activated signal.
       
  1203 */
       
  1204 void HbAbstractItemView::emitActivated(const QModelIndex &modelIndex)
       
  1205 {
       
  1206     emit activated(modelIndex);
       
  1207 }
       
  1208 
       
  1209 /*!
       
  1210     Emits the pressed signal.
       
  1211 */
       
  1212 void HbAbstractItemView::emitPressed(const QModelIndex &modelIndex)
       
  1213 {
       
  1214     emit pressed(modelIndex);
       
  1215 }
       
  1216 
       
  1217 /*!
       
  1218     Emits the released signal.
       
  1219 */
       
  1220 void HbAbstractItemView::emitReleased(const QModelIndex &modelIndex)
       
  1221 {
       
  1222     emit released(modelIndex);
       
  1223 }
       
  1224 
       
  1225 /*!
       
  1226     \deprecated HbAbstractItemView::indexCount() const
       
  1227         is deprecated. Use \a HbModelIterator::indexCount()
       
  1228 
       
  1229     Returns the total model index count that can be traversed with nextIndex and previousIndex functions.
       
  1230 */
       
  1231 int HbAbstractItemView::indexCount() const
       
  1232 {
       
  1233     qWarning("HbAbstractItemView::indexCount() is deprecated! Use HbModelIterator::indexCount().");
       
  1234 
       
  1235     Q_D(const HbAbstractItemView);
       
  1236     return d->mModelIterator->indexCount();
       
  1237 }
       
  1238 
       
  1239 /*!
       
  1240     \deprecated HbAbstractItemView::indexPosition(const QModelIndex &) const
       
  1241         is deprecated. Use \a HbModelIterator::indexPosition(const QModelIndex &) const
       
  1242 
       
  1243     Returns the position of \a index from the first index.
       
  1244 */
       
  1245 int HbAbstractItemView::indexPosition(const QModelIndex &index) const
       
  1246 {
       
  1247     qWarning("HbAbstractItemView::indexPosition(const QModelIndex &) is deprecated! Use HbModelIterator::indexPosition(const QModelIndex &).");
       
  1248 
       
  1249     Q_D(const HbAbstractItemView);
       
  1250     return d->mModelIterator->indexPosition(index);
       
  1251 }
       
  1252 
       
  1253 /*!
       
  1254     \deprecated HbAbstractItemView::nextIndex(const QModelIndex&) const
       
  1255         is deprecated. Use \a HbModelIterator::nextIndex(const QModelIndex&) const
       
  1256 
       
  1257     Returns the next model index from \a index. If QModelIndex() is given as a parameter
       
  1258     this should return the first model index.
       
  1259 
       
  1260     \note Returned QModelIndex() is interpret so that there is no next index from given one.
       
  1261 */
       
  1262 QModelIndex HbAbstractItemView::nextIndex(const QModelIndex &index) const
       
  1263 {
       
  1264     qWarning("HbAbstractItemView::nextIndex(const QModelIndex&) is deprecated! Use HbModelIterator::nextIndex(const QModelIndex&).");
       
  1265 
       
  1266     Q_D(const HbAbstractItemView);
       
  1267     return d->mModelIterator->nextIndex(index);
       
  1268 }
       
  1269 
       
  1270 /*!
       
  1271     \deprecated HbAbstractItemView::previousIndex(const QModelIndex&) const
       
  1272         is deprecated. Use \a HbModelIterator::previousIndex(const QModelIndex&) const
       
  1273 
       
  1274     Returns the previous model index from \a index. If QModelIndex() is given as a parameter
       
  1275     this should return the last model index.
       
  1276 
       
  1277     \note Returned QModelIndex() is interpret so that there is no previous index from given one.
       
  1278 */
       
  1279 QModelIndex HbAbstractItemView::previousIndex(const QModelIndex &index) const
       
  1280 {
       
  1281     qWarning("HbAbstractItemView::previousIndex(const QModelIndex&) is deprecated! Use HbModelIterator::previousIndex(const QModelIndex&).");
       
  1282 
       
  1283     Q_D(const HbAbstractItemView);
       
  1284     return d->mModelIterator->previousIndex(index);
       
  1285 }
       
  1286 
       
  1287 /*!
       
  1288     \reimp
       
  1289 */
       
  1290 bool HbAbstractItemView::scrollByAmount(const QPointF &delta)
       
  1291 {
       
  1292     Q_D(HbAbstractItemView);
       
  1293 
       
  1294     QPointF newDelta(delta);
       
  1295 
       
  1296     if (d->mContainer->itemRecycling()) {
       
  1297         newDelta = d->mContainer->recycleItems(delta);
       
  1298         d->mAnimationInitialPosition = d->mAnimationInitialPosition + newDelta - delta; 
       
  1299         d->refreshContainerGeometry();
       
  1300     }
       
  1301 
       
  1302     return HbScrollArea::scrollByAmount(newDelta);
       
  1303 }
       
  1304 
       
  1305 /*!
       
  1306     Returns the container widget.
       
  1307 */
       
  1308 HbAbstractItemContainer *HbAbstractItemView::container() const
       
  1309 {
       
  1310     Q_D(const HbAbstractItemView);
       
  1311     return d->mContainer;
       
  1312 }
       
  1313 
       
  1314 /*!
       
  1315     \reimp
       
  1316 */
       
  1317 QVariant HbAbstractItemView::itemChange(GraphicsItemChange change, const QVariant &value)
       
  1318 {
       
  1319     if (change == QGraphicsItem::ItemSceneHasChanged) {
       
  1320         HbMainWindow *window = mainWindow();
       
  1321         if (window) { // added to scene
       
  1322             QObject::connect(window, SIGNAL(aboutToChangeOrientation()),
       
  1323                 this, SLOT(orientationAboutToBeChanged()));
       
  1324             QObject::connect(window, SIGNAL(orientationChanged(Qt::Orientation)), 
       
  1325                 this, SLOT(orientationChanged(Qt::Orientation)));
       
  1326 
       
  1327             if (verticalScrollBar()) {
       
  1328                 verticalScrollBar()->installSceneEventFilter(this);
       
  1329             }
       
  1330             if (horizontalScrollBar()) {
       
  1331                 horizontalScrollBar()->installSceneEventFilter(this);
       
  1332             }
       
  1333         }
       
  1334         else { // removed from scene
       
  1335             QObject::disconnect(this, SLOT(orientationAboutToBeChanged()));
       
  1336             QObject::disconnect(this, SLOT(orientationChanged(Qt::Orientation)));
       
  1337 
       
  1338             if (verticalScrollBar()) {
       
  1339                 verticalScrollBar()->removeSceneEventFilter(this);
       
  1340             }
       
  1341             if (horizontalScrollBar()) {
       
  1342                 horizontalScrollBar()->removeSceneEventFilter(this);
       
  1343             }
       
  1344 
       
  1345         }
       
  1346 
       
  1347     }
       
  1348     return HbScrollArea::itemChange(change, value);
       
  1349 }
       
  1350 
       
  1351 /*!
       
  1352     \deprecated HbAbstractItemView::type() const
       
  1353         is deprecated.
       
  1354 
       
  1355     \reimp
       
  1356 */
       
  1357 int HbAbstractItemView::type() const
       
  1358 {
       
  1359     qWarning("HbAbstractItemView::type() const is deprecated!");
       
  1360 
       
  1361     return Type;
       
  1362 }
       
  1363 
       
  1364 /*!
       
  1365     Returns the current name of layout definition of view items of this view
       
  1366 
       
  1367     \sa setLayoutName()
       
  1368  */
       
  1369 QString HbAbstractItemView::layoutName() const
       
  1370 {
       
  1371     Q_D(const HbAbstractItemView);
       
  1372     
       
  1373     return d->mLayoutOptionName;
       
  1374 }
       
  1375 
       
  1376 /*!
       
  1377     Sets the name of layout definition \a layoutName for selecting 
       
  1378     the layout of view items of this view from css/xml files.
       
  1379 
       
  1380     This layoutName is accessible from css file as layoutName property
       
  1381     of the view item.
       
  1382 
       
  1383     This can be used for customization purposes. By default the layout name
       
  1384     is "default".
       
  1385 
       
  1386     \sa layoutOption()
       
  1387  */
       
  1388 void HbAbstractItemView::setLayoutName(const QString &layoutName)
       
  1389 {
       
  1390     Q_D(HbAbstractItemView);
       
  1391     
       
  1392     d->mLayoutOptionName = layoutName;
       
  1393     
       
  1394     QList<HbAbstractViewItem *> items = d->mContainer->items();
       
  1395     foreach (HbAbstractViewItem *item, items) {
       
  1396         QEvent* polishEvent = new QEvent( QEvent::Polish );
       
  1397         QCoreApplication::postEvent(item, polishEvent);
       
  1398     }
       
  1399 } 
       
  1400 
       
  1401 /*!
       
  1402     Sets the property informing whether all items in the item view have the same size.
       
  1403     
       
  1404     This property should only be set to true if it is guaranteed that all items in the view have 
       
  1405     the same size. This enables the view to do some optimizations for performance purposes.
       
  1406 
       
  1407     By default, this property is false.
       
  1408 */
       
  1409 void HbAbstractItemView::setUniformItemSizes(bool enable)
       
  1410 {
       
  1411     Q_D(HbAbstractItemView);
       
  1412     d->mContainer->setUniformItemSizes(enable);
       
  1413 }
       
  1414 
       
  1415 /*!
       
  1416     Returns the current value of the uniformItemsSizes property
       
  1417  */
       
  1418 bool HbAbstractItemView::uniformItemSizes() const
       
  1419 {
       
  1420     Q_D(const HbAbstractItemView);
       
  1421     return d->mContainer->uniformItemSizes();
       
  1422 }
       
  1423 
       
  1424 /*!
       
  1425     Returns pointer to HbModelIterator. It provides functions to work with QModelIndex.
       
  1426 */
       
  1427 HbModelIterator *HbAbstractItemView::modelIterator() const
       
  1428 {
       
  1429     Q_D(const HbAbstractItemView);
       
  1430     return d->mModelIterator;
       
  1431 }
       
  1432 
       
  1433 /*!
       
  1434     Sets the bitmask controlling the item animations. 
       
  1435  */
       
  1436  void HbAbstractItemView::setEnabledAnimations(HbAbstractItemView::ItemAnimations flags)
       
  1437 {
       
  1438     Q_D(HbAbstractItemView);
       
  1439     d->mEnabledAnimations = flags;
       
  1440 }
       
  1441 
       
  1442 /*!
       
  1443     Returns the mask controlling the item animations. 
       
  1444  */
       
  1445 HbAbstractItemView::ItemAnimations HbAbstractItemView::enabledAnimations() const
       
  1446 {
       
  1447     Q_D(const HbAbstractItemView);
       
  1448     return d->mEnabledAnimations;
       
  1449 }
       
  1450 
       
  1451 /*!
       
  1452     \reimp
       
  1453 
       
  1454     Sets the pressed item non-pressed.
       
  1455 */
       
  1456 void HbAbstractItemView::upGesture(int value)
       
  1457 {
       
  1458     Q_D(HbAbstractItemView);
       
  1459 
       
  1460     d->mPostponedScrollIndex = QPersistentModelIndex();
       
  1461 
       
  1462     if (d->mHitItem) {
       
  1463         d->mHitItem->setPressed(false, false);
       
  1464     }
       
  1465 
       
  1466     HbScrollArea::upGesture(value);
       
  1467 }
       
  1468 
       
  1469 /*!
       
  1470     \reimp
       
  1471 
       
  1472     Sets the pressed item non-pressed.
       
  1473 */
       
  1474 void HbAbstractItemView::downGesture(int value)
       
  1475 {
       
  1476     Q_D(HbAbstractItemView);
       
  1477 
       
  1478     d->mPostponedScrollIndex = QPersistentModelIndex();
       
  1479 
       
  1480     if (d->mHitItem) {
       
  1481         d->mHitItem->setPressed(false, false);
       
  1482     }
       
  1483 
       
  1484     HbScrollArea::downGesture(value);
       
  1485 }
       
  1486 
       
  1487 /*!
       
  1488     \reimp
       
  1489 
       
  1490     Sets the pressed item non-pressed.
       
  1491 */
       
  1492 void HbAbstractItemView::leftGesture(int value)
       
  1493 {
       
  1494     Q_D(HbAbstractItemView);
       
  1495 
       
  1496     d->mPostponedScrollIndex = QPersistentModelIndex();
       
  1497 
       
  1498     if (d->mHitItem) {
       
  1499         d->mHitItem->setPressed(false, false);
       
  1500     }
       
  1501 
       
  1502     HbScrollArea::leftGesture(value);
       
  1503 }
       
  1504 
       
  1505 /*!
       
  1506     \reimp
       
  1507 
       
  1508     Sets the pressed item non-pressed.
       
  1509 */
       
  1510 void HbAbstractItemView::rightGesture(int value)
       
  1511 {
       
  1512     Q_D(HbAbstractItemView);
       
  1513 
       
  1514     d->mPostponedScrollIndex = QPersistentModelIndex();
       
  1515 
       
  1516     if (d->mHitItem) {
       
  1517         d->mHitItem->setPressed(false, false);
       
  1518     }
       
  1519 
       
  1520     HbScrollArea::rightGesture(value);
       
  1521 }
       
  1522 
       
  1523 /*!
       
  1524     \reimp
       
  1525 */
       
  1526 bool HbAbstractItemView::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
       
  1527 {
       
  1528     Q_D(HbAbstractItemView);
       
  1529     if (    d->mPostponedScrollIndex.isValid()
       
  1530         &&  event->type() == QEvent::GraphicsSceneMousePress
       
  1531         &&  (   watched == verticalScrollBar()
       
  1532             ||  watched == horizontalScrollBar())) {
       
  1533         d->mPostponedScrollIndex = QPersistentModelIndex();
       
  1534     }
       
  1535     return false;
       
  1536 }
       
  1537 
       
  1538 #include "moc_hbabstractitemview.cpp"
       
  1539 
       
  1540