1 /////////////////////////////////////////////////////////////////////////
4 // Copyright(C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>//
5 // Copyright(C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>//
7 // This library is free software; you can redistribute it and/or //
8 // modify it under the terms of the GNU Lesser General Public //
9 // License as published by the Free Software Foundation; either //
10 // version 2.1 of the License, or (at your option) any later version. //
12 // This library is distributed in the hope that it will be useful, //
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
15 // Lesser General Public License for more details. //
17 // You should have received a copy of the GNU Lesser General Public //
18 // License along with this library; if not, write to the Free Software //
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA //
21 /////////////////////////////////////////////////////////////////////////
22 #include "kineticview.h"
27 KineticView::KineticView( QGraphicsWidget
*parent
)
28 : QGraphicsWidget( parent
), mScrollVelocity( 0 ), newclick( 0 ),
31 setFlag( QGraphicsItem::ItemIsSelectable
, true );
32 setAcceptedMouseButtons( Qt::LeftButton
);
34 mViewPort
= new QGraphicsWidget( this );
39 KineticView::~KineticView()
44 void KineticView::startTimer()
46 timerID
= QObject::startTimer( 50 );
48 void KineticView::setWidget( QGraphicsWidget
*item
)
51 item
->setParentItem( mViewPort
);
52 item
->setParentLayoutItem( mViewPort
);
54 QRectF tmpGeometry
= mWindow
->geometry();
55 mWindow
->setGeometry( QRectF( tmpGeometry
.x(), tmpGeometry
.y() +
57 mWindow
->geometry().width(),
58 mWindow
->geometry().height() ) );
63 bool KineticView::event ( QEvent
* event
)
66 switch( event
->type() ) {
68 case QEvent::GraphicsSceneMousePress
:
72 KineticScrolling::mousePressEvent( static_cast<QGraphicsSceneMouseEvent
*>(event
) );
73 QGraphicsWidget::mousePressEvent( static_cast<QGraphicsSceneMouseEvent
*>(event
) );
76 case QEvent::GraphicsSceneMouseMove
:
78 KineticScrolling::mouseMoveEvent( static_cast<QGraphicsSceneMouseEvent
*>(event
) );
79 QGraphicsWidget::mouseMoveEvent( static_cast<QGraphicsSceneMouseEvent
*>(event
) );
80 tmp1
= -mWindow
->size().height() + mViewPort
->size().height();
81 tmp1
= qMin( 0, tmp1
);
82 tmp2
= mWindow
->pos().y() - qRound( movement() );
83 mWindow
->setPos( 0, qBound( tmp1
, tmp2
, 0 ) );
86 case QEvent::GraphicsSceneMouseRelease
:
88 KineticScrolling::mouseReleaseEvent(
89 static_cast<QGraphicsSceneMouseEvent
*>( event
) );
90 mScrollVelocity
= kin_movement();
95 setScrollValue( mScrollVelocity
);
96 mScrollVelocity
*= 0.9;
97 if( !mScrollVelocity
|| newclick
) {
110 void KineticView::setScrollValue( int value
)
112 mWindow
->setPos( 0, qBound( qMin( 0.0,
113 -mWindow
->size().height()
114 + mViewPort
->size().height() ),
115 mWindow
->pos().y() - value
, 0.0) );