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 #include "focuspoint.h" 0017 0018 // Qt includes 0019 0020 #include <QTransform> 0021 0022 // KDE includes 0023 0024 #include <klocalizedstring.h> 0025 0026 // Local includes 0027 0028 #include "digikam_debug.h" 0029 #include "metaengine_rotation.h" 0030 0031 namespace Digikam 0032 { 0033 0034 class Q_DECL_HIDDEN FocusPoint::Private : public QSharedData 0035 { 0036 public: 0037 0038 explicit Private() 0039 : x_position(0.0), 0040 y_position(0.0), 0041 width (0.0), 0042 height (0.0), 0043 type (Inactive) 0044 { 0045 }; 0046 0047 float x_position; ///< Relative X coordinate of the center of focus point area (depending of original image width). 0048 float y_position; ///< Relative Y coordinate of the center of focus point area (depending of original image height). 0049 float width; ///< Relative Width of focus point area (depending of original image width). 0050 float height; ///< Relative Height of focus point area (depending of original image height). 0051 TypePoint type; ///< Focus point area type. See TypePoint enum definition for details. 0052 }; 0053 0054 FocusPoint::FocusPoint() 0055 : d(new Private) 0056 { 0057 } 0058 0059 FocusPoint::FocusPoint(float x_position, float y_position, float width, float height, TypePoint type) 0060 : d(new Private) 0061 { 0062 d->x_position = x_position; 0063 d->y_position = y_position; 0064 d->width = width; 0065 d->height = height; 0066 d->type = type; 0067 } 0068 0069 FocusPoint::FocusPoint(float x_position, float y_position, float width, float height) 0070 : d(new Private) 0071 { 0072 d->x_position = x_position; 0073 d->y_position = y_position; 0074 d->width = width; 0075 d->height = height; 0076 d->type = Inactive; 0077 } 0078 0079 FocusPoint::FocusPoint(const QRectF& rectF) 0080 : d(new Private) 0081 { 0082 setRect(rectF); 0083 d->type = Inactive; 0084 } 0085 0086 FocusPoint::FocusPoint(const FocusPoint& other) 0087 : d(other.d) 0088 { 0089 } 0090 0091 FocusPoint::~FocusPoint() 0092 { 0093 } 0094 0095 FocusPoint& FocusPoint::operator=(const FocusPoint& other) 0096 { 0097 d = other.d; 0098 0099 return *this; 0100 } 0101 0102 void FocusPoint::setType(TypePoint type) 0103 { 0104 d->type = type; 0105 } 0106 0107 FocusPoint::TypePoint FocusPoint::getType() const 0108 { 0109 return d->type; 0110 } 0111 0112 QString FocusPoint::getTypeDescription() const 0113 { 0114 switch (getType()) 0115 { 0116 case InFocus: 0117 { 0118 return i18nc("Focus point type description", "In Focus"); 0119 } 0120 0121 case Selected: 0122 { 0123 return i18nc("Focus point type description", "Selected"); 0124 } 0125 0126 case SelectedInFocus: 0127 { 0128 return i18nc("Focus point type description", "Selected In Focus"); 0129 } 0130 0131 default: // Inactive 0132 { 0133 return i18nc("Focus point type description", "Inactive"); 0134 } 0135 } 0136 } 0137 0138 QRect FocusPoint::getRectBySize(const QSize& size) const 0139 { 0140 return QRect(static_cast<int>((d->x_position - 0.5 * d->width) * size.width()), 0141 static_cast<int>((d->y_position - 0.5 * d->height) * size.height()), 0142 static_cast<int>(d->width * size.width()), 0143 static_cast<int>(d->height * size.height())); 0144 } 0145 0146 void FocusPoint::setCenterPosition(float x_position, float y_position) 0147 { 0148 d->x_position = x_position; 0149 d->y_position = y_position; 0150 } 0151 0152 void FocusPoint::setSize(float width, float height) 0153 { 0154 d->width = width; 0155 d->height = height; 0156 } 0157 0158 QPointF FocusPoint::getCenterPosition() const 0159 { 0160 return QPointF(d->x_position, d->y_position); 0161 } 0162 0163 QSizeF FocusPoint::getSize() const 0164 { 0165 return QSizeF(d->width, d->height); 0166 } 0167 0168 void FocusPoint::setRect(const QRectF& rectF) 0169 { 0170 d->x_position = rectF.topLeft().x() + rectF.width() * 0.5; 0171 d->y_position = rectF.topLeft().y() + rectF.height() * 0.5; 0172 d->width = rectF.width(); 0173 d->height = rectF.height(); 0174 } 0175 0176 QRectF FocusPoint::getRect() const 0177 { 0178 QRectF rect; 0179 rect.setSize(getSize()); 0180 rect.moveCenter(getCenterPosition()); 0181 0182 return rect; 0183 } 0184 0185 QDebug operator<<(QDebug dbg, const FocusPoint& fp) 0186 { 0187 dbg.nospace() << "FocusPoint::area:" 0188 << fp.getRect() << ", "; 0189 dbg.nospace() << "FocusPoint::type:" 0190 << fp.getTypeDescription(); 0191 0192 return dbg.space(); 0193 } 0194 0195 } // namespace Digikam