]> git.sur5r.net Git - minitube/blob - src/videoareawidget.cpp
Merge tag 'upstream/2.1.3'
[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 "videomimedata.h"
23 #include "mainwindow.h"
24 #ifdef APP_EXTRA
25 #include "extra.h"
26 #endif
27 #ifdef Q_WS_MAC
28 #include "macutils.h"
29 #endif
30
31 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) {
32     QBoxLayout *vLayout = new QVBoxLayout(this);
33     vLayout->setMargin(0);
34     vLayout->setSpacing(0);
35
36     QPalette p = palette();
37     p.setBrush(QPalette::Window, Qt::black);
38     setPalette(p);
39     setAutoFillBackground(true);
40
41     // hidden message widget
42     messageLabel = new QLabel(this);
43     messageLabel->setOpenExternalLinks(true);
44     messageLabel->setMargin(7);
45     messageLabel->setBackgroundRole(QPalette::ToolTipBase);
46     messageLabel->setForegroundRole(QPalette::ToolTipText);
47     messageLabel->setAutoFillBackground(true);
48     messageLabel->setWordWrap(true);
49     messageLabel->hide();
50     vLayout->addWidget(messageLabel);
51
52     stackedLayout = new QStackedLayout();
53     vLayout->addLayout(stackedLayout);
54
55     // snapshotPreview = new QLabel(this);
56     // stackedLayout->addWidget(snapshotPreview);
57     
58     setAcceptDrops(true);
59     setMouseTracking(true);
60     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
61 }
62
63 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
64     this->videoWidget = videoWidget;
65     videoWidget->setMouseTracking(true);
66     stackedLayout->addWidget(videoWidget);
67 }
68
69 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
70     this->loadingWidget = loadingWidget;
71     stackedLayout->addWidget(loadingWidget);
72     stackedLayout->setCurrentWidget(loadingWidget);
73 }
74
75 void VideoAreaWidget::showVideo() {
76     stackedLayout->setCurrentWidget(videoWidget);
77     loadingWidget->clear();
78 }
79
80 void VideoAreaWidget::showError(QString message) {
81     // loadingWidget->setError(message);
82     messageLabel->setText(message);
83     messageLabel->show();
84     stackedLayout->setCurrentWidget(loadingWidget);
85 }
86
87 void VideoAreaWidget::showLoading(Video *video) {
88     messageLabel->hide();
89     messageLabel->clear();
90     stackedLayout->setCurrentWidget(loadingWidget);
91     loadingWidget->setVideo(video);
92 }
93
94 /*
95 void VideoAreaWidget::showSnapshotPreview(QPixmap pixmap) {
96     snapshotPreview->setPixmap(pixmap);
97     stackedLayout->setCurrentWidget(snapshotPreview);
98 #ifdef APP_EXTRA
99     Extra::flashInWidget(snapshotPreview);
100 #endif
101     QTimer::singleShot(1500, this, SLOT(hideSnapshotPreview()));
102 }
103
104 void VideoAreaWidget::hideSnapshotPreview() {
105     stackedLayout->setCurrentWidget(videoWidget);
106 }
107 */
108
109 void VideoAreaWidget::clear() {
110     loadingWidget->clear();
111     messageLabel->hide();
112     messageLabel->clear();
113     // snapshotPreview->clear();
114     stackedLayout->setCurrentWidget(loadingWidget);
115 }
116
117 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
118     if (event->button() == Qt::LeftButton)
119         emit doubleClicked();
120 }
121
122 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
123     QWidget::mousePressEvent(event);
124
125     if(event->button() == Qt::RightButton)
126         emit rightClicked();
127
128     else if (event->button() == Qt::LeftButton) {
129         bool isNormalWindow = !window()->isMaximized() &&
130                 !MainWindow::instance()->isReallyFullScreen();
131         if (isNormalWindow) {
132             dragPosition = event->globalPos() - window()->frameGeometry().topLeft();
133             event->accept();
134         }
135     }
136 }
137
138 void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
139     bool isNormalWindow = !window()->isMaximized() &&
140             !MainWindow::instance()->isReallyFullScreen();
141     if (event->buttons() & Qt::LeftButton && isNormalWindow) {
142         QPoint p = event->globalPos() - dragPosition;
143 #ifdef Q_WS_MAC
144         mac::moveWindowTo(window()->winId(), p.x(), p.y());
145 #else
146         window()->move(p);
147 #endif
148         event->accept();
149     }
150 }
151
152 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
153     // qDebug() << event->mimeData()->formats();
154     if (event->mimeData()->hasFormat("application/x-minitube-video")) {
155         event->acceptProposedAction();
156     }
157 }
158
159 void VideoAreaWidget::dropEvent(QDropEvent *event) {
160     
161     const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
162     if(!videoMimeData ) return;
163     
164     QList<Video*> droppedVideos = videoMimeData->videos();
165     if (droppedVideos.isEmpty())
166         return;
167     Video *video = droppedVideos.first();
168     int row = listModel->rowForVideo(video);
169     if (row != -1)
170         listModel->setActiveRow(row);
171     event->acceptProposedAction();
172 }