1 #include "kineticview.h"
6 KineticView::KineticView( QGraphicsWidget
*parent
)
7 : QGraphicsWidget( parent
), mScrollVelocity( 0 )
9 setFlag(QGraphicsItem::ItemIsSelectable
, true);
10 setAcceptedMouseButtons( Qt::LeftButton
);
12 mViewPort
= new QGraphicsWidget( this );
17 KineticView::~KineticView()
22 void KineticView::startTimer()
24 QObject::startTimer( 50 );
26 void KineticView::setWidget( QGraphicsWidget
*item
)
29 item
->setParentItem( mViewPort
);
30 item
->setParentLayoutItem( mViewPort
);
32 QRectF tmpGeometry
= mWindow
->geometry();
33 mWindow
->setGeometry( QRectF(tmpGeometry
.x(), tmpGeometry
.y() + tmpGeometry
.height(), mWindow
->geometry().width(), mWindow
->geometry().height()));
38 bool KineticView::event ( QEvent
* event
)
40 switch( event
->type() ) {
41 case QEvent::GraphicsSceneMousePress
:
42 KineticScrolling::mousePressEvent(static_cast<QGraphicsSceneMouseEvent
*>(event
));
43 QGraphicsWidget::mousePressEvent(static_cast<QGraphicsSceneMouseEvent
*>(event
));
45 case QEvent::GraphicsSceneMouseMove
:
46 KineticScrolling::mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent
*>(event
));
47 QGraphicsWidget::mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent
*>(event
));
48 mWindow
->setPos( 0, qBound( qMin( ( qreal
)0, -mWindow
->size( ).height( )+mViewPort
->size( ).height( )),
49 mWindow
->pos( ).y( ) - movement() , ( qreal
)0));
51 case QEvent::GraphicsSceneMouseRelease
:
52 KineticScrolling::mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent
*>(event
));
54 mScrollVelocity
= movement();
59 setScrollValue( mScrollVelocity
);
60 mScrollVelocity
*= 0.9;
61 if( !mScrollVelocity
) {
62 QTimerEvent
*e
= static_cast<QTimerEvent
*>( event
);
63 killTimer( e
->timerId() );
73 void KineticView::setScrollValue( int value
)
75 mWindow
->setPos( 0, qBound( qMin( ( qreal
)0, -mWindow
->size().height()+mViewPort
->size().height()),
76 mWindow
->pos().y() - value
, (qreal
)0));