mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 02:54:46 -04:00
new scrolling mechanism for covers in ImportWidget
This commit is contained in:
@ -128,10 +128,13 @@ ImportWidget::ImportWidget(QWidget *parent) :
|
||||
coversView->setStyleSheet("QGraphicsView {background-color: #E6E6E6;border:none;}");
|
||||
|
||||
coversScene = new QGraphicsScene();
|
||||
coversScene->setSceneRect(0,0,coversView->width(),coversView->height());
|
||||
coversView->setAlignment(Qt::AlignLeft);
|
||||
coversView->setScene(coversScene);
|
||||
coversView->setFixedHeight(300);
|
||||
|
||||
coversView->setInteractive(false);
|
||||
|
||||
scrollAnimation = new QPropertyAnimation(coversView->horizontalScrollBar(), "value");
|
||||
|
||||
QLabel * topDecorator = new QLabel();
|
||||
QLabel * bottomDecorator = new QLabel();
|
||||
@ -208,7 +211,7 @@ ImportWidget::ImportWidget(QWidget *parent) :
|
||||
connect(stop,SIGNAL(clicked()),this,SIGNAL(stop()));
|
||||
//connect(stop,SIGNAL(clicked()),this,SLOT(addCoverTest()));
|
||||
|
||||
previousWidth = 10;
|
||||
previousWidth = 0;
|
||||
updatingCovers = false;
|
||||
elapsedTimer = new QElapsedTimer();
|
||||
elapsedTimer->start();
|
||||
@ -216,70 +219,49 @@ ImportWidget::ImportWidget(QWidget *parent) :
|
||||
|
||||
void ImportWidget::newComic(const QString & path, const QString & coverPath)
|
||||
{
|
||||
if(!this->isVisible())
|
||||
return;
|
||||
|
||||
currentComicLabel->setText("<font color=\"#565959\">"+path+"</font>");
|
||||
|
||||
if(((elapsedTimer->elapsed()>=1000) || ((previousWidth < coversView->width()) && (elapsedTimer->elapsed()>=500))) && !updatingCovers)//todo elapsed time
|
||||
if( ((elapsedTimer->elapsed()>=1100) || ((previousWidth < coversView->width()) && (elapsedTimer->elapsed()>=500))) && scrollAnimation->state() != QAbstractAnimation::Running)//todo elapsed time
|
||||
{
|
||||
updatingCovers = true;
|
||||
elapsedTimer->start();
|
||||
|
||||
QPixmap p(coverPath);
|
||||
p = p.scaledToHeight(300,Qt::SmoothTransformation);
|
||||
|
||||
QGraphicsPixmapItem * item = new QGraphicsPixmapItem(p);
|
||||
item->setPos(previousWidth,0);
|
||||
item->setZValue(i/10000.0);
|
||||
previousWidth += 10 + p.width();
|
||||
item->setPos(previousWidth, 0);
|
||||
coversScene->addItem(item);
|
||||
|
||||
elapsedTimer->start();
|
||||
if(previousWidth >= coversView->width()+200 && !updatingCovers)
|
||||
{
|
||||
updatingCovers = true;
|
||||
previousWidth += 10 + p.width();
|
||||
|
||||
foreach(QGraphicsItem * itemToRemove, coversScene->items())
|
||||
{
|
||||
QGraphicsPixmapItem * last = dynamic_cast<QGraphicsPixmapItem *>(itemToRemove);
|
||||
|
||||
if((last->pos().x()+last->pixmap().width())<=0)
|
||||
if((last->pos().x()+last->pixmap().width()) < coversView->horizontalScrollBar()->value()) //TODO check this
|
||||
{
|
||||
coversScene->removeItem(last);
|
||||
delete last;
|
||||
}
|
||||
//else
|
||||
// break;
|
||||
}
|
||||
|
||||
int width = p.width();
|
||||
QScrollBar * scrollBar = coversView->horizontalScrollBar();
|
||||
|
||||
foreach(QGraphicsItem * itemToMove, coversScene->items())
|
||||
{
|
||||
QTimeLine *timer = new QTimeLine(400);
|
||||
timer->setFrameRange(0, 24);
|
||||
timer->setUpdateInterval(17);
|
||||
float speedFactor = 2.5;
|
||||
int origin = scrollBar->value();
|
||||
int dest = origin + 10 + p.width();
|
||||
|
||||
QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
|
||||
animation->setItem(itemToMove);
|
||||
animation->setTimeLine(timer);
|
||||
|
||||
QPointF point = itemToMove->scenePos();
|
||||
float step = (width+10)/24.0;
|
||||
for (int i = 0; i < 24; ++i)
|
||||
animation->setPosAt(i / 24.0, QPointF(point.x()-((i+1)*step), point.y()));
|
||||
|
||||
timer->start();
|
||||
connect(timer,SIGNAL(finished()),timer,SLOT(deleteLater()));
|
||||
connect(timer,SIGNAL(finished()),animation,SLOT(deleteLater()));
|
||||
scrollAnimation->setDuration((dest-origin)*speedFactor);
|
||||
scrollAnimation->setStartValue(origin);
|
||||
scrollAnimation->setEndValue(dest);
|
||||
QEasingCurve easing(QEasingCurve::OutQuad);
|
||||
scrollAnimation->setEasingCurve(easing);
|
||||
scrollAnimation->start();
|
||||
}
|
||||
|
||||
QTimer::singleShot(400,this,SLOT(finishedUpdatingCover()));
|
||||
|
||||
previousWidth -= 10+width;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ImportWidget::finishedUpdatingCover()
|
||||
{
|
||||
updatingCovers = false;
|
||||
}
|
||||
|
||||
void ImportWidget::newCover(const QPixmap & image)
|
||||
@ -335,7 +317,7 @@ void ImportWidget::addCoverTest()
|
||||
|
||||
void ImportWidget::clear()
|
||||
{
|
||||
previousWidth = 10;
|
||||
previousWidth = 0;
|
||||
|
||||
//nos aseguramos de que las animaciones han finalizado antes de borrar
|
||||
QList<QGraphicsItem*> all = coversScene->items();
|
||||
@ -347,6 +329,11 @@ void ImportWidget::clear()
|
||||
}
|
||||
coversScene->clear();
|
||||
|
||||
delete coversScene;
|
||||
coversScene = new QGraphicsScene;
|
||||
|
||||
coversView->setScene(coversScene);
|
||||
|
||||
updatingCovers = false;
|
||||
|
||||
currentComicLabel->setText("<font color=\"#565959\">...</font>");
|
||||
|
@ -10,6 +10,7 @@ class QElapsedTimer;
|
||||
class QVBoxLayout;
|
||||
class QToolButton;
|
||||
class QResizeEvent;
|
||||
class QPropertyAnimation;
|
||||
|
||||
class ImportWidget : public QWidget
|
||||
{
|
||||
@ -24,11 +25,11 @@ public slots:
|
||||
void newCover(const QPixmap & image);
|
||||
void clear();
|
||||
void addCoverTest();
|
||||
void finishedUpdatingCover();
|
||||
void clearScene();
|
||||
void setImportLook();
|
||||
void setUpdateLook();
|
||||
void showCovers(bool hide);
|
||||
|
||||
private:
|
||||
QLabel * currentComicLabel;
|
||||
QLabel * portadasLabel;
|
||||
@ -38,6 +39,8 @@ private:
|
||||
QWidget * coversViewContainer;
|
||||
QGraphicsView * coversView;
|
||||
QGraphicsScene * coversScene;
|
||||
QPropertyAnimation * scrollAnimation;
|
||||
|
||||
int previousWidth;
|
||||
bool updatingCovers;
|
||||
QElapsedTimer * elapsedTimer;
|
||||
|
Reference in New Issue
Block a user