File: stars.cpp

package info (click to toggle)
dde-store 1.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 724 kB
  • sloc: cpp: 2,048; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (2)
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
#include "widgets/stars.h"
#include "backend/ratingshelper.h"
#include <QHBoxLayout>
#include <QLabel>

stars::stars(QString app)
{
    QHBoxLayout *layout = new QHBoxLayout;
    this->setLayout(layout);
    layout->setMargin(0);
    layout->setAlignment(Qt::AlignLeft);
    double rating = RatingsHelper::instance()->averageRating(app);
    for (int i = 0; i < int(rating); i++) {
        QLabel *star = new QLabel;
        star->setPixmap(QPixmap("://icons/star.png"));
        layout->addWidget(star);
    }
    if (QString::number(rating).endsWith(".5")) {
        QLabel *halfstar = new QLabel;
        halfstar->setPixmap(QPixmap("://icons/starhalf.png"));
        layout->addWidget(halfstar);
    }
    QLabel *total = new QLabel(tr("(%1 ratings)").arg(RatingsHelper::instance()->totalRatings(app)));
    layout->addWidget(total);
}