src/hbwidgets/itemviews/hbabstractviewitem.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    30 #include <hbnamespace.h>
    30 #include <hbnamespace.h>
    31 #include <hbstyleoptionabstractviewitem.h>
    31 #include <hbstyleoptionabstractviewitem.h>
    32 #include <hbstyle.h>
    32 #include <hbstyle.h>
    33 #include <hbiconitem.h>
    33 #include <hbiconitem.h>
    34 #include <hbframebackground.h>
    34 #include <hbframebackground.h>
    35 #include <hbtextitem.h>
    35 #include <hbabstractitemview_p.h>
       
    36 #include <hbwidgetfeedback.h>
       
    37 #include <hbtapgesture.h>
    36 
    38 
    37 #include <QPersistentModelIndex>
    39 #include <QPersistentModelIndex>
    38 #include <QGraphicsSceneMouseEvent>
    40 #include <QGraphicsLayout>
    39 #include <QGraphicsLinearLayout>
       
    40 #include <QVariant>
    41 #include <QVariant>
    41 #include <QCoreApplication>
    42 #include <QCoreApplication>
    42 #include <QEvent>
    43 #include <QEvent>
    43 #include <QDebug>
    44 #include <QDebug>
    44 
    45 
       
    46 #include <QGesture>
       
    47 #include <QGestureEvent>
       
    48 
       
    49 #ifdef QMAP_INT__ITEM_STATE_DEPRECATED
       
    50 #define HB_ITEM_STATE_ASSERT Q_ASSERT_X(0, "", "QMap<int,QVariant> based view item state system is deprecated. Use QHash<QString, QVariant> based instead" )
       
    51 #else
       
    52 #define HB_ITEM_STATE_ASSERT
       
    53 #endif
       
    54 
    45 const QString KDefaultLayoutOption = "default";
    55 const QString KDefaultLayoutOption = "default";
    46 const int HbAbstractViewItemShared::ViewItemDeferredDeleteEvent = QEvent::registerEventType();
    56 const int HbAbstractViewItemShared::ViewItemDeferredDeleteEvent = QEvent::registerEventType();
    47 
    57 
    48 /*!
    58 /*!
    49     @alpha
    59     @alpha
    65     
    75     
    66     To support multiple Abstractview items within single AbstractItemview, you must also provide an implementation of canSetModelIndex().
    76     To support multiple Abstractview items within single AbstractItemview, you must also provide an implementation of canSetModelIndex().
    67 
    77 
    68     If derived abstract view item has transient state information that is not meaningful to store within model index (child item cursor 
    78     If derived abstract view item has transient state information that is not meaningful to store within model index (child item cursor 
    69     position selection areas etc.) view item can use abstract views internal state model to store this information. This feature can
    79     position selection areas etc.) view item can use abstract views internal state model to store this information. This feature can
    70     be taken into use by implementing state() and setState() functions in derived class.
    80     be taken into use by implementing transientState() and setTransientState() functions in derived class.
    71 */
    81 */
    72 
    82 
    73 /*!
    83 /*!
       
    84     \deprecated HbAbstractViewItem::StateKey
       
    85         is deprecated. Please use string based state keys.
       
    86 
    74     \enum HbAbstractViewItem::StateKey
    87     \enum HbAbstractViewItem::StateKey
    75 
    88 
    76     HbAbstractViewItem's predefined set of state keys.
    89     HbAbstractViewItem's predefined set of state keys.
    77 
    90 
    78     This enum describes state keys for HbAbstractViewItem state values. State value can be accessed using this key.
    91     This enum describes state keys for HbAbstractViewItem state values. State value can be accessed using this key.
    79 */
    92 
    80 
    93     \sa HbAbstractViewItem::transientState()
    81 /*!
    94 */
       
    95 
       
    96 /*!
       
    97     \deprecated HbAbstractViewItem::FocusKey
       
    98         is deprecated. Please use string based state keys. This key is replaced by "focused".
       
    99 
    82     \var HbAbstractViewItem::FocusKey
   100     \var HbAbstractViewItem::FocusKey
    83          Predefined key for focus state value.
   101          Predefined key for focus state value.
    84 */
   102 */
    85 
   103 
    86 /*!
   104 /*!
       
   105     \deprecated HbAbstractViewItem::CheckStateKey
       
   106         is deprecated. Please use string based state keys. This key is replaced by "checkState".
       
   107 
       
   108     \var HbAbstractViewItem::CheckStateKey
       
   109         Predefined key for check state value. Default value is Qt::Unchecked.
       
   110 */
       
   111 
       
   112 /*!
       
   113     \deprecated HbAbstractViewItem::UserKey
       
   114         is deprecated. Please use string based state keys.
       
   115 
    87     \var HbAbstractViewItem::UserKey
   116     \var HbAbstractViewItem::UserKey
    88          First key that can be used by the derived class for it's own purposes.
   117          First key that can be used by the derived class for it's own purposes.
    89 */
   118 */
    90 
   119 
    91 /*!
   120 /*!
       
   121     \fn void HbAbstractViewItem::pressed(const QPointF &position)
       
   122 
       
   123     This signal is emitted when a touch down event is received for this view item.
       
   124     \a position is position of touch event in view item coordinates.
       
   125 
       
   126     \sa HbAbstractViewItem::released(const QPointF &position)
       
   127     \sa HbAbstractViewItem::activated(const QPointF &position)
       
   128 */
       
   129 
       
   130 /*!
       
   131     \fn void HbAbstractViewItem::released(const QPointF &position)
       
   132 
       
   133     This signal is emitted when a touch release event is received for this view item.
       
   134     \a position is position of touch event in view item coordinates.
       
   135 
       
   136     \sa HbAbstractViewItem::pressed(const QPointF &position)
       
   137     \sa HbAbstractViewItem::activated(const QPointF &position)
       
   138 */
       
   139 
       
   140 /*!
       
   141     \fn void HbAbstractViewItem::activated(const QPointF &position)
       
   142 
       
   143     This signal is emitted when view item is activated by the user.
       
   144     How to activate items depends on the input method; e.g., with mouse by clicking the item
       
   145     or with touch input by tapping the item.
       
   146     \a position is position of touch event in view item coordinates.
       
   147 
       
   148     \sa HbAbstractViewItem::pressed(const QPointF &position)
       
   149     \sa HbAbstractViewItem::released(const QPointF &position)
       
   150 */
       
   151 
       
   152 /*!
       
   153     \fn void HbAbstractViewItem::longPressed(const QPointF &position)
       
   154 
       
   155     This signal is emitted when long press event is received for this view item and long press is enabled in itemview.
       
   156     \a position is position of touch event in view item coordinates.
       
   157 
       
   158     \sa HbAbstractItemView::longPressEnabled()
       
   159 */
       
   160 
       
   161 
       
   162 /*!
    92     \fn HbAbstractViewItem::createItem 
   163     \fn HbAbstractViewItem::createItem 
    93 
   164 
    94     Creates a new item. 
   165     Creates a new item. 
    95 
   166 
    96     In most subclasses, createItem should be implemented like this:
   167     In most subclasses, createItem should be implemented like this:
    97 
   168 
    98     \snippet{ultimatecodesnippet/customlistviewitem.cpp,1}
   169     \snippet{ultimatecodesnippet/customlistviewitem.cpp,1}
    99 */
   170 */
   100 
       
   101 
   171 
   102 void HbAbstractViewItemPrivate::init()
   172 void HbAbstractViewItemPrivate::init()
   103 {
   173 {
   104     Q_Q(HbAbstractViewItem);
   174     Q_Q(HbAbstractViewItem);
   105 
   175 
   106     q->setProperty("state", "normal");
   176     q->setProperty("state", "normal");
   107 
   177 
   108     if (isPrototype()) {
   178     if (isPrototype()) {
   109         q->setFocusPolicy(Qt::ClickFocus);
   179         q->setFocusPolicy(Qt::ClickFocus);
   110     } else {
   180     } else {
       
   181         q->grabGesture(Qt::TapGesture);
   111         QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
   182         QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
   112         itemFlags |= QGraphicsItem::ItemIsFocusable;
   183         itemFlags |= QGraphicsItem::ItemIsFocusable;
   113         q->setFlags(itemFlags);
   184         q->setFlags(itemFlags);
   114 
   185 
   115         q->setFocusPolicy(mSharedData->mPrototype->focusPolicy());
   186         q->setFocusPolicy(mSharedData->mPrototype->focusPolicy());
   139     for (int i = 0; i < count; ++i) {
   210     for (int i = 0; i < count; ++i) {
   140         mSharedData->mCloneItems.at(i)->repolish();
   211         mSharedData->mCloneItems.at(i)->repolish();
   141     }
   212     }
   142 }
   213 }
   143 
   214 
   144 void HbAbstractViewItemPrivate::updateCloneItems()
   215 void HbAbstractViewItemPrivate::updateCloneItems(bool updateChildItems)
   145 {
   216 {
   146     int count(mSharedData->mCloneItems.count());
   217     int count(mSharedData->mCloneItems.count());
   147     for (int i = 0; i < count; ++i) {
   218     for (int i = 0; i < count; ++i) {
   148         mSharedData->mCloneItems.at(i)->updatePrimitives();
   219         if (updateChildItems) {
       
   220             mSharedData->mCloneItems.at(i)->updateChildItems();
       
   221         } else {
       
   222             mSharedData->mCloneItems.at(i)->updatePrimitives();
       
   223         }
   149     }
   224     }
   150 }
   225 }
   151 
   226 
   152 void HbAbstractViewItemPrivate::setInsidePopup(bool insidePopup)
   227 void HbAbstractViewItemPrivate::setInsidePopup(bool insidePopup)
   153 {
   228 {
   156     HbWidgetPrivate::setInsidePopup(insidePopup);
   231     HbWidgetPrivate::setInsidePopup(insidePopup);
   157     if (q) {
   232     if (q) {
   158         themingPending = true;
   233         themingPending = true;
   159         q->updatePrimitives();
   234         q->updatePrimitives();
   160         q->repolish();
   235         q->repolish();
       
   236     }
       
   237 }
       
   238 
       
   239 void HbAbstractViewItemPrivate::tapTriggered(QGestureEvent *event)
       
   240 {
       
   241     Q_Q(HbAbstractViewItem);
       
   242 
       
   243     HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
       
   244     QPointF position = event->mapToGraphicsScene(gesture->hotSpot());
       
   245     position = q->mapFromScene(position);
       
   246 
       
   247     switch (gesture->state()) {
       
   248         case Qt::GestureStarted: {
       
   249             HbWidgetFeedback::triggered(q, Hb::InstantPressed, 0);
       
   250             q->setPressed(true);
       
   251             emit q->pressed(position);
       
   252 
       
   253             break;
       
   254         }
       
   255         case Qt::GestureUpdated: {
       
   256             if (gesture->tapStyleHint() == HbTapGesture::TapAndHold 
       
   257                 && mSharedData->mItemView
       
   258                 && mSharedData->mItemView->longPressEnabled()) {
       
   259                 q->setPressed(false);
       
   260                 emit q->longPressed(position);
       
   261                 revealItem();
       
   262             }
       
   263             break;
       
   264         }
       
   265         case Qt::GestureFinished: {
       
   266             HbWidgetFeedback::triggered(q, Hb::InstantReleased, 0);
       
   267 
       
   268             if (gesture->tapStyleHint() == HbTapGesture::Tap 
       
   269 			    || (mSharedData->mItemView
       
   270                 && !mSharedData->mItemView->longPressEnabled())) {
       
   271                 q->setPressed(false);
       
   272 
       
   273                 HbWidgetFeedback::triggered(q, Hb::InstantClicked);
       
   274                 emit q->activated(position);
       
   275                 emit q->released(position);
       
   276                 revealItem();
       
   277             } else {
       
   278                 emit q->released(position);
       
   279             }
       
   280 
       
   281             break;
       
   282         }
       
   283         case Qt::GestureCanceled: {
       
   284             HbWidgetFeedback::triggered(q, Hb::InstantReleased, 0);
       
   285 
       
   286             // hides focus immediately
       
   287             q->setPressed(false, false);
       
   288 
       
   289             emit q->released(position);
       
   290             break;
       
   291         }
       
   292         default:
       
   293             break;
       
   294     }
       
   295 
       
   296     event->accept();
       
   297 }
       
   298 
       
   299 void HbAbstractViewItemPrivate::revealItem()
       
   300 {
       
   301     Q_Q(HbAbstractViewItem);
       
   302 
       
   303     if (mSharedData->mItemView) {
       
   304         static_cast<HbAbstractItemViewPrivate *>(mSharedData->mItemView->d_func())->revealItem(q, HbAbstractItemView::EnsureVisible);
   161     }
   305     }
   162 }
   306 }
   163 
   307 
   164 /*!
   308 /*!
   165     Constructs an abstract view item with the given parent.
   309     Constructs an abstract view item with the given parent.
   267 void HbAbstractViewItem::setModelIndex(const QModelIndex &index)
   411 void HbAbstractViewItem::setModelIndex(const QModelIndex &index)
   268 {
   412 {
   269     Q_D( HbAbstractViewItem );
   413     Q_D( HbAbstractViewItem );
   270     if (d->mIndex != index) {
   414     if (d->mIndex != index) {
   271         d->mIndex = index;
   415         d->mIndex = index;
       
   416 
   272         updateChildItems();
   417         updateChildItems();
   273     }
   418     }
   274 }
   419 }
   275 
   420 
   276 /*!
   421 /*!
   318 /*!
   463 /*!
   319     Returns the saved item's transient state. Transient state can be seen as a state data that is 
   464     Returns the saved item's transient state. Transient state can be seen as a state data that is 
   320     wanted to be preserved but it not meaningful to be stored inside model index because of it's
   465     wanted to be preserved but it not meaningful to be stored inside model index because of it's
   321     momentary nature. States will be saved inside AbstractItemview and restored when current model index is
   466     momentary nature. States will be saved inside AbstractItemview and restored when current model index is
   322     assigned to certain Abstract view item.
   467     assigned to certain Abstract view item.
       
   468 
       
   469     String in the returned table is usually name of a Qt property.
       
   470     Default values of properties should not be added into returned table.
       
   471 
       
   472     Derived class should first call base class implementation. After that it adds its own
       
   473     state items into returned table.
       
   474 */
       
   475 QHash<QString, QVariant> HbAbstractViewItem::transientState() const
       
   476 {
       
   477     Q_D( const HbAbstractViewItem );
       
   478     QHash<QString,QVariant> state;
       
   479     
       
   480     if (d->mFocused) {
       
   481         state.insert("focused", d->mFocused);
       
   482     }
       
   483     if (d->mCheckState != Qt::Unchecked) {
       
   484         state.insert("checkState", d->mCheckState);
       
   485     }
       
   486 
       
   487     return state;
       
   488 }
       
   489 
       
   490 /*!
       
   491     Sets the item's transient state using given \a state data.
       
   492 */
       
   493 void HbAbstractViewItem::setTransientState(const QHash<QString, QVariant> &state)
       
   494 {
       
   495     Q_D( HbAbstractViewItem );
       
   496     d->mFocused = state.value("focused").toBool();
       
   497     d->mCheckState = (Qt::CheckState)state.value("checkState").toInt();
       
   498 }
       
   499 
       
   500 
       
   501 /*!
       
   502      \deprecated HbAbstractViewItem::state() const
       
   503         is deprecated. Please use HbAbstractViewItem::transientState() instead. 
       
   504 
       
   505     Returns the saved item's transient state. Transient state can be seen as a state data that is 
       
   506     wanted to be preserved but it not meaningful to be stored inside model index because of it's
       
   507     momentary nature. States will be saved inside AbstractItemview and restored when current model index is
       
   508     assigned to certain Abstract view item.
   323 */
   509 */
   324 QMap<int,QVariant> HbAbstractViewItem::state() const
   510 QMap<int,QVariant> HbAbstractViewItem::state() const
   325 {
   511 {
       
   512     qWarning("HbAbstractViewItem::state() const is deprecated");
       
   513     HB_ITEM_STATE_ASSERT;
   326     Q_D( const HbAbstractViewItem );
   514     Q_D( const HbAbstractViewItem );
   327     QMap<int,QVariant> state;
   515     QMap<int,QVariant> state;
   328 
   516 
   329     state.insert(FocusKey, d->mFocused);
   517     state.insert(FocusKey, d->mFocused);
   330     state.insert(CheckStateKey, d->mCheckState);
   518     state.insert(CheckStateKey, d->mCheckState);
   331 
   519 
   332     return state;
   520     return state;
   333 }
   521 }
   334 
   522 
   335 /*!
   523 /*!
       
   524      \deprecated HbAbstractViewItem::setState(const QMap<int,QVariant> &)
       
   525         is deprecated. Please use HbAbstractViewItem::setTransientState(const QHash<QString, QVariant> &state) instead. 
       
   526 
   336     Restores the item's transient state using given \a state data.
   527     Restores the item's transient state using given \a state data.
   337 */
   528 */
   338 void HbAbstractViewItem::setState(const QMap<int,QVariant> &state)
   529 void HbAbstractViewItem::setState(const QMap<int,QVariant> &state)
   339 {
   530 {
       
   531     qWarning("HbAbstractViewItem::setState(const QMap<int,QVariant> &state) is deprecated");
       
   532     HB_ITEM_STATE_ASSERT;
   340     Q_D( HbAbstractViewItem );
   533     Q_D( HbAbstractViewItem );
   341     if (state.contains(FocusKey)) {
   534     if (state.contains(FocusKey)) {
   342         d->mFocused = state.value(FocusKey).toBool();
   535         d->mFocused = state.value(FocusKey).toBool();
   343     } else {
   536     } else {
   344         d->mFocused = false; 
   537         d->mFocused = false; 
   411 
   604 
   412     option->insidePopup = testAttribute(Hb::InsidePopup);
   605     option->insidePopup = testAttribute(Hb::InsidePopup);
   413 }
   606 }
   414 
   607 
   415 /*!
   608 /*!
   416     Check whether \a scenePosition of pressed down is inside selection area of view item in current selection mode.
   609     Check whether \a position is inside the selection area of the given selectionAreaType in the view item.
   417 
   610 
   418     Default selection areas are for
   611     Default selection areas are for
   419     \li HbAbstractItemView::SingleSelection mode: whole item
   612     \li HbAbstractViewItem::SingleSelection mode: whole item
   420     \li HbAbstractItemView::MultiSelection mode: touch area of selection icon. 
   613     \li HbAbstractViewItem::MultiSelection mode: whole item.
   421         Touch are is represented by primitive HbStyle::P_ItemViewItem_touchmultiselection.
   614     \li HbAbstractItemView::ContiguousSelection mode: whole item. (Note: HbAbstractItemView::ContiguousSelection is deprecated.)
   422     \li HbAbstractItemView::ContiguousSelection mode: touch area of selection icon. 
       
   423         Touch are is represented by primitive HbStyle::P_ItemViewItem_touchmultiselection.
       
   424     \li HbAbstractItemView::NoSelection mode: none
   615     \li HbAbstractItemView::NoSelection mode: none
   425 */
   616 
   426 bool HbAbstractViewItem::selectionAreaContains(const QPointF &scenePosition) const
   617     The \a selectionAreaType tells what kind of selection area is requested.  The parameter value ContiguousSelection returns 
   427 {
   618 	the area where mouse movement will extend the selection to new items. By default this contiguous selection area is 
   428     HB_SDD(const HbAbstractViewItem);
   619 	the HbStyle::P_ItemViewItem_touchmultiselection.
       
   620     
       
   621 */
       
   622 bool HbAbstractViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const
       
   623 {
       
   624     Q_D(const HbAbstractViewItem);
   429     bool contains = false;
   625     bool contains = false;
   430     if (sd->mItemView) {
   626     if (selectionAreaType == ContiguousSelection) {
   431         switch (sd->mItemView->selectionMode()) {
   627         if(     d->mMultiSelectionTouchArea 
   432             case HbAbstractItemView::SingleSelection: 
   628             &&  !d->mMultiSelectionTouchArea->boundingRect().isEmpty()) {
       
   629                 contains = d->mMultiSelectionTouchArea->boundingRect().contains(mapToItem(d->mMultiSelectionTouchArea, position));
       
   630             } else if (d->mSelectionItem) {
       
   631                 contains = d->mSelectionItem->boundingRect().contains(mapToItem(d->mMultiSelectionTouchArea, position));
       
   632             }
       
   633     } else {
       
   634         switch (selectionAreaType) {
       
   635             case SingleSelection: 
       
   636             case MultiSelection: 
       
   637             case ContiguousSelection: 
   433                 contains = true;
   638                 contains = true;
   434                 break;
   639                 break;
   435             case HbAbstractItemView::MultiSelection: 
       
   436                 // fall through
       
   437             case HbAbstractItemView::ContiguousSelection: {
       
   438                 // TODO: put assert back in action, when official layouts in use
       
   439                 /*Q_ASSERT_X(     d->mMultiSelectionTouchArea 
       
   440                             &&  d->mMultiSelectionTouchArea->boundingRect().size().width() > 0 
       
   441                             &&  d->mMultiSelectionTouchArea->boundingRect().size().height() > 0, "", "HbAbstractViewItem::selectionAreaContains(): d->mMultiSelectionTouchArea should exist");
       
   442                 */
       
   443                 if(     d->mMultiSelectionTouchArea 
       
   444                     &&  d->mMultiSelectionTouchArea->boundingRect().size().width() > 0 
       
   445                     &&  d->mMultiSelectionTouchArea->boundingRect().size().height() > 0) {
       
   446                     contains = d->mMultiSelectionTouchArea->boundingRect().contains(
       
   447                                     d->mMultiSelectionTouchArea->mapFromScene(scenePosition));
       
   448                 } else {
       
   449                     contains = d->mSelectionItem->boundingRect().contains(
       
   450                                     d->mSelectionItem->mapFromScene(scenePosition));
       
   451                 }
       
   452                 break;
       
   453             }
       
   454             default:
   640             default:
   455                 break;
   641                 break;
   456         }
   642         }
   457     }
   643     }
   458     return contains;
   644     return contains;
   471                 if (d->mBackgroundItem || d->mFrame || d->mFocusItem) {
   657                 if (d->mBackgroundItem || d->mFrame || d->mFocusItem) {
   472                     HbStyleOptionAbstractViewItem styleOption;
   658                     HbStyleOptionAbstractViewItem styleOption;
   473                     initStyleOption(&styleOption);
   659                     initStyleOption(&styleOption);
   474                     if (d->mFocusItem) {
   660                     if (d->mFocusItem) {
   475                         style()->updatePrimitive(d->mFocusItem, HbStyle::P_ItemViewItem_focus, &styleOption);
   661                         style()->updatePrimitive(d->mFocusItem, HbStyle::P_ItemViewItem_focus, &styleOption);
       
   662                     }
       
   663 
       
   664                     if (d->mFrame) {
       
   665                         style()->updatePrimitive(d->mFrame, HbStyle::P_ItemViewItem_frame, &styleOption);
       
   666                     }
       
   667 
       
   668                     if (d->mBackgroundItem) {
       
   669                         style()->updatePrimitive(d->mBackgroundItem, HbStyle::P_ItemViewItem_background, &styleOption);
   476                     }
   670                     }
   477                 }
   671                 }
   478                 break;
   672                 break;
   479             }
   673             }
   480             case QEvent::LayoutDirectionChange: {
   674             case QEvent::LayoutDirectionChange: {
   497 
   691 
   498     return false;
   692     return false;
   499 }
   693 }
   500 
   694 
   501 /*!
   695 /*!
       
   696     \reimp
       
   697 
       
   698     Invalidates parent layout when ItemTransformHasChanged is received.
       
   699 */
       
   700 QVariant HbAbstractViewItem::itemChange(GraphicsItemChange change, const QVariant &value)
       
   701 {
       
   702     switch (change) {
       
   703         case ItemTransformHasChanged: {
       
   704             QGraphicsLayoutItem *parentLayoutItem = this->parentLayoutItem();
       
   705             if (parentLayoutItem && parentLayoutItem->isLayout()) {
       
   706                 QGraphicsLayout *parentLayout = static_cast<QGraphicsLayout *>(parentLayoutItem);
       
   707                 parentLayout->invalidate();
       
   708             }
       
   709             break;
       
   710         }
       
   711         default:
       
   712             break;
       
   713     }
       
   714 
       
   715     return HbWidget::itemChange(change, value);
       
   716 }
       
   717 
       
   718 /*!
       
   719 
       
   720     \deprecated HbAbstractViewItem::primitive(HbStyle::Primitive)
       
   721        is deprecated.
       
   722 
   502   Provides access to primitives of HbAbstractViewItem.
   723   Provides access to primitives of HbAbstractViewItem.
   503   \param primitive is the type of the requested primitive. The available primitives are 
   724   \param primitive is the type of the requested primitive. The available primitives are 
   504   \c P_ItemViewItem_background
   725   \c P_ItemViewItem_background
   505   \c P_ItemViewItem_frame
   726   \c P_ItemViewItem_frame
   506   \c P_ItemViewItem_selection
   727   \c P_ItemViewItem_selection
   623         d->mModelItemType = itemType;
   844         d->mModelItemType = itemType;
   624         d->mItemsChanged = true;
   845         d->mItemsChanged = true;
   625         d->themingPending = true;
   846         d->themingPending = true;
   626     }
   847     }
   627 
   848 
       
   849     /* Summary of background and frame handling:
       
   850          d->mBackground is read from Qt::BackgroundRole of model
       
   851          d->mBackgroundItem is created from d-mBackground (Qt::BackgroundRole), if this is HbIcon or QBrush.
       
   852 
       
   853          If d->mBackgroundItem does not exist, d->mFrame is created from d-mBackground (Qt::BackgroundRole), 
       
   854          if this is HbFrameBackground otherwise it either is created from sd->mDefaultFrame, 
       
   855          not created at all or from system default.
       
   856     */
       
   857  
   628     // background
   858     // background
   629     QVariant currentBackground = d->mIndex.data(Qt::BackgroundRole);
   859     QVariant currentBackground = d->mIndex.data(Qt::BackgroundRole);
   630     if (currentBackground != d->mBackground) {
   860     if (currentBackground != d->mBackground) {
   631         d->mBackground = currentBackground;
   861         d->mBackground = currentBackground;
   632         if (currentBackground.canConvert<HbIcon>() 
   862         if (currentBackground.canConvert<HbIcon>() 
   633             || currentBackground.canConvert<QBrush>()) {
   863             || currentBackground.canConvert<QBrush>()) {
   634             if (!d->mBackgroundItem) {  
   864             if (!d->mBackgroundItem) {  
   635                 d->mItemsChanged = true;
   865                 d->mItemsChanged = true;
   636                 d->mBackgroundItem = style()->createPrimitive(HbStyle::P_ItemViewItem_background, this);
   866                 d->mBackgroundItem = style()->createPrimitive(HbStyle::P_ItemViewItem_background, this);
       
   867                 delete d->mFrame;
       
   868                 d->mFrame = 0;
   637             }
   869             }
   638         } 
   870         } else if (currentBackground.canConvert<HbFrameBackground>()) {
   639         else if (currentBackground.canConvert<HbFrameBackground>()) {
   871             if (!d->mFrame) {
       
   872                 d->mItemsChanged = true;
       
   873                 d->mFrame = style()->createPrimitive(HbStyle::P_ItemViewItem_frame, this);
       
   874                 delete d->mBackgroundItem;
       
   875                 d->mBackgroundItem = 0;
       
   876             }
       
   877         } else if (d->mBackgroundItem) {
       
   878             d->mItemsChanged = true;
       
   879             delete d->mBackgroundItem;
       
   880             d->mBackgroundItem = 0;
       
   881         }
       
   882     }
       
   883 
       
   884     // frame
       
   885     if (!d->mBackgroundItem) {
       
   886         if (    d->mModelItemType == Hb::ParentItem
       
   887             ||  d->mModelItemType == Hb::SeparatorItem
       
   888             ||  (   d->mModelItemType == Hb::StandardItem
       
   889                 &&  (   d->mBackground.canConvert<HbFrameBackground>()
       
   890                     ||  sd->mDefaultFrame.frameGraphicsName().length() > 0    
       
   891                     ||  sd->mDefaultFrame.isNull()))) { 
   640             if (!d->mFrame) {
   892             if (!d->mFrame) {
   641                 d->mItemsChanged = true;
   893                 d->mItemsChanged = true;
   642                 d->mFrame = style()->createPrimitive(HbStyle::P_ItemViewItem_frame, this);
   894                 d->mFrame = style()->createPrimitive(HbStyle::P_ItemViewItem_frame, this);
   643             }
   895             }
   644             if (d->mBackgroundItem) {
   896         } else if (d->mFrame) {
   645                 d->mItemsChanged = true;
   897             d->mItemsChanged = true;
   646                 delete d->mBackgroundItem;
   898             delete d->mFrame;
   647                 d->mBackgroundItem = 0;
   899             d->mFrame = 0;
   648             }
   900         }
   649         }
   901     } 
   650         else {
       
   651             if (d->mBackgroundItem) {
       
   652                 d->mItemsChanged = true;
       
   653                 delete d->mBackgroundItem;
       
   654                 d->mBackgroundItem = 0;
       
   655             }
       
   656         }
       
   657     }
       
   658     
       
   659     if (!d->mFrame) { // frame should always exists
       
   660         d->mItemsChanged = true;
       
   661         d->mFrame = style()->createPrimitive(HbStyle::P_ItemViewItem_frame, this);
       
   662     }
       
   663 
   902 
   664     GraphicsItemFlags itemFlags = flags();
   903     GraphicsItemFlags itemFlags = flags();
   665     Qt::ItemFlags indexFlags = d->mIndex.flags();
   904     Qt::ItemFlags indexFlags = d->mIndex.flags();
   666 
   905 
   667     if (indexFlags & Qt::ItemIsEnabled) {
   906     if (indexFlags & Qt::ItemIsEnabled) {
   668         if (!(itemFlags & QGraphicsItem::ItemIsFocusable)) {
   907         if (!(itemFlags & QGraphicsItem::ItemIsFocusable)) {
   669             itemFlags |= QGraphicsItem::ItemIsFocusable;
   908             itemFlags |= QGraphicsItem::ItemIsFocusable;
   670             setFocusPolicy(sd->mPrototype->focusPolicy());
   909             setFocusPolicy(sd->mPrototype->focusPolicy());
   671             setProperty("state", "normal");
   910             setProperty("state", "normal");
       
   911         grabGesture(Qt::TapGesture);
   672         }
   912         }
   673     } else {
   913     } else {
   674         if (itemFlags & QGraphicsItem::ItemIsFocusable) {
   914         if (itemFlags & QGraphicsItem::ItemIsFocusable) {
   675             itemFlags &= ~QGraphicsItem::ItemIsFocusable;
   915             itemFlags &= ~QGraphicsItem::ItemIsFocusable;
   676             setFocusPolicy(Qt::NoFocus);
   916             setFocusPolicy(Qt::NoFocus);
   677             setProperty("state", "disabled");
   917             setProperty("state", "disabled");
       
   918         ungrabGesture(Qt::TapGesture);
   678         }
   919         }
   679     }
   920     }
   680 
   921 
   681     // selection
   922     // selection
   682     HbAbstractItemView::SelectionMode selectionMode = HbAbstractItemView::NoSelection;
   923     HbAbstractItemView::SelectionMode selectionMode = HbAbstractItemView::NoSelection;
   832             HbEffect::cancel(d->mFocusItem, "pressed");
  1073             HbEffect::cancel(d->mFocusItem, "pressed");
   833 
  1074 
   834             HbEffect::start(this, sd->mItemType, "released");
  1075             HbEffect::start(this, sd->mItemType, "released");
   835             HbEffect::start(d->mFocusItem, sd->mItemType + QString("-focus"), "released", this, "_q_animationFinished");
  1076             HbEffect::start(d->mFocusItem, sd->mItemType + QString("-focus"), "released", this, "_q_animationFinished");
   836         } else {
  1077         } else {
   837             QCoreApplication::postEvent(this, new QEvent((QEvent::Type)HbAbstractViewItemShared::ViewItemDeferredDeleteEvent));
  1078             HbEffect::cancel(this, "pressed");
       
  1079             HbEffect::start(this, sd->mItemType, "released");
       
  1080             if (d->mFocusItem) {
       
  1081                 HbEffect::cancel(d->mFocusItem, "pressed");
       
  1082                 HbEffect::start(d->mFocusItem, sd->mItemType + QString("-focus"), "released", this, "_q_animationFinished");
       
  1083                 QCoreApplication::postEvent(this, new QEvent((QEvent::Type)HbAbstractViewItemShared::ViewItemDeferredDeleteEvent));
       
  1084             }
   838         }
  1085         }
   839     }
  1086     }
   840 }
  1087 }
   841 
  1088 
   842 /*!
  1089 /*!
   898             qgraphicsitem_cast<HbIconItem *>(static_cast<QGraphicsWidget*>(d->mBackgroundItem))->setBrush(d->mBackground.value<QBrush>());
  1145             qgraphicsitem_cast<HbIconItem *>(static_cast<QGraphicsWidget*>(d->mBackgroundItem))->setBrush(d->mBackground.value<QBrush>());
   899         } 
  1146         } 
   900     }
  1147     }
   901 }
  1148 }
   902 
  1149 
   903 
       
   904 /*!
       
   905     \reimp
       
   906 
       
   907     The default implementation ignores all mouse press events.
       
   908 */
       
   909 void HbAbstractViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
  1150 void HbAbstractViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
   910 {
  1151 {
   911     event->ignore();
  1152     HbWidget::mousePressEvent(event);
   912 }
  1153 }
   913 
  1154 
   914 /*!
       
   915     \reimp
       
   916 
       
   917     The default implementation ignores all mouse move events.
       
   918 */
       
   919 void HbAbstractViewItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  1155 void HbAbstractViewItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
   920 {
  1156 {
   921     event->ignore();
  1157     HbWidget::mouseMoveEvent(event);
   922 }
  1158 }
   923 
  1159 
   924 /*!
       
   925     \reimp
       
   926 
       
   927     The default implementation ignores all mouse release events.
       
   928 */
       
   929 void HbAbstractViewItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  1160 void HbAbstractViewItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   930 {
  1161 {
   931     event->ignore();
  1162     HbWidget::mouseReleaseEvent(event);
   932 }
  1163 }
   933 
  1164 
   934 /*!
  1165 /*!
   935     \reimp
  1166     \reimp
   936 */
  1167 */
   953 }
  1184 }
   954 
  1185 
   955 /*!
  1186 /*!
   956     Sets the default frame for standard view items as \a frame.  
  1187     Sets the default frame for standard view items as \a frame.  
   957     
  1188     
   958     This method will change the used frame for
  1189     This method will change the used frame for all view items that represent model index with Hb::StandardItem type.
   959     all view items that represent model index with Hb::StandardItem type.
  1190 
   960 
  1191     Input parameter with empty but non-null graphicsName string will remove the default frame.
   961     Input parameter with empty graphicsName string will remove the frame.
  1192     Input parameter with null graphicsName string will restore the system default frame.
   962     Input parameter with null graphicsName string will restore the default frame.
  1193 
       
  1194     This method has not immediate effect, if Qt::BackgroundRole includes HbFrameBackground object. Qt::BackgroundRole of model
       
  1195     has higher priority than any other frame type.
       
  1196 
       
  1197     Default frame is system default frame.
   963 
  1198 
   964     \sa defaultFrame
  1199     \sa defaultFrame
   965 */
  1200 */
   966 void HbAbstractViewItem::setDefaultFrame(const HbFrameBackground &frame)
  1201 void HbAbstractViewItem::setDefaultFrame(const HbFrameBackground &frame)
   967 {
  1202 {
   969     if (sd->mDefaultFrame != frame) {
  1204     if (sd->mDefaultFrame != frame) {
   970         sd->mDefaultFrame = frame;
  1205         sd->mDefaultFrame = frame;
   971         
  1206         
   972         int count(sd->mCloneItems.count());
  1207         int count(sd->mCloneItems.count());
   973         for (int i = 0; i < count; ++i) {
  1208         for (int i = 0; i < count; ++i) {
   974             sd->mCloneItems.at(i)->updatePrimitives();
  1209             sd->mCloneItems.at(i)->updateChildItems();
   975         }
  1210         }
   976     }
  1211     }
   977 }
  1212 }
   978 
  1213 
   979 /*!
  1214 /*!
   985 {
  1220 {
   986     HB_SDD(const HbAbstractViewItem);
  1221     HB_SDD(const HbAbstractViewItem);
   987     return sd->mDefaultFrame;
  1222     return sd->mDefaultFrame;
   988 }
  1223 }
   989 
  1224 
       
  1225 /*!
       
  1226     \reimp
       
  1227 */
       
  1228 void HbAbstractViewItem::gestureEvent(QGestureEvent *event)
       
  1229 {
       
  1230     if (event->gesture(Qt::TapGesture)) {
       
  1231         Q_D(HbAbstractViewItem);
       
  1232         d->tapTriggered(event);
       
  1233     } else {
       
  1234         HbWidget::gestureEvent(event);
       
  1235     }
       
  1236 }
       
  1237 
   990 
  1238 
   991 #include "moc_hbabstractviewitem.cpp"
  1239 #include "moc_hbabstractviewitem.cpp"
   992 
  1240