You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

radiowidget.cpp 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "radiowidget.h"
  2. #include "ui_radiowidget.h"
  3. #include <QDebug>
  4. RadioWidget::RadioWidget(QWidget *parent) : QFrame(parent), ui(new Ui::RadioWidget)
  5. {
  6. ui->setupUi(this);
  7. remaining = 0;
  8. timer = new QTimer(this);
  9. connect(timer, SIGNAL(timeout()), this, SLOT(countdown()));
  10. timer->setInterval(1000);
  11. }
  12. RadioWidget::~RadioWidget()
  13. {
  14. delete ui;
  15. }
  16. Radio *RadioWidget::getRadio()
  17. {
  18. return radio;
  19. }
  20. void RadioWidget::setRadio(Radio *r)
  21. {
  22. radio = r;
  23. ui->lblClaim->setText(radio->getClaim());
  24. QPalette p = ui->lblClaim->palette();
  25. p.setColor(QPalette::Foreground, radio->getTextColor());
  26. ui->lblClaim->setPalette(p);
  27. songChanged(0);
  28. ui->lblLogo->setText(radio->getName());
  29. connect(radio, SIGNAL(logoDownloaded(QPixmap)), this, SLOT(logoDownloaded(QPixmap)));
  30. connect(radio, SIGNAL(songChanged(Song*)), this, SLOT(songChanged(Song*)));
  31. radio->downloadLogo();
  32. }
  33. void RadioWidget::logoDownloaded(QPixmap l)
  34. {
  35. ui->lblLogo->setText("");
  36. ui->lblLogo->setPixmap(l);
  37. }
  38. void RadioWidget::songChanged(Song *s)
  39. {
  40. if(s == 0)
  41. {
  42. ui->lblSong->setText("--");
  43. ui->lblTime->setText("");
  44. }
  45. else
  46. {
  47. ui->lblSong->setText(s->getArtist() + "\n" + s->getTitle());
  48. remaining = s->getDuration()/1000;
  49. ui->lblTime->setText(QString::number(remaining));
  50. timer->start();
  51. }
  52. }
  53. void RadioWidget::countdown()
  54. {
  55. --remaining;
  56. ui->lblTime->setText(QString::number(remaining));
  57. }
  58. void RadioWidget::enterEvent(QEvent *)
  59. {
  60. setStyleSheet("background-color: rgb(225, 225, 225);");
  61. }
  62. void RadioWidget::leaveEvent(QEvent *)
  63. {
  64. setStyleSheet("background-color: none;");
  65. }
  66. void RadioWidget::mouseReleaseEvent(QMouseEvent *e)
  67. {
  68. if(e->button() == Qt::LeftButton)
  69. emit clicked(radio);
  70. }