3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #include "videoareawidget.h"
23 #include "loadingwidget.h"
24 #include "playlistmodel.h"
25 #include "videomimedata.h"
26 #include "mainwindow.h"
30 #include "snapshotpreview.h"
32 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent), videoWidget(0) {
33 QBoxLayout *vLayout = new QVBoxLayout(this);
34 vLayout->setMargin(0);
35 vLayout->setSpacing(0);
37 // hidden message widget
38 messageLabel = new QLabel(this);
39 messageLabel->setOpenExternalLinks(true);
40 messageLabel->setMargin(7);
41 messageLabel->setBackgroundRole(QPalette::ToolTipBase);
42 messageLabel->setForegroundRole(QPalette::ToolTipText);
43 messageLabel->setAutoFillBackground(true);
44 messageLabel->setWordWrap(true);
46 vLayout->addWidget(messageLabel);
48 stackedLayout = new QStackedLayout();
49 vLayout->addLayout(stackedLayout);
52 snapshotPreview = new SnapshotPreview();
53 connect(stackedLayout, SIGNAL(currentChanged(int)), snapshotPreview, SLOT(hide()));
57 setMouseTracking(true);
58 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
61 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
62 this->videoWidget = videoWidget;
63 videoWidget->setMouseTracking(true);
64 stackedLayout->addWidget(videoWidget);
67 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
68 this->loadingWidget = loadingWidget;
69 stackedLayout->addWidget(loadingWidget);
70 stackedLayout->setCurrentWidget(loadingWidget);
73 void VideoAreaWidget::showVideo() {
75 stackedLayout->setCurrentWidget(videoWidget);
76 loadingWidget->clear();
79 void VideoAreaWidget::showError(const QString &message) {
80 // loadingWidget->setError(message);
81 messageLabel->setText(message);
83 stackedLayout->setCurrentWidget(loadingWidget);
86 void VideoAreaWidget::showLoading(Video *video) {
88 messageLabel->clear();
89 stackedLayout->setCurrentWidget(loadingWidget);
90 loadingWidget->setVideo(video);
94 void VideoAreaWidget::showSnapshotPreview(const QPixmap &pixmap) {
95 bool soundOnly = false;
97 soundOnly = MainWindow::instance()->isReallyFullScreen();
99 snapshotPreview->start(videoWidget, pixmap, soundOnly);
102 void VideoAreaWidget::hideSnapshotPreview() {
107 void VideoAreaWidget::clear() {
108 loadingWidget->clear();
109 messageLabel->hide();
110 messageLabel->clear();
111 stackedLayout->setCurrentWidget(loadingWidget);
114 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
115 if (event->button() == Qt::LeftButton)
116 emit doubleClicked();
119 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
120 QWidget::mousePressEvent(event);
122 if(event->button() == Qt::RightButton)
125 else if (event->button() == Qt::LeftButton) {
126 bool isNormalWindow = !window()->isMaximized() &&
127 !MainWindow::instance()->isReallyFullScreen();
128 if (isNormalWindow) {
129 dragPosition = event->globalPos() - window()->frameGeometry().topLeft();
135 void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
136 bool isNormalWindow = !window()->isMaximized() &&
137 !MainWindow::instance()->isReallyFullScreen();
138 if (event->buttons() & Qt::LeftButton && isNormalWindow) {
139 QPoint p = event->globalPos() - dragPosition;
141 // FIXME mac::moveWindowTo(window()->winId(), p.x(), p.y());
149 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
150 // qDebug() << event->mimeData()->formats();
151 if (event->mimeData()->hasFormat("application/x-minitube-video")) {
152 event->acceptProposedAction();
156 void VideoAreaWidget::dropEvent(QDropEvent *event) {
158 const VideoMimeData* videoMimeData = qobject_cast<const VideoMimeData*>( event->mimeData() );
159 if(!videoMimeData ) return;
161 QList<Video*> droppedVideos = videoMimeData->videos();
162 if (droppedVideos.isEmpty())
164 Video *video = droppedVideos.first();
165 int row = listModel->rowForVideo(video);
167 listModel->setActiveRow(row);
168 event->acceptProposedAction();