From: Flavio Tordini Date: Sat, 19 Dec 2009 15:19:06 +0000 (+0100) Subject: Fixed time formatting bug with videos longer than 1 hour X-Git-Tag: 0.9~21 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=54b4d02b2a3f20705ebe366647e5ab2f2e1c9f8b;p=minitube Fixed time formatting bug with videos longer than 1 hour --- diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index beedc2b..9d05596 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -657,15 +657,13 @@ void MainWindow::tick(qint64 time) { currentTime->clear(); return; } - QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60); - currentTime->setText(displayTime.toString("mm:ss")); - - // remaining time tooltip - int remainingTimeInt = mediaObject->remainingTime(); - QTime remainingTime(0, (remainingTimeInt / 60000) % 60, (remainingTimeInt / 1000) % 60); - currentTime->setStatusTip(tr("Remaining time: %1").arg(remainingTime.toString("mm:ss"))); - - // qDebug() << "currentTime" << time << displayTime.toString("mm:ss"); + + currentTime->setText(formatTime(time)); + + // remaining time + const qint64 remainingTime = mediaObject->remainingTime(); + currentTime->setStatusTip(tr("Remaining time: %1").arg(formatTime(remainingTime))); + } void MainWindow::totalTimeChanged(qint64 time) { @@ -673,9 +671,19 @@ void MainWindow::totalTimeChanged(qint64 time) { totalTime->clear(); return; } - QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60); - totalTime->setText(displayTime.toString("/ mm:ss")); - // qDebug() << "totalTime" << time << displayTime.toString("mm:ss"); + totalTime->setText("/ " + formatTime(time)); +} + +QString MainWindow::formatTime(qint64 time) { + QTime displayTime; + displayTime = displayTime.addMSecs(time); + QString timeString; + // 60 * 60 * 1000 = 3600000 + if (time > 3600000) + timeString = displayTime.toString("h:mm:ss"); + else + timeString = displayTime.toString("m:ss"); + return timeString; } void MainWindow::volumeUp() { diff --git a/src/MainWindow.h b/src/MainWindow.h index 6ffc83f..7d3f23d 100755 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -86,6 +86,7 @@ private: void showWidget(QWidget*); QPixmap createHDPixmap(bool enabled); QIcon createHDIcon(); + static QString formatTime(qint64 time); // view mechanism QPointer faderWidget;