summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Stockwell <ext-gareth.stockwell@nokia.com>2009-11-18 16:50:53 (GMT)
committerGareth Stockwell <ext-gareth.stockwell@nokia.com>2009-11-19 09:56:27 (GMT)
commit20679e140afc2cea8ff16043d40a0da1145e4165 (patch)
tree16e1617ea1ca24d8ac8bc69fab673a8148134c07
parenta599898061b8b76bbd313d7b3ea0a4e0e9a6e8ed (diff)
downloadQt-20679e140afc2cea8ff16043d40a0da1145e4165.zip
Qt-20679e140afc2cea8ff16043d40a0da1145e4165.tar.gz
Qt-20679e140afc2cea8ff16043d40a0da1145e4165.tar.bz2
Added 'fullscreen video' menu option to media player
Task-number: QTBUG-5586 Reviewed-by: Frans Englich
-rw-r--r--demos/qmediaplayer/mediaplayer.cpp175
-rw-r--r--demos/qmediaplayer/mediaplayer.h43
2 files changed, 128 insertions, 90 deletions
diff --git a/demos/qmediaplayer/mediaplayer.cpp b/demos/qmediaplayer/mediaplayer.cpp
index 1cca3dc..a396c70 100644
--- a/demos/qmediaplayer/mediaplayer.cpp
+++ b/demos/qmediaplayer/mediaplayer.cpp
@@ -47,109 +47,105 @@
#include "ui_settings.h"
-class MediaVideoWidget : public Phonon::VideoWidget
+MediaVideoWidget::MediaVideoWidget(MediaPlayer *player, QWidget *parent) :
+ Phonon::VideoWidget(parent), m_player(player), m_action(this)
+{
+ m_action.setCheckable(true);
+ m_action.setChecked(false);
+ m_action.setShortcut(QKeySequence( Qt::AltModifier + Qt::Key_Return));
+ m_action.setShortcutContext(Qt::WindowShortcut);
+ connect(&m_action, SIGNAL(toggled(bool)), SLOT(setFullScreen(bool)));
+ addAction(&m_action);
+ setAcceptDrops(true);
+}
+
+void MediaVideoWidget::setFullScreen(bool enabled)
{
-public:
- MediaVideoWidget(MediaPlayer *player, QWidget *parent = 0) :
- Phonon::VideoWidget(parent), m_player(player), m_action(this)
- {
- m_action.setCheckable(true);
- m_action.setChecked(false);
- m_action.setShortcut(QKeySequence( Qt::AltModifier + Qt::Key_Return));
- m_action.setShortcutContext(Qt::WindowShortcut);
- connect(&m_action, SIGNAL(toggled(bool)), SLOT(setFullScreen(bool)));
- addAction(&m_action);
- setAcceptDrops(true);
- }
+ Phonon::VideoWidget::setFullScreen(enabled);
+ emit fullScreenChanged(enabled);
+}
-protected:
- void mouseDoubleClickEvent(QMouseEvent *e)
- {
- Phonon::VideoWidget::mouseDoubleClickEvent(e);
- setFullScreen(!isFullScreen());
- }
+void MediaVideoWidget::mouseDoubleClickEvent(QMouseEvent *e)
+{
+ Phonon::VideoWidget::mouseDoubleClickEvent(e);
+ setFullScreen(!isFullScreen());
+}
- void keyPressEvent(QKeyEvent *e)
- {
- if (e->key() == Qt::Key_Space && !e->modifiers()) {
- m_player->playPause();
- e->accept();
- return;
- } else if (e->key() == Qt::Key_Escape && !e->modifiers()) {
- setFullScreen(false);
- e->accept();
- return;
- }
- Phonon::VideoWidget::keyPressEvent(e);
+void MediaVideoWidget::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Space && !e->modifiers()) {
+ m_player->playPause();
+ e->accept();
+ return;
+ } else if (e->key() == Qt::Key_Escape && !e->modifiers()) {
+ setFullScreen(false);
+ e->accept();
+ return;
}
+ Phonon::VideoWidget::keyPressEvent(e);
+}
- bool event(QEvent *e)
+bool MediaVideoWidget::event(QEvent *e)
+{
+ switch(e->type())
{
- switch(e->type())
- {
- case QEvent::Close:
- //we just ignore the cose events on the video widget
- //this prevents ALT+F4 from having an effect in fullscreen mode
- e->ignore();
- return true;
- case QEvent::MouseMove:
+ case QEvent::Close:
+ //we just ignore the cose events on the video widget
+ //this prevents ALT+F4 from having an effect in fullscreen mode
+ e->ignore();
+ return true;
+ case QEvent::MouseMove:
#ifndef QT_NO_CURSOR
- unsetCursor();
+ unsetCursor();
#endif
- //fall through
- case QEvent::WindowStateChange:
- {
- //we just update the state of the checkbox, in case it wasn't already
- m_action.setChecked(windowState() & Qt::WindowFullScreen);
- const Qt::WindowFlags flags = m_player->windowFlags();
- if (windowState() & Qt::WindowFullScreen) {
- m_timer.start(1000, this);
- } else {
- m_timer.stop();
+ //fall through
+ case QEvent::WindowStateChange:
+ {
+ //we just update the state of the checkbox, in case it wasn't already
+ m_action.setChecked(windowState() & Qt::WindowFullScreen);
+ const Qt::WindowFlags flags = m_player->windowFlags();
+ if (windowState() & Qt::WindowFullScreen) {
+ m_timer.start(1000, this);
+ } else {
+ m_timer.stop();
#ifndef QT_NO_CURSOR
- unsetCursor();
+ unsetCursor();
#endif
- }
}
- break;
- default:
- break;
}
-
- return Phonon::VideoWidget::event(e);
+ break;
+ default:
+ break;
}
- void timerEvent(QTimerEvent *e)
- {
- if (e->timerId() == m_timer.timerId()) {
- //let's store the cursor shape
+ return Phonon::VideoWidget::event(e);
+}
+
+void MediaVideoWidget::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == m_timer.timerId()) {
+ //let's store the cursor shape
#ifndef QT_NO_CURSOR
- setCursor(Qt::BlankCursor);
+ setCursor(Qt::BlankCursor);
#endif
- }
- Phonon::VideoWidget::timerEvent(e);
- }
-
- void dropEvent(QDropEvent *e)
- {
- m_player->handleDrop(e);
}
+ Phonon::VideoWidget::timerEvent(e);
+}
- void dragEnterEvent(QDragEnterEvent *e) {
- if (e->mimeData()->hasUrls())
- e->acceptProposedAction();
- }
+void MediaVideoWidget::dropEvent(QDropEvent *e)
+{
+ m_player->handleDrop(e);
+}
-private:
- MediaPlayer *m_player;
- QBasicTimer m_timer;
- QAction m_action;
-};
+void MediaVideoWidget::dragEnterEvent(QDragEnterEvent *e) {
+ if (e->mimeData()->hasUrls())
+ e->acceptProposedAction();
+}
MediaPlayer::MediaPlayer(const QString &filePath,
const bool hasSmallScreen) :
- playButton(0), nextEffect(0), settingsDialog(0), ui(0),
+ playButton(0), nextEffect(0), settingsDialog(0), ui(0),
m_AudioOutput(Phonon::VideoCategory),
m_videoWidget(new MediaVideoWidget(this)),
m_hasSmallScreen(hasSmallScreen)
@@ -297,22 +293,30 @@ MediaPlayer::MediaPlayer(const QString &filePath,
QAction *scaleActionCrop = scaleMenu->addAction(tr("Scale and crop"));
scaleActionCrop->setCheckable(true);
scaleGroup->addAction(scaleActionCrop);
-
- fileMenu->addSeparator();
+
+ m_fullScreenAction = fileMenu->addAction(tr("Full screen video"));
+ m_fullScreenAction->setCheckable(true);
+ m_fullScreenAction->setEnabled(false); // enabled by hasVideoChanged
+ bool b = connect(m_fullScreenAction, SIGNAL(toggled(bool)), m_videoWidget, SLOT(setFullScreen(bool)));
+ Q_ASSERT(b);
+ b = connect(m_videoWidget, SIGNAL(fullScreenChanged(bool)), m_fullScreenAction, SLOT(setChecked(bool)));
+ Q_ASSERT(b);
+
+ fileMenu->addSeparator();
QAction *settingsAction = fileMenu->addAction(tr("&Settings..."));
-
+
// Setup signal connections:
connect(rewindButton, SIGNAL(clicked()), this, SLOT(rewind()));
//connect(openButton, SIGNAL(clicked()), this, SLOT(openFile()));
openButton->setMenu(fileMenu);
-
+
connect(playButton, SIGNAL(clicked()), this, SLOT(playPause()));
connect(forwardButton, SIGNAL(clicked()), this, SLOT(forward()));
//connect(openButton, SIGNAL(clicked()), this, SLOT(openFile()));
connect(settingsAction, SIGNAL(triggered(bool)), this, SLOT(showSettingsDialog()));
connect(openUrlAction, SIGNAL(triggered(bool)), this, SLOT(openUrl()));
connect(openFileAction, SIGNAL(triggered(bool)), this, SLOT(openFile()));
-
+
connect(m_videoWidget, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(showContextMenu(const QPoint &)));
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(showContextMenu(const QPoint &)));
connect(&m_MediaObject, SIGNAL(metaDataChanged()), this, SLOT(updateInfo()));
@@ -874,4 +878,5 @@ void MediaPlayer::hasVideoChanged(bool bHasVideo)
{
info->setVisible(!bHasVideo);
m_videoWindow.setVisible(bHasVideo);
+ m_fullScreenAction->setEnabled(bHasVideo);
}
diff --git a/demos/qmediaplayer/mediaplayer.h b/demos/qmediaplayer/mediaplayer.h
index c181e37..00f9b54 100644
--- a/demos/qmediaplayer/mediaplayer.h
+++ b/demos/qmediaplayer/mediaplayer.h
@@ -47,6 +47,8 @@
#include <QtCore/QTimerEvent>
#include <QtGui/QShowEvent>
#include <QtGui/QIcon>
+#include <QtCore/QBasicTimer>
+#include <QtGui/QAction>
#include <Phonon/AudioOutput>
#include <Phonon/BackendCapabilities>
@@ -67,6 +69,36 @@ class QMenu;
class Ui_settings;
QT_END_NAMESPACE
+class MediaPlayer;
+
+class MediaVideoWidget : public Phonon::VideoWidget
+{
+ Q_OBJECT
+
+public:
+ MediaVideoWidget(MediaPlayer *player, QWidget *parent = 0);
+
+public slots:
+ // Over-riding non-virtual Phonon::VideoWidget slot
+ void setFullScreen(bool);
+
+signals:
+ void fullScreenChanged(bool);
+
+protected:
+ void mouseDoubleClickEvent(QMouseEvent *e);
+ void keyPressEvent(QKeyEvent *e);
+ bool event(QEvent *e);
+ void timerEvent(QTimerEvent *e);
+ void dropEvent(QDropEvent *e);
+ void dragEnterEvent(QDragEnterEvent *e);
+
+private:
+ MediaPlayer *m_player;
+ QBasicTimer m_timer;
+ QAction m_action;
+};
+
class MediaPlayer :
public QWidget
{
@@ -74,7 +106,7 @@ class MediaPlayer :
public:
MediaPlayer(const QString &,
const bool hasSmallScreen);
-
+
void dragEnterEvent(QDragEnterEvent *e);
void dragMoveEvent(QDragMoveEvent *e);
void dropEvent(QDropEvent *e);
@@ -82,7 +114,7 @@ public:
void setFile(const QString &text);
void initVideoWindow();
void initSettingsDialog();
-
+
public slots:
void openFile();
void rewind();
@@ -104,7 +136,7 @@ private slots:
void stateChanged(Phonon::State newstate, Phonon::State oldstate);
void effectChanged();
void showSettingsDialog();
- void showContextMenu(const QPoint &);
+ void showContextMenu(const QPoint& point);
void bufferStatus(int percent);
void openUrl();
void configureEffect();
@@ -130,11 +162,12 @@ private:
Phonon::Effect *nextEffect;
QDialog *settingsDialog;
Ui_settings *ui;
-
+ QAction *m_fullScreenAction;
+
QWidget m_videoWindow;
Phonon::MediaObject m_MediaObject;
Phonon::AudioOutput m_AudioOutput;
- Phonon::VideoWidget *m_videoWidget;
+ MediaVideoWidget *m_videoWidget;
Phonon::Path m_audioOutputPath;
const bool m_hasSmallScreen;
};