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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-09-12
0007  * Description : Widget for assignment and confirmation of names for faces
0008  *
0009  * SPDX-FileCopyrightText: 2010      by Aditya Bhatt <adityabhatt1991 at gmail dot com>
0010  * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_ASSIGN_NAME_WIDGET_H
0018 #define DIGIKAM_ASSIGN_NAME_WIDGET_H
0019 
0020 // Qt includes
0021 
0022 #include <QFrame>
0023 #include <QVariant>
0024 
0025 namespace Digikam
0026 {
0027 
0028 class AddTagsComboBox;
0029 class AddTagsLineEdit;
0030 class CheckableAlbumFilterModel;
0031 class FaceTagsIface;
0032 class ItemInfo;
0033 class TAlbum;
0034 class TaggingAction;
0035 class TagModel;
0036 class TagPropertiesFilterModel;
0037 
0038 class AssignNameWidget : public QFrame
0039 {
0040     Q_OBJECT
0041     Q_PROPERTY(Mode mode READ mode WRITE setMode)
0042     Q_PROPERTY(TagEntryWidgetMode tagEntryWidgetMode READ tagEntryWidgetMode WRITE setTagEntryWidgetMode)
0043     Q_PROPERTY(LayoutMode layoutMode READ layoutMode WRITE setLayoutMode)
0044     Q_PROPERTY(VisualStyle visualStyle READ visualStyle WRITE setVisualStyle)
0045 
0046 public:
0047 
0048     enum Mode
0049     {
0050         InvalidMode,
0051         UnconfirmedEditMode,
0052         ConfirmedMode,
0053         ConfirmedEditMode,
0054         IgnoredMode
0055     };
0056     Q_ENUM(Mode)
0057 
0058     enum TagEntryWidgetMode
0059     {
0060         InvalidTagEntryWidgetMode,
0061         AddTagsComboBoxMode,
0062         AddTagsLineEditMode
0063     };
0064     Q_ENUM(TagEntryWidgetMode)
0065 
0066     enum LayoutMode
0067     {
0068         InvalidLayout,
0069         FullLine,
0070         TwoLines,
0071         Compact
0072     };
0073     Q_ENUM(LayoutMode)
0074 
0075     enum VisualStyle
0076     {
0077         InvalidVisualStyle,
0078         StyledFrame,
0079         TranslucentDarkRound,
0080         TranslucentThemedFrameless
0081     };
0082     Q_ENUM(VisualStyle)
0083 
0084 public:
0085 
0086     /**
0087      * Please take care: you must set all four modes before usage!
0088      */
0089     explicit AssignNameWidget(QWidget* const parent = nullptr);
0090     ~AssignNameWidget() override;
0091 
0092     /**
0093      * Set the tag model to use for completion.
0094      */
0095     void setAlbumModels(TagModel* const model,
0096                         TagPropertiesFilterModel* const filteredModel,
0097                         CheckableAlbumFilterModel* const filterModel);
0098     void setDefaultModel();
0099 
0100     void setMode(Mode mode);
0101     Mode mode()                             const;
0102 
0103     void setTagEntryWidgetMode(TagEntryWidgetMode mode);
0104     TagEntryWidgetMode tagEntryWidgetMode() const;
0105 
0106     void setLayoutMode(LayoutMode mode);
0107     LayoutMode layoutMode()                 const;
0108 
0109     void setVisualStyle(VisualStyle style);
0110     VisualStyle visualStyle()               const;
0111 
0112     ItemInfo info()                         const;
0113     QVariant  faceIdentifier()              const;
0114 
0115     /// The combo box or line edit in use, if any
0116     AddTagsComboBox* comboBox()             const;
0117     AddTagsLineEdit* lineEdit()             const;
0118 
0119 public Q_SLOTS:
0120 
0121     /**
0122      * The identifying information emitted with the signals
0123      */
0124     void setUserData(const ItemInfo& info, const QVariant& faceIdentifier = QVariant());
0125 
0126     /**
0127      * Sets the suggested (UnconfirmedEditMode) or assigned (ConfirmedMode) tag to be displayed.
0128      */
0129     void setCurrentTag(int tagId);
0130     void setCurrentTag(TAlbum* album);
0131     void setCurrentFace(const FaceTagsIface& face);
0132 
0133     /**
0134      * Set a parent tag for suggesting a parent tag for a new tag, and a default action.
0135      */
0136     void setParentTag(TAlbum* album);
0137 
0138 Q_SIGNALS:
0139 
0140     /**
0141      * A name has been assigned to the associated face.
0142      * This can be an existing tag, or a new tag, as described by TaggingAction.
0143      * For convenience, info() and faceIdentifier() are provided.
0144      */
0145     void assigned(const TaggingAction& action, const ItemInfo& info, const QVariant& faceIdentifier);
0146 
0147     /**
0148      * The suggestion has been rejected and the face will be moved to Unknown.
0149      * For convenience, info() and faceIdentifier() are provided.
0150      */
0151     void rejected(const ItemInfo& info, const QVariant& faceIdentifier);
0152 
0153     void ignored(const ItemInfo& info, const QVariant& faceIdentifier);
0154 
0155     /**
0156      * In IgnoredMode, this signal is emitted when the user clicked on the label
0157      */
0158     void ignoredClicked(const ItemInfo& info, const QVariant& faceIdentifier);
0159 
0160     /**
0161      * In ConfirmedMode, this signal is emitted when the user clicked on the label
0162      */
0163     void labelClicked(const ItemInfo& info, const QVariant& faceIdentifier);
0164 
0165     /**
0166      * An action has been selected. This purely signals user interaction,
0167      * no fixed decision - mouse hover may be enough to emit this signal.
0168      * The action may be invalid (user switched back to empty selection).
0169      */
0170     void selected(const TaggingAction& action, const ItemInfo& info, const QVariant& faceIdentifier);
0171 
0172 protected:
0173 
0174     void keyPressEvent(QKeyEvent* e) override;
0175     void showEvent(QShowEvent* e)    override;
0176 
0177 protected Q_SLOTS:
0178 
0179     void slotConfirm();
0180     void slotReject();
0181     void slotIgnore();
0182     void slotActionActivated(const TaggingAction& action);
0183     void slotActionSelected(const TaggingAction& action);
0184     void slotIgnoredClicked();
0185     void slotLabelClicked();
0186 
0187 private:
0188 
0189     class Private;
0190     Private* const d;
0191 };
0192 
0193 } // namespace Digikam
0194 
0195 #endif // DIGIKAM_ASSIGN_NAME_WIDGET_H