src/hbwidgets/itemviews/hbtumbleview.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    25 
    25 
    26 #include "hblistview_p.h"
    26 #include "hblistview_p.h"
    27 #include "hblistitemcontainer_p.h"
    27 #include "hblistitemcontainer_p.h"
    28 #include "hblistitemcontainer_p_p.h"
    28 #include "hblistitemcontainer_p_p.h"
    29 #include "hbmodeliterator.h"
    29 #include "hbmodeliterator.h"
       
    30 #include "hbstyleprimitivedata.h"
    30 
    31 
    31 #include <hbtumbleview.h>
    32 #include <hbtumbleview.h>
    32 #include <hbtumbleviewitem.h>
    33 #include <hbtumbleviewitem.h>
    33 #include <hbevent.h>
    34 #include <hbevent.h>
    34 #include <hbstyleoption_p.h>
    35 #include <hbstyleoption_p.h>
       
    36 #include <hbstyleframeprimitivedata.h>
    35 
    37 
    36 #include <QGraphicsSceneMouseEvent>
    38 #include <QGraphicsSceneMouseEvent>
    37 #include <QStringListModel>
    39 #include <QStringListModel>
    38 #include <QItemSelectionModel>
    40 #include <QItemSelectionModel>
    39 #include <QTapGesture>
    41 #include <QTapGesture>
       
    42 
    40 
    43 
    41 #define HB_TUMBLE_ITEM_ANIMATION_TIME 500
    44 #define HB_TUMBLE_ITEM_ANIMATION_TIME 500
    42 #define HB_TUMBLE_PREFERRED_ITEMS 3
    45 #define HB_TUMBLE_PREFERRED_ITEMS 3
    43 
    46 
    44 //#define HBTUMBLE_DEBUG
    47 //#define HBTUMBLE_DEBUG
   111 
   114 
   112     QModelIndex mDelayedSelectIndex;
   115     QModelIndex mDelayedSelectIndex;
   113     QTimer mDelayedSelectTimer;
   116     QTimer mDelayedSelectTimer;
   114 
   117 
   115     //primitives
   118     //primitives
   116     QGraphicsItem   *mBackground;
   119     QGraphicsObject   *mBackground;
   117     QGraphicsItem   *mFrame;//overlay
   120     QGraphicsObject   *mFrame;//overlay
   118     QGraphicsItem   *mHighlight;
   121     QGraphicsObject   *mHighlight;
       
   122     QGraphicsObject   *mDivider;
   119     int             mSelected;
   123     int             mSelected;
   120     bool mNeedScrolling;
   124     bool mNeedScrolling;
   121     QGraphicsItem   *mDivider;
   125     
   122 };
   126 };
   123 
   127 
   124 
   128 
   125 HbTumbleViewItemContainer::HbTumbleViewItemContainer(QGraphicsItem* parent )
   129 HbTumbleViewItemContainer::HbTumbleViewItemContainer(QGraphicsItem* parent )
   126     :HbListItemContainer(*(new HbTumbleViewItemContainerPrivate),parent)
   130     :HbListItemContainer(*(new HbTumbleViewItemContainerPrivate),parent)
   392     ,mDelayedSelectIndex()
   396     ,mDelayedSelectIndex()
   393     ,mDelayedSelectTimer(0)
   397     ,mDelayedSelectTimer(0)
   394     ,mBackground(0)
   398     ,mBackground(0)
   395     ,mFrame(0)
   399     ,mFrame(0)
   396     ,mHighlight(0)
   400     ,mHighlight(0)
       
   401     ,mDivider(0)
   397     ,mSelected(-1)
   402     ,mSelected(-1)
   398     ,mNeedScrolling(true)
   403     ,mNeedScrolling(true) 
   399     ,mDivider(0)
   404     
   400 {
   405 {
   401 }
   406 }
   402 
   407 
   403 qreal HbTumbleViewPrivate::topBoundary()
   408 qreal HbTumbleViewPrivate::topBoundary()
   404 {
   409 {
   570 void HbTumbleViewPrivate::createPrimitives()
   575 void HbTumbleViewPrivate::createPrimitives()
   571 {
   576 {
   572     Q_Q(HbTumbleView);
   577     Q_Q(HbTumbleView);
   573 
   578 
   574     //this is the highlight which is placed at center
   579     //this is the highlight which is placed at center
       
   580     
   575     if(!mHighlight) {
   581     if(!mHighlight) {
   576         mHighlight = q->style()->createPrimitive(HbStyle::P_TumbleView_highlight,q);
   582         mHighlight = q->style()->createPrimitive(HbStyle::PT_FrameItem,"highlight",q);
   577         q->style()->setItemName(mHighlight,"highlight");
   583         }
   578     }
   584     if(!mDivider) {
   579     if(!mDivider){
   585         mDivider = q->style()->createPrimitive(HbStyle::PT_FrameItem,"separator",q);
   580         mDivider = q->style()->createPrimitive(HbStyle::P_DateTimePicker_separator,q);
       
   581         q->style()->setItemName(mDivider,"separator");
       
   582         mDivider->hide();
   586         mDivider->hide();
   583     }
   587         }
   584 
   588     if(!mFrame) {
       
   589         mFrame = q->style()->createPrimitive(HbStyle::PT_FrameItem,"frame",q);
       
   590         }
       
   591     if(!mBackground) {
       
   592         mBackground = q->style()->createPrimitive(HbStyle::PT_FrameItem,"background",q);
       
   593         }
   585 }
   594 }
   586 
   595 
   587 
   596 
   588 void HbTumbleViewPrivate::calculateItemHeight()
   597 void HbTumbleViewPrivate::calculateItemHeight()
   589 {
   598 {
   749     \return current index of the item selected in the tumbler.
   758     \return current index of the item selected in the tumbler.
   750 */
   759 */
   751 int HbTumbleView::selected() const
   760 int HbTumbleView::selected() const
   752 {
   761 {
   753     return currentIndex().row();
   762     return currentIndex().row();
   754 }
       
   755 
       
   756 /*!
       
   757     \deprecated HbTumbleView::primitive(HbStyle::Primitive)
       
   758         is deprecated.
       
   759 
       
   760     \reimp
       
   761 */
       
   762 QGraphicsItem *HbTumbleView::primitive(HbStyle::Primitive id) const
       
   763 {
       
   764     Q_D(const HbTumbleView);
       
   765 
       
   766     switch(id) {
       
   767         case HbStyle::P_TumbleView_background:
       
   768             return d->mBackground;
       
   769         case HbStyle::P_TumbleView_frame:
       
   770             return d->mFrame;
       
   771         case HbStyle::P_TumbleView_highlight:
       
   772             return d->mHighlight;
       
   773         default:
       
   774             return HbListView::primitive(id);
       
   775     }
       
   776 }
       
   777 
       
   778 /*!
       
   779     \reimp
       
   780 */
       
   781 QGraphicsItem *HbTumbleView::primitive(const QString &itemName) const
       
   782 {
       
   783     return HbListView::primitive(itemName);
       
   784 }
   763 }
   785 
   764 
   786 /*!
   765 /*!
   787     \reimp
   766     \reimp
   788 */
   767 */
   804             d->setPressedState(item);
   783             d->setPressedState(item);
   805         } 
   784         } 
   806     }
   785     }
   807 }
   786 }
   808 
   787 
       
   788 void HbTumbleView::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive)
       
   789 {
       
   790     HbWidget::initPrimitiveData(primitiveData, primitive);
       
   791     QString itemName = HbStyle::itemName(primitive);
       
   792     if(itemName == QLatin1String("separator")) {
       
   793         HbStyleFramePrimitiveData *frameItem  = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData);
       
   794         frameItem->frameGraphicsName= QLatin1String("qtg_graf_tumbler_divider");
       
   795         frameItem->frameType = HbFrameDrawer::OnePiece;
       
   796         (const_cast<QGraphicsObject *> (primitive))->setZValue(2);
       
   797         }
       
   798         
       
   799     if(itemName == QLatin1String("highlight")) {
       
   800        HbStyleFramePrimitiveData *frameItem  = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData);
       
   801        frameItem->frameGraphicsName= QLatin1String("qtg_fr_tumbler_highlight_pri");
       
   802        frameItem->frameType = HbFrameDrawer::ThreePiecesHorizontal;
       
   803        (const_cast<QGraphicsObject *> (primitive))->setZValue(-1);
       
   804        }
       
   805 
       
   806     if (itemName == QLatin1String("frame")) {
       
   807         HbStyleFramePrimitiveData *frameItem  = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData);
       
   808         frameItem->frameGraphicsName= QLatin1String("qtg_fr_tumbler_overlay");
       
   809         frameItem->frameType = HbFrameDrawer::NinePieces;
       
   810         (const_cast<QGraphicsObject *> (primitive))->setZValue(-4);
       
   811         }
       
   812 
       
   813     if (itemName == QLatin1String("background")) {
       
   814         HbStyleFramePrimitiveData *frameItem  = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData);
       
   815         frameItem->frameGraphicsName= QLatin1String("qtg_fr_tumbler_bg");
       
   816         frameItem->frameType = HbFrameDrawer::NinePieces;
       
   817         (const_cast<QGraphicsObject *> (primitive))->setZValue(-5);
       
   818         }
       
   819 }
       
   820 
   809 /*!
   821 /*!
   810     \reimp
   822     \reimp
   811 */
   823 */
   812 void HbTumbleView::updatePrimitives()
   824 void HbTumbleView::updatePrimitives()
   813 {                   
   825 {                   
   814     Q_D(HbTumbleView);
   826     Q_D(HbTumbleView);
   815 
   827     HbListView::updatePrimitives();
   816     HbStyleOption opt;
   828     if(d->mBackground){
   817     initStyleOption(&opt);
   829         HbStyleFramePrimitiveData data;
   818 
   830         initPrimitiveData(&data,d->mBackground);
   819     if(d->mBackground) {
   831         style()->updatePrimitive(d->mBackground,&data,this);
   820         style()->updatePrimitive(d->mBackground,HbStyle::P_TumbleView_background,&opt);
   832        }
   821     }
   833 
   822     if(d->mFrame) {
   834     if(d->mFrame) {
   823         style()->updatePrimitive(d->mFrame,HbStyle::P_TumbleView_frame,&opt);
   835         HbStyleFramePrimitiveData data;
   824     } 
   836         initPrimitiveData(&data,d->mFrame);
       
   837         style()->updatePrimitive(d->mFrame,&data,this);
       
   838        }
       
   839 
   825     if(d->mHighlight) {
   840     if(d->mHighlight) {
   826         style()->updatePrimitive(d->mHighlight,HbStyle::P_TumbleView_highlight,&opt);
   841         HbStyleFramePrimitiveData data;
   827     }
   842         initPrimitiveData (&data,d->mHighlight);
   828     if(d->mDivider){
   843         style()->updatePrimitive(d->mHighlight,&data,this);
   829         style()->updatePrimitive(d->mDivider, HbStyle::P_DateTimePicker_separator, &opt);
   844        }
   830     }
   845 
   831     HbListView::updatePrimitives();
   846     if (d->mDivider) {
       
   847         HbStyleFramePrimitiveData data;
       
   848         initPrimitiveData (&data,d->mDivider);
       
   849         style()->updatePrimitive(d->mDivider,&data,this);
       
   850         }
   832 
   851 
   833 }
   852 }
   834 
   853 
   835 /*!
   854 /*!
   836    \reimp
   855    \reimp
  1119         }
  1138         }
  1120     }
  1139     }
  1121     HbListView::gestureEvent(event);
  1140     HbListView::gestureEvent(event);
  1122 }
  1141 }
  1123 
  1142 
       
  1143 QGraphicsItem *HbTumbleView::primitive(const QString &itemName) const
       
  1144 {
       
  1145     Q_D(const HbTumbleView);
       
  1146 
       
  1147     if(!itemName.compare(QString("background"))){
       
  1148         return d->mBackground;
       
  1149     }
       
  1150     if(!itemName.compare(QString("frame"))){
       
  1151         return d->mFrame;
       
  1152     }
       
  1153     if(!itemName.compare(QString("highlight"))){
       
  1154         return d->mHighlight;
       
  1155     }
       
  1156     if(!itemName.compare(QString("separator"))){
       
  1157         return d->mDivider;
       
  1158     }
       
  1159 
       
  1160     return HbListView::primitive(itemName);
       
  1161 }
       
  1162 
       
  1163 
  1124 #include "moc_hbtumbleview.cpp"
  1164 #include "moc_hbtumbleview.cpp"