|
|
|
|
@ -186,23 +186,29 @@ void Converter::convertImages(const QTextBlock &parent, const QDir &dir, QTextDo |
|
|
|
|
if (textFragment.isValid()) { |
|
|
|
|
const QTextCharFormat textCharFormat = textFragment.charFormat(); |
|
|
|
|
if (textCharFormat.isImageFormat()) { |
|
|
|
|
// TODO: Show images from http URIs
|
|
|
|
|
|
|
|
|
|
QTextImageFormat format; |
|
|
|
|
|
|
|
|
|
const qreal specifiedHeight = textCharFormat.toImageFormat().height(); |
|
|
|
|
const qreal specifiedWidth = textCharFormat.toImageFormat().width(); |
|
|
|
|
|
|
|
|
|
format.setName(QDir::cleanPath(dir.absoluteFilePath(textCharFormat.toImageFormat().name()))); |
|
|
|
|
const QImage img = QImage(format.name()); |
|
|
|
|
|
|
|
|
|
setImageSize(format, specifiedWidth, specifiedHeight, img.width(), img.height()); |
|
|
|
|
|
|
|
|
|
QTextCursor cursor(textDocument); |
|
|
|
|
cursor.setPosition(textFragment.position(), QTextCursor::MoveAnchor); |
|
|
|
|
cursor.setPosition(textFragment.position() + textFragment.length(), QTextCursor::KeepAnchor); |
|
|
|
|
cursor.removeSelectedText(); |
|
|
|
|
cursor.insertImage(format); |
|
|
|
|
|
|
|
|
|
const QString imageFilePath = QDir::cleanPath(dir.absoluteFilePath(textCharFormat.toImageFormat().name())); |
|
|
|
|
if (QFile::exists(imageFilePath)) { |
|
|
|
|
format.setName(imageFilePath); |
|
|
|
|
const QImage img = QImage(format.name()); |
|
|
|
|
|
|
|
|
|
setImageSize(format, specifiedWidth, specifiedHeight, img.width(), img.height()); |
|
|
|
|
|
|
|
|
|
cursor.insertImage(format); |
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) |
|
|
|
|
} else if ((!textCharFormat.toImageFormat().property(QTextFormat::ImageAltText).toString().isEmpty())) { |
|
|
|
|
cursor.insertText(textCharFormat.toImageFormat().property(QTextFormat::ImageAltText).toString()); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|