File indexing completed on 2025-01-05 03:56:31

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 28/08/2021
0007  * Description : Focus point properties container (relative to original image size)
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2021 by Phuoc Khanh Le <phuockhanhnk94 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_FOCUSPOINT_H
0017 #define DIGIKAM_FOCUSPOINT_H
0018 
0019 // Qt includes
0020 
0021 #include <QVariant>
0022 #include <QStringList>
0023 #include <QRectF>
0024 #include <QDebug>
0025 #include <QExplicitlySharedDataPointer>
0026 
0027 // Local includes
0028 
0029 #include "digikam_export.h"
0030 #include "metaengine.h"
0031 
0032 namespace Digikam
0033 {
0034 
0035 class DIGIKAM_EXPORT FocusPoint
0036 {
0037 public:
0038 
0039     enum TypePoint
0040     {
0041         Inactive        = 0,    ///< The AF-point is not active.
0042         InFocus         = 1,    ///< The AF-point is in focus.
0043         Selected        = 2,    ///< The AF-point is selected but not in focus.
0044         SelectedInFocus = 3     ///< The AF-point is selected and in focus.
0045     };
0046 
0047 public:
0048 
0049     /**
0050      * Focus point container contructors. Position and size are in float and a relative to the original image size.
0051      * Typically, the area is define as percents of values depending of image size used to extract information from metadata.
0052      * Like this, focus area can be drawn easily over a resized version of image.
0053      */
0054     FocusPoint(float x_position, float y_position, float width, float height, TypePoint type);
0055     FocusPoint(float x_position, float y_position, float width, float height);
0056     explicit FocusPoint(const QRectF& rectF);
0057     FocusPoint(const FocusPoint& other);
0058     FocusPoint();
0059     ~FocusPoint();
0060 
0061     /**
0062      * Equivalent to the copy constructor
0063      */
0064     FocusPoint& operator=(const FocusPoint& other);
0065 
0066     /**
0067      * Focus point type properties accessor. See TypePoint enum definition for details.
0068      */
0069     void      setType(TypePoint type);
0070     TypePoint getType()                                     const;
0071     QString   getTypeDescription()                          const;
0072 
0073     /**
0074      * Accessors to relative properties of focus point area.
0075      */
0076     void setCenterPosition(float x_position, float y_position);
0077     void setSize(float width, float height);
0078     void setRect(const QRectF& rectF);
0079     QPointF getCenterPosition()                             const;
0080     QSizeF  getSize()                                       const;
0081     QRectF  getRect()                                       const;
0082 
0083     /**
0084      * Return the real aera properties in image coordinates depending of the size.
0085      */
0086     QRect   getRectBySize(const QSize& size)                const;
0087 
0088 private:
0089 
0090     class Private;
0091     QExplicitlySharedDataPointer<Private> d;
0092 };
0093 
0094 /**
0095  * Boolean Operators over TypePoint type.
0096  */
0097 inline FocusPoint::TypePoint operator|(FocusPoint::TypePoint type1, FocusPoint::TypePoint type2)
0098 {
0099     return (static_cast<FocusPoint::TypePoint>(static_cast<int>(type1) | static_cast<int>(type2)));
0100 }
0101 
0102 inline FocusPoint::TypePoint operator&(FocusPoint::TypePoint type1, FocusPoint::TypePoint type2)
0103 {
0104     return (static_cast<FocusPoint::TypePoint>(static_cast<int>(type1) & static_cast<int>(type2)));
0105 }
0106 
0107 inline FocusPoint::TypePoint& operator|=(FocusPoint::TypePoint& type1, FocusPoint::TypePoint type2)
0108 {
0109     return (type1 = type1 | type2);
0110 }
0111 
0112 inline FocusPoint::TypePoint& operator&=(FocusPoint::TypePoint& type1, FocusPoint::TypePoint type2)
0113 {
0114     return (type1 = type1 & type2);
0115 }
0116 
0117 //! qDebug() stream operator. Writes property @fp to the debug output in a nicely formatted way.
0118 DIGIKAM_EXPORT QDebug operator<<(QDebug dbg, const FocusPoint& fp);
0119 
0120 } // namespace Digikam
0121 
0122 #endif // DIGIKAM_FOCUSPOINT_H