Debian Codegraph @

src/ratingwidget.h

raw symbols SCIP
1 /*
2 Copyright 2010, David Sansome <[email protected]>
3 Copyright (C) 2005-2014 Mario Stephan <[email protected]>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef RATINGWIDGET_H
20 #define RATINGWIDGET_H
21
22 #include <QFrame>
23 #include <QPixmap>
24
25 class RatingPainter {
26 public:
27 RatingPainter();
28
29 static const int kStarCount = 5;
30 static const int kStarSize = 15;
31 static QRect Contents(const QRect& rect);
32 static double RatingForPos(const QPoint& pos, const QRect& rect);
33
34 void Paint(QPainter* painter, const QRect& rect, float rating) const;
35
36 private:
37 QPixmap stars_[kStarCount*2+1];
38 };
39
40 class RatingWidget : public QWidget {
41 Q_OBJECT
42 Q_PROPERTY(float rating READ rating WRITE setRating);
43
44 public:
45 RatingWidget(QWidget* parent = 0);
46
47 QSize sizeHint() const;
48
49 float rating() const { return rating_; }
50 void setRating(float rating);
51
52 signals:
53 void RatingChanged(float rating);
54
55 protected:
56 void paintEvent(QPaintEvent*);
57 void mousePressEvent(QMouseEvent* e);
58 void mouseMoveEvent(QMouseEvent* e);
59 void leaveEvent(QEvent*);
60
61 private:
62 RatingPainter painter_;
63 float rating_;
64 float hover_rating_;
65 };
66
67 #endif // RATINGWIDGET_H
68