2022-01-03 22:54:22 +01:00
|
|
|
#include "previewresultpdf.h"
|
|
|
|
PreviewResultPdf::PreviewResultPdf(const PreviewResult &o)
|
|
|
|
{
|
|
|
|
this->documentPath = o.getDocumentPath();
|
|
|
|
this->page = o.getPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *PreviewResultPdf::createPreviewWidget()
|
|
|
|
{
|
|
|
|
ClickLabel *label = new ClickLabel();
|
|
|
|
label->setPixmap(QPixmap::fromImage(previewImage));
|
|
|
|
label->setToolTip(getDocumentPath());
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PreviewResultPdf::hasPreview()
|
|
|
|
{
|
|
|
|
bool result = !this->previewImage.isNull();
|
|
|
|
return result;
|
|
|
|
}
|
2022-05-27 09:29:28 +02:00
|
|
|
|
|
|
|
QByteArray PreviewResultPdf::serialize() const
|
|
|
|
{
|
|
|
|
QByteArray result;
|
|
|
|
QDataStream stream{&result, QIODevice::WriteOnly};
|
|
|
|
PreviewResultType type = PreviewResultType::PDF;
|
|
|
|
stream << type << this->documentPath << this->page << this->previewImage;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<PreviewResultPdf> PreviewResultPdf::deserialize(QByteArray &ba)
|
|
|
|
{
|
|
|
|
PreviewResultPdf *result = new PreviewResultPdf();
|
|
|
|
PreviewResultType type;
|
|
|
|
|
|
|
|
QDataStream stream{&ba, QIODevice::ReadOnly};
|
|
|
|
stream >> type;
|
|
|
|
if(type != PreviewResultType::PDF)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Invalid byte array: Not a pdf preview");
|
|
|
|
}
|
|
|
|
stream >> result->documentPath >> result->page >> result->previewImage;
|
|
|
|
return QSharedPointer<PreviewResultPdf>(result);
|
|
|
|
}
|