Sayonara Player
RatingLabel.h
1 /* RatingLabel.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (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 {
38  class RatingLabel :
39  public QLabel
40  {
41  Q_OBJECT
42  PIMPL(RatingLabel)
43 
44  public:
45  RatingLabel(QWidget* parent, bool enabled=true);
46  ~RatingLabel() override;
47 
52  void setRating(Rating rating);
53  Rating rating() const;
54 
60  Rating ratingAt(QPoint pos) const;
61 
66  void setVerticalOffset(int offset);
67 
74  void paint(QPainter* painter, const QRect& rect);
75 
80  QSize sizeHint() const override;
81 
86  QSize minimumSizeHint() const override;
87  };
88 
96  class RatingEditor : public QWidget
97  {
98  Q_OBJECT
99  PIMPL(RatingEditor)
100 
101  signals:
102  void sigFinished(bool save);
103 
104  public:
105  RatingEditor(QWidget* parent);
106  RatingEditor(Rating rating, QWidget* parent);
107  ~RatingEditor() override;
108 
113  void setRating(Rating rating);
114 
126  Rating rating() const;
127 
132  void setVerticalOffset(int offset);
133 
139  void setMouseTrackable(bool b);
140 
145  QSize sizeHint() const override;
146 
151  QSize minimumSizeHint() const override;
152 
153  protected:
154  void paintEvent(QPaintEvent* e) override;
155 
156  void focusInEvent(QFocusEvent* e) override;
157  void focusOutEvent(QFocusEvent* e) override;
158 
159  void mousePressEvent(QMouseEvent* e) override;
160  void mouseMoveEvent(QMouseEvent* e) override;
161  void mouseReleaseEvent(QMouseEvent* e) override;
162  };
163 }
164 
165 #endif // RATINGLABEL_H
void setMouseTrackable(bool b)
Enable mouse move events. If disabled, there's no live update.
void setRating(Rating rating)
Sets the actual rating.
void paint(QPainter *painter, const QRect &rect)
Called from outside. Mostly from delegates or from the RatingEditor class.
void setVerticalOffset(int offset)
Set an offset where to begin drawing stars.
A simple label, not suitable for editing. For editing, use the RatingEditor class....
Definition: RatingLabel.h:38
void setVerticalOffset(int offset)
The y-offset where the stars should be painted.
void setRating(Rating rating)
Set a rating from one to 5.
QSize minimumSizeHint() const override
Same as sizeHint.
Rating rating() const
Returns the actual rating. This is not neccessarily the rating currently visible. Consider the case w...
QSize sizeHint() const override
about 20px in height and 5x20px in width
QSize minimumSizeHint() const override
Same as RatingLabel::minimumSizeHint.
Rating ratingAt(QPoint pos) const
Returns the rating regarding the current mouse position.
QSize sizeHint() const override
Same as RatingLabel::sizeHint.
This class is used for the actual editing of a RatingLabel While the RatingLabel class is used in pai...
Definition: RatingLabel.h:96