X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fvideoareawidget.cpp;h=7999bcedb864d1db999b55f9621dd5c4acd8bbeb;hb=9277680c902cc6fcf05aeda3773ecec792a9930e;hp=b1781ac2be18be8ebc568aaffc9b1438e2d138a2;hpb=db7068c0121ead4cffffa3a770172a940f137725;p=minitube diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index b1781ac..7999bce 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -1,11 +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); - + // hidden message widget messageLabel = new QLabel(this); messageLabel->setOpenExternalLinks(true); @@ -16,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) { @@ -35,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(); @@ -49,17 +84,31 @@ void VideoAreaWidget::showError(QString message) { } void VideoAreaWidget::showLoading(Video *video) { - this->loadingWidget->setVideo(video); - stackedLayout->setCurrentWidget(loadingWidget); 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) { @@ -68,8 +117,33 @@ void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) { } void VideoAreaWidget::mousePressEvent(QMouseEvent *event) { - switch(event->button() == Qt::RightButton) - emit rightClicked(); + QWidget::mousePressEvent(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) { @@ -93,16 +167,3 @@ void VideoAreaWidget::dropEvent(QDropEvent *event) { listModel->setActiveRow(row); event->acceptProposedAction(); } - -void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) { - // qDebug() << "VideoAreaWidget::mouseMoveEvent" << event->pos(); - - QWidget* mainWindow = window(); - bool visible = event->pos().y() <= 0; - bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible)); - if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed"; - - visible = event->pos().x() <= 0; - ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible)); - if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed"; -}