remove unused code
[kineticlist.git] / kineticview.cpp
blob531c6904f8ddc3af2de9b222ace7637e0122035f
1 #include "kineticview.h"
3 #include <QObject>
4 #include <QDebug>
6 KineticView::KineticView( QGraphicsWidget *parent)
7 : QGraphicsWidget( parent ), mScrollVelocity( 0 )
9 setFlag(QGraphicsItem::ItemIsSelectable, true);
10 setAcceptedMouseButtons( Qt::LeftButton );
12 mViewPort = new QGraphicsWidget( this );
14 resize(300, 700);
17 KineticView::~KineticView()
19 delete mWindow;
22 void KineticView::startTimer()
24 QObject::startTimer( 50 );
26 void KineticView::setWidget( QGraphicsWidget *item)
28 mWindow = 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()));
35 update();
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));
44 break;
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));
50 break;
51 case QEvent::GraphicsSceneMouseRelease:
52 KineticScrolling::mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
54 mScrollVelocity = movement();
55 startTimer();
57 break;
58 case QEvent::Timer:
59 setScrollValue( mScrollVelocity );
60 mScrollVelocity *= 0.9;
61 if( !mScrollVelocity ) {
62 QTimerEvent *e = static_cast<QTimerEvent*>( event );
63 killTimer( e->timerId() );
65 break;
66 default:
67 break;
70 return true;
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));