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"
26 /* FIXME: make this portably */
28 #include <QGraphicsGridLayout>
31 * - kill the fscking timer in overshut
32 * - bump effect when rolling (twice should be enough)
33 * - add a scrollbar for reference
34 * - kinetic velocity parameterized upon count of list items
35 * - ringbuffer (minimize number of items in the QGV).
36 * - parameterize dimensions
39 KineticView::KineticView( QGraphicsWidget
*parent
)
40 : QGraphicsWidget( parent
), mScrollVelocity( 0 ), newclick( 0 ),
41 timerID( 0 ), overshut( 30 )
43 setSizePolicy( QSizePolicy::Expanding
, QSizePolicy::Expanding
);
45 mViewPort
= new QGraphicsWidget( this );
46 mViewPort
->setSizePolicy( QSizePolicy::Expanding
, QSizePolicy::Expanding
);
47 mViewPort
->setFlag( QGraphicsItem::ItemClipsChildrenToShape
, true);
48 layout
= new QGraphicsGridLayout( this );
49 layout
->addItem( mViewPort
, 0, 0 );
51 setAcceptedMouseButtons( Qt::LeftButton
);
54 KineticView::~KineticView()
59 void KineticView::startTimer(int interval
)
61 timerID
= QObject::startTimer( interval
);
63 void KineticView::setWidget( QGraphicsWidget
*item
)
66 mWindow
->setSizePolicy( QSizePolicy::Expanding
, QSizePolicy::Fixed
);
67 mWindow
->setParentItem( mViewPort
);
68 mWindow
->setPos( 0, 0 );
69 mWindow
->setAcceptedMouseButtons( Qt::LeftButton
);
74 void KineticView::bounceTimer()
77 if ( direction
== DOWN
)
80 mWindow
->setPos( 0, cposition
);
82 if ( ( direction
== UP
) && ( cposition
< 0 ) ) {
83 qDebug() << "Done UP bouncing.....!!!!!!!!!";
90 } else if ( ( direction
== DOWN
) &&
91 ( ( cposition
- overshut
) > minimalPos
) ) {
92 qDebug() << "Done DOWN bouncing.....!!!!!!!!!";
95 cposition
= minimalPos
+ overshut
;
101 qDebug() << "cposition: " << cposition
;
104 void KineticView::setScrollValue( int value
)
106 minimalPos
= -mWindow
->size().height() + mViewPort
->size().height() - overshut
;
107 minimalPos
= qMin( overshut
, minimalPos
);
108 maximumPos
= mWindow
->pos().y() - value
;
110 cposition
= qBound( minimalPos
, maximumPos
, overshut
);
111 mWindow
->setPos( 0, cposition
);
113 if ( cposition
== overshut
) {
114 qDebug() << "UPPER edge: animate overshut";
119 } else if ( cposition
== minimalPos
) {
120 qDebug() << "LOWER edge: animate overshut";
128 void KineticView::mousePressEvent( QGraphicsSceneMouseEvent
*event
)
132 killTimer( timerID
);
134 KineticScrolling::mousePressEvent( static_cast<QGraphicsSceneMouseEvent
*>(event
) );
137 void KineticView::mouseMoveEvent( QGraphicsSceneMouseEvent
*event
)
140 KineticScrolling::mouseMoveEvent( static_cast<QGraphicsSceneMouseEvent
*>(event
) );
141 QGraphicsWidget::mouseMoveEvent( static_cast<QGraphicsSceneMouseEvent
*>(event
) );
142 setScrollValue( movement() );
145 void KineticView::mouseReleaseEvent( QGraphicsSceneMouseEvent
*event
)
148 KineticScrolling::mouseReleaseEvent(
149 static_cast<QGraphicsSceneMouseEvent
*>( event
) );
150 mScrollVelocity
= kin_movement();
154 void KineticView::timerEvent( QTimerEvent
*event
)
156 qDebug() << "timer......" << "direction: " << direction
157 << "\tnewclick: " << newclick
158 << "\tvelocity: " << mScrollVelocity
159 << "\tcposition: " << cposition
;
163 killTimer( timerID
);
167 if (direction
== NONE
) {
168 setScrollValue( qRound( mScrollVelocity
) );
170 mScrollVelocity
*= 0.9;
171 if ( qAbs( mScrollVelocity
) < 5.0 ) {
173 killTimer( timerID
);