1 #include "channelwidget.h"
2 #include "videosource.h"
6 ChannelWidget::ChannelWidget(VideoSource *videoSource, YTUser *user, QWidget *parent) :
9 this->videoSource = videoSource;
11 setMinimumSize(132, 176);
12 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
14 connect(user, SIGNAL(infoLoaded()), SLOT(gotUserInfo()));
15 // user->loadfromAPI();
17 connect(this, SIGNAL(activated()), SLOT(activate()));
20 void ChannelWidget::activate() {
21 // YTUser.checked(user->getUserId());
22 emit activated(videoSource);
25 void ChannelWidget::gotUserInfo() {
26 connect(user, SIGNAL(thumbnailLoaded(QByteArray)), SLOT(gotUserThumbnail(QByteArray)));
27 // user->loadThumbnail();
31 void ChannelWidget::paintEvent(QPaintEvent *) {
32 if (thumbnail.isNull()) return;
34 const int w = width();
35 const int h = height();
38 p.drawPixmap((w - thumbnail.width()) / 2, 0, thumbnail);
39 //(h - thumbnail.height()) / 2
41 QRect nameBox = rect();
42 nameBox.adjust(0, 0, 0, -thumbnail.height() - 10);
43 nameBox.translate(0, h - nameBox.height());
45 QString name = user->getDisplayName();
50 f.setFamily("Helvetica");
53 QRect textBox = p.boundingRect(nameBox, Qt::AlignTop | Qt::AlignHCenter | Qt::TextWordWrap, name);
54 if (textBox.height() > nameBox.height()) {
56 textBox = p.boundingRect(nameBox, Qt::AlignTop | Qt::AlignHCenter | Qt::TextWordWrap, name);
57 if (textBox.height() > nameBox.height()) {
58 p.setClipRect(nameBox);
64 p.drawText(nameBox, Qt::AlignHCenter | Qt::AlignTop | Qt::TextWordWrap, name);
66 p.drawText(textBox, Qt::AlignCenter | Qt::TextWordWrap, name);
72 pen.setBrush(palette().highlight());
80 void ChannelWidget::gotUserThumbnail(QByteArray bytes) {
81 thumbnail.loadFromData(bytes);
82 if (thumbnail.width() > 88)
83 thumbnail = thumbnail.scaledToWidth(88, Qt::SmoothTransformation);