1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2009-09-08
7  * Description : global macros, variables and flags
8  *
9  * Copyright (C) 2009-2010 by Andi Clemens <andi dot clemens at gmail dot com>
10  * Copyright (C) 2009-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_GLOBALS_H
26 #define DIGIKAM_GLOBALS_H
27 
28 // Qt includes
29 
30 #include <QStringList>
31 #include <QIODevice>
32 #include <QProcessEnvironment>
33 
34 // Local includes
35 
36 #include "digikam_export.h"
37 
38 class QWidget;
39 class QObject;
40 class QShortcut;
41 class QKeySequence;
42 
43 /**
44  * Macros for image filters.
45  */
46 #define CLAMP0255(a)   qBound(0,a,255)
47 #define CLAMP065535(a) qBound(0,a,65535)
48 #define CLAMP(x,l,u)   qBound(l,x,u)
49 #define MAX3(a, b, c)  (qMax(qMax(a,b),c))
50 #define MIN3(a, b, c)  (qMin(qMin(a,b),c))
51 
52 /**
53  * Degrees to radian conversion coeff (PI/180). To optimize computation.
54  */
55 #define DEG2RAD 0.017453292519943
56 
57 namespace Digikam
58 {
59 
60 /**
61  * Field value limits for all digiKam-specific fields (not EXIF/IPTC fields)
62  */
63 static const int RatingMin          = 0;
64 static const int RatingMax          = 5;
65 static const int NoRating           = -1;
66 
67 // --------------------------------------------------------
68 
69 /**
70  * Segments for histograms and curves
71  */
72 static const int NUM_SEGMENTS_16BIT = 65536;
73 static const int NUM_SEGMENTS_8BIT  = 256;
74 static const int MAX_SEGMENT_16BIT  = NUM_SEGMENTS_16BIT - 1;
75 static const int MAX_SEGMENT_8BIT   = NUM_SEGMENTS_8BIT  - 1;
76 
77 // --------------------------------------------------------
78 
79 /**
80  * Delay in milliseconds to automatically expands album tree-view with D&D
81  * See bug #286263 for details.
82  */
83 static const int AUTOEXPANDDELAY    = 800;
84 
85 // --------------------------------------------------------
86 
87 enum ColorLabel
88 {
89     NoColorLabel        = 0,
90     RedLabel,
91     OrangeLabel,
92     YellowLabel,
93     GreenLabel,
94     BlueLabel,
95     MagentaLabel,
96     GrayLabel,
97     BlackLabel,
98     WhiteLabel,
99     FirstColorLabel     = NoColorLabel,
100     LastColorLabel      = WhiteLabel,
101     NumberOfColorLabels = LastColorLabel + 1
102 };
103 
104 // --------------------------------------------------------
105 
106 enum PickLabel
107 {
108     NoPickLabel        = 0,
109     RejectedLabel,
110     PendingLabel,
111     AcceptedLabel,
112     FirstPickLabel     = NoPickLabel,
113     LastPickLabel      = AcceptedLabel,
114     NumberOfPickLabels = LastPickLabel + 1
115 };
116 
117 // --------------------------------------------------------
118 
119 enum HistogramBoxType
120 {
121     RGB = 0,
122     RGBA,
123     LRGB,
124     LRGBA,
125     LRGBC,
126     LRGBAC
127 };
128 
129 enum HistogramScale
130 {
131     LinScaleHistogram = 0,      ///< Linear scale
132     LogScaleHistogram           ///< Logarithmic scale
133 };
134 
135 enum HistogramRenderingType
136 {
137     FullImageHistogram = 0,     ///< Full image histogram rendering.
138     ImageSelectionHistogram     ///< Image selection histogram rendering.
139 };
140 
141 // --------------------------------------------------------
142 
143 enum ChannelType
144 {
145     LuminosityChannel = 0,
146     RedChannel,
147     GreenChannel,
148     BlueChannel,
149     AlphaChannel,
150     ColorChannels
151 };
152 
153 // --------------------------------------------------------
154 
155 /**
156  * Convenience method for creating keyboard shortcuts.
157  */
158 DIGIKAM_EXPORT QShortcut* defineShortcut(QWidget* const w, const QKeySequence& key, const QObject* receiver, const char* slot);
159 
160 /**
161  * Return list of supported image formats by Qt for reading or writing operations if suitable
162  * container used by QFileDialog.
163  * For simple container of type mime, use 'allTypes' string.
164  * Supported modes are QIODevice::ReadOnly, QIODevice::WriteOnly, and QIODevice::ReadWrite.
165  */
166 DIGIKAM_EXPORT QStringList supportedImageMimeTypes(QIODevice::OpenModeFlag mode, QString& allTypes);
167 
168 /**
169  * Return true if filePath is an image readable by application for thumbnail, preview, or edit.
170  */
171 DIGIKAM_EXPORT bool isReadableImageFile(const QString& filePath);
172 
173 /**
174  * Show a dialog with all RAW camera supported by digiKam, through libraw.
175  */
176 DIGIKAM_EXPORT void showRawCameraList();
177 
178 /**
179  * Return true if application run in AppImage bundle.
180  */
181 DIGIKAM_EXPORT bool isRunningInAppImageBundle();
182 
183 /**
184  * If digiKam run into AppImage, return a cleaned environment for QProcess to execute a
185  * program outside the bundle without broken run-time dependencies.
186  * Use case : system based Hugin CLI tools called by Panorama wizard.
187  * If digiKam do not run as AppImage bundle, this method return a QProcessEnvironment instance
188  * based on system environment.
189  */
190 DIGIKAM_EXPORT QProcessEnvironment adjustedEnvironmentForAppImage();
191 
192 /**
193  * Static method to initialize DrMinGw crash handler under windows.
194  * This method is typically called from main() function.
195  */
196 DIGIKAM_EXPORT void tryInitDrMingw();
197 
198 /**
199  * Style sheet for transparent QToolButtons over image and video preview.
200  */
201 DIGIKAM_EXPORT QString toolButtonStyleSheet();
202 
203 /**
204  * Prefix of macOS Bundle to access to internal Unix hierarchy.
205  */
206 DIGIKAM_EXPORT QString macOSBundlePrefix();
207 
208 } // namespace Digikam
209 
210 #endif // DIGIKAM_GLOBALS_H
211