代码拉取完成,页面将自动刷新
#include <QPainter>
#include <QDebug>
#include <QThreadPool>
#include "pixmapelement.h"
#include "loader.h"
PixmapOpenJob::PixmapOpenJob(PixmapElement * element):QRunnable(),m_element(element)
{
Q_ASSERT(element);
}
void PixmapOpenJob::run()
{
m_element->loadPixmap();
}
PixmapElement::PixmapElement(
BaseElement *parent,
BaseSpace * space,
QRectF initRect
):
BaseElement(parent,space,initRect),
m_loading(false),
m_loader(new Loader(this))
{
}
void PixmapElement::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
QPixmap pixmap = this->pixmap();
painter->drawPixmap(this->rect(),pixmap,pixmap.rect());
}
void PixmapElement::startLoad()
{
m_loading=true;
m_loader->start();
}
void PixmapElement::finishLoad(bool)
{
//m_geometry.setSize(pixmapNode->pixmap().rect().size());
m_loader->stop();
this->update();
m_loading = false;
}
void PixmapElement::updateProgress(int progress)
{
if (m_loader)
m_loader->setProgress(progress);
}
void PixmapElement::load()
{
PixmapOpenJob* job = new PixmapOpenJob(this);
QThreadPool::globalInstance()->start(job);
}
void PixmapElement::loadPixmap()
{
startLoad();
updateProgress(0);
// Document * doc =document();
// QDir tempDir = doc->tempPath();
// updateProgress(5);
// QFileInfo originalFileInfo(m_originName);
// QString fileSuffix = originalFileInfo.suffix();
// QString tempFileName = tempDir.absoluteFilePath(
// QString("%1.%2").arg(this->id()).arg(fileSuffix));
// QFileInfo tempFileInfo(tempFileName);
// if (!tempFileInfo.exists()){
// QFile file(m_originName);
// file.open(QIODevice::ReadOnly);
// file.copy(tempFileName);
// }
// updateProgress(50);
// QFile tempFile(tempFileName);
// tempFile.open(QIODevice::ReadOnly);
// updateProgress(80);
// QByteArray data = tempFile.readAll();
// char * fmt = fileSuffix.toLatin1().data();
// this->m_pixmap.loadFromData(data,fmt);
// this->setRect(QRectF(QPointF(0,0),this->m_pixmap.size()));
// updateProgress(100);
// finishLoad(true);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。