src/hbwidgets/itemviews/hbindexfeedback_p.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbindexfeedback_p.h"
    26 #include "hbindexfeedback_p.h"
    27 #include "hbindexfeedback.h"
    27 #include "hbindexfeedback.h"
    28 
    28 
       
    29 #include <hbapplication.h>
    29 #include <hbscrollbar.h>
    30 #include <hbscrollbar.h>
    30 #include <hbabstractitemview.h>
    31 #include <hbabstractitemview.h>
    31 #include <hbabstractviewitem.h>
    32 #include <hbabstractviewitem.h>
    32 #include <hbstyle.h>
    33 #include <hbstyle.h>
    33 #include <hbabstractitemcontainer_p.h>
    34 #include <hbabstractitemcontainer_p.h>
    34 #include <hbapplication.h>
    35 #include <hbtextitem.h>
       
    36 #include <hbframeitem.h>
       
    37 #include <hbframedrawer.h>
    35 
    38 
    36 #include <hbeffect.h>
    39 #include <hbeffect.h>
    37 #include <hbeffectinternal_p.h>
    40 #include <hbeffectinternal_p.h>
    38 
    41 
    39 #include <hbstyleoptionindexfeedback_p.h>
    42 #include <hbabstractitemview_p.h>
    40 
    43 
    41 #include <QTimer>
    44 #include <QTimer>
    42 #include <QSize>
    45 #include <QSize>
    43 #include <QGraphicsScene>
    46 #include <QGraphicsScene>
    44 
    47 
   116 {
   119 {
   117     Q_Q( HbIndexFeedback );
   120     Q_Q( HbIndexFeedback );
   118 
   121 
   119     //mItemView = 0; // double check that this is safe.
   122     //mItemView = 0; // double check that this is safe.
   120 
   123 
   121     HbEffect::add(HB_INDEXFEEDBACK_TYPE, "indexfeedback_appear", EFFECT_IFAPPEAR);
       
   122     if (!HbEffect::add(HB_INDEXFEEDBACK_TYPE, "indexfeedback_disappear", EFFECT_IFDISAPPEAR)) {
   124     if (!HbEffect::add(HB_INDEXFEEDBACK_TYPE, "indexfeedback_disappear", EFFECT_IFDISAPPEAR)) {
   123         mDisappearTimer = new QTimer(q);
   125         mDisappearTimer = new QTimer(q);
   124         mDisappearTimer->setSingleShot(true);
   126         mDisappearTimer->setSingleShot(true);
   125         mDisappearTimer->setInterval(INDEX_FEEDBACK_DISAPPEAR_DURATION);
   127         mDisappearTimer->setInterval(INDEX_FEEDBACK_DISAPPEAR_DURATION);
   126         q->connect(mDisappearTimer, SIGNAL(timeout()),
   128         q->connect(mDisappearTimer, SIGNAL(timeout()),
   142 /*
   144 /*
   143     Update the data for, and show the index feedback (if it's not already shown)
   145     Update the data for, and show the index feedback (if it's not already shown)
   144 */
   146 */
   145 void HbIndexFeedbackPrivate::showIndexFeedback()
   147 void HbIndexFeedbackPrivate::showIndexFeedback()
   146 {
   148 {
       
   149     Q_Q( HbIndexFeedback );
   147     if (!mItemView 
   150     if (!mItemView 
   148         || mIndexFeedbackPolicy == HbIndexFeedback::IndexFeedbackNone) {
   151         || mIndexFeedbackPolicy == HbIndexFeedback::IndexFeedbackNone) {
   149         return;
   152         return;
   150     }
   153     }
   151 
   154 
   152     QList <HbAbstractViewItem *> visibleItems = mItemView->visibleItems();
   155     HbAbstractItemViewPrivate *viewPrivate = HbAbstractItemViewPrivate::d_ptr(mItemView);
   153 
   156     QList<HbAbstractViewItem *> items = viewPrivate->mContainer->items();
   154     QModelIndex targetIndex = visibleItems.first()->modelIndex();   
   157     QModelIndex targetIndex;
   155     qreal top = visibleItems.first()->mapToItem(mItemView, 0, 0).y();
   158 
   156     if (top < 0 
   159     const int count(items.count());
   157         && visibleItems.count() > 1) {
   160     for (int i = 0; i < count; ++i) {
   158         targetIndex = visibleItems.at(1)->modelIndex();
   161         HbAbstractViewItem *item = items.at(i);
       
   162         if(viewPrivate->visible(item, true)) {
       
   163             targetIndex = item->modelIndex();
       
   164             break;
       
   165         }
   159     }
   166     }
   160 
   167 
   161     if (targetIndex.isValid()) {
   168     if (targetIndex.isValid()) {
   162         QVariant data = targetIndex.data(Hb::IndexFeedbackRole);
   169         QVariant data = targetIndex.data(Hb::IndexFeedbackRole);
   163         if (data.canConvert<QString>()) {
   170         if (data.canConvert<QString>()) {
   164 
   171 
   165             QString testString = displayText(data);
   172             QString testString = displayText(data);
   166             if (testString != mPopupContent) {
   173             if (testString != mPopupContent) {
   167                 mPopupContent = testString;
   174                 mPopupContent = testString;
   168                 updatePrimitives();
   175                 q->updatePrimitives();
   169             }
   176             }
   170 
   177 
   171             if (mTextItem && mTextItem->opacity() == 0.0) {
   178            if (mTextItem) {
   172                 HbEffect::start(mPopupItemList, HB_INDEXFEEDBACK_TYPE, EFFECT_IFAPPEAR);
   179                 mTextItem->setOpacity(1.0);
   173             }
       
   174             if (mTextItem) {
       
   175                 mTextItem->show();
   180                 mTextItem->show();
   176             }
   181             }
   177 
   182 
   178             if (mPopupItem) {
   183             if (mPopupItem) {
       
   184                 mPopupItem->setOpacity(1.0);
   179                 mPopupItem->show();
   185                 mPopupItem->show();
   180             }
   186             }
   181 
   187 
   182             if (mDisappearTimer) {
   188             if (mDisappearTimer) {
   183                 mDisappearTimer->stop();
   189                 mDisappearTimer->stop();
   222     This is show the index feedback and start the dismissal timer with the
   228     This is show the index feedback and start the dismissal timer with the
   223     press timeout.
   229     press timeout.
   224 */
   230 */
   225 void HbIndexFeedbackPrivate::scrollBarPressed()
   231 void HbIndexFeedbackPrivate::scrollBarPressed()
   226 {
   232 {
       
   233     cancelEffect(EFFECT_IFDISAPPEAR);
   227     showIndexFeedback();
   234     showIndexFeedback();
   228 
   235 
   229     // need to record the scrollbar values    
   236     // need to record the scrollbar values    
   230 
   237 
   231     // TODO::The values are storred here is a work around for a bug in hbscrollbar.
   238     // TODO::The values are storred here is a work around for a bug in hbscrollbar.
   332 {
   339 {
   333     mItemView = 0;
   340     mItemView = 0;
   334 }
   341 }
   335 
   342 
   336 /*
   343 /*
   337     Update the primitives for the index feedback.
   344     Create the primitives for the index feedback.
   338 */
   345 */
   339 void HbIndexFeedbackPrivate::updatePrimitives()
   346 void HbIndexFeedbackPrivate::createPrimitives()
   340 {
   347 {
   341     Q_Q( HbIndexFeedback );
   348     Q_Q( HbIndexFeedback );
   342 
   349 
   343     HbStyleOptionIndexFeedback option;
       
   344     q->initStyleOption(&option);
       
   345     if (mTextItem) {
       
   346         q->style()->updatePrimitive(mTextItem, HbStyle::P_IndexFeedback_popup_text, &option);
       
   347     }
       
   348     if (mPopupItem) {
       
   349         q->style()->updatePrimitive(mPopupItem, HbStyle::P_IndexFeedback_popup_background, &option);
       
   350     }
       
   351 }
       
   352 
       
   353 /*
       
   354     Create the primitives for the index feedback.
       
   355 */
       
   356 void HbIndexFeedbackPrivate::createPrimitives()
       
   357 {
       
   358     Q_Q( HbIndexFeedback );
       
   359 
       
   360     mPopupItemList.clear();
   350     mPopupItemList.clear();
   361 
   351 
   362     if (!mTextItem) {
   352     if (!mTextItem) {
   363         mTextItem = q->style()->createPrimitive(HbStyle::P_IndexFeedback_popup_text, q);
   353         mTextItem = q->style()->createPrimitive(HbStyle::PT_TextItem, QLatin1String("index-text"), q);
       
   354         mTextItem->setZValue(4);
       
   355 
       
   356         HbTextItem *textItem = qobject_cast<HbTextItem*>(mTextItem);
       
   357         if (textItem) {
       
   358             textItem->setAlignment(Qt::AlignCenter);
       
   359             textItem->setTextWrapping(Hb::TextNoWrap);
       
   360         }
       
   361 
   364         mTextItem->hide();
   362         mTextItem->hide();
   365         mPopupItemList.append(mTextItem);
   363         mPopupItemList.append(mTextItem);
   366     }
   364     }
   367 
   365 
   368     if (!mPopupItem) {
   366     if (!mPopupItem) {
   369         mPopupItem = q->style()->createPrimitive(HbStyle::P_IndexFeedback_popup_background, q);
   367         mPopupItem = q->style()->createPrimitive(HbStyle::PT_FrameItem, QLatin1String("index-background"), q);
       
   368         mPopupItem->setZValue(3);
       
   369         HbFrameItem *frameItem = qobject_cast<HbFrameItem*>(mPopupItem);
       
   370         if (frameItem) {
       
   371             HbFrameDrawer &frameDrawer(frameItem->frameDrawer());
       
   372             frameDrawer.setFrameGraphicsName(QLatin1String("qtg_fr_popup_preview"));
       
   373             frameDrawer.setFrameType(HbFrameDrawer::NinePieces);
       
   374 
       
   375             qreal cornerPieceSize = 0;
       
   376             q->style()->parameter(QLatin1String("hb-param-background-popup-preview"),cornerPieceSize);
       
   377             frameDrawer.setBorderWidths(cornerPieceSize, cornerPieceSize, cornerPieceSize, cornerPieceSize);
       
   378         }
       
   379 
   370         mPopupItem->hide();
   380         mPopupItem->hide();
   371         mPopupItemList.append(mPopupItem);
   381         mPopupItemList.append(mPopupItem);
   372     }
   382     }
   373 }
   383 }
   374 
   384 
   551             break;
   561             break;
   552     }
   562     }
   553 
   563 
   554     return retVal;
   564     return retVal;
   555 }
   565 }
       
   566 
       
   567 void HbIndexFeedbackPrivate::cancelEffect(const QString& effect)
       
   568 {
       
   569     int count = mPopupItemList.count();
       
   570     for (int i=0; i<count; i++) {
       
   571         HbEffect::cancel(mPopupItemList.at(i),effect);
       
   572     }
       
   573 }
       
   574