src/hbcore/gui/hbscrollarea.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    29 #include "hbdeviceprofile.h"
    29 #include "hbdeviceprofile.h"
    30 #include "hbinstance.h"
    30 #include "hbinstance.h"
    31 #include <hbwidgetfeedback.h>
    31 #include <hbwidgetfeedback.h>
    32 #include <hbevent.h>
    32 #include <hbevent.h>
    33 #include "hbglobal_p.h"
    33 #include "hbglobal_p.h"
       
    34 #include <hbtapgesture.h>
       
    35 #include <hbnamespace_p.h>
    34 
    36 
    35 #include <QGesture>
    37 #include <QGesture>
    36 
    38 
    37 #include <QDebug>
    39 #include <QDebug>
    38 
    40 
   140     This signal is emitted whenever a scrolling action ends.
   142     This signal is emitted whenever a scrolling action ends.
   141 */
   143 */
   142 
   144 
   143 /*!
   145 /*!
   144     \fn void HbScrollArea::scrollPositionChanged(QPointF newposition)
   146     \fn void HbScrollArea::scrollPositionChanged(QPointF newposition)
   145     This signal is emitted when scroll position is changed.
   147     This signal is emitted when scroll position is changed and someone is connected to the signal.
   146 */
   148 */
   147 
   149 
   148 /*!
   150 /*!
   149     \enum HbScrollArea::ClampingStyle
   151     \enum HbScrollArea::ClampingStyle
   150 
   152 
   439 {
   441 {
   440     Q_D( HbScrollArea );
   442     Q_D( HbScrollArea );
   441 
   443 
   442     bool isChanged = (d->mScrollDirections != value);
   444     bool isChanged = (d->mScrollDirections != value);
   443 
   445 
   444     d->mScrollDirections = value;
   446     d->mScrollDirections = value;        
       
   447     if (d->mContents && isChanged) {
       
   448         QPointF pos = d->mContents->pos();
       
   449         QEvent layoutRequest(QEvent::LayoutRequest);
       
   450         QCoreApplication::sendEvent(this, &layoutRequest);
       
   451         d->mContents->setPos(pos);
       
   452     }
   445 
   453 
   446     if (isChanged) {
   454     if (isChanged) {
   447         emit scrollDirectionsChanged( value );
   455         emit scrollDirectionsChanged( value );
   448     }
   456     }
   449 }
   457 }
   689             //qDebug() << "focusout";
   697             //qDebug() << "focusout";
   690             if ( !d->positionOutOfBounds() ) {
   698             if ( !d->positionOutOfBounds() ) {
   691                 d->stopAnimating();
   699                 d->stopAnimating();
   692             }
   700             }
   693         } else if( event->type() == QEvent::GestureOverride ) {
   701         } else if( event->type() == QEvent::GestureOverride ) {
   694             if(static_cast<QGestureEvent *>(event)->gesture(Qt::TapGesture) &&
   702             if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(static_cast<QGestureEvent *>(event)->gesture(Qt::TapGesture))) {
   695                     d->mIsAnimating && !d->positionOutOfBounds() && !d->mMultiFlickEnabled) {
   703                 if (d->mIsAnimating && !d->positionOutOfBounds() && !d->mMultiFlickEnabled) {
   696                 event->accept();
   704                     event->accept();
   697                 return true;
   705                     return true;
       
   706                 } else if (tap->state() == Qt::GestureStarted){
       
   707                     if (d->mAbleToScrollY) {
       
   708                         tap->setProperty(HbPrivate::VerticallyRestricted.latin1(), true);
       
   709                     }
       
   710                     if (d->mAbleToScrollX){
       
   711                         tap->setProperty(HbPrivate::HorizontallyRestricted.latin1(), true);
       
   712                     }
       
   713                 }
   698             }
   714             }
   699         } else if (event->type() == QEvent::LayoutRequest) {
   715         } else if (event->type() == QEvent::LayoutRequest) {
   700             if (d->mContents) {
   716             if (d->mContents) {
   701                 if (preferredSize() != d->mContents->preferredSize()) {
   717                 if (preferredSize() != d->mContents->preferredSize()) {
   702                     updateGeometry();
   718                     updateGeometry();
   765     Q_UNUSED(obj);
   781     Q_UNUSED(obj);
   766     Q_D(HbScrollArea);
   782     Q_D(HbScrollArea);
   767     if (event && event->type() == QEvent::GraphicsSceneResize) {
   783     if (event && event->type() == QEvent::GraphicsSceneResize) {
   768         if (isVisible()) {            
   784         if (isVisible()) {            
   769             d->adjustContent();
   785             d->adjustContent();
       
   786         }
       
   787 
       
   788         if (d->mAbleToScrollX && d->mHorizontalScrollBar->isVisible()) {
       
   789             d->updateScrollBar(Qt::Horizontal);
       
   790         }
       
   791 
       
   792         if (d->mAbleToScrollY && d->mVerticalScrollBar->isVisible()) {
       
   793             d->updateScrollBar(Qt::Vertical);
   770         }
   794         }
   771     }  // no else
   795     }  // no else
   772 
   796 
   773     return false;
   797     return false;
   774 }
   798 }
  1048     Scrolls the contents of the scroll area to the \a newPosition in a given \a time.
  1072     Scrolls the contents of the scroll area to the \a newPosition in a given \a time.
  1049     If the time is 0, contents is scrolled to the position instantly.
  1073     If the time is 0, contents is scrolled to the position instantly.
  1050 */
  1074 */
  1051 void HbScrollArea::scrollContentsTo (const QPointF& newPosition, int time) {
  1075 void HbScrollArea::scrollContentsTo (const QPointF& newPosition, int time) {
  1052     Q_D(HbScrollArea);
  1076     Q_D(HbScrollArea);
       
  1077 
       
  1078     if (!contentWidget())
       
  1079         return;
       
  1080 
  1053     if (time > 0){
  1081     if (time > 0){
  1054         d->startTargetAnimation (newPosition, qMax (0, time));
  1082         d->startTargetAnimation (newPosition, qMax (0, time));
  1055     } else {
  1083     } else {
  1056         scrollByAmount(newPosition - (-d->mContents->pos()));
  1084         scrollByAmount(newPosition - (-d->mContents->pos()));
  1057         d->stopScrolling();
  1085         d->stopScrolling();
  1058 
       
  1059     }
  1086     }
  1060 }
  1087 }
  1061 
  1088 
  1062 /*!
  1089 /*!
  1063   \reimp
  1090   \reimp
  1105     if (d->mContinuationIndicators) {
  1132     if (d->mContinuationIndicators) {
  1106         d->updateIndicators(-d->mContents->pos());
  1133         d->updateIndicators(-d->mContents->pos());
  1107     }
  1134     }
  1108 }
  1135 }
  1109 
  1136 
       
  1137 /*!
       
  1138   \reimp
       
  1139 
       
  1140  */
       
  1141 void HbScrollArea::timerEvent(QTimerEvent *event)
       
  1142 {
       
  1143     Q_D(HbScrollArea);
       
  1144     if (event->timerId() == d->mScrollTimerId) {
       
  1145         d->_q_animateScrollTimeout();
       
  1146     } else if (event->timerId() == d->mScrollBarHideTimerId) {
       
  1147         d->_q_hideScrollBars();
       
  1148     }
       
  1149 }
       
  1150 
       
  1151 /*!
       
  1152     \reimp
       
  1153 */
       
  1154 void HbScrollArea::disconnectNotify (const char *signal)
       
  1155 {
       
  1156     Q_D(HbScrollArea);
       
  1157     if (d->mEmitPositionChangedSignal &&
       
  1158         QLatin1String(signal) == SIGNAL(scrollPositionChanged(QPointF))) {
       
  1159         if (receivers(SIGNAL(scrollPositionChanged(QPointF))) == 0) {
       
  1160             d->mEmitPositionChangedSignal = false;
       
  1161         }
       
  1162     }
       
  1163     HbWidget::disconnectNotify(signal);
       
  1164 }
       
  1165 
       
  1166 /*!
       
  1167     \reimp
       
  1168 */
       
  1169 void HbScrollArea::connectNotify(const char * signal)
       
  1170 {
       
  1171     Q_D(HbScrollArea);
       
  1172     if (!d->mEmitPositionChangedSignal &&
       
  1173         QLatin1String(signal) == SIGNAL(scrollPositionChanged(QPointF))) {
       
  1174         d->mEmitPositionChangedSignal = true;
       
  1175     }
       
  1176     HbWidget::connectNotify(signal);
       
  1177 }
  1110 #include "moc_hbscrollarea.cpp"
  1178 #include "moc_hbscrollarea.cpp"