From d3ad7add8875810ac4b905f02b6f38fa4086e0b6 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Fri, 8 Jan 2010 22:00:50 +0100 Subject: [PATCH] Enhanced fullscreen mode Removed commented code for video download --- CHANGES | 3 ++ TODO | 3 -- src/MainWindow.cpp | 108 +++++++--------------------------------- src/MainWindow.h | 22 ++------ src/loadingwidget.cpp | 2 + src/videoareawidget.cpp | 14 ++++++ src/videoareawidget.h | 1 + src/videowidget.cpp | 8 +-- 8 files changed, 47 insertions(+), 114 deletions(-) diff --git a/CHANGES b/CHANGES index 7b10903..b5bb252 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ 0.9 - ? +- Clear recent keywords +- Show the toolbar when mouse hits the top of the screen in Fullscreen mode +- Show the playlist when mouse hits the left side of the screen in Fullscreen mode - Fixed toolbar search suggestions working just once (Thanks to Salvatore Benedetto) - Fixed time formatting bug with videos longer than 1 hour (Thanks to Rene Bogusch) - Norwegian translation by Jan W. Skjoldal diff --git a/TODO b/TODO index efc2fae..030e86a 100644 --- a/TODO +++ b/TODO @@ -32,11 +32,8 @@ ## Minor Features - Restore status when a recent keyword is clicked: skipped videos, sortBar and play time -- Clear recent keywords - Safe search levels (in the status bar beside HD) - Show buffering progress (when Phonon backends will work) -- Mark playlist items that have errors -- Settings: number of "Recent Keywords", Phonon settings, HD or not - Show the toolbar when mouse hits the top of the screen in Fullscreen mode with animation - Show the playlist when mouse hits the left side of the screen in Fullscreen mode with animation - Show more thumbs on hover with animated crossfade diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 50de29b..f9dd824 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -8,7 +8,7 @@ MainWindow::MainWindow() : mediaObject(0), audioOutput(0), aboutView(0) { - + m_fullscreen = false; // views mechanism @@ -599,7 +599,7 @@ void MainWindow::fullscreen() { // workaround: prevent focus on the search bar // it steals the Space key needed for Play/Pause mainToolBar->setEnabled(m_fullscreen); - + m_fullscreen = !m_fullscreen; setUpdatesEnabled(true); @@ -725,93 +725,6 @@ void MainWindow::volumeMutedChanged(bool muted) { statusBar()->showMessage(tr("Volume is unmuted")); } -/* -void MainWindow::abortDownload() { - QProgressDialog* dlg = dynamic_cast(this->sender()); - QMap::iterator cur; - QMap::iterator end; - // locate the DownloadResource by its dialog address and trigger abortion - for(cur=m_downloads.begin(), end=m_downloads.end(); cur!=end; cur++){ - if(cur.value().dialog == dlg) cur.key()->abort(); - } -} - -void MainWindow::download() { - if(mediaObject == NULL || mediaObject->currentSource().url().isEmpty()){ - // complain unless video source apperas to be valid - QMessageBox::critical(this, tr("No Video playing"), tr("You must first play the video you intent to download !")); - return; - } - QString filename = QFileDialog::getSaveFileName(this, - tr("Save video as..."), - tr("minitube video.mp4"), - "Video File(*.avi *.mp4)" - ); - if(!filename.isNull()) { - // open destination file and initialize download - DownloadResource res; - res.file = new QFile(filename); - if(res.file->open(QFile::WriteOnly) == true) { - res.dialog = new QProgressDialog(tr("Downloading: ") + res.file->fileName(), - tr("Abort Download"), 0, 100, this); - connect(res.dialog, SIGNAL(canceled()), this, SLOT(abortDownload())); - download(mediaObject->currentSource().url(), res); - }else{ - QMessageBox::critical(this, tr("File creation failed"), res.file->errorString()); - delete res.file; - } - } -} - -void MainWindow::download(const QUrl& url, const DownloadResource& res) { - // create and store request and connect the reply signals - QNetworkReply *r = The::networkAccessManager()->get(QNetworkRequest(url)); - m_downloads.insert(r, res); - connect(r, SIGNAL(finished()), this, SLOT(replyFinished())); - connect(r, SIGNAL(readyRead()), this, SLOT(replyReadyRead())); - connect(r, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); - connect(r, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(replyDownloadProgress(qint64,qint64))); - connect(r, SIGNAL(metaDataChanged()), this, SLOT(replyMetaDataChanged())); -} - -void MainWindow::replyReadyRead() { - QNetworkReply* r = dynamic_cast(this->sender()); - m_downloads[r].file->write(r->readAll()); -} - -void MainWindow::replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { - QNetworkReply* r = dynamic_cast(this->sender()); - if (bytesTotal > 0 && bytesReceived >0) - m_downloads[r].dialog->setValue( double(100.0/bytesTotal)*bytesReceived ); // pssst :-X -} - -void MainWindow::replyError(QNetworkReply::NetworkError code) { - QNetworkReply* r = dynamic_cast(this->sender()); - QMessageBox::critical(this, tr("Download failed"), r->errorString()); -} - -void MainWindow::replyFinished() { - QNetworkReply* r = dynamic_cast(this->sender()); - m_downloads[r].dialog->close(); - m_downloads[r].file->close(); - delete m_downloads[r].file; - m_downloads.remove(r); -} - -void MainWindow::replyMetaDataChanged() { - QNetworkReply* r = dynamic_cast(this->sender()); - QUrl url = r->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); - if(url.isValid()) { - // redirect - request new url, but keep the resources - qDebug() << "redirecting to: " << url.toString(); - download(url, m_downloads[r]); - m_downloads.remove(r); - } -} - -*/ - - QPixmap MainWindow::createHDPixmap(bool enabled) { QPixmap pixmap = QPixmap(24,24); pixmap.fill(Qt::transparent); @@ -883,3 +796,20 @@ void MainWindow::hdIndicator(bool isHd) { hdAct->setToolTip(tr("The current video is not in High Definition")); } } + +void MainWindow::showFullscreenToolbar(bool show) { + if (!m_fullscreen) return; + + if (show) { + mainToolBar->show(); + } else { + mainToolBar->hide(); + } + mainToolBar->setEnabled(show); +} + +void MainWindow::showFullscreenPlaylist(bool show) { + if (!m_fullscreen) return; + mediaView->setPlaylistVisible(show); +} + diff --git a/src/MainWindow.h b/src/MainWindow.h index e8d2ed5..675597f 100755 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -30,13 +30,6 @@ public slots: protected: void closeEvent(QCloseEvent *); - /* - struct DownloadResource - { - QProgressDialog* dialog; - QFile* file; - };*/ - private slots: void fadeInWidget(QWidget *oldWidget, QWidget *newWidget); void goBack(); @@ -63,17 +56,9 @@ private slots: void volumeChanged(qreal newVolume); void volumeMutedChanged(bool muted); - /* - // download related stuff - void abortDownload(); - void download(); - void download(const QUrl& url, const DownloadResource& res); - void replyReadyRead(); - void replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); - void replyError(QNetworkReply::NetworkError code); - void replyFinished(); - void replyMetaDataChanged(); - */ + // fullscreen toolbar + void showFullscreenToolbar(bool show); + void showFullscreenPlaylist(bool show); private: void initPhonon(); @@ -149,7 +134,6 @@ private: bool m_fullscreen; bool m_maximized; - // QMap m_downloads; }; #endif diff --git a/src/loadingwidget.cpp b/src/loadingwidget.cpp index ef565b3..b4f8eaf 100644 --- a/src/loadingwidget.cpp +++ b/src/loadingwidget.cpp @@ -46,6 +46,8 @@ LoadingWidget::LoadingWidget(QWidget *parent) : QWidget(parent) { layout->addWidget(progressBar); */ + setMouseTracking(true); + setLayout(layout); } diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index 1d743a8..a733fc1 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -23,6 +23,7 @@ VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { setLayout(vLayout); setAcceptDrops(true); + setMouseTracking(true); } void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) { @@ -92,3 +93,16 @@ void VideoAreaWidget::dropEvent(QDropEvent *event) { listModel->setActiveRow(row); event->acceptProposedAction(); } + +void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) { + // qDebug() << "VideoAreaWidget::mouseMoveEvent" << event->pos(); + + QMainWindow* mainWindow = dynamic_cast(qApp->topLevelWidgets().first()); + bool visible = event->pos().y() <= 0; + bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible)); + if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed"; + + visible = event->pos().x() <= 0; + ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible)); + if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed"; +} diff --git a/src/videoareawidget.h b/src/videoareawidget.h index fa37a59..e1f7cea 100644 --- a/src/videoareawidget.h +++ b/src/videoareawidget.h @@ -31,6 +31,7 @@ protected: void mousePressEvent(QMouseEvent *event); void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); + void mouseMoveEvent(QMouseEvent *event); private: QStackedLayout *stackedLayout; diff --git a/src/videowidget.cpp b/src/videowidget.cpp index 71179cb..ed6d689 100644 --- a/src/videowidget.cpp +++ b/src/videowidget.cpp @@ -2,15 +2,17 @@ VideoWidget::VideoWidget(QWidget *parent) : Phonon::VideoWidget(parent) { // mouse autohide - // setMouseTracking(true); + setMouseTracking(true); mouseTimer = new QTimer(this); mouseTimer->setInterval(3000); mouseTimer->setSingleShot(true); connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse())); } -void VideoWidget::mouseMoveEvent(QMouseEvent * /* event */) { - // qDebug() << "mouseMoveEvent"; +void VideoWidget::mouseMoveEvent(QMouseEvent *event) { + Phonon::VideoWidget::mouseMoveEvent(event); + + // qDebug() << "VideoWidget::mouseMoveEvent" << event->pos(); // show the normal cursor unsetCursor(); -- 2.39.5