File indexing completed on 2025-01-19 03:53:22

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2014-05-17
0007  * Description : Album Labels Tree View.
0008  *
0009  * SPDX-FileCopyrightText: 2014-2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0010  * SPDX-FileCopyrightText: 2014-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_ALBUM_LABELS_TREEVIEW_H
0017 #define DIGIKAM_ALBUM_LABELS_TREEVIEW_H
0018 
0019 // Qt includes
0020 
0021 #include <QTreeWidget>
0022 
0023 // Local includes
0024 
0025 #include "coredbconstants.h"
0026 #include "album.h"
0027 #include "statesavingobject.h"
0028 #include "itemlisterrecord.h"
0029 
0030 namespace Digikam
0031 {
0032 
0033 class LabelsTreeView : public QTreeWidget, public StateSavingObject
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038 
0039     enum Labels
0040     {
0041         Ratings = 0,
0042         Picks,
0043         Colors
0044     };
0045 
0046 public:
0047 
0048     explicit LabelsTreeView(QWidget* const parent = nullptr, bool setCheckable = false);
0049     ~LabelsTreeView() override;
0050 
0051     /**
0052      * @return true if the tree widget is checkable
0053      *         and false if not
0054      */
0055     bool isCheckable()                           const;
0056 
0057     /**
0058      * @return true if Loading state function is running
0059      */
0060     bool isLoadingState()                        const;
0061 
0062     /**
0063      * @return a Pixmap of a 30*30 pixels golden star used
0064      *         for rating and widget icon
0065      */
0066     QPixmap goldenStarPixmap(bool fillin=true)   const;
0067 
0068     /**
0069      * @brief Creates a 30*30 rectangular pixmap with
0070      *        specific color
0071      *
0072      * @param color wanted to be set
0073      * @return pixmap has a rectangle filled with the color
0074      */
0075     QPixmap colorRectPixmap(const QColor& color) const;
0076 
0077     /**
0078      * @brief Provide the current selection from the tree-view
0079      *        hierarchy
0080      *
0081      * @return a QHash with three keys: "Ratings", "Picks", and
0082      *         "Colors", every key dedicated to an int list which
0083      *         holds the rows selected
0084      */
0085     QHash<Labels, QList<int> > selectedLabels();
0086 
0087     /**
0088      * @brief Loading and saving state function inherited from
0089      *        StateSavingObject
0090      */
0091     void doLoadState() override;
0092     void doSaveState() override;
0093 
0094     /**
0095      * @brief Restores the selection state from the AlbumHistory
0096      *        class
0097      *
0098      * @param neededLabels is a QHash to restore the selection
0099      *        from it, the hash is formatted just like the hash
0100      *        generated from @see selectedLabels()
0101      */
0102     void restoreSelectionFromHistory(QHash<Labels, QList<int> > neededLabels);
0103 
0104     /**
0105      * @brief Emits a signal to the search handler to set the Current
0106      *        album from currently selected labels
0107      */
0108     void setCurrentAlbum();
0109 
0110 private:
0111 
0112     /**
0113      * @brief Initializing the tree-view hierarchy
0114      */
0115     void initTreeView();
0116     void initRatingsTree();
0117     void initPicksTree();
0118     void initColorsTree();
0119 
0120 private Q_SLOTS:
0121 
0122     void slotSettingsChanged();
0123 
0124 Q_SIGNALS:
0125 
0126     void signalSetCurrentAlbum();
0127 
0128 private:
0129 
0130     class Private;
0131     Private* const d;
0132 };
0133 
0134 } // namespace Digikam
0135 
0136 #endif // DIGIKAM_ALBUM_LABELS_TREEVIEW_H