File indexing completed on 2025-01-19 03:57:58

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 28/08/2021
0007  * Description : Managing of focus point items on a GraphicsDImgView
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 "focuspointitem.h"
0017 
0018 // Qt includes
0019 
0020 #include <QPainter>
0021 #include <QPen>
0022 
0023 // Local includes
0024 
0025 #include "digikam_debug.h"
0026 #include "assignnamewidgetstates.h"
0027 
0028 namespace Digikam
0029 {
0030 
0031 class Q_DECL_HIDDEN FocusPointItem::Private
0032 {
0033 public:
0034 
0035     explicit Private()
0036         : color(QColor::fromRgb(0, 0, 0, 255)), ///< alpha is 100 to let more transparency
0037           width(3.0F)
0038     {
0039     }
0040 
0041     FocusPoint point;
0042     QColor     color;
0043     float      width;
0044 };
0045 
0046 FocusPointItem::FocusPointItem(QGraphicsItem* const parent)
0047     : RegionFrameItem(parent),
0048       d              (new Private)
0049 {
0050 }
0051 
0052 FocusPointItem::~FocusPointItem()
0053 {
0054     delete d;
0055 }
0056 
0057 void FocusPointItem::setPoint(const FocusPoint& point)
0058 {
0059     d->point = point;
0060     setEditable(false);
0061 
0062     switch (d->point.getType())
0063     {
0064         case FocusPoint::TypePoint::Inactive:
0065         {
0066             d->color.setAlpha(130);
0067             d->width = 1;
0068             break;
0069         }
0070 
0071         case FocusPoint::TypePoint::Selected:
0072         case FocusPoint::TypePoint::SelectedInFocus:
0073         {
0074             d->color.setRed(255);
0075             break;
0076         }
0077 
0078         default: // FocusPoint::TypePoint::InFocus
0079         {
0080             // TODO
0081             break;
0082         }
0083     }
0084 }
0085 
0086 FocusPoint FocusPointItem::point() const
0087 {
0088     return d->point;
0089 }
0090 
0091 void FocusPointItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
0092 {
0093     QPen pen;
0094     pen.setWidth(d->width);
0095     pen.setColor(d->color);
0096 
0097     QRectF drawRect = boundingRect();
0098 
0099     qCDebug(DIGIKAM_GENERAL_LOG) << "FocusPointsItem: rectangle:" << drawRect;
0100 
0101     painter->setPen(pen);
0102     painter->drawRect(drawRect);
0103 }
0104 
0105 void FocusPointItem::setEditable(bool allowEdit)
0106 {
0107     changeFlags(GeometryEditable, allowEdit);
0108 }
0109 
0110 } // namespace Digikam
0111 
0112 #include "moc_focuspointitem.cpp"