From e242e15905c9bc252588ceb6130c3e51970592b2 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Mon, 31 Aug 2009 23:20:55 +0200 Subject: [PATCH] Moved autohide to Phonon:VideoWidget subclass Fixed loading of empty url when pressing Stop --- src/MediaView.cpp | 22 ++++++++++++++-------- src/MediaView.h | 2 ++ src/videoareawidget.cpp | 19 +------------------ src/videoareawidget.h | 7 +------ src/videowidget.cpp | 27 +++++++++++++++++++++++++++ src/videowidget.h | 26 ++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 src/videowidget.cpp create mode 100644 src/videowidget.h diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 5b294da..f5b256f 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -12,6 +12,8 @@ namespace The { MediaView::MediaView(QWidget *parent) : QWidget(parent) { + reallyStopped = false; + QBoxLayout *layout = new QHBoxLayout(); layout->setMargin(0); @@ -77,7 +79,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { videoAreaWidget = new VideoAreaWidget(this); videoAreaWidget->setMinimumSize(320,240); - videoWidget = new Phonon::VideoWidget(this); + videoWidget = new VideoWidget(this); videoAreaWidget->setVideoWidget(videoWidget); videoAreaWidget->setListModel(listModel); @@ -93,6 +95,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { errorTimer->setSingleShot(true); errorTimer->setInterval(3000); connect(errorTimer, SIGNAL(timeout()), SLOT(skipVideo())); + } MediaView::~MediaView() { @@ -119,6 +122,8 @@ void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) { } void MediaView::search(SearchParams *searchParams) { + reallyStopped = false; + this->searchParams = searchParams; // start serching for videos @@ -156,15 +161,15 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) break; case Phonon::PlayingState: - qDebug("playing"); + //qDebug("playing"); videoAreaWidget->showVideo(); break; case Phonon::StoppedState: - qDebug("stopped"); + //qDebug("stopped"); // play() has already been called when setting the source // but Phonon on Linux needs a little more help to start playback - mediaObject->play(); + if (!reallyStopped) mediaObject->play(); // Workaround for Mac playback start problem if (!timerPlayFlag) { @@ -174,15 +179,15 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) break; case Phonon::PausedState: - qDebug("paused"); + //qDebug("paused"); break; case Phonon::BufferingState: - qDebug("buffering"); + //qDebug("buffering"); break; case Phonon::LoadingState: - qDebug("loading"); + //qDebug("loading"); break; default: @@ -204,8 +209,9 @@ void MediaView::pause() { void MediaView::stop() { listModel->abortSearch(); + reallyStopped = true; mediaObject->stop(); - mediaObject->clear(); + // mediaObject->clear(); } void MediaView::activeRowChanged(int row) { diff --git a/src/MediaView.h b/src/MediaView.h index a536402..5344cc6 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -92,9 +92,11 @@ private: LoadingWidget *loadingWidget; bool timerPlayFlag; + bool reallyStopped; QTimer *errorTimer; Video *skippedVideo; + }; #endif // __MEDIAVIEW_H__ diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index abba1e0..81a29cb 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -23,16 +23,11 @@ VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { setLayout(vLayout); setAcceptDrops(true); - // mouse autohide - setMouseTracking(true); - mouseTimer = new QTimer(this); - mouseTimer->setInterval(3000); - mouseTimer->setSingleShot(true); - connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse())); } void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) { this->videoWidget = videoWidget; + videoWidget->setMouseTracking(true); stackedLayout->addWidget(videoWidget); } @@ -69,18 +64,6 @@ void VideoAreaWidget::mousePressEvent(QMouseEvent *event) { emit rightClicked(); } -void VideoAreaWidget::mouseMoveEvent(QMouseEvent * /* event */) { - // show the normal cursor - videoWidget->unsetCursor(); - - // then hide it again after a few seconds - mouseTimer->start(); -} - -void VideoAreaWidget::hideMouse() { - videoWidget->setCursor(QCursor(Qt::BlankCursor)); -} - void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) { qDebug() << event->mimeData()->formats(); if (event->mimeData()->hasFormat("application/x-minitube-video")) { diff --git a/src/videoareawidget.h b/src/videoareawidget.h index 34650cc..3fd1cab 100644 --- a/src/videoareawidget.h +++ b/src/videoareawidget.h @@ -2,7 +2,6 @@ #define VIDEOAREAWIDGET_H #include -#include #include "video.h" #include "loadingwidget.h" #include "ListModel.h" @@ -31,10 +30,6 @@ protected: void mousePressEvent(QMouseEvent *event); void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); - void mouseMoveEvent (QMouseEvent *event); - -private slots: - void hideMouse(); private: QStackedLayout *stackedLayout; @@ -42,7 +37,7 @@ private: LoadingWidget *loadingWidget; ListModel *listModel; QLabel *messageLabel; - QTimer *mouseTimer; + }; #endif // VIDEOAREAWIDGET_H diff --git a/src/videowidget.cpp b/src/videowidget.cpp new file mode 100644 index 0000000..c0137ed --- /dev/null +++ b/src/videowidget.cpp @@ -0,0 +1,27 @@ +#include "videowidget.h" + +VideoWidget::VideoWidget(QWidget *parent) : Phonon::VideoWidget(parent) { +//#ifndef Q_WS_MAC + // mouse autohide + // setMouseTracking(true); + mouseTimer = new QTimer(this); + mouseTimer->setInterval(3000); + mouseTimer->setSingleShot(true); + connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse())); +// #endif +} + +void VideoWidget::mouseMoveEvent(QMouseEvent * /* event */) { + qDebug() << "mouseMoveEvent"; + + // 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 new file mode 100644 index 0000000..5d0e016 --- /dev/null +++ b/src/videowidget.h @@ -0,0 +1,26 @@ +#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