File indexing completed on 2025-04-27 03:58:35

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-02-14
0007  * Description : pick label widget
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_PICK_LABEL_WIDGET_H
0016 #define DIGIKAM_PICK_LABEL_WIDGET_H
0017 
0018 // Qt includes
0019 
0020 #include <QColor>
0021 #include <QPushButton>
0022 #include <QEvent>
0023 #include <QList>
0024 #include <QMetaType>
0025 #include <QMenu>
0026 
0027 // Local includes
0028 
0029 #include "dlayoutbox.h"
0030 #include "digikam_globals.h"
0031 #include "digikam_export.h"
0032 
0033 namespace Digikam
0034 {
0035 
0036 class DIGIKAM_EXPORT PickLabelWidget : public DVBox
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041 
0042     explicit PickLabelWidget(QWidget* const parent = nullptr);
0043     ~PickLabelWidget() override;
0044 
0045     /**
0046      * Show or not on the bottom view the description of label with shortcuts.
0047      */
0048     void setDescriptionBoxVisible(bool b);
0049 
0050     /**
0051      * Set all Color Label buttons exclusive or not. Default is true as only one can be selected.
0052      * Non-exclusive mode is dedicated for Advanced Search tool.
0053      */
0054     void setButtonsExclusive(bool b);
0055 
0056     /**
0057      * Turn on Color Label buttons using list. Pass an empty list to clear all selection.
0058      */
0059     void setPickLabels(const QList<PickLabel>& list);
0060 
0061     /**
0062      * Return the list of Pick Label buttons turned on or an empty list of none.
0063      */
0064     QList<PickLabel> pickLabels() const;
0065 
0066     static QString labelPickName(PickLabel label);
0067 
0068     static QIcon buildIcon(PickLabel label);
0069 
0070 Q_SIGNALS:
0071 
0072     void signalPickLabelChanged(int);
0073 
0074 protected:
0075 
0076     bool eventFilter(QObject* obj, QEvent* ev) override;
0077 
0078 private:
0079 
0080     void updateDescription(PickLabel label);
0081 
0082 private:
0083 
0084     class Private;
0085     Private* const d;
0086 };
0087 
0088 // ------------------------------------------------------------------------------
0089 
0090 class DIGIKAM_EXPORT PickLabelSelector : public QPushButton
0091 {
0092     Q_OBJECT
0093 
0094 public:
0095 
0096     explicit PickLabelSelector(QWidget* const parent = nullptr);
0097     ~PickLabelSelector() override;
0098 
0099     void setPickLabel(PickLabel label);
0100     PickLabel pickLabel();
0101 
0102     PickLabelWidget* pickLabelWidget() const;
0103 
0104 Q_SIGNALS:
0105 
0106     void signalPickLabelChanged(int);
0107 
0108 private Q_SLOTS:
0109 
0110     void slotPickLabelChanged(int);
0111 
0112 private:
0113 
0114     class Private;
0115     Private* const d;
0116 };
0117 
0118 // ------------------------------------------------------------------------------
0119 
0120 class DIGIKAM_EXPORT PickLabelMenuAction : public QMenu
0121 {
0122     Q_OBJECT
0123 
0124 public:
0125 
0126     explicit PickLabelMenuAction(QMenu* const parent = nullptr);
0127     ~PickLabelMenuAction() override;
0128 
0129 Q_SIGNALS:
0130 
0131     void signalPickLabelChanged(int);
0132 };
0133 
0134 } // namespace Digikam
0135 
0136 Q_DECLARE_METATYPE(QList<Digikam::PickLabel>)
0137 
0138 #endif // DIGIKAM_PICK_LABEL_WIDGET_H