File indexing completed on 2025-01-19 03:59:21
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-28-07 0007 * Description : Import icon view tool tip 0008 * 0009 * SPDX-FileCopyrightText: 2012 by Islam Wazery <wazery at ubuntu dot com> 0010 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "importtooltipfiller.h" 0017 0018 // Qt includes 0019 0020 #include <QDateTime> 0021 #include <QTextDocument> 0022 #include <QLocale> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 // Local includes 0029 0030 #include "importsettings.h" 0031 #include "itempropertiestab.h" 0032 #include "ditemtooltip.h" 0033 #include "camiteminfo.h" 0034 0035 namespace Digikam 0036 { 0037 0038 QString ImportToolTipFiller::CamItemInfoTipContents(const CamItemInfo& info) 0039 { 0040 QString str; 0041 ImportSettings* const settings = ImportSettings::instance(); 0042 DToolTipStyleSheet cnt(settings->getToolTipsFont()); 0043 0044 PhotoInfoContainer photoInfo = info.photoInfo; 0045 QString tip = cnt.tipHeader; 0046 0047 // -- File properties ---------------------------------------------- 0048 0049 if (settings->getToolTipsShowFileName() || 0050 settings->getToolTipsShowFileDate() || 0051 settings->getToolTipsShowFileSize() || 0052 settings->getToolTipsShowImageType() || 0053 settings->getToolTipsShowImageDim()) 0054 { 0055 tip += cnt.headBeg + i18n("File Properties") + cnt.headEnd; 0056 0057 if (settings->getToolTipsShowFileName()) 0058 { 0059 tip += cnt.cellBeg + i18nc("filename", 0060 "Name:") + cnt.cellMid; 0061 tip += info.name + cnt.cellEnd; 0062 } 0063 0064 if (settings->getToolTipsShowFileDate()) 0065 { 0066 QDateTime createdDate = info.ctime; 0067 str = QLocale().toString(createdDate, QLocale::ShortFormat); 0068 tip += cnt.cellBeg + i18n("Date:") + cnt.cellMid + str + cnt.cellEnd; 0069 } 0070 0071 if (settings->getToolTipsShowFileSize()) 0072 { 0073 tip += cnt.cellBeg + i18n("Size:") + cnt.cellMid; 0074 QString localeFileSize = QLocale().toString(info.size); 0075 str = i18n("%1 (%2)", ItemPropertiesTab::humanReadableBytesCount(info.size), localeFileSize); 0076 tip += str + cnt.cellEnd; 0077 } 0078 0079 if (settings->getToolTipsShowImageType()) 0080 { 0081 tip += cnt.cellBeg + i18n("Type:") + cnt.cellMid + info.mime + cnt.cellEnd; 0082 } 0083 0084 if (settings->getToolTipsShowImageDim()) 0085 { 0086 if ((info.width == 0) || (info.height == 0) || (info.width == -1) || (info.height == -1)) 0087 { 0088 str = i18nc("unknown / invalid image dimension", 0089 "Unknown"); 0090 } 0091 else 0092 { 0093 QString mpixels = QLocale().toString(info.width*info.height/1000000.0, 'f', 1); 0094 str = i18nc("width x height (megapixels Mpx)", "%1x%2 (%3Mpx)", 0095 info.width, info.height, mpixels); 0096 } 0097 0098 tip += cnt.cellBeg + i18n("Dimensions:") + cnt.cellMid + str + cnt.cellEnd; 0099 } 0100 } 0101 0102 // -- Photograph Info ----------------------------------------------------------------------- 0103 0104 // NOTE: these info require \"Use File Metadata\" option from Camera Setup Behavior page. 0105 0106 if (settings->getToolTipsShowPhotoMake() || 0107 settings->getToolTipsShowPhotoLens() || 0108 settings->getToolTipsShowPhotoFocal() || 0109 settings->getToolTipsShowPhotoExpo() || 0110 settings->getToolTipsShowPhotoFlash() || 0111 settings->getToolTipsShowPhotoWB()) 0112 { 0113 if (!photoInfo.isNull()) 0114 { 0115 QString metaStr; 0116 tip += cnt.headBeg + i18n("Photograph Properties") + cnt.headEnd; 0117 0118 if (settings->getToolTipsShowPhotoMake()) 0119 { 0120 ItemPropertiesTab::shortenedMakeInfo(photoInfo.make); 0121 ItemPropertiesTab::shortenedModelInfo(photoInfo.model); 0122 0123 str = QString::fromUtf8("%1 / %2").arg(photoInfo.make.isEmpty() ? cnt.unavailable : photoInfo.make) 0124 .arg(photoInfo.model.isEmpty() ? cnt.unavailable : photoInfo.model); 0125 0126 if (str.length() > cnt.maxStringLength) 0127 { 0128 str = str.left(cnt.maxStringLength-3) + QLatin1String("..."); 0129 } 0130 0131 metaStr += cnt.cellBeg + i18n("Make/Model:") + cnt.cellMid + str.toHtmlEscaped() + cnt.cellEnd; 0132 } 0133 0134 if (settings->getToolTipsShowPhotoLens()) 0135 { 0136 str = photoInfo.lens.isEmpty() ? cnt.unavailable : photoInfo.lens; 0137 QString lens = i18nc("camera lens", "Lens:"); 0138 0139 if (str.length() > cnt.maxStringLength) 0140 { 0141 int space = str.lastIndexOf(QLatin1Char(' '), cnt.maxStringLength); 0142 0143 if (space == -1) 0144 space = cnt.maxStringLength; 0145 0146 metaStr += cnt.cellBeg + lens + cnt.cellMid + str.left(space).toHtmlEscaped() + cnt.cellEnd; 0147 0148 str = str.mid(space+1); 0149 lens = QString(); 0150 } 0151 0152 if (str.length() > cnt.maxStringLength) 0153 { 0154 str = str.left(cnt.maxStringLength-3) + QLatin1String("..."); 0155 } 0156 0157 metaStr += cnt.cellBeg + lens + cnt.cellMid + str.toHtmlEscaped() + cnt.cellEnd; 0158 } 0159 0160 if (settings->getToolTipsShowPhotoFocal()) 0161 { 0162 str = photoInfo.aperture.isEmpty() ? cnt.unavailable : photoInfo.aperture; 0163 0164 if (photoInfo.focalLength35mm.isEmpty()) 0165 { 0166 str += QString::fromUtf8(" / %1").arg(photoInfo.focalLength.isEmpty() ? cnt.unavailable : photoInfo.focalLength); 0167 } 0168 else 0169 { 0170 str += QString::fromUtf8(" / %1").arg(i18n("%1 (%2)",photoInfo.focalLength, photoInfo.focalLength35mm)); 0171 } 0172 0173 if (str.length() > cnt.maxStringLength) 0174 { 0175 str = str.left(cnt.maxStringLength-3) + QLatin1String("..."); 0176 } 0177 0178 metaStr += cnt.cellBeg + i18n("Aperture/Focal:") + cnt.cellMid + str.toHtmlEscaped() + cnt.cellEnd; 0179 } 0180 0181 if (settings->getToolTipsShowPhotoExpo()) 0182 { 0183 str = QString::fromUtf8("%1 / %2").arg(photoInfo.exposureTime.isEmpty() ? cnt.unavailable : photoInfo.exposureTime) 0184 .arg(photoInfo.sensitivity.isEmpty() ? cnt.unavailable : i18n("%1 ISO",photoInfo.sensitivity)); 0185 0186 if (str.length() > cnt.maxStringLength) 0187 { 0188 str = str.left(cnt.maxStringLength-3) + QLatin1String("..."); 0189 } 0190 0191 metaStr += cnt.cellBeg + i18n("Exposure/Sensitivity:") + cnt.cellMid + str.toHtmlEscaped() + cnt.cellEnd; 0192 } 0193 0194 if (settings->getToolTipsShowPhotoFlash()) 0195 { 0196 str = photoInfo.flash.isEmpty() ? cnt.unavailable : photoInfo.flash; 0197 0198 if (str.length() > cnt.maxStringLength) 0199 { 0200 str = str.left(cnt.maxStringLength-3) + QLatin1String("..."); 0201 } 0202 0203 metaStr += cnt.cellBeg + i18nc("camera flash settings", 0204 "Flash:") + cnt.cellMid + str.toHtmlEscaped() + cnt.cellEnd; 0205 } 0206 0207 if (settings->getToolTipsShowPhotoWB()) 0208 { 0209 str = photoInfo.whiteBalance.isEmpty() ? cnt.unavailable : photoInfo.whiteBalance; 0210 0211 if (str.length() > cnt.maxStringLength) 0212 { 0213 str = str.left(cnt.maxStringLength-3) + QLatin1String("..."); 0214 } 0215 0216 metaStr += cnt.cellBeg + i18n("White Balance:") + cnt.cellMid + str.toHtmlEscaped() + cnt.cellEnd; 0217 } 0218 0219 tip += metaStr; 0220 } 0221 } 0222 0223 tip += cnt.tipFooter; 0224 0225 return tip; 0226 } 0227 0228 } // namespace Digikam