mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
editor: guess the image title from image path when inserting an image
This commit is contained in:
parent
0ef38171e9
commit
b6b73c3f82
@ -31,6 +31,8 @@ VInsertImageDialog::VInsertImageDialog(const QString &p_title,
|
||||
fetchImageFromClipboard();
|
||||
}
|
||||
|
||||
autoCompleteTitleFromPath();
|
||||
|
||||
handleInputChanged();
|
||||
}
|
||||
|
||||
@ -178,6 +180,8 @@ void VInsertImageDialog::handleBrowseBtnClicked()
|
||||
|
||||
setPath(filePath);
|
||||
|
||||
autoCompleteTitleFromPath();
|
||||
|
||||
m_imageTitleEdit->setFocus();
|
||||
}
|
||||
|
||||
@ -341,3 +345,18 @@ int VInsertImageDialog::getOverridenWidth() const
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void VInsertImageDialog::autoCompleteTitleFromPath()
|
||||
{
|
||||
if (!m_imageTitleEdit->text().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString imgPath = m_pathEdit->text();
|
||||
if (imgPath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_imageTitleEdit->setText(QFileInfo(imgPath).baseName());
|
||||
m_imageTitleEdit->selectAll();
|
||||
}
|
||||
|
@ -67,6 +67,8 @@ private:
|
||||
|
||||
void setImageControlsVisible(bool p_visible);
|
||||
|
||||
void autoCompleteTitleFromPath();
|
||||
|
||||
VMetaWordLineEdit *m_imageTitleEdit;
|
||||
VLineEdit *m_pathEdit;
|
||||
QPushButton *browseBtn;
|
||||
|
@ -1580,7 +1580,12 @@ QStringList VUtils::parseCombinedArgString(const QString &p_program)
|
||||
|
||||
QImage VUtils::imageFromFile(const QString &p_filePath)
|
||||
{
|
||||
QImage img;
|
||||
QImage img(p_filePath);
|
||||
if (!img.isNull()) {
|
||||
return img;
|
||||
}
|
||||
|
||||
// @p_filePath may has a wrong suffix which indicates a wrong image format.
|
||||
QFile file(p_filePath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "fail to open image file" << p_filePath;
|
||||
|
@ -158,7 +158,7 @@ void VMdEditOperations::insertImageFromPath(const QString &p_title,
|
||||
p_urlInLink.clear();
|
||||
|
||||
// Make sure src image is valid.
|
||||
if (QImage(p_srcImagePath).isNull()) {
|
||||
if (VUtils::imageFromFile(p_srcImagePath).isNull()) {
|
||||
qWarning() << "fail to insert invalid source image" << p_srcImagePath;
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user