123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "radiowidget.h"
- #include "ui_radiowidget.h"
- #include <QDebug>
-
- RadioWidget::RadioWidget(QWidget *parent) : QFrame(parent), ui(new Ui::RadioWidget)
- {
- ui->setupUi(this);
- remaining = 0;
- timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(countdown()));
- timer->setInterval(1000);
- }
-
- RadioWidget::~RadioWidget()
- {
- delete ui;
- }
-
- Radio *RadioWidget::getRadio()
- {
- return radio;
- }
-
- void RadioWidget::setRadio(Radio *r)
- {
- radio = r;
- ui->lblClaim->setText(radio->getClaim());
- QPalette p = ui->lblClaim->palette();
- p.setColor(QPalette::Foreground, radio->getTextColor());
- ui->lblClaim->setPalette(p);
- songChanged(0);
- ui->lblLogo->setText(radio->getName());
- connect(radio, SIGNAL(logoDownloaded(QPixmap)), this, SLOT(logoDownloaded(QPixmap)));
- connect(radio, SIGNAL(songChanged(Song*)), this, SLOT(songChanged(Song*)));
- radio->downloadLogo();
- }
-
- void RadioWidget::logoDownloaded(QPixmap l)
- {
- ui->lblLogo->setText("");
- ui->lblLogo->setPixmap(l);
- }
-
- void RadioWidget::songChanged(Song *s)
- {
- if(s == 0)
- {
- ui->lblSong->setText("--");
- ui->lblTime->setText("");
- }
- else
- {
- ui->lblSong->setText(s->getArtist() + "\n" + s->getTitle());
- remaining = s->getDuration()/1000;
-
- ui->lblTime->setText(QString::number(remaining));
- timer->start();
- }
- }
-
- void RadioWidget::countdown()
- {
- --remaining;
- ui->lblTime->setText(QString::number(remaining));
- }
-
- void RadioWidget::enterEvent(QEvent *)
- {
- setStyleSheet("background-color: rgb(225, 225, 225);");
- }
-
- void RadioWidget::leaveEvent(QEvent *)
- {
- setStyleSheet("background-color: none;");
- }
-
- void RadioWidget::mouseReleaseEvent(QMouseEvent *e)
- {
- if(e->button() == Qt::LeftButton)
- emit clicked(radio);
- }
|