File indexing completed on 2025-01-19 03:57:55
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-09-17 0007 * Description : Managing of face tag region items on a GraphicsDImgView 0008 * 0009 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_FACE_GROUP_H 0017 #define DIGIKAM_FACE_GROUP_H 0018 0019 // Qt includes 0020 0021 #include <QObject> 0022 #include <QPointF> 0023 0024 class QGraphicsSceneHoverEvent; 0025 0026 namespace Digikam 0027 { 0028 0029 class Album; 0030 class ItemInfo; 0031 class GraphicsDImgView; 0032 class RegionFrameItem; 0033 class TaggingAction; 0034 0035 class FaceGroup : public QObject 0036 { 0037 Q_OBJECT 0038 Q_PROPERTY(bool visible READ isVisible WRITE setVisible) 0039 0040 public: 0041 0042 /** 0043 * Constructs a new face group, managing RegionFrameItems for faces 0044 * of a particular image, displayed on a GraphicsDImgView. 0045 */ 0046 explicit FaceGroup(GraphicsDImgView* const view); 0047 ~FaceGroup() override; 0048 0049 bool isVisible() const; 0050 ItemInfo info() const; 0051 bool hasVisibleItems() const; 0052 0053 QList<RegionFrameItem*> items() const; 0054 0055 /** 0056 * Auto suggest applies if an image has not been scanned, 0057 * or an unknown face is registered. 0058 * In this case, a new scan will be triggered. 0059 */ 0060 void setAutoSuggest(bool doAutoSuggest); 0061 bool autoSuggest() const; 0062 0063 /** 0064 * Even if visible() is false, show the item under the mouse cursor 0065 */ 0066 void setShowOnHover(bool show); 0067 bool showOnHover() const; 0068 0069 /** 0070 * Returns the item in this group closest to scene position p. 0071 * If given, manhattanLength is set to the manhattan length between 0072 * p and the closest point of the returned item's bounding rectangle. 0073 * In particular, if p is inside the item's rectangle, manhattanLength is 0. 0074 */ 0075 RegionFrameItem* closestItem(const QPointF& p, 0076 qreal* const manhattanLength = nullptr) const; 0077 0078 bool acceptsMouseClick(const QPointF& scenePos); 0079 void itemHoverEnterEvent(QGraphicsSceneHoverEvent* event); 0080 void itemHoverMoveEvent(QGraphicsSceneHoverEvent* event); 0081 void itemHoverLeaveEvent(QGraphicsSceneHoverEvent* event); 0082 void leaveEvent(QEvent*); 0083 void enterEvent(QEvent*); 0084 0085 /** 0086 * Returns a boolean whether there is at least one unconfirmed face in the group or not. 0087 */ 0088 bool hasUnconfirmed(); 0089 0090 public Q_SLOTS: 0091 0092 /** 0093 * Shows or hides the frames 0094 */ 0095 void setVisible(bool visible); 0096 void setVisibleItem(RegionFrameItem* item); 0097 0098 /** 0099 * Sets the current ItemInfo 0100 */ 0101 void setInfo(const ItemInfo& info); 0102 0103 /** 0104 * Prepares to load a new info. 0105 * Closes the face group for editing. 0106 * Pass a null info if about to close. 0107 */ 0108 void aboutToSetInfo(const ItemInfo& info); 0109 0110 void aboutToSetInfoAfterRotate(const ItemInfo& info); 0111 0112 /** 0113 * Enters a special state where by click + drag a new face can be created 0114 */ 0115 void addFace(); 0116 0117 /** 0118 * Rejects (clears) all faces on the current image 0119 */ 0120 void rejectAll(); 0121 0122 /** 0123 * Mark all unconfirmed faces as ignored on the current image 0124 */ 0125 void markAllAsIgnored(); 0126 0127 protected: 0128 0129 void load(); 0130 void clear(); 0131 void applyItemGeometryChanges(); 0132 0133 protected Q_SLOTS: 0134 0135 void itemStateChanged(int); 0136 void startAutoSuggest(); 0137 void slotAlbumsUpdated(int type); 0138 void slotAlbumRenamed(Album* album); 0139 void slotAssigned(const TaggingAction& action, const ItemInfo& info, const QVariant& faceIdentifier); 0140 void slotRejected(const ItemInfo& info, const QVariant& faceIdentifier); 0141 void slotIgnored(const ItemInfo& info, const QVariant& faceIdentifier); 0142 void slotLabelClicked(const ItemInfo& info, const QVariant& faceIdentifier); 0143 void slotIgnoredClicked(const ItemInfo& info, const QVariant& faceIdentifier); 0144 void slotAddItemStarted(const QPointF& pos); 0145 void slotAddItemMoving(const QRectF& rect); 0146 void slotAddItemFinished(const QRectF& rect); 0147 void cancelAddItem(); 0148 void focusRandomFace(); 0149 0150 private: 0151 0152 // Disable 0153 FaceGroup() = delete; 0154 FaceGroup(const FaceGroup&) = delete; 0155 FaceGroup& operator=(const FaceGroup&) = delete; 0156 0157 private: 0158 0159 class Private; 0160 Private* const d; 0161 }; 0162 0163 } // namespace Digikam 0164 0165 #endif // DIGIKAM_FACE_GROUP_H