Sayonara Player
RatingLabel.h
1 /* RatingLabel.h */
2 
3 /* Copyright (C) 2011-2016 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 
22 
23 #ifndef RATINGLABEL_H
24 #define RATINGLABEL_H
25 
26 #include <QLabel>
27 #include <QPaintEvent>
28 #include <QMouseEvent>
29 #include <QFocusEvent>
30 #include <QPalette>
31 #include <QPainter>
32 #include <QRect>
33 #include <QPoint>
34 #include <QPixmap>
35 
40 class RatingLabel : public QLabel
41 {
42  Q_OBJECT
43 
44 signals:
45  void sig_finished(bool);
46 
47 
48 public:
49  RatingLabel(QWidget *parent, bool enabled=true);
50  virtual ~RatingLabel();
51 
52  void set_rating(int rating);
53  int get_rating() const;
54 
55  void kill_yourself();
56 
57  void increase();
58  void decrease();
59 
60 
61 protected:
62  void paintEvent(QPaintEvent *e) override;
63  void focusInEvent(QFocusEvent* e) override;
64  void focusOutEvent(QFocusEvent* e) override;
65  void mousePressEvent(QMouseEvent *ev) override;
66  void mouseReleaseEvent(QMouseEvent* ev) override;
67  void mouseMoveEvent(QMouseEvent *ev) override;
68 
69 
70 private:
71  QWidget* _parent=nullptr;
72  bool _enabled;
73  int _rating;
74  quint8 _icon_size;
75  QPixmap _pm_active;
76  QPixmap _pm_inactive;
77 
78 private:
79  void update_rating(int rating);
80  int calc_rating(QPoint pos) const;
81 };
82 
83 
84 
85 #endif // RATINGLABEL_H
The RatingLabel class.
Definition: RatingLabel.h:40