+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube. If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
#include "loadingwidget.h"
LoadingWidget::LoadingWidget(QWidget *parent) : QWidget(parent) {
QPalette p = palette();
- p.setBrush(QPalette::Window, Qt::black);
+ p.setBrush(backgroundRole(), Qt::black);
p.setBrush(QPalette::Text, Qt::white);
setPalette(p);
setAutoFillBackground(true);
- QFont bigFont;
- bigFont.setPointSize(bigFont.pointSize()*4);
- QFontMetrics fm(bigFont);
- int textHeightInPixels = fm.height();
- int spacing = textHeightInPixels / 2;
-
- QBoxLayout *layout = new QVBoxLayout();
- layout->setSpacing(spacing);
- layout->setMargin(spacing);
+ QBoxLayout *layout = new QVBoxLayout(this);
titleLabel = new QLabel(this);
titleLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
titleLabel->setPalette(p);
titleLabel->setForegroundRole(QPalette::Text);
titleLabel->setWordWrap(true);
- titleLabel->setFont(bigFont);
titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(titleLabel);
- QFont biggerFont;
- biggerFont.setPointSize(biggerFont.pointSize()*2);
-
descriptionLabel = new QLabel(this);
descriptionLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
descriptionLabel->setPalette(p);
descriptionLabel->setForegroundRole(QPalette::Text);
descriptionLabel->setWordWrap(true);
- descriptionLabel->setFont(biggerFont);
- descriptionLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ descriptionLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
layout->addWidget(descriptionLabel);
- /*
progressBar = new QProgressBar(this);
- progressBar->hide();
+ progressBar->setAutoFillBackground(false);
+ progressBar->setBackgroundRole(QPalette::Window);
+ progressBar->setPalette(p);
+ // progressBar->hide();
+ progressBar->setStyleSheet("QProgressBar {max-height:3px; background:black; border:0} QProgressBar::chunk {background:white}");
+ progressBar->setTextVisible(false);
layout->addWidget(progressBar);
- */
setMouseTracking(true);
-
- setLayout(layout);
}
void LoadingWidget::setVideo(Video *video) {
+
+ QFont titleFont;
+#ifdef APP_MAC
+ titleFont.setFamily("Helvetica Neue");
+#endif
+#ifdef APP_WIN
+ titleFont.setFamily("Segoe UI Light");
+#endif
+ titleFont.setStyleName("Light");
+ int smallerDimension = qMin(height(), width());
+ titleFont.setPixelSize(smallerDimension / 12);
+ titleFont.setHintingPreference(QFont::PreferNoHinting);
+ QFontMetrics fm(titleFont);
+ int textHeightInPixels = fm.height();
+ int spacing = textHeightInPixels / 2;
+ layout()->setSpacing(spacing);
+ layout()->setMargin(spacing);
+
QString title = video->title();
// enhance legibility by splitting the title
title = title.replace(" - ", "<p>");
title = title.replace("] ", "]<p>");
title = title.replace(" [", "<p>[");
titleLabel->setText(title);
- descriptionLabel->setText(video->description());
+ titleLabel->setVisible(window()->height() > 100);
+ titleLabel->setFont(titleFont);
+
+ static const int maxDescLength = 256;
+ QString videoDesc = video->description();
+ if (videoDesc.length() > maxDescLength) {
+ videoDesc.truncate(maxDescLength-1);
+ videoDesc.append("...");
+ }
+ QFont descFont(titleFont);
+ descFont.setPixelSize(descFont.pixelSize() / 2);
+ descFont.setHintingPreference(QFont::PreferNoHinting);
+ descriptionLabel->setFont(descFont);
+ descriptionLabel->setText(videoDesc);
+ bool hiddenDesc = height() < 400;
+ if (hiddenDesc)
+ titleLabel->setAlignment(Qt::AlignCenter);
+ else
+ titleLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
+ descriptionLabel->setVisible(!hiddenDesc);
+
// progressBar->hide();
+ progressBar->setValue(0);
+ startTime.start();
}
void LoadingWidget::setError(QString message) {
titleLabel->setText(tr("Error"));
descriptionLabel->setText(message);
// progressBar->hide();
+ progressBar->setValue(0);
}
-void LoadingWidget::bufferStatus(int /* percent */) {
+void LoadingWidget::bufferStatus(int percent) {
+ // qDebug() << percent;
+
/*
- qDebug() << percent;
- progressBar->setShown(percent > 0);
+ if (progressBar->isHidden() && percent > 0) {
+ progressBar->show();
+ QPropertyAnimation *animation = new QPropertyAnimation(progressBar, "opacity");
+ animation->setDuration(1000);
+ animation->setStartValue(0.0);
+ animation->setEndValue(1.0);
+ animation->start();
+ }*/
+ // progressBar->setShown(percent > 0);
+ if (startTime.elapsed() < 1000) return;
+ if (progressBar->value() == 0 && percent > 80) return;
progressBar->setValue(percent);
- */
}
void LoadingWidget::clear() {
titleLabel->clear();
descriptionLabel->clear();
// progressBar->hide();
+ progressBar->setValue(0);
}