1 #include "loadingwidget.h"
3 LoadingWidget::LoadingWidget(QWidget *parent) : QWidget(parent) {
5 QPalette p = palette();
6 p.setBrush(QPalette::Window, Qt::black);
7 p.setBrush(QPalette::Text, Qt::white);
10 setAutoFillBackground(true);
13 bigFont.setPointSize(bigFont.pointSize()*4);
14 QFontMetrics fm(bigFont);
15 int textHeightInPixels = fm.height();
16 int spacing = textHeightInPixels / 2;
18 QBoxLayout *layout = new QVBoxLayout();
19 layout->setSpacing(spacing);
20 layout->setMargin(spacing);
22 titleLabel = new QLabel(this);
23 titleLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
24 titleLabel->setPalette(p);
25 titleLabel->setForegroundRole(QPalette::Text);
26 titleLabel->setWordWrap(true);
27 titleLabel->setFont(bigFont);
28 titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
29 layout->addWidget(titleLabel);
32 biggerFont.setPointSize(biggerFont.pointSize()*2);
34 descriptionLabel = new QLabel(this);
35 descriptionLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
36 descriptionLabel->setPalette(p);
37 descriptionLabel->setForegroundRole(QPalette::Text);
38 descriptionLabel->setWordWrap(true);
39 descriptionLabel->setFont(biggerFont);
40 descriptionLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
41 layout->addWidget(descriptionLabel);
43 progressBar = new QProgressBar(this);
44 progressBar->setAutoFillBackground(false);
45 progressBar->setBackgroundRole(QPalette::Window);
46 progressBar->setPalette(p);
47 // progressBar->hide();
48 progressBar->setStyleSheet("QProgressBar {max-height:3px; background:black; border:0} QProgressBar::chunk {background:white}");
49 progressBar->setTextVisible(false);
50 layout->addWidget(progressBar);
52 setMouseTracking(true);
57 void LoadingWidget::setVideo(Video *video) {
58 QString title = video->title();
59 // enhance legibility by splitting the title
60 title = title.replace(" - ", "<p>");
61 title = title.replace("] ", "]<p>");
62 title = title.replace(" [", "<p>[");
63 titleLabel->setText(title);
64 descriptionLabel->setText(video->description());
65 // progressBar->hide();
66 progressBar->setValue(0);
70 void LoadingWidget::setError(QString message) {
71 titleLabel->setText(tr("Error"));
72 descriptionLabel->setText(message);
73 // progressBar->hide();
74 progressBar->setValue(0);
77 void LoadingWidget::bufferStatus(int percent) {
78 // qDebug() << percent;
81 if (progressBar->isHidden() && percent > 0) {
83 QPropertyAnimation *animation = new QPropertyAnimation(progressBar, "opacity");
84 animation->setDuration(1000);
85 animation->setStartValue(0.0);
86 animation->setEndValue(1.0);
89 // progressBar->setShown(percent > 0);
90 if (startTime.elapsed() < 1000) return;
91 if (progressBar->value() == 0 && percent > 80) return;
92 progressBar->setValue(percent);
95 void LoadingWidget::clear() {
97 descriptionLabel->clear();
98 // progressBar->hide();
99 progressBar->setValue(0);