From: Flavio Tordini Date: Sat, 27 Jun 2009 17:38:57 +0000 (+0200) Subject: Added current and total time in the status bar X-Git-Tag: 0.4~24 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=26b2d5bee5cf7b055a13b924324d628ad25b1e2c;p=minitube Added current and total time in the status bar --- diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 806a0f7..17c6c8f 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -280,6 +280,10 @@ void MainWindow::createToolBars() { } void MainWindow::createStatusBar() { + currentTime = new QLabel(this); + statusBar()->addPermanentWidget(currentTime); + totalTime = new QLabel(this); + statusBar()->addPermanentWidget(totalTime); statusBar()->show(); } @@ -389,6 +393,8 @@ void MainWindow::showSettings() { void MainWindow::showSearch() { showWidget(searchView); + currentTime->clear(); + totalTime->clear(); } void MainWindow::showMedia(QString query) { @@ -439,6 +445,8 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState case Phonon::LoadingState: skipAct->setEnabled(true); pauseAct->setEnabled(false); + currentTime->clear(); + totalTime->clear(); break; default: @@ -478,10 +486,30 @@ void MainWindow::initPhonon() { if (mediaObject) delete mediaObject; if (audioOutput) delete audioOutput; mediaObject = new Phonon::MediaObject(this); + mediaObject->setTickInterval(100); connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged(Phonon::State, Phonon::State))); + connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); + connect(mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); seekSlider->setMediaObject(mediaObject); audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); volumeSlider->setAudioOutput(audioOutput); Phonon::createPath(mediaObject, audioOutput); } + +void MainWindow::tick(qint64 time) { + QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60); + currentTime->setText(displayTime.toString("mm:ss")); + // qDebug() << "currentTime" << time << displayTime.toString("mm:ss"); +} + +void MainWindow::totalTimeChanged(qint64 time) { + if (time <= 0) { + 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"); +} + diff --git a/src/MainWindow.h b/src/MainWindow.h index cbd6de8..99d7abb 100755 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -39,6 +39,8 @@ private slots: void stop(); void stateChanged(Phonon::State newState, Phonon::State oldState); void searchFocus(); + void tick(qint64 time); + void totalTimeChanged(qint64 time); private: void initPhonon(); @@ -100,6 +102,8 @@ private: Phonon::VolumeSlider *volumeSlider; Phonon::MediaObject *mediaObject; Phonon::AudioOutput *audioOutput; + QLabel *currentTime; + QLabel *totalTime; bool m_fullscreen; }; diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 381edac..64c85e2 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -102,7 +102,6 @@ void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) { this, SLOT(stateChanged(Phonon::State, Phonon::State))); connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)), this, SLOT(currentSourceChanged(Phonon::MediaSource))); - // connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int))); }