JKQtExtras
a library of useful Qt widgets and tools
jkqtestarratingwidget.h
1 /*
2  Copyright (c) 2013-2020 Jan W. Krieger (<jan@jkrieger.de>)
3 
4  This software is free software: you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License (LGPL) as published by
6  the Free Software Foundation, either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License (LGPL) for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License (LGPL)
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef JKQTESTARRATINGWIDGET_H
19 #define JKQTESTARRATINGWIDGET_H
20 
21 #include <QWidget>
22 #include <QIcon>
23 #include <QMouseEvent>
24 #include <QPaintEvent>
25 #include <QFrame>
26 #include "jkqtextras_imexport.h"
27 
28 /*! \brief a rating widget which displays five stars where the user may select how many are selected
29  \ingroup JKQtExtrasWidgetsLabels
30 
31  Screenshot:
32  \image html JKQTEStarRatingWidget.png
33 
34  Basic usage is simple:
35 
36  \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTEStarRatingWidget
37 
38  You can set the images/icons to be used for present/unpresent stars and the limiter to the
39  left that allows to set rating 0 when clicked:
40  - setStarImage()
41  - setDarkStarImage()
42  - setNoStarImage()
43  .
44 
45 */
47  Q_OBJECT
48  Q_PROPERTY(int data READ rating WRITE setRating )
49  Q_PROPERTY(int rating READ rating WRITE setRating USER true)
50  Q_PROPERTY(QPixmap darkStarImage READ darkStarImage WRITE setDarkStarImage USER true)
51  Q_PROPERTY(QPixmap starImage READ starImage WRITE setStarImage USER true)
52  Q_PROPERTY(QPixmap noStarImage READ noStarImage WRITE setNoStarImage USER true)
53  public:
54  /** Default constructor */
55  JKQTEStarRatingWidget(QWidget* parent=NULL);
56  /** Default destructor */
58  /** \brief returns the current rating (between 0 and maximum() ) */
59  int rating() const;
60  /** \brief returns the current maximum rating */
61  int maximum() const;
62  /** \brief the pixmap to use for a selected star */
63  QPixmap starImage() const;
64  /** \brief the pixmap to use for no stars at all (rating() \c ==0 ) */
65  QPixmap noStarImage() const;
66  /** \brief the pixmap to use for an unselected star */
67  QPixmap darkStarImage() const;
68 
69  public slots:
70  /** \brief sets the pixmap to use for a selected star */
71  void setStarImage(const QPixmap &starImage);
72  /** \brief sets the pixmap to use for no stars at all (rating() \c ==0 ) */
73  void setNoStarImage(const QPixmap &noStarImage);
74  /** \brief sets the pixmap to use for an unselected star */
75  void setDarkStarImage(const QPixmap &darkStarImage);
76  /** \brief sets the current rating (between 0 and maximum() ) */
77  void setRating(int value);
78  /** \brief sets the current maximum rating */
79  void setMaximum(int value);
80  /** \brief sets the frame style of the widget (see <a href="https://doc.qt.io/qt-5/qframe.html#setFrameStyle">QFrame::setFrameStyle()</a>) */
81  void setFrameStyle(int);
82  /** \brief sets the frame shape of the widget (see <a href="https://doc.qt.io/qt-5/qframe.html#setFrameShape">QFrame::setFrameShape()</a>) */
83  void setFrameShape(Shape);
84  /** \brief sets the frame shadow of the widget (see <a href="https://doc.qt.io/qt-5/qframe.html#setFrameShadow">QFrame::setFrameShadow()</a>) */
85  void setFrameShadow(Shadow);
86  /** \brief sets the frame line width of the widget (see <a href="https://doc.qt.io/qt-5/qframe.html#setLineWidth">QFrame::setLineWidth()</a>) */
87  void setLineWidth(int);
88  /** \brief sets the frame mid line width of the widget (see <a href="https://doc.qt.io/qt-5/qframe.html#setMidLineWidth">QFrame::setMidLineWidth()</a>) */
89  void setMidLineWidth(int);
90  /** \brief sets the frame rectangle of the widget (see <a href="https://doc.qt.io/qt-5/qframe.html#setFrameRect">QFrame::setFrameRect()</a>) */
91  void setFrameRect(const QRect &);
92  signals:
93  /** \brief signal emitted when the rating changes */
94  void ratingChanged(int rating);
95  protected:
96  QPixmap m_starImage;
97  QPixmap m_noStarImage;
98  QPixmap m_darkStarImage;
99  int m_rating;
102  virtual void paintEvent ( QPaintEvent * event );
103  virtual void mouseReleaseEvent ( QMouseEvent * event );
104  private:
105 };
106 
107 #endif // JKQTESTARRATINGWIDGET_H
JKQTEStarRatingWidget::m_rating
int m_rating
Definition: jkqtestarratingwidget.h:99
JKQTEStarRatingWidget::JKQTEStarRatingWidget
JKQTEStarRatingWidget(QWidget *parent=NULL)
JKQTEStarRatingWidget::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *event)
JKQTEStarRatingWidget::setLineWidth
void setLineWidth(int)
sets the frame line width of the widget (see QFrame::setLineWidth())
JKQTEStarRatingWidget::setNoStarImage
void setNoStarImage(const QPixmap &noStarImage)
sets the pixmap to use for no stars at all (rating() ==0 )
JKQTEStarRatingWidget::m_noStarImage
QPixmap m_noStarImage
Definition: jkqtestarratingwidget.h:97
JKQTEStarRatingWidget::maximum
int maximum() const
returns the current maximum rating
JKQTEStarRatingWidget::m_maximum
int m_maximum
Definition: jkqtestarratingwidget.h:100
JKQTEStarRatingWidget::setStarImage
void setStarImage(const QPixmap &starImage)
sets the pixmap to use for a selected star
JKQTEXTRAS_LIB_EXPORT
#define JKQTEXTRAS_LIB_EXPORT
Definition: jkqtextras_imexport.h:95
JKQTEStarRatingWidget::paintEvent
virtual void paintEvent(QPaintEvent *event)
JKQTEStarRatingWidget::setFrameStyle
void setFrameStyle(int)
sets the frame style of the widget (see QFrame::setFrameStyle())
JKQTEStarRatingWidget::m_darkStarImage
QPixmap m_darkStarImage
Definition: jkqtestarratingwidget.h:98
JKQTEStarRatingWidget::setDarkStarImage
void setDarkStarImage(const QPixmap &darkStarImage)
sets the pixmap to use for an unselected star
JKQTEStarRatingWidget::setRating
void setRating(int value)
sets the current rating (between 0 and maximum() )
JKQTEStarRatingWidget::setMidLineWidth
void setMidLineWidth(int)
sets the frame mid line width of the widget (see QFrame::setMidLineWidth())
JKQTEStarRatingWidget::setWidgetSizes
void setWidgetSizes()
JKQTEStarRatingWidget::m_starImage
QPixmap m_starImage
Definition: jkqtestarratingwidget.h:96
JKQTEStarRatingWidget::~JKQTEStarRatingWidget
virtual ~JKQTEStarRatingWidget()
JKQTEStarRatingWidget::rating
int rating() const
returns the current rating (between 0 and maximum() )
JKQTEStarRatingWidget::setFrameRect
void setFrameRect(const QRect &)
sets the frame rectangle of the widget (see QFrame::setFrameRect())
JKQTEStarRatingWidget::darkStarImage
QPixmap darkStarImage() const
the pixmap to use for an unselected star
JKQTEStarRatingWidget::setFrameShadow
void setFrameShadow(Shadow)
sets the frame shadow of the widget (see QFrame::setFrameShadow())
JKQTEStarRatingWidget::starImage
QPixmap starImage() const
the pixmap to use for a selected star
JKQTEStarRatingWidget::noStarImage
QPixmap noStarImage() const
the pixmap to use for no stars at all (rating() ==0 )
JKQTEStarRatingWidget::setFrameShape
void setFrameShape(Shape)
sets the frame shape of the widget (see QFrame::setFrameShape())
JKQTEStarRatingWidget
a rating widget which displays five stars where the user may select how many are selected
Definition: jkqtestarratingwidget.h:46
JKQTEStarRatingWidget::setMaximum
void setMaximum(int value)
sets the current maximum rating
JKQTEStarRatingWidget::ratingChanged
void ratingChanged(int rating)
signal emitted when the rating changes