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-2010 by Andi Clemens <andi dot clemens at gmail dot com>
0010  * SPDX-FileCopyrightText: 2009-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 #ifndef DIGIKAM_GLOBALS_H
0017 #define DIGIKAM_GLOBALS_H
0018 
0019 // Qt includes
0020 
0021 #include <QStringList>
0022 #include <QDateTime>
0023 #include <QIODevice>
0024 #include <QProcessEnvironment>
0025 
0026 // Local includes
0027 
0028 #include "digikam_export.h"
0029 
0030 class QWidget;
0031 class QObject;
0032 class QShortcut;
0033 class QKeySequence;
0034 class QApplication;
0035 class QDate;
0036 
0037 /**
0038  * Macros for image filters.
0039  */
0040 #define CLAMP0255(a)   qBound(0,a,255)
0041 #define CLAMP065535(a) qBound(0,a,65535)
0042 #define CLAMP(x,l,u)   qBound(l,x,u)
0043 #define MAX3(a, b, c)  (qMax(qMax(a,b),c))
0044 #define MIN3(a, b, c)  (qMin(qMin(a,b),c))
0045 
0046 /**
0047  * Degrees to radian conversion coeff (PI/180). To optimize computation.
0048  */
0049 #define DEG2RAD 0.017453292519943
0050 
0051 /**
0052  * Macro for Qt::endl which was introduced in Qt 5.14.0
0053  */
0054 #define QT_ENDL Qt::endl
0055 
0056 /**
0057  * Macro for Qt::KeepEmptyParts and Qt::SkipEmptyParts which were introduced in Qt 5.14.0
0058  * to be used with QString::split()
0059  */
0060 #define QT_KEEP_EMPTY_PARTS Qt::KeepEmptyParts
0061 #define QT_SKIP_EMPTY_PARTS Qt::SkipEmptyParts
0062 
0063 /**
0064  * Macro to use right return type with qHash(), changed with new Qt6 API.
0065  */
0066 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
0067 #   define QT_HASH_TYPE /* clazy:exclude=qt6-qhash-signature */ uint
0068 #else
0069 #   define QT_HASH_TYPE size_t
0070 #endif
0071 
0072 namespace Digikam
0073 {
0074 
0075 /**
0076  * Field value limits for all digiKam-specific fields (not EXIF/IPTC fields)
0077  */
0078 static const int RatingMin          = 0;
0079 static const int RatingMax          = 5;
0080 static const int NoRating           = -1;
0081 
0082 // --------------------------------------------------------
0083 
0084 /**
0085  * Segments for histograms and curves
0086  */
0087 static const int NUM_SEGMENTS_16BIT = 65536;
0088 static const int NUM_SEGMENTS_8BIT  = 256;
0089 static const int MAX_SEGMENT_16BIT  = NUM_SEGMENTS_16BIT - 1;
0090 static const int MAX_SEGMENT_8BIT   = NUM_SEGMENTS_8BIT  - 1;
0091 
0092 // --------------------------------------------------------
0093 
0094 /**
0095  * Delay in milliseconds to automatically expands album tree-view with D&D
0096  * See bug #286263 for details.
0097  */
0098 static const int AUTOEXPANDDELAY    = 800;
0099 
0100 // --------------------------------------------------------
0101 
0102 enum ColorLabel
0103 {
0104     NoColorLabel        = 0,
0105     RedLabel,
0106     OrangeLabel,
0107     YellowLabel,
0108     GreenLabel,
0109     BlueLabel,
0110     MagentaLabel,
0111     GrayLabel,
0112     BlackLabel,
0113     WhiteLabel,
0114     FirstColorLabel     = NoColorLabel,
0115     LastColorLabel      = WhiteLabel,
0116     NumberOfColorLabels = LastColorLabel + 1
0117 };
0118 
0119 // --------------------------------------------------------
0120 
0121 enum PickLabel
0122 {
0123     NoPickLabel        = 0,
0124     RejectedLabel,
0125     PendingLabel,
0126     AcceptedLabel,
0127     FirstPickLabel     = NoPickLabel,
0128     LastPickLabel      = AcceptedLabel,
0129     NumberOfPickLabels = LastPickLabel + 1
0130 };
0131 
0132 // --------------------------------------------------------
0133 
0134 enum HistogramBoxType
0135 {
0136     RGB = 0,
0137     RGBA,
0138     LRGB,
0139     LRGBA,
0140     LRGBC,
0141     LRGBAC
0142 };
0143 
0144 enum HistogramScale
0145 {
0146     LinScaleHistogram = 0,      ///< Linear scale
0147     LogScaleHistogram           ///< Logarithmic scale
0148 };
0149 
0150 enum HistogramRenderingType
0151 {
0152     FullImageHistogram = 0,     ///< Full image histogram rendering.
0153     ImageSelectionHistogram     ///< Image selection histogram rendering.
0154 };
0155 
0156 // --------------------------------------------------------
0157 
0158 enum ChannelType
0159 {
0160     LuminosityChannel = 0,
0161     RedChannel,
0162     GreenChannel,
0163     BlueChannel,
0164     AlphaChannel,
0165     ColorChannels
0166 };
0167 
0168 // --------------------------------------------------------
0169 
0170 /**
0171  * Convenience method for creating keyboard shortcuts.
0172  */
0173 DIGIKAM_EXPORT QShortcut* defineShortcut(QWidget* const w, const QKeySequence& key, const QObject* receiver, const char* slot);
0174 
0175 /**
0176  * Return list of supported image formats by Qt for reading or writing operations if suitable
0177  * container used by QFileDialog.
0178  * For simple container of type mime, use 'allTypes' string.
0179  * Supported modes are QIODevice::ReadOnly, QIODevice::WriteOnly, and QIODevice::ReadWrite.
0180  */
0181 DIGIKAM_EXPORT QStringList supportedImageMimeTypes(QIODevice::OpenModeFlag mode, QString& allTypes);
0182 
0183 /**
0184  * Return true if filePath is an image readable by application for thumbnail, preview, or edit.
0185  */
0186 DIGIKAM_EXPORT bool isReadableImageFile(const QString& filePath);
0187 
0188 /**
0189  * Show a dialog with all RAW camera supported by digiKam, through libraw.
0190  */
0191 DIGIKAM_EXPORT void showRawCameraList();
0192 
0193 /**
0194  * Style sheet for transparent QToolButtons over image and video preview.
0195  */
0196 DIGIKAM_EXPORT QString toolButtonStyleSheet();
0197 
0198 // --- Static functions for the bundles ---
0199 
0200 /**
0201  * Return true if application run in AppImage bundle.
0202  */
0203 DIGIKAM_EXPORT bool isRunningInAppImageBundle();
0204 
0205 /**
0206  * If digiKam run into AppImage, return a cleaned environment for QProcess to execute a
0207  * program outside the bundle without broken run-time dependencies.
0208  * Use case : system based Hugin CLI tools called by Panorama wizard.
0209  * If digiKam do not run as AppImage bundle, this method return a QProcessEnvironment instance
0210  * based on system environment.
0211  */
0212 DIGIKAM_EXPORT QProcessEnvironment adjustedEnvironmentForAppImage();
0213 
0214 /**
0215  * Static method to initialize DrMinGw crash handler under windows.
0216  * This method is typically called from main() function.
0217  */
0218 DIGIKAM_EXPORT void tryInitDrMingw();
0219 
0220 /**
0221  * Prefix of macOS Bundle to access to internal Unix hierarchy.
0222  */
0223 DIGIKAM_EXPORT QString macOSBundlePrefix();
0224 
0225 /**
0226  * For bundles only, unload all Qt translation files at run-time in application instance.
0227  */
0228 DIGIKAM_EXPORT void unloadQtTranslationFiles(QApplication& app);
0229 
0230 /**
0231  * For bundles only, load standard Qt translation files at run-time in application instance.
0232  */
0233 DIGIKAM_EXPORT void loadStdQtTranslationFiles(QApplication& app);
0234 
0235 /**
0236  * For bundles only, load ECM Qt translation files at run-time in application instance.
0237  */
0238 DIGIKAM_EXPORT void loadEcmQtTranslationFiles(QApplication& app);
0239 
0240 /**
0241  * For bundles only, main function to manage all Qt translation files at run-time in application instance.
0242  */
0243 DIGIKAM_EXPORT void installQtTranslationFiles(QApplication& app);
0244 
0245 /**
0246  * This method returns QDateTime from with date set to parameter date and time set to start of the day.
0247  */
0248 DIGIKAM_EXPORT QDateTime startOfDay(const QDate&);
0249 
0250 /**
0251  * For bundles only, find or set KSycoca database file in the cache directory.
0252  */
0253 DIGIKAM_EXPORT void setupKSycocaDatabaseFile();
0254 
0255 /**
0256  * Open online handbook at the section/chapter/reference page.
0257  *
0258  * if section and chapter and reference are empty, fromt page is open.  (https://en.wikipedia.org/wiki/Matrix_(protocol)#Bridges)
0259  * if only chapter and reference are empty, section page is open.       (as: https://docs.digikam.org/en/main_window.html)
0260  * if only reference is empty, chapter from section page is open.       (as: https://docs.digikam.org/en/main_window/people_view.html)
0261  * else reference at chapter from section page is open.                 (as: https://docs.digikam.org/en/main_window/people_view.html#face-recognition)
0262  */
0263 DIGIKAM_EXPORT void openOnlineDocumentation(const QString& section = QString(), const QString& chapter = QString(), const QString& reference = QString());
0264 
0265 } // namespace Digikam
0266 
0267 #endif // DIGIKAM_GLOBALS_H