From 36115887ddc809a806f2aa4c5688964fcf96bddc Mon Sep 17 00:00:00 2001 From: Flavio Date: Tue, 11 Sep 2012 16:34:22 +0200 Subject: [PATCH] Sidebar and mouse autohide in fullscreen mode for Mac --- src/MainWindow.cpp | 40 +++++++++++++++++++++++++++++++++++++++- src/MainWindow.h | 4 ++++ src/MediaView.cpp | 12 +++++++++++- src/MediaView.h | 1 + 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 600d794..299b9df 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -124,6 +124,11 @@ MainWindow::MainWindow() : setAcceptDrops(true); + mouseTimer = new QTimer(this); + mouseTimer->setInterval(3000); + mouseTimer->setSingleShot(true); + connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse())); + QTimer::singleShot(0, this, SLOT(checkForUpdate())); } @@ -155,12 +160,35 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) { } #endif +#ifndef Q_WS_X11 + // mac::IsFullScreen(winId()) + if (event->type() == QEvent::MouseMove && m_fullscreen) { + + // show the normal cursor + unsetCursor(); + // then hide it again after a few seconds + mouseTimer->start(); + + QMouseEvent *mouseEvent = static_cast (event); + const int x = mouseEvent->pos().x(); + const QString className = QString(obj->metaObject()->className()); + const bool isHoveringVideo = className == "QGLWidget"; + // qDebug() << obj << x << isHoveringVideo << mediaView->isPlaylistVisible(); + if (mediaView->isPlaylistVisible()) { + if (isHoveringVideo && x > 5) mediaView->setPlaylistVisible(false); + } else { + bool visible = (isHoveringVideo && x >= 0 && x < 5); + mediaView->setPlaylistVisible(visible); + } + } +#endif + if (event->type() == QEvent::ToolTip) { // kill tooltips return true; } // standard event processing - return QObject::eventFilter(obj, event); + return QMainWindow::eventFilter(obj, event); } void MainWindow::createActions() { @@ -1035,6 +1063,11 @@ void MainWindow::updateUIForFullscreen() { if (views->currentWidget() == mediaView) mediaView->setFocus(); + + if (!m_fullscreen) { + mouseTimer->stop(); + unsetCursor(); + } } void MainWindow::compactView(bool enable) { @@ -1427,3 +1460,8 @@ void MainWindow::messageReceived(const QString &message) { showMedia(searchParams); } } + +void MainWindow::hideMouse() { + setCursor(Qt::BlankCursor); + mediaView->setPlaylistVisible(false); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 713422d..d22cf94 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -83,6 +83,8 @@ private slots: void showActionInStatusBar(QAction*, bool show); void showStopAfterThisInStatusBar(bool show); + void hideMouse(); + private: void initPhonon(); void createActions(); @@ -158,6 +160,8 @@ private: bool m_fullscreen; bool m_maximized; + QTimer *mouseTimer; + }; #endif diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 204f956..611992e 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -13,6 +13,9 @@ #include "playlistwidget.h" #include "refinesearchwidget.h" #include "sidebarwidget.h" +#ifdef APP_MAC +#include "macfullscreen.h" +#endif namespace The { NetworkAccess* http(); @@ -80,7 +83,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { videoAreaWidget = new VideoAreaWidget(this); // videoAreaWidget->setMinimumSize(320,240); -#ifdef APP_MAC_NO +#ifdef APP_MAC // mouse autohide does not work on the Mac (no mouseMoveEvent) videoWidget = new Phonon::VideoWidget(this); #else @@ -177,6 +180,7 @@ void MediaView::search(SearchParams *searchParams) { sidebar->getRefineSearchWidget()->setSearchParams(searchParams); sidebar->hideSuggestions(); + } void MediaView::searchAgain() { @@ -622,7 +626,13 @@ void MediaView::searchMostViewed() { } void MediaView::setPlaylistVisible(bool visible) { + if (splitter->widget(0)->isVisible() == visible) return; splitter->widget(0)->setVisible(visible); + listView->setFocus(); +} + +bool MediaView::isPlaylistVisible() { + return splitter->widget(0)->isVisible(); } void MediaView::timerPlay() { diff --git a/src/MediaView.h b/src/MediaView.h index e4dec2a..9d30c50 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -60,6 +60,7 @@ public slots: void removeSelected(); void moveUpSelected(); void moveDownSelected(); + bool isPlaylistVisible(); void setPlaylistVisible(bool visible=true); void saveSplitterState(); void downloadVideo(); -- 2.39.5