File indexing completed on 2024-04-28 04:21:26

0001 // SPDX-FileCopyrightText: 2014-2022 The KPhotoAlbum Development Team
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #ifndef TAGGEDAREA_H
0006 #define TAGGEDAREA_H
0007 
0008 #include <QFrame>
0009 
0010 namespace Viewer
0011 {
0012 
0013 /**
0014  * @brief The TaggedArea class represents a positionable tag in the viewer.
0015  * It does not allow any manipulation of the tag data.
0016  *
0017  * ## Styling
0018  * The appearance is based on the properties selected() and highlighted().
0019  * The following styles are expected to be set for a proper appearance of TaggedArea:
0020  *  - `Viewer--TaggedArea`
0021  *  - `Viewer--TaggedArea:hover`
0022  *  - `Viewer--TaggedArea[highlighted="true"]`
0023  */
0024 class TaggedArea : public QFrame
0025 {
0026     Q_OBJECT
0027     Q_PROPERTY(bool selected MEMBER m_selected READ selected WRITE setSelected RESET deselect)
0028     Q_PROPERTY(bool highlighted MEMBER m_highlighted READ highlighted WRITE setHighlighted)
0029 
0030 public:
0031     explicit TaggedArea(QWidget *parent = nullptr);
0032     void setTagInfo(QString category, QString localizedCategory, QString tag);
0033     void setActualGeometry(QRect geometry);
0034     QRect actualGeometry() const;
0035 
0036     /**
0037      * @brief When selected, the TaggedArea is shown (just like when hovering with the mouse).
0038      * This is used to make the area visible when the corresponding tag in the ViewerWidget is hovered.
0039      * @return \c true, if the area is visible.
0040      */
0041     bool selected() const;
0042     void setSelected(bool selected);
0043     void deselect();
0044 
0045     /**
0046      * @brief highlighted
0047      * @return \c true, when the area should be visibly highlighted, \c false otherwise.
0048      */
0049     bool highlighted() const;
0050     /**
0051      * @brief setHighlighted sets the highlighted property of the area.
0052      * An area with the highlighted tag set to \c true will be visibly highlighted.
0053      * @param highlighted
0054      */
0055     void setHighlighted(bool highlighted);
0056 
0057 public Q_SLOTS:
0058     /**
0059      * @brief checkIsSelected set the \c selected property if tagData matches the tag.
0060      * @param tagData
0061      */
0062     void checkIsSelected(const QPair<QString, QString> &tagData);
0063 
0064 protected:
0065     /**
0066      * @brief repolish tells the widget to reevaluate its style.
0067      * This required when the style is dynamically changed because a property changed.
0068      */
0069     void repolish();
0070 
0071 private:
0072     QPair<QString, QString> m_tagInfo;
0073     QRect m_actualGeometry;
0074     bool m_selected = false;
0075     bool m_highlighted = false;
0076 };
0077 
0078 }
0079 
0080 #endif // TAGGEDAREA_H
0081 // vi:expandtab:tabstop=4 shiftwidth=4: