X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Floadingwidget.cpp;h=66ec79d2a1eafcb9f4a48ac1d559a8a696677ec6;hb=HEAD;hp=79efe0d3d0431477d1d84527781f54536dad9d1b;hpb=7cdd5bd476021ec84d54c4ec5be02280e1e9e548;p=minitube
diff --git a/src/loadingwidget.cpp b/src/loadingwidget.cpp
index 79efe0d..66ec79d 100644
--- a/src/loadingwidget.cpp
+++ b/src/loadingwidget.cpp
@@ -19,83 +19,75 @@ along with Minitube. If not, see
"); - title = title.replace("] ", "]
"); - title = title.replace(" [", "
["); + static const QLatin1String p("
"); + title.replace(QLatin1String(" - "), p); + title.replace(QLatin1String(" | "), p); + title.replace(QLatin1String(" â "), p); + title.replace(QLatin1String(": "), p); + title.replace(QLatin1String("; "), p); + title.replace(QLatin1String("] "), QLatin1String("]
")); + title.replace(QLatin1String(" ["), QLatin1String("
[")); + title.replace(QLatin1String(" ("), QLatin1String("
(")); + title.replace(QLatin1String(") "), QLatin1String(")
")); titleLabel->setText(title); titleLabel->setVisible(window()->height() > 100); - titleLabel->setFont(titleFont); - static const int maxDescLength = 256; - QString videoDesc = video->description(); + const int maxDescLength = 500; + + QString videoDesc = video->getDescription(); if (videoDesc.length() > maxDescLength) { - videoDesc.truncate(maxDescLength-1); - videoDesc.append("..."); + videoDesc.truncate(maxDescLength); + videoDesc = videoDesc.trimmed(); + videoDesc.append("â¦"); + } else if (videoDesc.endsWith(QLatin1String(" ..."))) { + videoDesc = videoDesc.left(videoDesc.length() - 4); + videoDesc.append("â¦"); } - QFont descFont(titleFont); - descFont.setPixelSize(descFont.pixelSize() / 2); - descFont.setHintingPreference(QFont::PreferNoHinting); - descriptionLabel->setFont(descFont); + static const QRegExp linkRE("(https?://\\S+)"); + videoDesc.replace(linkRE, QStringLiteral("\\1")); descriptionLabel->setText(videoDesc); bool hiddenDesc = height() < 400; if (hiddenDesc) @@ -104,39 +96,45 @@ void LoadingWidget::setVideo(Video *video) { titleLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); descriptionLabel->setVisible(!hiddenDesc); - // progressBar->hide(); progressBar->setValue(0); startTime.start(); } -void LoadingWidget::setError(QString message) { +void LoadingWidget::setError(const QString &message) { titleLabel->setText(tr("Error")); descriptionLabel->setText(message); - // progressBar->hide(); progressBar->setValue(0); } -void LoadingWidget::bufferStatus(int percent) { - // qDebug() << percent; - - /* - 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::bufferStatus(qreal value) { + int percent = value * 100.; + if (startTime.elapsed() > 1000 && percent > progressBar->value()) + progressBar->setValue(percent); +} + +void LoadingWidget::adjustFontSize() { + QFont f = titleLabel->font(); + int smallerDimension = qMin(height(), width()); + f.setPixelSize(smallerDimension / 12); + QFontMetrics fm(f); + int textHeightInPixels = fm.height(); + int spacing = textHeightInPixels / 2; + layout()->setSpacing(spacing); + layout()->setMargin(spacing); + titleLabel->setFont(f); + + QFont descFont = descriptionLabel->font(); + descFont.setPixelSize(f.pixelSize() / 2); + descriptionLabel->setFont(descFont); } void LoadingWidget::clear() { titleLabel->clear(); descriptionLabel->clear(); - // progressBar->hide(); progressBar->setValue(0); } + +void LoadingWidget::resizeEvent(QResizeEvent *e) { + Q_UNUSED(e); + if (isVisible()) adjustFontSize(); +}