]> git.sur5r.net Git - minitube/blobdiff - src/videoareawidget.cpp
Update watch file to use releases instead of tags
[minitube] / src / videoareawidget.cpp
index bf2ae03312302b58f33557e840aa6249196bbea0..19973fa7485c487eea7f3aae4470642662135a63 100644 (file)
@@ -1,17 +1,73 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #include "videoareawidget.h"
+#include "loadingwidget.h"
+#include "mainwindow.h"
+#include "playlistmodel.h"
+#include "video.h"
 #include "videomimedata.h"
+#ifdef Q_OS_MAC
+#include "macutils.h"
+#endif
+#include "snapshotpreview.h"
+#include "fontutils.h"
+
+namespace {
+
+class MessageWidget : public QWidget {
+public:
+    MessageWidget(QWidget *parent = nullptr) : QWidget(parent) {
+        QPalette p = palette();
+        p.setColor(QPalette::Window, Qt::black);
+        p.setColor(QPalette::WindowText, Qt::darkGray);
+        p.setColor(QPalette::Base, Qt::black);
+        p.setColor(QPalette::Text, Qt::darkGray);
+        setPalette(p);
+        setAutoFillBackground(true);
+
+        QBoxLayout *l = new QHBoxLayout(this);
+        l->setMargin(32);
+        l->setSpacing(32);
+        l->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
+
+        QLabel *arrowLabel = new QLabel("←");
+        arrowLabel->setFont(FontUtils::light(64));
+        arrowLabel->setPalette(p);
+        l->addWidget(arrowLabel);
+
+        QLabel *msgLabel = new QLabel(tr("Pick a video"));
+        msgLabel->setFont(FontUtils::light(32));
+        msgLabel->setPalette(p);
+        l->addWidget(msgLabel);
+    }
+};
+}
 
-VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) {
-    QBoxLayout *vLayout = new QVBoxLayout(this);
-    vLayout->setMargin(0);
-    vLayout->setSpacing(0);
+VideoAreaWidget::VideoAreaWidget(QWidget *parent)
+    : QWidget(parent), videoWidget(0), messageWidget(0) {
+    setAttribute(Qt::WA_OpaquePaintEvent);
 
-#ifdef APP_WIN
-    QPalette p = palette();
-    p.setBrush(QPalette::Window, Qt::black);
-    setPalette(p);
-    setAutoFillBackground(true);
-#endif
+    QBoxLayout *layout = new QVBoxLayout(this);
+    layout->setMargin(0);
+    layout->setSpacing(0);
 
     // hidden message widget
     messageLabel = new QLabel(this);
@@ -22,63 +78,82 @@ VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) {
     messageLabel->setAutoFillBackground(true);
     messageLabel->setWordWrap(true);
     messageLabel->hide();
-    vLayout->addWidget(messageLabel);
-    
+    layout->addWidget(messageLabel);
+
     stackedLayout = new QStackedLayout();
-    vLayout->addLayout(stackedLayout);
-    
-    setLayout(vLayout);
+    layout->addLayout(stackedLayout);
+
+#ifdef APP_SNAPSHOT
+    snapshotPreview = new SnapshotPreview();
+    connect(stackedLayout, SIGNAL(currentChanged(int)), snapshotPreview, SLOT(hide()));
+#endif
+
     setAcceptDrops(true);
-    
-    setMouseTracking(true);
+    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+    setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
+            SLOT(showContextMenu(const QPoint &)));
 }
 
 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
     this->videoWidget = videoWidget;
-    videoWidget->setMouseTracking(true);
     stackedLayout->addWidget(videoWidget);
 }
 
 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
     this->loadingWidget = loadingWidget;
     stackedLayout->addWidget(loadingWidget);
+    stackedLayout->setCurrentWidget(loadingWidget);
 }
 
 void VideoAreaWidget::showVideo() {
-    stackedLayout->setCurrentWidget(videoWidget);
+    if (videoWidget) stackedLayout->setCurrentWidget(videoWidget);
+    loadingWidget->clear();
 }
 
-void VideoAreaWidget::showError(QString message) {
-    // loadingWidget->setError(message);
+void VideoAreaWidget::showError(const QString &message) {
     messageLabel->setText(message);
     messageLabel->show();
     stackedLayout->setCurrentWidget(loadingWidget);
 }
 
+void VideoAreaWidget::showPickMessage() {
+    if (!messageWidget) {
+        messageWidget = new MessageWidget();
+        stackedLayout->addWidget(messageWidget);
+    }
+    stackedLayout->setCurrentWidget(messageWidget);
+}
+
 void VideoAreaWidget::showLoading(Video *video) {
-    stackedLayout->setCurrentWidget(loadingWidget);
-    this->loadingWidget->setVideo(video);
     messageLabel->hide();
     messageLabel->clear();
+    stackedLayout->setCurrentWidget(loadingWidget);
+    loadingWidget->setVideo(video);
 }
 
+#ifdef APP_SNAPSHOT
+void VideoAreaWidget::showSnapshotPreview(const QPixmap &pixmap) {
+    bool soundOnly = false;
+#ifdef APP_MAC
+    soundOnly = MainWindow::instance()->isReallyFullScreen();
+#endif
+    snapshotPreview->start(videoWidget, pixmap, soundOnly);
+}
+
+void VideoAreaWidget::hideSnapshotPreview() {}
+#endif
+
 void VideoAreaWidget::clear() {
-    stackedLayout->setCurrentWidget(loadingWidget);
     loadingWidget->clear();
     messageLabel->hide();
     messageLabel->clear();
+    stackedLayout->setCurrentWidget(loadingWidget);
 }
 
 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
-    if (event->button() == Qt::LeftButton)
-        emit doubleClicked();
-}
-
-void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
-    QWidget::mousePressEvent(event);
-
-    if(event->button() == Qt::RightButton)
-        emit rightClicked();
+    if (event->button() == Qt::LeftButton) emit doubleClicked();
 }
 
 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
@@ -89,54 +164,18 @@ void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
 }
 
 void VideoAreaWidget::dropEvent(QDropEvent *event) {
-    
-    const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
-    if(!videoMimeData ) return;
-    
-    QList<Video*> droppedVideos = videoMimeData->videos();
-    if (droppedVideos.isEmpty())
-        return;
-    Video *video = droppedVideos.first();
+    const VideoMimeData *videoMimeData = qobject_cast<const VideoMimeData *>(event->mimeData());
+    if (!videoMimeData) return;
+
+    QVector<Video *> droppedVideos = videoMimeData->getVideos();
+    if (droppedVideos.isEmpty()) return;
+    Video *video = droppedVideos.at(0);
     int row = listModel->rowForVideo(video);
-    if (row != -1)
-        listModel->setActiveRow(row);
+    if (row != -1) 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
+void VideoAreaWidget::showContextMenu(const QPoint &point) {
+    QMenu *menu = MainWindow::instance()->getMenu("video");
+    menu->exec(mapToGlobal(point));
 }