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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2005-08-15
0007  * Description : a widget to draw stars rating
0008  *
0009  * SPDX-FileCopyrightText: 2005      by Owen Hirst <n8rider@sbcglobal.net>
0010  * SPDX-FileCopyrightText: 2006-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_RATING_WIDGET_H
0017 #define DIGIKAM_RATING_WIDGET_H
0018 
0019 // Qt includes
0020 
0021 #include <QWidget>
0022 #include <QPaintEvent>
0023 #include <QMouseEvent>
0024 #include <QPolygon>
0025 #include <QIcon>
0026 #include <QMenu>
0027 
0028 // Local includes
0029 
0030 #include "dlayoutbox.h"
0031 #include "digikam_export.h"
0032 
0033 namespace Digikam
0034 {
0035 
0036 class DIGIKAM_EXPORT RatingWidget : public QWidget
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041 
0042     explicit RatingWidget(QWidget* const parent);
0043     ~RatingWidget() override;
0044 
0045     void setRating(int val);
0046     int  rating() const;
0047 
0048     void setTracking(bool tracking);
0049     bool hasTracking() const;
0050 
0051     void setFading(bool fading);
0052     bool hasFading() const;
0053 
0054     void startFading();
0055     void stopFading();
0056     void setVisibleImmediately();
0057 
0058     void setVisible(bool visible)                   override;
0059     int  maximumVisibleWidth() const;
0060 
0061     /**
0062      * Pre-computed star polygon for a 15x15 pixmap.
0063      */
0064     static QPolygon starPolygon();
0065     static QIcon buildIcon(int rate, int size);
0066 
0067 Q_SIGNALS:
0068 
0069     void signalRatingModified(int);    ///< Not managed by tracking properties
0070     void signalRatingChanged(int);
0071 
0072 protected:
0073 
0074     int regPixmapWidth()         const;
0075 
0076     QPixmap starPixmap()         const;
0077     QPixmap starPixmapFilled()   const;
0078     QPixmap starPixmapDisabled() const;
0079 
0080     void regeneratePixmaps();
0081     void setupTimeLine();
0082     void applyFading(QPixmap& pix);
0083 
0084     void mousePressEvent(QMouseEvent*)      override;
0085     void mouseMoveEvent(QMouseEvent*)       override;
0086     void mouseReleaseEvent(QMouseEvent*)    override;
0087     void paintEvent(QPaintEvent*)           override;
0088 
0089 protected Q_SLOTS:
0090 
0091     void setFadingValue(int value);
0092 
0093 private Q_SLOTS:
0094 
0095     void slotThemeChanged();
0096 
0097 private:
0098 
0099     class Private;
0100     Private* const d;
0101 };
0102 
0103 // --------------------------------------------------------------------
0104 
0105 class DIGIKAM_EXPORT RatingBox : public DVBox
0106 {
0107     Q_OBJECT
0108 
0109 public:
0110 
0111     explicit RatingBox(QWidget* const parent);
0112     ~RatingBox() override;
0113 
0114 Q_SIGNALS:
0115 
0116     void signalRatingChanged(int);
0117 
0118 private Q_SLOTS:
0119 
0120     void slotUpdateDescription(int);
0121 
0122 private:
0123 
0124     class Private;
0125     Private* const d;
0126 };
0127 
0128 // --------------------------------------------------------------------
0129 
0130 class DIGIKAM_EXPORT RatingMenuAction : public QMenu
0131 {
0132     Q_OBJECT
0133 
0134 public:
0135 
0136     explicit RatingMenuAction(QMenu* const parent = nullptr);
0137     ~RatingMenuAction() override;
0138 
0139 Q_SIGNALS:
0140 
0141     void signalRatingChanged(int);
0142 };
0143 
0144 } // namespace Digikam
0145 
0146 #endif // DIGIKAM_RATING_WIDGET_H