]> git.sur5r.net Git - minitube/blob - src/loadingwidget.cpp
Imported Upstream version 1.4.1
[minitube] / src / loadingwidget.cpp
1 #include "loadingwidget.h"
2
3 LoadingWidget::LoadingWidget(QWidget *parent) : QWidget(parent) {
4
5     QPalette p = palette();
6     p.setBrush(QPalette::Window, Qt::black);
7     p.setBrush(QPalette::Text, Qt::white);
8     setPalette(p);
9
10     setAutoFillBackground(true);
11
12     QFont bigFont;
13     bigFont.setPointSize(bigFont.pointSize()*4);
14     QFontMetrics fm(bigFont);
15     int textHeightInPixels = fm.height();
16     int spacing = textHeightInPixels / 2;
17
18     QBoxLayout *layout = new QVBoxLayout();
19     layout->setSpacing(spacing);
20     layout->setMargin(spacing);
21
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);
30
31     QFont biggerFont;
32     biggerFont.setPointSize(biggerFont.pointSize()*2);
33
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);
42
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);
51
52     setMouseTracking(true);
53
54     setLayout(layout);
55 }
56
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);
67     startTime.start();
68 }
69
70 void LoadingWidget::setError(QString message) {
71     titleLabel->setText(tr("Error"));
72     descriptionLabel->setText(message);
73     // progressBar->hide();
74     progressBar->setValue(0);
75 }
76
77 void LoadingWidget::bufferStatus(int percent) {
78     // qDebug() << percent;
79
80     /*
81     if (progressBar->isHidden() && percent > 0) {
82         progressBar->show();
83         QPropertyAnimation *animation = new QPropertyAnimation(progressBar, "opacity");
84         animation->setDuration(1000);
85         animation->setStartValue(0.0);
86         animation->setEndValue(1.0);
87         animation->start();
88     }*/
89     // progressBar->setShown(percent > 0);
90     if (startTime.elapsed() < 1000) return;
91     if (progressBar->value() == 0 && percent > 80) return;
92     progressBar->setValue(percent);
93 }
94
95 void LoadingWidget::clear() {
96     titleLabel->clear();
97     descriptionLabel->clear();
98     // progressBar->hide();
99     progressBar->setValue(0);
100 }