mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 14:29:54 +08:00
minor-fix: scale images keeping aspect ration when previewing images in dialogs
This commit is contained in:
parent
18ed9b761a
commit
f9080db71c
@ -95,6 +95,22 @@ void VConfirmDeletionDialog::setupUI(const QString &p_title,
|
|||||||
m_listWidget = new QListWidget();
|
m_listWidget = new QListWidget();
|
||||||
connect(m_listWidget, &QListWidget::currentRowChanged,
|
connect(m_listWidget, &QListWidget::currentRowChanged,
|
||||||
this, &VConfirmDeletionDialog::currentFileChanged);
|
this, &VConfirmDeletionDialog::currentFileChanged);
|
||||||
|
connect(m_listWidget, &QListWidget::itemActivated,
|
||||||
|
this, [this](QListWidgetItem *p_item) {
|
||||||
|
// Open it using resource manager.
|
||||||
|
if (!p_item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfirmItemWidget *widget = getItemWidget(p_item);
|
||||||
|
Q_ASSERT(widget);
|
||||||
|
QString filePath = m_items[widget->getIndex()].m_path;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty()) {
|
||||||
|
QUrl url = QUrl::fromLocalFile(filePath);
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
m_previewer = new QLabel();
|
m_previewer = new QLabel();
|
||||||
|
|
||||||
@ -195,7 +211,12 @@ void VConfirmDeletionDialog::currentFileChanged(int p_row)
|
|||||||
if (!image.isNull()) {
|
if (!image.isNull()) {
|
||||||
int width = 512 * VUtils::calculateScaleFactor();
|
int width = 512 * VUtils::calculateScaleFactor();
|
||||||
QSize previewSize(width, width);
|
QSize previewSize(width, width);
|
||||||
m_previewer->setPixmap(image.scaled(previewSize));
|
if (image.width() > width || image.height() > width) {
|
||||||
|
m_previewer->setPixmap(image.scaled(previewSize, Qt::KeepAspectRatio));
|
||||||
|
} else {
|
||||||
|
m_previewer->setPixmap(image);
|
||||||
|
}
|
||||||
|
|
||||||
succeed = true;
|
succeed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,15 @@ void VInsertImageDialog::setImage(const QImage &image)
|
|||||||
} else {
|
} else {
|
||||||
*(this->image) = image;
|
*(this->image) = image;
|
||||||
}
|
}
|
||||||
imagePreviewLabel->setPixmap(QPixmap::fromImage(this->image->scaled(previewSize)));
|
|
||||||
|
QPixmap pixmap;
|
||||||
|
if (image.width() > width || image.height() > width) {
|
||||||
|
pixmap = QPixmap::fromImage(this->image->scaled(previewSize, Qt::KeepAspectRatio));
|
||||||
|
} else {
|
||||||
|
pixmap = QPixmap::fromImage(*(this->image));
|
||||||
|
}
|
||||||
|
|
||||||
|
imagePreviewLabel->setPixmap(pixmap);
|
||||||
imagePreviewLabel->setVisible(true);
|
imagePreviewLabel->setVisible(true);
|
||||||
enableOkButton();
|
enableOkButton();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user