File indexing completed on 2025-03-09 03:52:10
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2014-09-19 0007 * Description : slide properties widget 0008 * 0009 * SPDX-FileCopyrightText: 2014-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2019-2020 by Minh Nghia Duong <minhnghiaduong997 at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "slideproperties.h" 0017 0018 // Qt includes 0019 0020 #include <QTextDocument> 0021 #include <QApplication> 0022 #include <QDateTime> 0023 #include <QPixmap> 0024 #include <QLocale> 0025 0026 // KDE includes 0027 0028 #include <klocalizedstring.h> 0029 0030 // Local includes 0031 0032 #include "digikam_debug.h" 0033 #include "dinfointerface.h" 0034 #include "itempropertiestab.h" 0035 0036 using namespace Digikam; 0037 0038 namespace DigikamGenericSlideShowPlugin 0039 { 0040 0041 class Q_DECL_HIDDEN SlideProperties::Private 0042 { 0043 public: 0044 0045 explicit Private() 0046 : maxStringLen(80), 0047 settings (nullptr) 0048 { 0049 } 0050 0051 const int maxStringLen; 0052 0053 QUrl url; 0054 0055 SlideShowSettings* settings; 0056 0057 DInfoInterface::DInfoMap infoMap; 0058 }; 0059 0060 SlideProperties::SlideProperties(SlideShowSettings* const settings, QWidget* const parent) 0061 : QWidget(parent), 0062 d (new Private) 0063 { 0064 setMouseTracking(true); 0065 d->settings = settings; 0066 } 0067 0068 SlideProperties::~SlideProperties() 0069 { 0070 delete d; 0071 } 0072 0073 void SlideProperties::setCurrentUrl(const QUrl& url) 0074 { 0075 d->infoMap = d->settings->iface->itemInfo(url); 0076 d->url = url; 0077 0078 update(); 0079 } 0080 0081 void SlideProperties::paintEvent(QPaintEvent*) 0082 { 0083 QPainter p(this); 0084 p.setFont(d->settings->captionFont); 0085 0086 DItemInfo item(d->infoMap); 0087 0088 QString str; 0089 /* 0090 PhotoInfoContainer photoInfo = d->info.photoInfo; 0091 */ 0092 QString comment = item.comment(); 0093 QString title = item.title(); 0094 QStringList tags = item.keywords(); 0095 int offset = 0; 0096 0097 // Display tag names. 0098 0099 if (d->settings->printTags) 0100 { 0101 printTags(p, offset, tags); 0102 } 0103 0104 // Display Titles. 0105 0106 if (d->settings->printTitle) 0107 { 0108 str.clear(); 0109 0110 if (!title.isEmpty()) 0111 { 0112 str += title; 0113 printInfoText(p, offset, str); 0114 } 0115 } 0116 0117 // Display Captions if no Titles. 0118 0119 if (d->settings->printCapIfNoTitle) 0120 { 0121 str.clear(); 0122 0123 if (title.isEmpty()) 0124 { 0125 str += comment; 0126 printComments(p, offset, str); 0127 } 0128 } 0129 0130 // Display Comments. 0131 0132 if (d->settings->printComment) 0133 { 0134 str = comment; 0135 printComments(p, offset, str); 0136 } 0137 0138 // Display Make and Model. 0139 0140 if (d->settings->printMakeModel) 0141 { 0142 str.clear(); 0143 0144 QString make = item.make(); 0145 QString model = item.model(); 0146 0147 if (!make.isEmpty()) 0148 { 0149 ItemPropertiesTab::shortenedMakeInfo(make); 0150 str = make; 0151 } 0152 0153 if (!model.isEmpty()) 0154 { 0155 if (!make.isEmpty()) 0156 { 0157 str += QLatin1String(" / "); 0158 } 0159 0160 ItemPropertiesTab::shortenedModelInfo(model); 0161 str += model; 0162 } 0163 0164 printInfoText(p, offset, str); 0165 } 0166 0167 // Display Lens model. 0168 0169 if (d->settings->printLensModel) 0170 { 0171 str.clear(); 0172 0173 QString lens = item.lens(); 0174 0175 if (!lens.isEmpty()) 0176 { 0177 str = lens; 0178 printInfoText(p, offset, str); 0179 } 0180 } 0181 0182 // Display Exposure and Sensitivity. 0183 0184 if (d->settings->printExpoSensitivity) 0185 { 0186 str.clear(); 0187 0188 QString exposureTime = item.exposureTime(); 0189 QString sensitivity = item.sensitivity(); 0190 0191 if (!exposureTime.isEmpty()) 0192 { 0193 str = exposureTime; 0194 } 0195 0196 if (!sensitivity.isEmpty()) 0197 { 0198 if (!exposureTime.isEmpty()) 0199 { 0200 str += QLatin1String(" / "); 0201 } 0202 0203 str += i18n("%1 ISO", sensitivity); 0204 } 0205 0206 printInfoText(p, offset, str); 0207 } 0208 0209 // Display Aperture and Focal. 0210 0211 if (d->settings->printApertureFocal) 0212 { 0213 str.clear(); 0214 0215 QString aperture = item.aperture(); 0216 QString focalLength = item.focalLength(); 0217 QString focalLength35mm = item.focalLength35mm(); 0218 0219 if (!aperture.isEmpty()) 0220 { 0221 str = aperture; 0222 } 0223 0224 if (focalLength35mm.isEmpty()) 0225 { 0226 if (!focalLength.isEmpty()) 0227 { 0228 if (!aperture.isEmpty()) 0229 { 0230 str += QLatin1String(" / "); 0231 } 0232 0233 str += focalLength; 0234 } 0235 } 0236 else 0237 { 0238 if (!aperture.isEmpty()) 0239 { 0240 str += QLatin1String(" / "); 0241 } 0242 0243 if (!focalLength.isEmpty()) 0244 { 0245 str += QString::fromUtf8("%1 (%2)").arg(focalLength).arg(focalLength35mm); 0246 } 0247 else 0248 { 0249 str += QString::fromUtf8("%1").arg(focalLength35mm); 0250 } 0251 } 0252 0253 printInfoText(p, offset, str); 0254 } 0255 0256 // Display Creation Date. 0257 0258 if (d->settings->printDate) 0259 { 0260 QDateTime dateTime = item.dateTime(); 0261 0262 if (dateTime.isValid()) 0263 { 0264 str = QLocale().toString(dateTime, QLocale::ShortFormat); 0265 printInfoText(p, offset, str); 0266 } 0267 } 0268 0269 // Display image File Name. 0270 0271 if (d->settings->printName) 0272 { 0273 printInfoText(p, offset, d->url.fileName()); 0274 } 0275 } 0276 0277 void SlideProperties::printInfoText(QPainter& p, int& offset, const QString& str, const QColor& pcol) 0278 { 0279 if (!str.isEmpty()) 0280 { 0281 offset += QFontMetrics(p.font()).lineSpacing(); 0282 p.setPen(Qt::black); 0283 0284 for (int x = -1 ; x <= 1 ; ++x) 0285 { 0286 for (int y = offset + 1 ; y >= offset - 1 ; --y) 0287 { 0288 p.drawText(x, p.window().height() - y, str); 0289 } 0290 } 0291 0292 p.setPen(pcol); 0293 p.drawText(0, p.window().height() - offset, str); 0294 } 0295 } 0296 0297 void SlideProperties::printComments(QPainter& p, int& offset, const QString& comments) 0298 { 0299 QStringList commentsByLines; 0300 0301 uint commentsIndex = 0; // Comments QString index 0302 0303 while (commentsIndex < (uint)comments.length()) 0304 { 0305 QString newLine; 0306 bool breakLine = false; // End Of Line found 0307 uint currIndex; // Comments QString current index 0308 0309 // Check minimal lines dimension 0310 0311 uint commentsLinesLengthLocal = d->maxStringLen; 0312 0313 for (currIndex = commentsIndex ; 0314 (currIndex < (uint)comments.length()) && !breakLine ; ++currIndex) 0315 { 0316 if ((comments.at(currIndex) == QLatin1Char('\n')) || comments.at(currIndex).isSpace()) 0317 { 0318 breakLine = true; 0319 } 0320 } 0321 0322 if (commentsLinesLengthLocal <= (currIndex - commentsIndex)) 0323 { 0324 commentsLinesLengthLocal = (currIndex - commentsIndex); 0325 } 0326 0327 breakLine = false; 0328 0329 for (currIndex = commentsIndex ; 0330 (currIndex <= (commentsIndex + commentsLinesLengthLocal)) && 0331 (currIndex < (uint)comments.length()) && !breakLine ; 0332 ++currIndex) 0333 { 0334 breakLine = (comments.at(currIndex) == QLatin1Char('\n')) ? true : false; 0335 0336 if (breakLine) 0337 { 0338 newLine.append(QLatin1Char(' ')); 0339 } 0340 else 0341 { 0342 newLine.append(comments.at(currIndex)); 0343 } 0344 } 0345 0346 commentsIndex = currIndex; // The line is ended 0347 0348 if (commentsIndex != (uint)comments.length()) 0349 { 0350 while (!newLine.endsWith(QLatin1Char(' '))) 0351 { 0352 newLine.truncate(newLine.length() - 1); 0353 --commentsIndex; 0354 } 0355 } 0356 0357 commentsByLines.prepend(newLine.trimmed()); 0358 } 0359 0360 for (int i = 0 ; i < (int)commentsByLines.count() ; ++i) 0361 { 0362 printInfoText(p, offset, commentsByLines.at(i)); 0363 } 0364 } 0365 0366 void SlideProperties::printTags(QPainter& p, int& offset, QStringList& tags) 0367 { 0368 tags.removeDuplicates(); 0369 tags.sort(); 0370 0371 QString str = tags.join(QLatin1String(", ")); 0372 0373 if (!str.isEmpty()) 0374 { 0375 printInfoText(p, offset, str, qApp->palette().color(QPalette::Link).name()); 0376 } 0377 } 0378 0379 } // namespace DigikamGenericSlideShowPlugin 0380 0381 #include "moc_slideproperties.cpp"