preview: scaled in-place preview of diagrams

This commit is contained in:
Le Tan 2018-05-14 22:24:30 +08:00
parent 423cc76ee5
commit 14070ab67a

View File

@ -402,6 +402,8 @@ void VLivePreviewHelper::processForInplacePreview(int p_idx)
void VLivePreviewHelper::updateInplacePreview()
{
Qt::TransformationMode tMode = Qt::SmoothTransformation;
qreal sf = VUtils::calculateScaleFactor();
QSet<int> blocks;
QVector<QSharedPointer<VImageToPreview> > images;
for (int i = 0; i < m_codeBlocks.size(); ++i) {
@ -410,13 +412,27 @@ void VLivePreviewHelper::updateInplacePreview()
// Generate the image.
bool valid = false;
if (cb.hasImageData()) {
cb.inplacePreview()->m_image.loadFromData(cb.imageData().toUtf8(),
QPixmap tmpImg;
tmpImg.loadFromData(cb.imageData().toUtf8(),
cb.imageFormat().toLocal8Bit().data());
if (sf < 1.1) {
cb.inplacePreview()->m_image.swap(tmpImg);
} else {
cb.inplacePreview()->m_image = tmpImg.scaledToWidth(tmpImg.width() * sf, tMode);
}
images.append(cb.inplacePreview());
valid = true;
} else if (cb.hasImageDataBa()) {
cb.inplacePreview()->m_image.loadFromData(cb.imageDataBa(),
QPixmap tmpImg;
tmpImg.loadFromData(cb.imageDataBa(),
cb.imageFormat().toLocal8Bit().data());
if (sf < 1.1) {
cb.inplacePreview()->m_image.swap(tmpImg);
} else {
cb.inplacePreview()->m_image = tmpImg.scaledToWidth(tmpImg.width() * sf, tMode);
}
images.append(cb.inplacePreview());
valid = true;
}