| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2010-09-17 |
| 7 |
* Description : Managing of face tag region items on a GraphicsDImgView |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> |
| 10 |
* SPDX-FileCopyrightText: 2012-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 11 |
* |
| 12 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 13 |
* |
| 14 |
* ============================================================ */ |
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
// Qt includes |
| 19 |
|
| 20 |
#include <QObject> |
| 21 |
#include <QPointF> |
| 22 |
|
| 23 |
class QGraphicsSceneHoverEvent; |
| 24 |
|
| 25 |
namespace Digikam |
| 26 |
{ |
| 27 |
|
| 28 |
class Album; |
| 29 |
class ItemInfo; |
| 30 |
class ImageTagChangeset; |
| 31 |
class GraphicsDImgView; |
| 32 |
class RegionFrameItem; |
| 33 |
class TaggingAction; |
| 34 |
|
| 35 |
class FaceGroup : public QObject |
| 36 |
{ |
| 37 |
Q_OBJECT |
| 38 |
Q_PROPERTY(bool visible READ isVisible WRITE setVisible) |
| 39 |
|
| 40 |
public: |
| 41 |
|
| 42 |
/** |
| 43 |
* Constructs a new face group, managing RegionFrameItems for faces |
| 44 |
* of a particular image, displayed on a GraphicsDImgView. |
| 45 |
*/ |
| 46 |
explicit FaceGroup(GraphicsDImgView* const view); |
| 47 |
~FaceGroup() override; |
| 48 |
|
| 49 |
bool isVisible() const; |
| 50 |
ItemInfo info() const; |
| 51 |
bool hasVisibleItems() const; |
| 52 |
|
| 53 |
QList<RegionFrameItem*> items() const; |
| 54 |
|
| 55 |
/** |
| 56 |
* Auto suggest applies if an image has not been scanned, |
| 57 |
* or an unknown face is registered. |
| 58 |
* In this case, a new scan will be triggered. |
| 59 |
*/ |
| 60 |
void setAutoSuggest(bool doAutoSuggest); |
| 61 |
bool autoSuggest() const; |
| 62 |
|
| 63 |
/** |
| 64 |
* Even if visible() is false, show the item under the mouse cursor. |
| 65 |
*/ |
| 66 |
void setShowOnHover(bool show); |
| 67 |
bool showOnHover() const; |
| 68 |
|
| 69 |
/** |
| 70 |
* Returns the item in this group closest to scene position p. |
| 71 |
* If given, manhattanLength is set to the manhattan length between |
| 72 |
* p and the closest point of the returned item's bounding rectangle. |
| 73 |
* In particular, if p is inside the item's rectangle, manhattanLength is 0. |
| 74 |
*/ |
| 75 |
RegionFrameItem* closestItem(const QPointF& p, |
| 76 |
qreal* const manhattanLength = nullptr) const; |
| 77 |
|
| 78 |
bool acceptsMouseClick(const QPointF& scenePos); |
| 79 |
void itemHoverEnterEvent(QGraphicsSceneHoverEvent* event); |
| 80 |
void itemHoverMoveEvent(QGraphicsSceneHoverEvent* event); |
| 81 |
void itemHoverLeaveEvent(QGraphicsSceneHoverEvent* event); |
| 82 |
void leaveEvent(QEvent*); |
| 83 |
void enterEvent(QEvent*); |
| 84 |
|
| 85 |
/** |
| 86 |
* Returns a boolean whether there is at least one unconfirmed face in the group or not. |
| 87 |
*/ |
| 88 |
bool hasUnconfirmed(); |
| 89 |
|
| 90 |
public Q_SLOTS: |
| 91 |
|
| 92 |
/** |
| 93 |
* Shows or hides the frames. |
| 94 |
*/ |
| 95 |
void setVisible(bool visible); |
| 96 |
void setVisibleItem(RegionFrameItem* item); |
| 97 |
|
| 98 |
/** |
| 99 |
* Sets the current ItemInfo. |
| 100 |
*/ |
| 101 |
void setInfo(const ItemInfo& info); |
| 102 |
|
| 103 |
/** |
| 104 |
* Prepares to load a new info. |
| 105 |
* Closes the face group for editing. |
| 106 |
* Pass a null info if about to close. |
| 107 |
*/ |
| 108 |
void aboutToSetInfo(const ItemInfo& info); |
| 109 |
|
| 110 |
/** |
| 111 |
* Enters a special state where by click + drag a new face can be created. |
| 112 |
*/ |
| 113 |
void addFace(); |
| 114 |
|
| 115 |
/** |
| 116 |
* Rejects (clears) all faces on the current image. |
| 117 |
*/ |
| 118 |
void rejectAll(); |
| 119 |
|
| 120 |
/** |
| 121 |
* Mark all unconfirmed faces as ignored on the current image. |
| 122 |
*/ |
| 123 |
void markAllAsIgnored(); |
| 124 |
|
| 125 |
protected: |
| 126 |
|
| 127 |
void load(); |
| 128 |
void applyItemGeometryChanges(); |
| 129 |
|
| 130 |
protected Q_SLOTS: |
| 131 |
|
| 132 |
void itemStateChanged(int); |
| 133 |
void startAutoSuggest(); |
| 134 |
void slotAlbumsUpdated(int type); |
| 135 |
void slotAlbumRenamed(Album* album); |
| 136 |
void slotImageTagChange(const ImageTagChangeset& changeset); |
| 137 |
void slotAssigned(const TaggingAction& action, const ItemInfo& info, const QVariant& faceIdentifier); |
| 138 |
void slotRejected(const ItemInfo& info, const QVariant& faceIdentifier); |
| 139 |
void slotIgnored(const ItemInfo& info, const QVariant& faceIdentifier); |
| 140 |
void slotLabelClicked(const ItemInfo& info, const QVariant& faceIdentifier); |
| 141 |
void slotIgnoredClicked(const ItemInfo& info, const QVariant& faceIdentifier); |
| 142 |
void slotAddItemStarted(const QPointF& pos); |
| 143 |
void slotAddItemMoving(const QRectF& rect); |
| 144 |
void slotAddItemFinished(const QRectF& rect); |
| 145 |
void slotCancelAddItem(); |
| 146 |
void slotFocusRandomFace(); |
| 147 |
|
| 148 |
private: |
| 149 |
|
| 150 |
/// @note disabled |
| 151 |
FaceGroup() = delete; |
| 152 |
FaceGroup(const FaceGroup&) = delete; |
| 153 |
FaceGroup& operator=(const FaceGroup&) = delete; |
| 154 |
|
| 155 |
private: |
| 156 |
|
| 157 |
class Private; |
| 158 |
Private* const d = nullptr; |
| 159 |
}; |
| 160 |
|
| 161 |
} // namespace Digikam |