]> git.sur5r.net Git - minitube/blob - src/videoareawidget.cpp
Imported Upstream version 2.5.1
[minitube] / src / videoareawidget.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
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.
10
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.
15
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/>.
18
19 $END_LICENSE */
20
21 #include "videoareawidget.h"
22 #include "video.h"
23 #include "loadingwidget.h"
24 #include "playlistmodel.h"
25 #include "videomimedata.h"
26 #include "mainwindow.h"
27 #ifdef Q_OS_MAC
28 #include "macutils.h"
29 #endif
30 #include "snapshotpreview.h"
31
32 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent), videoWidget(0) {
33     QBoxLayout *vLayout = new QVBoxLayout(this);
34     vLayout->setMargin(0);
35     vLayout->setSpacing(0);
36
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);
45     messageLabel->hide();
46     vLayout->addWidget(messageLabel);
47
48     stackedLayout = new QStackedLayout();
49     vLayout->addLayout(stackedLayout);
50
51 #ifdef APP_SNAPSHOT
52     snapshotPreview = new SnapshotPreview();
53     connect(stackedLayout, SIGNAL(currentChanged(int)), snapshotPreview, SLOT(hide()));
54 #endif
55
56     setAcceptDrops(true);
57     setMouseTracking(true);
58     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
59 }
60
61 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
62     this->videoWidget = videoWidget;
63     videoWidget->setMouseTracking(true);
64     stackedLayout->addWidget(videoWidget);
65 }
66
67 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
68     this->loadingWidget = loadingWidget;
69     stackedLayout->addWidget(loadingWidget);
70     stackedLayout->setCurrentWidget(loadingWidget);
71 }
72
73 void VideoAreaWidget::showVideo() {
74     if (videoWidget)
75         stackedLayout->setCurrentWidget(videoWidget);
76     loadingWidget->clear();
77 }
78
79 void VideoAreaWidget::showError(const QString &message) {
80     // loadingWidget->setError(message);
81     messageLabel->setText(message);
82     messageLabel->show();
83     stackedLayout->setCurrentWidget(loadingWidget);
84 }
85
86 void VideoAreaWidget::showLoading(Video *video) {
87     messageLabel->hide();
88     messageLabel->clear();
89     stackedLayout->setCurrentWidget(loadingWidget);
90     loadingWidget->setVideo(video);
91 }
92
93 #ifdef APP_SNAPSHOT
94 void VideoAreaWidget::showSnapshotPreview(const QPixmap &pixmap) {
95     bool soundOnly = false;
96 #ifdef APP_MAC
97     soundOnly = MainWindow::instance()->isReallyFullScreen();
98 #endif
99     snapshotPreview->start(videoWidget, pixmap, soundOnly);
100 }
101
102 void VideoAreaWidget::hideSnapshotPreview() {
103
104 }
105 #endif
106
107 void VideoAreaWidget::clear() {
108     loadingWidget->clear();
109     messageLabel->hide();
110     messageLabel->clear();
111     stackedLayout->setCurrentWidget(loadingWidget);
112 }
113
114 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
115     if (event->button() == Qt::LeftButton)
116         emit doubleClicked();
117 }
118
119 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
120     QWidget::mousePressEvent(event);
121
122     if(event->button() == Qt::RightButton)
123         emit rightClicked();
124
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();
130             event->accept();
131         }
132     }
133 }
134
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;
140 #ifdef Q_OS_MAC
141         // FIXME mac::moveWindowTo(window()->winId(), p.x(), p.y());
142 #else
143         window()->move(p);
144 #endif
145         event->accept();
146     }
147 }
148
149 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
150     // qDebug() << event->mimeData()->formats();
151     if (event->mimeData()->hasFormat("application/x-minitube-video")) {
152         event->acceptProposedAction();
153     }
154 }
155
156 void VideoAreaWidget::dropEvent(QDropEvent *event) {
157     
158     const VideoMimeData* videoMimeData = qobject_cast<const VideoMimeData*>( event->mimeData() );
159     if(!videoMimeData ) return;
160     
161     QList<Video*> droppedVideos = videoMimeData->videos();
162     if (droppedVideos.isEmpty())
163         return;
164     Video *video = droppedVideos.first();
165     int row = listModel->rowForVideo(video);
166     if (row != -1)
167         listModel->setActiveRow(row);
168     event->acceptProposedAction();
169 }