src/hbcore/gui/hbscrollarea.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    40 
    40 
    41 /*!
    41 /*!
    42  @beta
    42  @beta
    43  @hbcore
    43  @hbcore
    44  \class HbScrollArea
    44  \class HbScrollArea
    45  \brief HbScrollArea provides a finger-touch enabled scrollable container class.  
    45  \brief HbScrollArea provides a finger-touch enabled scrollable container class.
    46  
    46 
    47  HbScrollArea handles the events need to scroll the contents placed inside it.  It also
    47  HbScrollArea handles the events need to scroll the contents placed inside it.  It also
    48  handles the display of scrollbar while scrolling is occurring.
    48  handles the display of scrollbar while scrolling is occurring.
    49  
    49 
    50  HbScrollArea is used by constructing a QGraphicsWidget that contains the content to be
    50  HbScrollArea is used by constructing a QGraphicsWidget widget that contains the content to be
    51  displayed, then calling the setContentWidget() method.  The content widget must have its size
    51  displayed by calling the HbScrollArea::setContentWidget() method. Scrollarea resizes the content
    52  set appropriately either by associating a layout with the widget or by explicitly setting
    52  widget by using QGraphicsWidget::sizeHint() function. This function returns the sizehint i.e.
    53  the size (e.g. by calling QGraphicsWidget::setGeometry()).
    53  height and width of the content widget which is constrained by scrollarea based on the scrollarea
    54  
    54  direction.
       
    55 
       
    56  If the scrollarea direction is Vertical, scrollarea resizes the width of the content widget
       
    57  else if it is horizontal, it resizes the height of contect widget.
       
    58 
    55  The class can be used by itself to provide default scrolling behavior or can be
    59  The class can be used by itself to provide default scrolling behavior or can be
    56  subclassed to add touch feedback, selection feedback, etc.
    60  subclassed to add touch feedback, selection feedback, etc.
    57  
    61 
    58  By default, the class provides dragging, flicking with animated follow-on, a
    62  By default, the class provides dragging, flicking with animated follow-on, a
    59  simple inertia algorithm for slowing the animated follow-on scrolling and
    63  simple inertia algorithm for slowing the animated follow-on scrolling and
    60  a bounce-back algorithm for animating the content back to its bounding
    64  a bounce-back algorithm for animating the content back to its bounding
    61  limits at the end of a drag or flick action.
    65  limits at the end of a drag or flick action.
    62  */
    66  */
   762                     newSize.setWidth(size().width());
   766                     newSize.setWidth(size().width());
   763                     sizeChanged = true;
   767                     sizeChanged = true;
   764                 }
   768                 }
   765                 if (sizeChanged) {
   769                 if (sizeChanged) {
   766                     d->mContents->resize(newSize);
   770                     d->mContents->resize(newSize);
       
   771                     d->updateScrollMetrics();
   767                 } else {
   772                 } else {
   768                     d->adjustContent();
   773                     d->adjustContent();
   769                 }
   774                 }
   770             }
   775             }
   771         }
   776         }
  1089 /*!
  1094 /*!
  1090   \reimp
  1095   \reimp
  1091  */
  1096  */
  1092 void HbScrollArea::polish(HbStyleParameters& params)
  1097 void HbScrollArea::polish(HbStyleParameters& params)
  1093 {
  1098 {
  1094     Q_D(HbScrollArea);
  1099     if (isVisible()) {
  1095 
  1100         Q_D(HbScrollArea);
  1096     d->doLazyInit();
  1101         d->doLazyInit();
  1097 
  1102 
  1098     // fetch scrolling parameters from css
  1103         // fetch scrolling parameters from css
  1099     const QString SpeedFactor = "speed-factor";
  1104         const QLatin1String SpeedFactor("speed-factor");
  1100     const QString IntertiaSpeedFactor = "inertia-speed-factor";
  1105         const QLatin1String IntertiaSpeedFactor("inertia-speed-factor");
  1101     const QString MaxScrollSpeed = "max-scroll-speed";
  1106         const QLatin1String MaxScrollSpeed("max-scroll-speed");
  1102     const QString SpringStrength = "spring-strength";
  1107         const QLatin1String SpringStrength("spring-strength");
  1103     const QString SpringDampingFactor = "spring-damping-factor";
  1108         const QLatin1String SpringDampingFactor("spring-damping-factor");
  1104     const QString FrictionPerMilliSecond = "friction";
  1109         const QLatin1String FrictionPerMilliSecond("friction");
  1105 
  1110 
  1106     params.addParameter(SpeedFactor);
  1111         params.addParameter(SpeedFactor);
  1107     params.addParameter(IntertiaSpeedFactor);
  1112         params.addParameter(IntertiaSpeedFactor);
  1108     params.addParameter(MaxScrollSpeed);
  1113         params.addParameter(MaxScrollSpeed);
  1109     params.addParameter(SpringStrength);
  1114         params.addParameter(SpringStrength);
  1110     params.addParameter(SpringDampingFactor);
  1115         params.addParameter(SpringDampingFactor);
  1111     params.addParameter(FrictionPerMilliSecond);
  1116         params.addParameter(FrictionPerMilliSecond);
  1112     HbWidget::polish(params);
  1117         HbWidget::polish(params);
  1113 
  1118 
  1114     if (!params.value(SpeedFactor).isNull()) {
  1119         if (!params.value(SpeedFactor).isNull()) {
  1115         d->mSpeedFactor = params.value(SpeedFactor).toDouble();
  1120             d->mSpeedFactor = params.value(SpeedFactor).toDouble();
  1116     }
  1121         }
  1117     if (!params.value(IntertiaSpeedFactor).isNull()) {
  1122         if (!params.value(IntertiaSpeedFactor).isNull()) {
  1118         d->mInertiaSpeedFactor = params.value(IntertiaSpeedFactor).toDouble();
  1123             d->mInertiaSpeedFactor = params.value(IntertiaSpeedFactor).toDouble();
  1119     }
  1124         }
  1120     if (!params.value(MaxScrollSpeed).isNull()) {
  1125         if (!params.value(MaxScrollSpeed).isNull()) {
  1121         d->mMaxScrollSpeed = params.value(MaxScrollSpeed).toDouble();
  1126             d->mMaxScrollSpeed = params.value(MaxScrollSpeed).toDouble();
  1122     }
  1127         }
  1123     if (!params.value(SpringStrength).isNull()) {
  1128         if (!params.value(SpringStrength).isNull()) {
  1124         d->mSpringStrength = params.value(SpringStrength).toDouble();
  1129             d->mSpringStrength = params.value(SpringStrength).toDouble();
  1125     }
  1130         }
  1126     if (!params.value(SpringDampingFactor).isNull()) {
  1131         if (!params.value(SpringDampingFactor).isNull()) {
  1127         d->mSpringDampingFactor = params.value(SpringDampingFactor).toDouble();
  1132             d->mSpringDampingFactor = params.value(SpringDampingFactor).toDouble();
  1128     }
  1133         }
  1129     if (!params.value(FrictionPerMilliSecond).isNull()) {
  1134         if (!params.value(FrictionPerMilliSecond).isNull()) {
  1130         d->mFrictionPerMilliSecond = params.value(FrictionPerMilliSecond).toDouble();
  1135             d->mFrictionPerMilliSecond = params.value(FrictionPerMilliSecond).toDouble();
  1131     }
  1136         }
  1132     if (d->mContinuationIndicators) {
  1137         if (d->mContinuationIndicators) {
  1133         d->updateIndicators(-d->mContents->pos());
  1138             d->updateIndicators(-d->mContents->pos());
       
  1139         }
       
  1140     } else {
       
  1141         HbWidget::polish(params);
  1134     }
  1142     }
  1135 }
  1143 }
  1136 
  1144 
  1137 /*!
  1145 /*!
  1138   \reimp
  1146   \reimp
  1147         d->_q_hideScrollBars();
  1155         d->_q_hideScrollBars();
  1148     }
  1156     }
  1149 }
  1157 }
  1150 
  1158 
  1151 /*!
  1159 /*!
       
  1160  \reimp
       
  1161  */
       
  1162 QPainterPath HbScrollArea::shape() const
       
  1163 {
       
  1164     Q_D(const HbScrollArea);
       
  1165     if ( d->mClearCachedRect){
       
  1166         d->reCalculateCachedValue();
       
  1167     }
       
  1168     return d->mShape;
       
  1169 }
       
  1170 
       
  1171 /*!
       
  1172  \reimp
       
  1173  */
       
  1174 QRectF HbScrollArea::boundingRect() const
       
  1175 
       
  1176 {
       
  1177     Q_D(const HbScrollArea);
       
  1178     if (d->mClearCachedRect) {
       
  1179         d->reCalculateCachedValue();
       
  1180     }
       
  1181     return d->mBoundingRect;
       
  1182 }
       
  1183 
       
  1184 /*!
       
  1185  \reimp
       
  1186  */
       
  1187 void HbScrollArea::setGeometry(const QRectF& rect)
       
  1188 {
       
  1189     Q_D(HbScrollArea);
       
  1190     d->mClearCachedRect = true;
       
  1191     HbWidget::setGeometry(rect);
       
  1192 }
       
  1193 
       
  1194 /*!
  1152     \reimp
  1195     \reimp
  1153 */
  1196 */
  1154 void HbScrollArea::disconnectNotify (const char *signal)
  1197 void HbScrollArea::disconnectNotify (const char *signal)
  1155 {
  1198 {
  1156     Q_D(HbScrollArea);
  1199     Q_D(HbScrollArea);