Sayonara Player
RatingLabel.h
1 /* RatingLabel.h */
2 
3 /* Copyright (C) 2011-2019 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef RATINGLABEL_H
22 #define RATINGLABEL_H
23 
24 #include "Utils/Pimpl.h"
25 
26 #include <QLabel>
27 #include <QPoint>
28 #include <QSize>
29 
30 namespace Gui
31 {
36  class RatingLabel : public QLabel
37  {
38  Q_OBJECT
39  PIMPL(RatingLabel)
40 
41  signals:
42  void sig_finished(bool);
43 
44 
45  public:
46  RatingLabel(QWidget* parent, bool enabled=true);
47  virtual ~RatingLabel();
48 
53  void set_rating(Rating rating);
54  Rating get_rating() const;
55 
60  void set_offset_y(int offset);
61 
62  protected:
63  void paintEvent(QPaintEvent *e) override;
64  void focusInEvent(QFocusEvent* e) override;
65  void focusOutEvent(QFocusEvent* e) override;
66  void mousePressEvent(QMouseEvent *ev) override;
67  void mouseReleaseEvent(QMouseEvent* ev) override;
68  void mouseMoveEvent(QMouseEvent *ev) override;
69 
70  QSize sizeHint() const override;
71  QSize minimumSizeHint() const override;
72 
73  private:
74  void update_rating(Rating rating);
75  Rating calc_rating(QPoint pos) const;
76  };
77 }
78 
79 #endif // RATINGLABEL_H
The RatingLabel class.
Definition: RatingLabel.h:36
void set_rating(Rating rating)
Set a rating from one to 5.
void set_offset_y(int offset)
The y-offset where the stars should be painted.