From ff4b9b0e01897183a4af54faed326ef17ac4053d Mon Sep 17 00:00:00 2001 From: Flavio Date: Wed, 12 Sep 2012 18:30:58 +0200 Subject: [PATCH] Unified fullscreen code and removed the old one CLI help --- minitube.pro | 2 -- src/MainWindow.cpp | 72 ++++++++++++++++++++++++----------------- src/MainWindow.h | 1 + src/MediaView.cpp | 7 ---- src/main.cpp | 16 +++++++-- src/videoareawidget.cpp | 38 ---------------------- src/videoareawidget.h | 2 -- src/videowidget.cpp | 27 ---------------- src/videowidget.h | 26 --------------- 9 files changed, 57 insertions(+), 134 deletions(-) delete mode 100644 src/videowidget.cpp delete mode 100644 src/videowidget.h diff --git a/minitube.pro b/minitube.pro index 1c28998..e705eb1 100644 --- a/minitube.pro +++ b/minitube.pro @@ -44,7 +44,6 @@ HEADERS += src/MainWindow.h \ src/loadingwidget.h \ src/videoareawidget.h \ src/autocomplete.h \ - src/videowidget.h \ src/videodefinition.h \ src/fontutils.h \ src/globalshortcuts.h \ @@ -87,7 +86,6 @@ SOURCES += src/main.cpp \ src/loadingwidget.cpp \ src/videoareawidget.cpp \ src/autocomplete.cpp \ - src/videowidget.cpp \ src/videodefinition.cpp \ src/constants.cpp \ src/fontutils.cpp \ diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c72b1d9..adf0e85 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -30,6 +30,7 @@ #else #include "searchlineedit.h" #endif +#include static MainWindow *singleton = 0; @@ -39,12 +40,12 @@ MainWindow* MainWindow::instance() { } MainWindow::MainWindow() : + updateChecker(0), aboutView(0), downloadView(0), mediaObject(0), audioOutput(0), - m_fullscreen(false), - updateChecker(0) { + m_fullscreen(false) { singleton = this; @@ -125,7 +126,7 @@ MainWindow::MainWindow() : setAcceptDrops(true); mouseTimer = new QTimer(this); - mouseTimer->setInterval(3000); + mouseTimer->setInterval(5000); mouseTimer->setSingleShot(true); connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse())); @@ -147,42 +148,38 @@ void MainWindow::changeEvent(QEvent* event) { } bool MainWindow::eventFilter(QObject *obj, QEvent *event) { -#ifdef Q_WS_X11 - if (event->type() == QEvent::MouseMove && this->m_fullscreen) { - QMouseEvent *mouseEvent = static_cast (event); - int x = mouseEvent->pos().x(); - int y = mouseEvent->pos().y(); - - if (y < 0 && (obj == this->mainToolBar || !(y <= 10-this->mainToolBar->height() && y >= 0-this->mainToolBar->height() ))) - this->mainToolBar->setVisible(false); - if (x < 0) - this->mediaView->setPlaylistVisible(false); - } -#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(); + if (m_fullscreen && event->type() == QEvent::MouseMove) { 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(); + const bool isHoveringVideo = (className == "QGLWidget") || (className == "VideoAreaWidget"); + + // qDebug() << obj << mouseEvent->pos() << isHoveringVideo << mediaView->isPlaylistVisible(); + if (mediaView->isPlaylistVisible()) { if (isHoveringVideo && x > 5) mediaView->setPlaylistVisible(false); } else { - bool visible = (isHoveringVideo && x >= 0 && x < 5); - mediaView->setPlaylistVisible(visible); + if (isHoveringVideo && x >= 0 && x < 5) mediaView->setPlaylistVisible(true); + } + +#ifndef APP_MAC + const int y = mouseEvent->pos().y(); + if (mainToolBar->isVisible()) { + if (isHoveringVideo && y > 5) mainToolBar->setVisible(false); + } else { + if (isHoveringVideo && y >= 0 && y < 5) mainToolBar->setVisible(true); } - } #endif + // show the normal cursor + unsetCursor(); + // then hide it again after a few seconds + mouseTimer->start(); + + } + if (event->type() == QEvent::ToolTip) { // kill tooltips return true; @@ -1132,7 +1129,6 @@ void MainWindow::compactView(bool enable) { } void MainWindow::searchFocus() { - QWidget *view = views->currentWidget(); toolbarSearch->selectAll(); toolbarSearch->setFocus(); } @@ -1455,6 +1451,8 @@ void MainWindow::messageReceived(const QString &message) { if (skipAct->isEnabled()) skipAct->trigger(); } else if (message == "--previous") { if (skipBackwardAct->isEnabled()) skipBackwardAct->trigger(); + } else if (message.startsWith("--")) { + MainWindow::printHelp(); } else if (!message.isEmpty()) { SearchParams *searchParams = new SearchParams(); searchParams->setKeywords(message); @@ -1465,4 +1463,20 @@ void MainWindow::messageReceived(const QString &message) { void MainWindow::hideMouse() { setCursor(Qt::BlankCursor); mediaView->setPlaylistVisible(false); +#ifndef APP_MAC + mainToolBar->setVisible(false); +#endif +} + +void MainWindow::printHelp() { + QString msg = QString("%1 %2\n\n").arg(Constants::NAME, Constants::VERSION); + msg += "Usage: minitube [options]\n"; + msg += "Options:\n"; + msg += " --toggle-playing\t"; + msg += "Start or pause playback.\n"; + msg += " --next\t\t"; + msg += "Skip to the next video.\n"; + msg += " --previous\t\t"; + msg += "Go back to the previous video.\n"; + std::cout << msg.toLocal8Bit().data(); } diff --git a/src/MainWindow.h b/src/MainWindow.h index d22cf94..ee21703 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -26,6 +26,7 @@ public: Phonon::SeekSlider* getSeekSlider() { return seekSlider; } void readSettings(); void writeSettings(); + static void printHelp(); public slots: void showMedia(SearchParams *params); diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 611992e..012266c 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -82,14 +82,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { videoAreaWidget = new VideoAreaWidget(this); // videoAreaWidget->setMinimumSize(320,240); - -#ifdef APP_MAC - // mouse autohide does not work on the Mac (no mouseMoveEvent) videoWidget = new Phonon::VideoWidget(this); -#else - videoWidget = new VideoWidget(this); -#endif - videoAreaWidget->setVideoWidget(videoWidget); videoAreaWidget->setListModel(listModel); diff --git a/src/main.cpp b/src/main.cpp index 008efc7..f03d0f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,11 @@ int main(int argc, char **argv) { QtSingleApplication app(argc, argv); QString message = app.arguments().size() > 1 ? app.arguments().at(1) : ""; + if (message == "--help") { + MainWindow::printHelp(); + return 0; + } + if (app.sendMessage(message)) return 0; @@ -106,9 +111,14 @@ int main(int argc, char **argv) { if (app.arguments().size() > 1) { QString query = app.arguments().at(1); - SearchParams *searchParams = new SearchParams(); - searchParams->setKeywords(query); - mainWin.showMedia(searchParams); + if (query.startsWith("--")) { + mainWin.messageReceived(query); + return 0; + } else { + SearchParams *searchParams = new SearchParams(); + searchParams->setKeywords(query); + mainWin.showMedia(searchParams); + } } // Seed random number generator diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index 7bbbeee..13fecd8 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -120,41 +120,3 @@ void VideoAreaWidget::dropEvent(QDropEvent *event) { listModel->setActiveRow(row); event->acceptProposedAction(); } - -void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) { - QWidget::mouseMoveEvent(event); - -#ifdef Q_WS_X11 - QWidget* mainWindow = window(); - if (!mainWindow->isFullScreen()) return; - - // qDebug() << "VideoAreaWidget::mouseMoveEvent" << event->pos(); - - const int x = event->pos().x(); - const int y = event->pos().y(); - - bool visible = y <= 10; - bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible)); - if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed"; - - visible = x <= 10; - ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible)); - if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed"; -#endif -} - -void VideoAreaWidget::leaveEvent(QMouseEvent *event) { - QWidget::leaveEvent(event); - -#ifdef Q_WS_X11 - QWidget* mainWindow = window(); - if (!mainWindow->isFullScreen()) return; - - bool visible = false; - bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible)); - if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed"; - - ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible)); - if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed"; -#endif -} diff --git a/src/videoareawidget.h b/src/videoareawidget.h index 7d318c1..a34cfbf 100644 --- a/src/videoareawidget.h +++ b/src/videoareawidget.h @@ -32,8 +32,6 @@ protected: void mousePressEvent(QMouseEvent *event); void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void leaveEvent(QMouseEvent *event); private slots: void hideSnapshotPreview(); diff --git a/src/videowidget.cpp b/src/videowidget.cpp deleted file mode 100644 index df59365..0000000 --- a/src/videowidget.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "videowidget.h" - -VideoWidget::VideoWidget(QWidget *parent) : Phonon::VideoWidget(parent) { - // mouse autohide - setMouseTracking(true); - mouseTimer = new QTimer(this); - mouseTimer->setInterval(3000); - mouseTimer->setSingleShot(true); - connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse())); -} - -void VideoWidget::mouseMoveEvent(QMouseEvent *event) { - QWidget::mouseMoveEvent(event); - - // qDebug() << "VideoWidget::mouseMoveEvent" << event->pos(); - - // show the normal cursor - unsetCursor(); - - // then hide it again after a few seconds - mouseTimer->start(); -} - -void VideoWidget::hideMouse() { - // qDebug() << "hideMouse()"; - setCursor(Qt::BlankCursor); -} diff --git a/src/videowidget.h b/src/videowidget.h deleted file mode 100644 index deac833..0000000 --- a/src/videowidget.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef VIDEOWIDGET_H -#define VIDEOWIDGET_H - -#include -#include -#include - -class VideoWidget : public Phonon::VideoWidget { - - Q_OBJECT - -public: - VideoWidget(QWidget *parent); - -protected: - void mouseMoveEvent (QMouseEvent *event); - -private slots: - void hideMouse(); - -private: - QTimer *mouseTimer; - -}; - -#endif // VIDEOWIDGET_H -- 2.39.5