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