From 1066fa45ea83a6a353b4394c13c823a4fa86d080 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Wed, 4 Nov 2020 00:16:37 +0800 Subject: [PATCH] feat: more useful information from property dialog --- languages/PineapplePictures.ts | 128 ++++++++++++++++++++----- languages/PineapplePictures_zh_CN.ts | 138 +++++++++++++++++++++------ metadatamodel.cpp | 59 +++++++++--- metadatamodel.h | 1 + 4 files changed, 264 insertions(+), 62 deletions(-) diff --git a/languages/PineapplePictures.ts b/languages/PineapplePictures.ts index 8286787..ccbb938 100644 --- a/languages/PineapplePictures.ts +++ b/languages/PineapplePictures.ts @@ -170,7 +170,7 @@ GraphicsView - + File url list is empty @@ -180,12 +180,18 @@ - - Image data is invalid + + + Image data is invalid or currently unsupported + Image data is invalid + + + + Not supported mimedata: %1 @@ -253,44 +259,120 @@ MetadataDialog - + Image Metadata MetadataModel - - - General - General info about the image, section name. - - - - - File Name - - - - - File Size - - - Last Modified + Origin + Section name. - Image Size + Image + Section name. - + + File + Section name. + + + + + Camera + Section name. + + + + + %1 File + + + + + Description + Section name. + + + + + Advanced photo + Section name. + + + + + GPS + Section name. + + + + + Dimensions + + + + + Aspect Ratio + + + + + Name + + + + + Item type + + + + + Folder path + + + + + Size + + + + + Date Created + + + + + Date Modified + + + + %1 x %2 + + + %1 : %2 + + + + + Property + + + + + Value + + SettingsDialog diff --git a/languages/PineapplePictures_zh_CN.ts b/languages/PineapplePictures_zh_CN.ts index edfdf2b..067bee7 100644 --- a/languages/PineapplePictures_zh_CN.ts +++ b/languages/PineapplePictures_zh_CN.ts @@ -170,7 +170,7 @@ GraphicsView - + File url list is empty 文件 URL 列表为空 @@ -180,12 +180,18 @@ 文件不是有效的图片文件 - + + + Image data is invalid or currently unsupported + 图像数据无效或暂未支持 + + + Image data is invalid 图片数据无效 - + Not supported mimedata: %1 不受支持的 MimeData 格式:%1 @@ -225,7 +231,7 @@ Properties - + 属性 @@ -253,43 +259,119 @@ MetadataDialog - + Image Metadata - + 图像元信息 MetadataModel - - - General - General info about the image, section name. - - - - - File Name - - - - - File Size - - - Last Modified - + Origin + Section name. + 来源 - Image Size - + Image + Section name. + 图像 - + + File + Section name. + 文件 + + + + Camera + Section name. + 照相机 + + + + %1 File + %1 文件 + + + + Description + Section name. + 说明 + + + + Advanced photo + Section name. + 高级照片 + + + + GPS + Section name. + GPS + + + + Dimensions + 分辨率 + + + + Aspect Ratio + 纵横比 + + + + Name + 名称 + + + + Item type + 项目类型 + + + + Folder path + 文件夹路径 + + + + Size + 大小 + + + + Date Created + 创建日期 + + + + Date Modified + 修改日期 + + + %1 x %2 - + %1 x %2 + + + + %1 : %2 + %1 : %2 + + + + Property + 属性 + + + + Value + diff --git a/metadatamodel.cpp b/metadatamodel.cpp index 517b46a..ecacc62 100644 --- a/metadatamodel.cpp +++ b/metadatamodel.cpp @@ -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 §ionKey, const QString §ionDisplayName) { if (m_sections.contains(sectionKey)) { diff --git a/metadatamodel.h b/metadatamodel.h index 9f1c904..babfe70 100644 --- a/metadatamodel.h +++ b/metadatamodel.h @@ -13,6 +13,7 @@ public: void setFile(const QString & imageFilePath); static QString imageSize(const QSize &size); + static QString imageSizeRatio(const QSize &size); bool appendSection(const QString & sectionKey, const QString & sectionDisplayName); bool appendProperty(const QString & sectionKey, const QString & propertyKey, const QString & propertyDisplayName, const QString & propertyValue = QString());