X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fvideoareawidget.cpp;h=62106148c4560d16a6a88065b1138b007c577b06;hb=29f9a13b38a0547b70236d24300668385e1dbf6e;hp=bf2ae03312302b58f33557e840aa6249196bbea0;hpb=c420dd995be8f80ae4ace7e4ffa86710b68ea5ff;p=minitube diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index bf2ae03..6210614 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -1,18 +1,39 @@ +/* $BEGIN_LICENSE + +This file is part of Minitube. +Copyright 2009, Flavio Tordini + +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 . + +$END_LICENSE */ + #include "videoareawidget.h" +#include "video.h" +#include "loadingwidget.h" +#include "playlistmodel.h" #include "videomimedata.h" +#include "mainwindow.h" +#ifdef Q_OS_MAC +#include "macutils.h" +#endif +#include "snapshotpreview.h" -VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { +VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent), videoWidget(0) { QBoxLayout *vLayout = new QVBoxLayout(this); vLayout->setMargin(0); vLayout->setSpacing(0); -#ifdef APP_WIN - QPalette p = palette(); - p.setBrush(QPalette::Window, Qt::black); - setPalette(p); - setAutoFillBackground(true); -#endif - // hidden message widget messageLabel = new QLabel(this); messageLabel->setOpenExternalLinks(true); @@ -23,14 +44,18 @@ VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { messageLabel->setWordWrap(true); messageLabel->hide(); vLayout->addWidget(messageLabel); - + stackedLayout = new QStackedLayout(); vLayout->addLayout(stackedLayout); - - setLayout(vLayout); + +#ifdef APP_SNAPSHOT + snapshotPreview = new SnapshotPreview(); + connect(stackedLayout, SIGNAL(currentChanged(int)), snapshotPreview, SLOT(hide())); +#endif + setAcceptDrops(true); - setMouseTracking(true); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) { @@ -42,13 +67,16 @@ void VideoAreaWidget::setVideoWidget(QWidget *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) { +void VideoAreaWidget::showError(const QString &message) { // loadingWidget->setError(message); messageLabel->setText(message); messageLabel->show(); @@ -56,17 +84,31 @@ void VideoAreaWidget::showError(QString message) { } 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) { @@ -79,6 +121,29 @@ void VideoAreaWidget::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::RightButton) emit rightClicked(); + + else if (event->button() == Qt::LeftButton) { + bool isNormalWindow = !window()->isMaximized() && + !MainWindow::instance()->isReallyFullScreen(); + if (isNormalWindow) { + dragPosition = event->globalPos() - window()->frameGeometry().topLeft(); + event->accept(); + } + } +} + +void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) { + bool isNormalWindow = !window()->isMaximized() && + !MainWindow::instance()->isReallyFullScreen(); + if (event->buttons() & Qt::LeftButton && isNormalWindow) { + QPoint p = event->globalPos() - dragPosition; +#ifdef Q_OS_MAC + // FIXME mac::moveWindowTo(window()->winId(), p.x(), p.y()); +#else + window()->move(p); +#endif + event->accept(); + } } void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) { @@ -90,7 +155,7 @@ void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) { void VideoAreaWidget::dropEvent(QDropEvent *event) { - const VideoMimeData* videoMimeData = dynamic_cast( event->mimeData() ); + const VideoMimeData* videoMimeData = qobject_cast( event->mimeData() ); if(!videoMimeData ) return; QList droppedVideos = videoMimeData->videos(); @@ -102,41 +167,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 -}