-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarrating.h
44 lines (34 loc) · 1.13 KB
/
starrating.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef STARRATING_H
#define STARRATING_H
#include <QtWidgets/QWidget>
class StarRating : public QWidget
{
Q_OBJECT
public:
enum EditMode { Editable, ReadOnly };
StarRating(QWidget *parent = 0);
StarRating(int starCount = 1, int maxStarCount = 5);
void paint(QPainter *painter, const QRect &rect,
const QPalette &palette, EditMode mode) const;
QSize sizeHint() const;
int starCount() const { return myStarCount; }
int maxStarCount() const { return myMaxStarCount; }
void setStarCount(int starCount);
void setMaxStarCount(int maxStarCount) { myMaxStarCount = maxStarCount; }
void setEditable(bool editable=true) { mode = editable ? Editable : ReadOnly; }
signals:
void starCountChanged(int starCount);
protected:
void paintEvent(QPaintEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
int starAtPosition(int x);
EditMode mode;
QPolygonF starPolygon;
QPolygonF diamondPolygon;
int myStarCount;
int myMaxStarCount;
};
#endif // STARRATING_H