src/hbwidgets/itemviews/hbindexfeedback.cpp
changeset 30 80e4d18b72f5
parent 7 923ff622b8b9
equal deleted inserted replaced
28:b7da29130b0e 30:80e4d18b72f5
    27 #include "hbindexfeedback_p.h"
    27 #include "hbindexfeedback_p.h"
    28 
    28 
    29 #include "hbabstractitemview.h"
    29 #include "hbabstractitemview.h"
    30 
    30 
    31 #include <hbscrollbar.h>
    31 #include <hbscrollbar.h>
    32 #include <hbstyleoptionindexfeedback_p.h>
    32 #include <hbframeitem.h>
       
    33 #include <hbtextitem.h>
    33 #include <hbstyleparameters.h>
    34 #include <hbstyleparameters.h>
    34 #include <hbstyle.h>
    35 #include <hbstyle.h>
    35 #include <hbdeviceprofile.h>
    36 #include <hbdeviceprofile.h>
       
    37 #include <hbstyletextprimitivedata.h>
       
    38 #include <hbstyleframeprimitivedata.h>
    36 
    39 
    37 #include <QEvent>
    40 #include <QEvent>
    38 #include <QObject>
    41 #include <QObject>
    39 #include <QGraphicsScene>
    42 #include <QGraphicsScene>
       
    43 #include <QGraphicsObject>
    40 
    44 
    41 /*!
    45 /*!
    42     @alpha
    46     @alpha
    43     @hbwidgets
    47     @hbwidgets
    44     \class HbIndexFeedback
    48     \class HbIndexFeedback
    58     The sizing and number of characters to display are controlled by the IndexFeedbackPolicy.
    62     The sizing and number of characters to display are controlled by the IndexFeedbackPolicy.
    59 
    63 
    60     \sa HbAbstractItemView, HbIndexFeedback::IndexFeedbackPolicy.
    64     \sa HbAbstractItemView, HbIndexFeedback::IndexFeedbackPolicy.
    61 
    65 
    62     \primitives
    66     \primitives
    63     \primitive{index-text} HbTextItem representing the text in the HbIndexFeedback. 
    67     \primitive{index-text} HbTextItem with item name "index-text" representing the text in the HbIndexFeedback. 
    64     \primitive{index-background} HbFrameItem representing the background of the HbIndexFeedback. 
    68     \primitive{index-background} HbFrameItem with item name "index-background" representing the background of the HbIndexFeedback. 
    65 */
    69 */
    66 
    70 
    67 /*!
    71 /*!
    68     \enum HbIndexFeedback::IndexFeedbackPolicy
    72     \enum HbIndexFeedback::IndexFeedbackPolicy
    69 
    73 
   170 
   174 
   171     if (policy != d->mIndexFeedbackPolicy) {
   175     if (policy != d->mIndexFeedbackPolicy) {
   172         d->_q_hideIndexFeedbackNow();
   176         d->_q_hideIndexFeedbackNow();
   173         d->mIndexFeedbackPolicy = policy;
   177         d->mIndexFeedbackPolicy = policy;
   174         d->calculatePopupRects();
   178         d->calculatePopupRects();
   175         d->updatePrimitives();
   179         updatePrimitives();
   176     }
   180     }
   177 }
   181 }
   178 
   182 
   179 /*!
   183 /*!
   180     \brief Returns the index feedback policy.
   184     \brief Returns the index feedback policy.
   290         
   294         
   291             case QEvent::GraphicsSceneResize:
   295             case QEvent::GraphicsSceneResize:
   292             case QEvent::Resize:
   296             case QEvent::Resize:
   293                     d->_q_hideIndexFeedbackNow();
   297                     d->_q_hideIndexFeedbackNow();
   294                     d->calculatePopupRects();
   298                     d->calculatePopupRects();
   295                     d->updatePrimitives();
   299                     updatePrimitives();
   296                 break;
   300                 break;
   297 
   301 
   298             default:
   302             default:
   299                 // do nothing, ignore other events.
   303                 // do nothing, ignore other events.
   300                 break;
   304                 break;
   302     }
   306     }
   303 
   307 
   304     return QObject::eventFilter(obj, ev);
   308     return QObject::eventFilter(obj, ev);
   305 }
   309 }
   306 
   310 
   307 /*
   311 /*!
   308     For use with HbStyle.
   312   Initializes the HbIndexFeedback primitive data. 
   309 
   313   
   310     Provide the correct data to use in the 'model.'
   314   This function calls HbWidgetBase::initPrimitiveData().
   311 */
   315   \a primitiveData is data object, which is populated with data. \a primitive is the primitive.
   312 void HbIndexFeedback::initStyleOption(HbStyleOptionIndexFeedback *option) const
   316 */
   313 {
   317 void HbIndexFeedback::initPrimitiveData(HbStylePrimitiveData     *primitiveData, 
   314     Q_D( const HbIndexFeedback );
   318                                        const QGraphicsObject     *primitive)
   315 
   319 {
   316     HbWidget::initStyleOption(option);
   320     Q_ASSERT_X(primitive && primitiveData, "HbIndexFeedback::initPrimitiveData" , "NULL data not permitted");
   317 
   321     Q_D(HbIndexFeedback);
   318     if (!d->mItemView) {
   322 
   319         return;
   323     HbWidgetBase::initPrimitiveData(primitiveData, primitive);
   320     }
   324     
   321 
   325     if (primitiveData->type == HbStylePrimitiveData::SPD_Text) {
   322     HbFontSpec fontSpec;
   326         HbStyleTextPrimitiveData *textPrimitiveData = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData);
   323     qreal margin = 0;
   327 
   324 
   328         HbFontSpec fontSpec;
   325     style()->parameter(QLatin1String("hb-param-margin-gene-popup"), margin);
   329         switch (d->mIndexFeedbackPolicy) {
   326 
   330             case IndexFeedbackSingleCharacter: {
   327     switch (d->mIndexFeedbackPolicy) {
       
   328         case IndexFeedbackSingleCharacter:
       
   329             {
       
   330                 fontSpec = HbFontSpec(HbFontSpec::Primary);
   331                 fontSpec = HbFontSpec(HbFontSpec::Primary);
   331                 fontSpec.setTextHeight(d->textHeight());
   332                 fontSpec.setTextHeight(d->textHeight());
   332             }
   333                 }
   333             break;
   334                 break;
   334             
   335             case IndexFeedbackThreeCharacter: {
   335         case IndexFeedbackThreeCharacter:
       
   336             {
       
   337                 fontSpec = HbFontSpec(HbFontSpec::Primary);
   336                 fontSpec = HbFontSpec(HbFontSpec::Primary);
   338                 fontSpec.setTextHeight(d->textHeight());
   337                 fontSpec.setTextHeight(d->textHeight());
   339             }
   338                 }
   340             break;
   339                 break;
   341 
   340             case IndexFeedbackString: {
   342         case IndexFeedbackString:
       
   343             {
       
   344                 fontSpec = HbFontSpec(HbFontSpec::Primary);
   341                 fontSpec = HbFontSpec(HbFontSpec::Primary);
   345                 qreal textHeight = 0;
   342                 qreal textHeight = 0;
   346                 style()->parameter(QLatin1String("hb-param-text-height-primary"), textHeight);
   343                 style()->parameter(QLatin1String("hb-param-text-height-primary"), textHeight);
   347                 fontSpec.setTextHeight( textHeight );
   344                 fontSpec.setTextHeight( textHeight );
   348             }
   345                 }
   349             break;
   346                 break;
   350 
   347             case IndexFeedbackNone:
   351         case IndexFeedbackNone:
   348                 // no initialisation
   352             // leave the HbStyleOption uninitialized
   349                 return;
   353             return;
   350         }
   354     }
   351         textPrimitiveData->fontSpec = fontSpec;
   355 
   352 
   356     option->text = d->mPopupContent;
   353         textPrimitiveData->text = d->mPopupContent;
   357     option->fontSpec = fontSpec;
   354         textPrimitiveData->geometry = d->mPopupTextRect;
   358     option->textRect = d->mPopupTextRect;
   355 
   359     option->popupRect = d->mPopupBackgroundRect;
   356     } else if (primitiveData->type == HbStylePrimitiveData::SPD_Frame) {
       
   357         HbStyleFramePrimitiveData *framePrimitiveData = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData);
       
   358         framePrimitiveData->geometry = d->mPopupBackgroundRect;
       
   359     }
       
   360 }
       
   361 
       
   362 
       
   363 
       
   364 /*
       
   365     Update the primitives for the index feedback.
       
   366 */
       
   367 void HbIndexFeedback::updatePrimitives()
       
   368 {
       
   369     Q_D( HbIndexFeedback );
       
   370 
       
   371     if (d->mTextItem) {
       
   372         HbStyleTextPrimitiveData textPrimitiveData;
       
   373         initPrimitiveData(&textPrimitiveData, d->mTextItem);
       
   374         style()->updatePrimitive(d->mTextItem, &textPrimitiveData, this);
       
   375     }
       
   376     if (d->mPopupItem) {
       
   377         HbStyleFramePrimitiveData framePrimitiveData;
       
   378         initPrimitiveData(&framePrimitiveData, d->mPopupItem);
       
   379         style()->updatePrimitive(d->mPopupItem, &framePrimitiveData, this);
       
   380     }
   360 }
   381 }
   361 
   382 
   362 void HbIndexFeedback::polish(HbStyleParameters& params)
   383 void HbIndexFeedback::polish(HbStyleParameters& params)
   363 {
   384 {
   364     Q_D( HbIndexFeedback );
   385     Q_D( HbIndexFeedback );