From 82a630ccf229e7896e8f9186d7568f4b84d00361 Mon Sep 17 00:00:00 2001 From: Flavio Date: Tue, 24 Jul 2012 18:16:33 +0200 Subject: [PATCH] Tentative snapshot impl. Phonon is broken so feature stays disabled. --- src/MainWindow.cpp | 12 ++++++++++-- src/MediaView.cpp | 11 ++++++++++- src/MediaView.h | 1 + src/videoareawidget.cpp | 20 ++++++++++++++++++++ src/videoareawidget.h | 5 +++++ src/videowidget.cpp | 2 +- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 5f3ee91..e9b6a0b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -388,6 +388,13 @@ void MainWindow::createActions() { connect(action, SIGNAL(triggered()), mediaView, SLOT(downloadVideo())); actions->insert("download", action); + /* + action = new QAction(tr("&Snapshot"), this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S)); + actions->insert("snapshot", action); + connect(action, SIGNAL(triggered()), mediaView, SLOT(snapshot())); + */ + QString shareTip = tr("Share the current video using %1"); action = new QAction("&Twitter", this); @@ -507,11 +514,12 @@ void MainWindow::createMenus() { videoMenu->addAction(findVideoPartsAct); videoMenu->addSeparator(); videoMenu->addAction(webPageAct); -#ifndef APP_NO_DOWNLOADS videoMenu->addSeparator(); +#ifndef APP_NO_DOWNLOADS videoMenu->addAction(The::globalActions()->value("download")); - videoMenu->addAction(copyLinkAct); + // videoMenu->addAction(copyLinkAct); #endif + // videoMenu->addAction(The::globalActions()->value("snapshot")); QMenu* viewMenu = menuBar()->addMenu(tr("&View")); menus->insert("view", viewMenu); diff --git a/src/MediaView.cpp b/src/MediaView.cpp index dcfd054..f4ef727 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -76,7 +76,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { videoAreaWidget = new VideoAreaWidget(this); // videoAreaWidget->setMinimumSize(320,240); -#ifdef APP_MAC +#ifdef APP_MAC_NO // mouse autohide does not work on the Mac (no mouseMoveEvent) videoWidget = new Phonon::VideoWidget(this); #else @@ -703,6 +703,15 @@ void MediaView::downloadVideo() { if (mainWindow) mainWindow->statusBar()->showMessage(message); } +void MediaView::snapshot() { + QImage image = videoWidget->snapshot(); + qDebug() << image.size(); + + const QPixmap& pixmap = QPixmap::grabWindow(videoWidget->winId()); + // qDebug() << pixmap.size(); + videoAreaWidget->showSnapshotPreview(pixmap); +} + void MediaView::fullscreen() { videoAreaWidget->setParent(0); videoAreaWidget->showFullScreen(); diff --git a/src/MediaView.h b/src/MediaView.h index 9a56597..a69bef3 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -62,6 +62,7 @@ public slots: void setPlaylistVisible(bool visible=true); void saveSplitterState(); void downloadVideo(); + void snapshot(); void fullscreen(); void findVideoParts(); diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index bf2ae03..0efdbb4 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -1,5 +1,8 @@ #include "videoareawidget.h" #include "videomimedata.h" +#ifndef Q_WS_X11 +#include "extra.h" +#endif VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { QBoxLayout *vLayout = new QVBoxLayout(this); @@ -26,6 +29,9 @@ VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { stackedLayout = new QStackedLayout(); vLayout->addLayout(stackedLayout); + + snapshotPreview = new QLabel(this); + stackedLayout->addWidget(snapshotPreview); setLayout(vLayout); setAcceptDrops(true); @@ -62,11 +68,25 @@ void VideoAreaWidget::showLoading(Video *video) { messageLabel->clear(); } +void VideoAreaWidget::showSnapshotPreview(QPixmap pixmap) { + snapshotPreview->setPixmap(pixmap); + stackedLayout->setCurrentWidget(snapshotPreview); +#ifndef Q_WS_X11 + Extra::flashInWidget(snapshotPreview); +#endif + QTimer::singleShot(1500, this, SLOT(hideSnapshotPreview())); +} + +void VideoAreaWidget::hideSnapshotPreview() { + stackedLayout->setCurrentWidget(videoWidget); +} + void VideoAreaWidget::clear() { stackedLayout->setCurrentWidget(loadingWidget); loadingWidget->clear(); messageLabel->hide(); messageLabel->clear(); + snapshotPreview->clear(); } void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) { diff --git a/src/videoareawidget.h b/src/videoareawidget.h index 60112f5..7d318c1 100644 --- a/src/videoareawidget.h +++ b/src/videoareawidget.h @@ -21,6 +21,7 @@ public: void setListModel(ListModel *listModel) { this->listModel = listModel; } + void showSnapshotPreview(QPixmap pixmap); signals: void doubleClicked(); @@ -34,12 +35,16 @@ protected: void mouseMoveEvent(QMouseEvent *event); void leaveEvent(QMouseEvent *event); +private slots: + void hideSnapshotPreview(); + private: QStackedLayout *stackedLayout; QWidget *videoWidget; LoadingWidget *loadingWidget; ListModel *listModel; QLabel *messageLabel; + QLabel *snapshotPreview; }; diff --git a/src/videowidget.cpp b/src/videowidget.cpp index ed6d689..df59365 100644 --- a/src/videowidget.cpp +++ b/src/videowidget.cpp @@ -10,7 +10,7 @@ VideoWidget::VideoWidget(QWidget *parent) : Phonon::VideoWidget(parent) { } void VideoWidget::mouseMoveEvent(QMouseEvent *event) { - Phonon::VideoWidget::mouseMoveEvent(event); + QWidget::mouseMoveEvent(event); // qDebug() << "VideoWidget::mouseMoveEvent" << event->pos(); -- 2.39.5