Sayonara Player
RatingLabel.h
1 /* RatingLabel.h */
2 
3 /* Copyright (C) 2011-2017 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 <QLabel>
25 #include <QPoint>
26 #include <QPixmap>
27 
32 class RatingLabel : public QLabel
33 {
34  Q_OBJECT
35 
36 signals:
37  void sig_finished(bool);
38 
39 
40 public:
41  RatingLabel(QWidget *parent, bool enabled=true);
42  virtual ~RatingLabel();
43 
44  void set_rating(int rating);
45  int get_rating() const;
46 
47 
48 protected:
49  void paintEvent(QPaintEvent *e) override;
50  void focusInEvent(QFocusEvent* e) override;
51  void focusOutEvent(QFocusEvent* e) override;
52  void mousePressEvent(QMouseEvent *ev) override;
53  void mouseReleaseEvent(QMouseEvent* ev) override;
54  void mouseMoveEvent(QMouseEvent *ev) override;
55 
56 
57 private:
58  QWidget* _parent=nullptr;
59  bool _enabled;
60  int _rating;
61  quint8 _icon_size;
62  QPixmap _pm_active;
63  QPixmap _pm_inactive;
64 
65 private:
66  void update_rating(int rating);
67  int calc_rating(QPoint pos) const;
68 };
69 
70 #endif // RATINGLABEL_H
The RatingLabel class.
Definition: RatingLabel.h:32