File indexing completed on 2025-01-05 03:51:16
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-09-08 0007 * Description : global macros, variables and flags 0008 * 0009 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "digikam_globals_p.h" 0016 0017 namespace Digikam 0018 { 0019 0020 QShortcut* defineShortcut(QWidget* const w, const QKeySequence& key, const QObject* receiver, const char* slot) 0021 { 0022 QShortcut* const s = new QShortcut(w); 0023 s->setKey(key); 0024 s->setContext(Qt::WidgetWithChildrenShortcut); 0025 QObject::connect(s, SIGNAL(activated()), receiver, slot); 0026 0027 return s; 0028 } 0029 0030 QStringList supportedImageMimeTypes(QIODevice::OpenModeFlag mode, QString& allTypes) 0031 { 0032 QStringList formats; 0033 QList<QByteArray> supported; 0034 0035 switch (mode) 0036 { 0037 case QIODevice::ReadOnly: 0038 { 0039 supported = QImageReader::supportedImageFormats(); 0040 break; 0041 } 0042 0043 case QIODevice::WriteOnly: 0044 { 0045 supported = QImageWriter::supportedImageFormats(); 0046 break; 0047 } 0048 0049 case QIODevice::ReadWrite: 0050 { 0051 supported = QImageWriter::supportedImageFormats() + QImageReader::supportedImageFormats(); 0052 break; 0053 } 0054 0055 default: 0056 { 0057 qCDebug(DIGIKAM_GENERAL_LOG) << "Unsupported mode!"; 0058 break; 0059 } 0060 } 0061 0062 Q_FOREACH (const QByteArray& frm, supported) 0063 { 0064 if (QString::fromLatin1(frm).contains(QLatin1String("tif"), Qt::CaseInsensitive) || 0065 QString::fromLatin1(frm).contains(QLatin1String("tiff"), Qt::CaseInsensitive)) 0066 { 0067 continue; 0068 } 0069 0070 if (QString::fromLatin1(frm).contains(QLatin1String("jpg"), Qt::CaseInsensitive) || 0071 QString::fromLatin1(frm).contains(QLatin1String("jpeg"), Qt::CaseInsensitive)) 0072 { 0073 continue; 0074 } 0075 0076 #ifdef HAVE_JASPER 0077 0078 if (QString::fromLatin1(frm).contains(QLatin1String("jp2"), Qt::CaseInsensitive) || 0079 QString::fromLatin1(frm).contains(QLatin1String("j2k"), Qt::CaseInsensitive) || 0080 QString::fromLatin1(frm).contains(QLatin1String("jpx"), Qt::CaseInsensitive) || 0081 QString::fromLatin1(frm).contains(QLatin1String("jpc"), Qt::CaseInsensitive) || 0082 QString::fromLatin1(frm).contains(QLatin1String("pgx"), Qt::CaseInsensitive)) 0083 { 0084 continue; 0085 } 0086 0087 #endif // HAVE_JASPER 0088 0089 #ifdef HAVE_X265 0090 0091 if (QString::fromLatin1(frm).contains(QLatin1String("heic"), Qt::CaseInsensitive) || 0092 QString::fromLatin1(frm).contains(QLatin1String("heif"), Qt::CaseInsensitive) || 0093 QString::fromLatin1(frm).contains(QLatin1String("hif"), Qt::CaseInsensitive)) 0094 { 0095 continue; 0096 } 0097 0098 #endif // HAVE_X265 0099 0100 #ifdef HAVE_IMAGE_MAGICK 0101 0102 if (QString::fromLatin1(frm).contains(QLatin1String("fts"), Qt::CaseInsensitive) || 0103 QString::fromLatin1(frm).contains(QLatin1String("fit"), Qt::CaseInsensitive) || 0104 QString::fromLatin1(frm).contains(QLatin1String("fits"), Qt::CaseInsensitive)) 0105 { 0106 continue; 0107 } 0108 0109 #endif // HAVE_IMAGE_MAGICK 0110 0111 formats.append(i18n("%1 Image (%2)", QString::fromLatin1(frm).toUpper(), QLatin1String("*.") + QLatin1String(frm))); 0112 allTypes.append(QString::fromLatin1("*.%1 ").arg(QLatin1String(frm))); 0113 } 0114 0115 formats.append(i18n("TIFF Image (*.tiff *.tif)")); 0116 allTypes.append(QLatin1String("*.tiff *.tif ")); 0117 formats.append(i18n("JPEG Image (*.jpg *.jpeg *.jpe)")); 0118 allTypes.append(QLatin1String("*.jpg *.jpeg *.jpe ")); 0119 0120 #ifdef HAVE_JASPER 0121 0122 formats.append(i18n("JPEG2000 Image (*.jp2 *.j2k *.jpx *.pgx)")); 0123 allTypes.append(QLatin1String("*.jp2 *.j2k *.jpx *.pgx ")); 0124 0125 #endif // HAVE_JASPER 0126 0127 formats << i18n("Progressive Graphics file (*.pgf)"); 0128 allTypes.append(QLatin1String("*.pgf ")); 0129 0130 #ifdef HAVE_X265 0131 0132 formats << i18n("High Efficiency Image Coding (*.heic *.heif)"); 0133 allTypes.append(QLatin1String("*.heic *.heif ")); 0134 0135 #endif // HAVE_X265 0136 0137 #ifdef HAVE_IMAGE_MAGICK 0138 0139 formats << i18n("Flexible Image Transport System (*.fts *.fit *.fits)"); 0140 allTypes.append(QLatin1String("*.fts *.fit *.fits ")); 0141 0142 #endif // HAVE_IMAGE_MAGICK 0143 0144 if (mode != QIODevice::WriteOnly) 0145 { 0146 formats << i18n("Raw Images (%1)", DRawDecoder::rawFiles()); 0147 allTypes.append(DRawDecoder::rawFiles()); 0148 formats << i18n("All supported files (%1)", allTypes); 0149 } 0150 0151 return formats; 0152 } 0153 0154 bool isReadableImageFile(const QString& filePath) 0155 { 0156 QFileInfo info(filePath); 0157 0158 if (info.isFile() && !info.isSymLink() && !info.isDir() && !info.isRoot()) 0159 { 0160 QString path = info.absoluteFilePath(); 0161 QMimeType mtype = QMimeDatabase().mimeTypeForFile(path); 0162 QString suffix = info.suffix().toUpper(); 0163 0164 // Add extra check of the image extensions that are still 0165 // unknown in older Qt versions or have an application mime type. 0166 0167 if (mtype.name().startsWith(QLatin1String("image/")) || 0168 (suffix == QLatin1String("PGF")) || 0169 (suffix == QLatin1String("KRA")) || 0170 (suffix == QLatin1String("CR3")) || 0171 (suffix == QLatin1String("HIF")) || 0172 (suffix == QLatin1String("HEIC")) || 0173 (suffix == QLatin1String("HEIF")) || 0174 DRawDecoder::rawFiles().contains(suffix)) 0175 { 0176 return true; 0177 } 0178 } 0179 0180 return false; 0181 } 0182 0183 void showRawCameraList() 0184 { 0185 RawCameraDlg* const dlg = new RawCameraDlg(qApp->activeWindow()); 0186 dlg->show(); 0187 } 0188 0189 QString toolButtonStyleSheet() 0190 { 0191 return QLatin1String("QToolButton { padding: 1px; background-color: " 0192 " qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " 0193 " stop: 0 rgba(100, 100, 100, 50%), " 0194 " stop: 1 rgba(170, 170, 170, 50%)); " 0195 "border: 1px solid rgba(170, 170, 170, 10%); } " 0196 0197 "QToolButton:hover { border-color: white; } " 0198 0199 "QToolButton:pressed { background-color: " 0200 " qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " 0201 " stop: 0 rgba(40, 40, 40, 50%), " 0202 " stop: 1 rgba(90, 90, 90, 50%)); " 0203 "border-color: white; } " 0204 0205 "QToolButton:checked { background-color: " 0206 " qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " 0207 " stop: 0 rgba(40, 40, 40, 50%), " 0208 " stop: 1 rgba(90, 90, 90, 50%)); } " 0209 0210 "QToolButton:disabled { background-color: " 0211 " qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " 0212 " stop: 0 rgba(40, 40, 40, 50%), " 0213 " stop: 1 rgba(50, 50, 50, 50%)); }"); 0214 } 0215 0216 QDateTime startOfDay(const QDate& date) 0217 { 0218 return date.startOfDay(); 0219 } 0220 0221 void openOnlineDocumentation(const QString& section, const QString& chapter, const QString& reference) 0222 { 0223 QUrl url; 0224 0225 if (section.isEmpty()) 0226 { 0227 if (QApplication::applicationName() == QLatin1String("showfoto")) 0228 { 0229 url = QUrl(QString::fromUtf8("https://docs.digikam.org/en/showfoto_editor.html")); 0230 } 0231 else 0232 { 0233 url = QUrl(QString::fromUtf8("https://docs.digikam.org/en/index.html")); 0234 } 0235 } 0236 else 0237 { 0238 if (chapter.isEmpty()) 0239 { 0240 url = QUrl(QString::fromUtf8("https://docs.digikam.org/en/%1.html").arg(section)); 0241 } 0242 else 0243 { 0244 if (reference.isEmpty()) 0245 { 0246 url = QUrl(QString::fromUtf8("https://docs.digikam.org/en/%1/%2.html").arg(section).arg(chapter)); 0247 } 0248 else 0249 { 0250 url = QUrl(QString::fromUtf8("https://docs.digikam.org/en/%1/%2.html#%3").arg(section).arg(chapter).arg(reference)); 0251 } 0252 } 0253 } 0254 0255 #ifdef HAVE_QWEBENGINE 0256 0257 WebBrowserDlg* const browser = new WebBrowserDlg(url, qApp->activeWindow()); 0258 browser->show(); 0259 0260 #else 0261 0262 QDesktopServices::openUrl(url); 0263 0264 #endif 0265 0266 } 0267 0268 } // namespace Digikam