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 
35 class Rating {
36 
37 public:
38  Rating();
39  Rating(quint8 rating);
40 
41  void paint(QPainter *painter, const QRect &rect,
42  const QPalette &palette, bool has_focus) const;
43 
44  void set_rating(quint8 rating);
45  quint8 get_rating() const;
46 
47 private:
48  quint8 _rating;
49 };
50 
51 
52 Q_DECLARE_METATYPE(Rating)
53 
54 class RatingLabel : public QLabel
55 {
56  Q_OBJECT
57 
58 signals:
59  void sig_finished(bool);
60 
61 
62 public:
63  RatingLabel(QWidget *parent, bool enabled=true);
64  virtual ~RatingLabel();
65 
66  virtual void paintEvent(QPaintEvent *e) override;
67  virtual void focusInEvent(QFocusEvent* e) override;
68  virtual void focusOutEvent(QFocusEvent* e) override;
69  virtual void mousePressEvent(QMouseEvent *ev) override;
70  virtual void mouseReleaseEvent(QMouseEvent* ev) override;
71  virtual void mouseMoveEvent(QMouseEvent *ev) override;
72 
73  void set_rating(Rating rating);
74  Rating get_rating() const;
75 
76  int get_id() const;
77 
78  void kill_yourself();
79 
80  void increase();
81  void decrease();
82 
83 
84 
85 private:
86 
87  QWidget* _parent=nullptr;
88  bool _enabled;
89  int _id;
90  Rating _rating;
91 
92  void update_rating(int rating);
93  int calc_rating(QPoint pos) const;
94 
95 };
96 
97 
98 
99 #endif // RATINGLABEL_H
Definition: RatingLabel.h:35
Definition: RatingLabel.h:54