| 1 |
#include "widgets/stars.h" |
| 2 |
#include "backend/ratingshelper.h" |
| 3 |
#include <QHBoxLayout> |
| 4 |
#include <QLabel> |
| 5 |
|
| 6 |
stars::stars(QString app) |
| 7 |
{ |
| 8 |
QHBoxLayout *layout = new QHBoxLayout; |
| 9 |
this->setLayout(layout); |
| 10 |
layout->setMargin(0); |
| 11 |
layout->setAlignment(Qt::AlignLeft); |
| 12 |
double rating = RatingsHelper::instance()->averageRating(app); |
| 13 |
for (int i = 0; i < int(rating); i++) { |
| 14 |
QLabel *star = new QLabel; |
| 15 |
star->setPixmap(QPixmap("://icons/star.png")); |
| 16 |
layout->addWidget(star); |
| 17 |
} |
| 18 |
if (QString::number(rating).endsWith(".5")) { |
| 19 |
QLabel *halfstar = new QLabel; |
| 20 |
halfstar->setPixmap(QPixmap("://icons/starhalf.png")); |
| 21 |
layout->addWidget(halfstar); |
| 22 |
} |
| 23 |
QLabel *total = new QLabel(tr("(%1 ratings)").arg(RatingsHelper::instance()->totalRatings(app))); |
| 24 |
layout->addWidget(total); |
| 25 |
} |