modificado el scroll autom?tico (animation framework)

This commit is contained in:
Luis Ángel San Martín 2012-11-06 19:31:17 +01:00
parent 4cee4117f8
commit bd1edd440b
2 changed files with 19 additions and 19 deletions

View File

@ -96,8 +96,6 @@ drag(false)
render = new Render(); render = new Render();
scroller = new QTimer(this);
hideCursorTimer = new QTimer(); hideCursorTimer = new QTimer();
hideCursorTimer->setSingleShot(true); hideCursorTimer->setSingleShot(true);
@ -109,6 +107,9 @@ drag(false)
hideCursorTimer->start(2500); hideCursorTimer->start(2500);
setMouseTracking(true); setMouseTracking(true);
//animations
verticalScroller = new QPropertyAnimation(verticalScrollBar(), "sliderPosition");
} }
void Viewer::createConnections() void Viewer::createConnections()
@ -249,15 +250,16 @@ void Viewer::scrollDown()
if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum()) if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum())
{ {
next(); next();
scroller->stop();
} }
else else
{ {
int currentPos = verticalScrollBar()->sliderPosition(); int currentPos = verticalScrollBar()->sliderPosition();
verticalScrollBar()->setSliderPosition(currentPos=currentPos+posByStep); verticalScroller->setDuration(250);
if((verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum()) verticalScroller->setStartValue(currentPos);
||(verticalScrollBar()->sliderPosition()>=nextPos)) verticalScroller->setEndValue(nextPos);
scroller->stop();
verticalScroller->start();
emit backgroundChanges(); emit backgroundChanges();
} }
} }
@ -267,15 +269,16 @@ void Viewer::scrollUp()
if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum()) if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum())
{ {
prev(); prev();
scroller->stop();
} }
else else
{ {
int currentPos = verticalScrollBar()->sliderPosition(); int currentPos = verticalScrollBar()->sliderPosition();
verticalScrollBar()->setSliderPosition(currentPos=currentPos-posByStep); verticalScroller->setDuration(250);
if((verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum()) verticalScroller->setStartValue(currentPos);
||(verticalScrollBar()->sliderPosition()<=nextPos)) verticalScroller->setEndValue(nextPos);
scroller->stop();
verticalScroller->start();
emit backgroundChanges(); emit backgroundChanges();
} }
} }
@ -290,18 +293,14 @@ void Viewer::keyPressEvent(QKeyEvent *event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Space: case Qt::Key_Space:
disconnect(scroller,SIGNAL(timeout()),this,0);
connect(scroller,SIGNAL(timeout()),this,SLOT(scrollDown()));
posByStep = height()/STEPS; posByStep = height()/STEPS;
nextPos=verticalScrollBar()->sliderPosition()+static_cast<int>((height()*0.80)); nextPos=verticalScrollBar()->sliderPosition()+static_cast<int>((height()*0.80));
scroller->start(20); scrollDown();
break; break;
case Qt::Key_B: case Qt::Key_B:
disconnect(scroller,SIGNAL(timeout()),this,0);
connect(scroller,SIGNAL(timeout()),this,SLOT(scrollUp()));
posByStep = height()/STEPS; posByStep = height()/STEPS;
nextPos=verticalScrollBar()->sliderPosition()-static_cast<int>((height()*0.80)); nextPos=verticalScrollBar()->sliderPosition()-static_cast<int>((height()*0.80));
scroller->start(20); scrollUp();
break; break;
case Qt::Key_S: case Qt::Key_S:
goToFlowSwitch(); goToFlowSwitch();

View File

@ -78,7 +78,8 @@ virtual void mouseReleaseEvent ( QMouseEvent * event );
bool information; bool information;
bool doublePage; bool doublePage;
QLabel * informationLabel; QLabel * informationLabel;
QTimer * scroller; //QTimer * scroller;
QPropertyAnimation * verticalScroller;
int posByStep; int posByStep;
int nextPos; int nextPos;
GoToFlowWidget * goToFlow; GoToFlowWidget * goToFlow;