From bd1edd440b6614c4de8d3dc6c90cef298dec10be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 6 Nov 2012 19:31:17 +0100 Subject: [PATCH] modificado el scroll autom?tico (animation framework) --- YACReader/viewer.cpp | 35 +++++++++++++++++------------------ YACReader/viewer.h | 3 ++- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index cb55892c..cd25da00 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -96,8 +96,6 @@ drag(false) render = new Render(); - scroller = new QTimer(this); - hideCursorTimer = new QTimer(); hideCursorTimer->setSingleShot(true); @@ -109,6 +107,9 @@ drag(false) hideCursorTimer->start(2500); setMouseTracking(true); + + //animations + verticalScroller = new QPropertyAnimation(verticalScrollBar(), "sliderPosition"); } void Viewer::createConnections() @@ -249,15 +250,16 @@ void Viewer::scrollDown() if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum()) { next(); - scroller->stop(); } else { int currentPos = verticalScrollBar()->sliderPosition(); - verticalScrollBar()->setSliderPosition(currentPos=currentPos+posByStep); - if((verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum()) - ||(verticalScrollBar()->sliderPosition()>=nextPos)) - scroller->stop(); + verticalScroller->setDuration(250); + verticalScroller->setStartValue(currentPos); + verticalScroller->setEndValue(nextPos); + + verticalScroller->start(); + emit backgroundChanges(); } } @@ -267,15 +269,16 @@ void Viewer::scrollUp() if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum()) { prev(); - scroller->stop(); } else { int currentPos = verticalScrollBar()->sliderPosition(); - verticalScrollBar()->setSliderPosition(currentPos=currentPos-posByStep); - if((verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum()) - ||(verticalScrollBar()->sliderPosition()<=nextPos)) - scroller->stop(); + verticalScroller->setDuration(250); + verticalScroller->setStartValue(currentPos); + verticalScroller->setEndValue(nextPos); + + verticalScroller->start(); + emit backgroundChanges(); } } @@ -290,18 +293,14 @@ void Viewer::keyPressEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Space: - disconnect(scroller,SIGNAL(timeout()),this,0); - connect(scroller,SIGNAL(timeout()),this,SLOT(scrollDown())); posByStep = height()/STEPS; nextPos=verticalScrollBar()->sliderPosition()+static_cast((height()*0.80)); - scroller->start(20); + scrollDown(); break; case Qt::Key_B: - disconnect(scroller,SIGNAL(timeout()),this,0); - connect(scroller,SIGNAL(timeout()),this,SLOT(scrollUp())); posByStep = height()/STEPS; nextPos=verticalScrollBar()->sliderPosition()-static_cast((height()*0.80)); - scroller->start(20); + scrollUp(); break; case Qt::Key_S: goToFlowSwitch(); diff --git a/YACReader/viewer.h b/YACReader/viewer.h index d21dc2d9..e7889044 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -78,7 +78,8 @@ virtual void mouseReleaseEvent ( QMouseEvent * event ); bool information; bool doublePage; QLabel * informationLabel; - QTimer * scroller; + //QTimer * scroller; + QPropertyAnimation * verticalScroller; int posByStep; int nextPos; GoToFlowWidget * goToFlow;