1
0

feat: more useful information from property dialog

This commit is contained in:
Gary Wang
2020-11-04 00:16:37 +08:00
parent 71c38c8e96
commit 1066fa45ea
4 changed files with 264 additions and 62 deletions

View File

@@ -21,21 +21,45 @@ void MetadataModel::setFile(const QString &imageFilePath)
QFileInfo fileInfo(imageFilePath);
// It'll be fine if we don't re-use the image reader we pass to the graphics scene for now.
QImageReader imgReader(imageFilePath);
imgReader.setAutoTransform(true);
imgReader.setDecideFormatFromContent(true);
const QString & itemTypeString = tr("%1 File").arg(QString(imgReader.format().toUpper()));
const QString & sizeString = QLocale().formattedDataSize(fileInfo.size());
const QString & timeString = QLocale().toString(fileInfo.lastModified(), QLocale::LongFormat);
const QString & imageSizeString = imageSize(imgReader.size());
const QString & birthTimeString = QLocale().toString(fileInfo.birthTime(), QLocale::LongFormat);
const QString & lastModifiedTimeString = QLocale().toString(fileInfo.lastModified(), QLocale::LongFormat);
const QString & imageDimensionsString = imageSize(imgReader.size());
const QString & imageRatioString = imageSizeRatio(imgReader.size());
appendSection(QStringLiteral("General"), tr("General", "General info about the image, section name."));
#if 0
appendSection(QStringLiteral("Description"), tr("Description", "Section name."));
appendSection(QStringLiteral("Origin"), tr("Origin", "Section name."));
#endif // 0
appendSection(QStringLiteral("Image"), tr("Image", "Section name."));
#if 0
appendSection(QStringLiteral("Camera"), tr("Camera", "Section name."));
appendSection(QStringLiteral("AdvancedPhoto"), tr("Advanced photo", "Section name."));
appendSection(QStringLiteral("GPS"), tr("GPS", "Section name."));
#endif // 0
appendSection(QStringLiteral("File"), tr("File", "Section name."));
appendProperty(QStringLiteral("General"), QStringLiteral("General.Name"),
tr("File Name"), fileInfo.fileName());
appendProperty(QStringLiteral("General"), QStringLiteral("General.Size"),
tr("File Size"), sizeString);
appendProperty(QStringLiteral("General"), QStringLiteral("General.Time"),
tr("Last Modified"), timeString);
appendProperty(QStringLiteral("General"), QStringLiteral("General.ImageSize"),
tr("Image Size"), imageSizeString);
appendProperty(QStringLiteral("Image"), QStringLiteral("Image.Dimensions"),
tr("Dimensions"), imageDimensionsString);
appendProperty(QStringLiteral("Image"), QStringLiteral("Image.SizeRatio"),
tr("Aspect Ratio"), imageRatioString);
appendProperty(QStringLiteral("File"), QStringLiteral("File.Name"),
tr("Name"), fileInfo.fileName());
appendProperty(QStringLiteral("File"), QStringLiteral("File.ItemType"),
tr("Item type"), itemTypeString);
appendProperty(QStringLiteral("File"), QStringLiteral("File.Path"),
tr("Folder path"), fileInfo.path());
appendProperty(QStringLiteral("File"), QStringLiteral("File.Size"),
tr("Size"), sizeString);
appendProperty(QStringLiteral("File"), QStringLiteral("File.CreatedTime"),
tr("Date Created"), birthTimeString);
appendProperty(QStringLiteral("File"), QStringLiteral("File.LastModified"),
tr("Date Modified"), lastModifiedTimeString);
}
QString MetadataModel::imageSize(const QSize &size)
@@ -51,6 +75,19 @@ QString MetadataModel::imageSize(const QSize &size)
return imageSize;
}
int simplegcd(int a, int b) {
return b == 0 ? a : simplegcd(b, a % b);
}
QString MetadataModel::imageSizeRatio(const QSize &size)
{
if (!size.isValid()) {
return QStringLiteral("-");
}
int gcd = simplegcd(size.width(), size.height());
return tr("%1 : %2").arg(QString::number(size.width() / gcd), QString::number(size.height() / gcd));
}
bool MetadataModel::appendSection(const QString &sectionKey, const QString &sectionDisplayName)
{
if (m_sections.contains(sectionKey)) {