+/* $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);
layout->addWidget(progressBar);
setMouseTracking(true);
-
- setLayout(layout);
}
void LoadingWidget::setVideo(Video *video) {
+
+ QFont titleFont;
+#ifdef APP_MAC
+ titleFont.setFamily("Helvetica");
+#endif
+#ifdef APP_WIN
+ titleFont.setFamily("Segoe UI Light");
+#endif
+ 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();