代码拉取完成,页面将自动刷新
同步操作将从 kimtaikee/HahaCrawler 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <QStackedWidget>
#include <QLabel>
#include <QRoundProgressBar.h>
#include <QUrl>
#include <QVBoxLayout>
#include <QThread>
#include <QFileInfo>
#include <QMovie>
#include <QDebug>
#include <QScrollArea>
#include <QHBoxLayout>
#include "imageitem.h"
#include "filedownloader.h"
class ImageItemPrivate
{
public:
ImageItemPrivate(ImageItem* q);
bool isMovie(const QUrl& url);
QUrl url;
QString description;
QString localPath;
ImageItem* q_ptr;
QScrollArea* scrollArea;
QStackedWidget* stackWidget;
QLabel* imageLabel;
QLabel* descLabel;
QRoundProgressBar* pgsBar;
};
ImageItemPrivate::ImageItemPrivate(ImageItem *q) : q_ptr(q)
{
QVBoxLayout* layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
scrollArea = new QScrollArea(q_ptr);
scrollArea->setWidgetResizable(true);
stackWidget = new QStackedWidget(q_ptr);
imageLabel = new QLabel(q_ptr);
descLabel = new QLabel(q_ptr);
descLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
QWidget* labelWidget = new QWidget(q_ptr);
QHBoxLayout* labelWidgetLayout = new QHBoxLayout;
labelWidgetLayout->addWidget(imageLabel);
labelWidgetLayout->addWidget(descLabel);
labelWidget->setLayout(labelWidgetLayout);
scrollArea->setWidget(labelWidget);
pgsBar = new QRoundProgressBar(q_ptr);
pgsBar->setBarStyle(QRoundProgressBar::StyleLine);
pgsBar->setValue(0);
stackWidget->addWidget(pgsBar);
stackWidget->addWidget(scrollArea);
layout->addWidget(stackWidget);
q_ptr->setLayout(layout);
q_ptr->setMinimumHeight(200);
}
bool ImageItemPrivate::isMovie(const QUrl &url)
{
QFileInfo fi(url.toString());
return fi.suffix().compare("gif", Qt::CaseInsensitive) == 0;
}
ImageItem::ImageItem(QWidget *parent) : QWidget(parent)
{
d_ptr = new ImageItemPrivate(this);
}
ImageItem::~ImageItem()
{
delete d_ptr;
}
void ImageItem::setUrl(const QUrl& url)
{
if (d_ptr->url != url) {
d_ptr->url = url;
// show pgsbar and download image
d_ptr->stackWidget->setCurrentWidget(d_ptr->pgsBar);
d_ptr->pgsBar->setValue(0);
QThread* thread = new QThread();
Jcr::FileDownloader* fd = new Jcr::FileDownloader(url);
fd->setSaveDir("G:/HAHACRAWLERDATA");
connect(thread, SIGNAL(started()), fd, SLOT(start()));
connect(fd, SIGNAL(finished()), thread, SLOT(terminate()));
connect(fd, SIGNAL(finished()), thread, SLOT(deleteLater()));
connect(fd, SIGNAL(percentCompleted(float)), this, SLOT(onPercentCompleted(float)));
thread->start();
}
}
QUrl ImageItem::url() const
{
return d_ptr->url;
}
void ImageItem::setDescription(const QString& desc)
{
d_ptr->descLabel->setText(desc);
}
QString ImageItem::description() const
{
return d_ptr->descLabel->text();
}
QString ImageItem::localPath() const
{
return d_ptr->localPath;
}
void ImageItem::onPercentCompleted(float percent)
{
if (percent == 1.0) {
Jcr::FileDownloader* fd = qobject_cast<Jcr::FileDownloader*>(sender());
d_ptr->stackWidget->setCurrentWidget(d_ptr->scrollArea);
d_ptr->localPath = fd->localPath();
if (d_ptr->isMovie(d_ptr->localPath)) {
QMovie* mv = new QMovie(this);
mv->setFileName(d_ptr->localPath);
d_ptr->imageLabel->setMovie(mv);
mv->start();
} else {
d_ptr->imageLabel->setPixmap(QPixmap(d_ptr->localPath));
}
fd->deleteLater();
} else {
d_ptr->pgsBar->setValue(percent * 100);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。