Initial commit (software version 0.2.0)
[movie-schedule] / src / ui / ratingprovider.cpp
1 // Copyright 2010 Jochen Becher
2 //
3 // This file is part of MovieSchedule.
4 //
5 // MovieSchedule is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // MovieSchedule 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 General Public License
16 // along with MovieSchedule.  If not, see <http://www.gnu.org/licenses/>.
17
18 #include "ratingprovider.h"
19
20 #include <QPixmap>
21
22 RatingProvider::RatingProvider()
23 {
24     _instance = this;
25 }
26
27 void RatingProvider::Load()
28 {
29     /*
30       The files loaded here are created from files in svg format under license
31       Creative Commons Attribution-Share Alike 2.5 Generic from author "Andreas 06"
32       on commons.wikimedia.org/wiki.
33      */
34     _rating_stars.reserve(11);
35     for (int i = 0; i < 10; ++i) {
36         _rating_stars.append(QPixmap(QString(":/resources/%1.png").arg(i)));
37     }
38 }
39
40 QPixmap RatingProvider::GetRating(double percentage)
41 {
42     if (percentage < 0.0 || percentage > 1.0) {
43         return QPixmap();
44     }
45     return _rating_stars[(int) (percentage * 10.0)];
46 }
47
48 RatingProvider *RatingProvider::_instance;
49
50 RatingSingleton::RatingSingleton()
51 {
52     _instance.Load();
53 }