+/* $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 "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);
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) {
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();
}
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) {
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) {
listModel->setActiveRow(row);
event->acceptProposedAction();
}
-
-void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
- QWidget::mouseMoveEvent(event);
-
- 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";
-}