]> git.sur5r.net Git - minitube/blob - src/videoarea.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / videoarea.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 "videoarea.h"
22 #include "loadingwidget.h"
23 #include "mainwindow.h"
24 #include "playlistmodel.h"
25 #include "video.h"
26 #include "videomimedata.h"
27 #ifdef Q_OS_MAC
28 #include "macutils.h"
29 #endif
30 #include "fontutils.h"
31 #include "snapshotpreview.h"
32
33 namespace {
34
35 class PickMessage : public QWidget {
36 public:
37     PickMessage(QWidget *parent = nullptr) : QWidget(parent) {
38         setAutoFillBackground(true);
39
40         QBoxLayout *l = new QHBoxLayout(this);
41         l->setMargin(32);
42         l->setSpacing(32);
43         l->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
44
45         QLabel *arrowLabel = new QLabel("←");
46         arrowLabel->setFont(FontUtils::light(64));
47         l->addWidget(arrowLabel);
48
49         QLabel *msgLabel = new QLabel(tr("Pick a video"));
50         msgLabel->setFont(FontUtils::light(32));
51         l->addWidget(msgLabel);
52     }
53 };
54 } // namespace
55
56 VideoArea::VideoArea(QWidget *parent)
57     : QWidget(parent), videoWidget(nullptr), messageWidget(nullptr) {
58     setAttribute(Qt::WA_OpaquePaintEvent);
59
60     QBoxLayout *layout = new QVBoxLayout(this);
61     layout->setMargin(0);
62     layout->setSpacing(0);
63
64     stackedLayout = new QStackedLayout();
65     layout->addLayout(stackedLayout);
66
67 #ifdef APP_SNAPSHOT
68     snapshotPreview = new SnapshotPreview();
69     connect(stackedLayout, SIGNAL(currentChanged(int)), snapshotPreview, SLOT(hide()));
70 #endif
71
72     setAcceptDrops(true);
73     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
74
75     setContextMenuPolicy(Qt::CustomContextMenu);
76     connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
77             SLOT(showContextMenu(const QPoint &)));
78 }
79
80 void VideoArea::setVideoWidget(QWidget *videoWidget) {
81     this->videoWidget = videoWidget;
82     stackedLayout->addWidget(videoWidget);
83 }
84
85 void VideoArea::setLoadingWidget(LoadingWidget *loadingWidget) {
86     this->loadingWidget = loadingWidget;
87     stackedLayout->addWidget(loadingWidget);
88     stackedLayout->setCurrentWidget(loadingWidget);
89 }
90
91 void VideoArea::showVideo() {
92     if (videoWidget) stackedLayout->setCurrentWidget(videoWidget);
93     loadingWidget->clear();
94 }
95
96 void VideoArea::showPickMessage() {
97     if (!messageWidget) {
98         messageWidget = new PickMessage();
99         stackedLayout->addWidget(messageWidget);
100     }
101     stackedLayout->setCurrentWidget(messageWidget);
102 }
103
104 void VideoArea::showLoading(Video *video) {
105     loadingWidget->setVideo(video);
106     stackedLayout->setCurrentWidget(loadingWidget);
107 }
108
109 #ifdef APP_SNAPSHOT
110 void VideoArea::showSnapshotPreview(const QPixmap &pixmap) {
111     bool soundOnly = MainWindow::instance()->isReallyFullScreen();
112     snapshotPreview->start(videoWidget, pixmap, soundOnly);
113 }
114 #endif
115
116 void VideoArea::clear() {
117     loadingWidget->clear();
118     stackedLayout->setCurrentWidget(loadingWidget);
119 }
120
121 void VideoArea::mouseDoubleClickEvent(QMouseEvent *event) {
122     if (event->button() == Qt::LeftButton) emit doubleClicked();
123 }
124
125 void VideoArea::dragEnterEvent(QDragEnterEvent *event) {
126     // qDebug() << event->mimeData()->formats();
127     if (event->mimeData()->hasFormat("application/x-minitube-video")) {
128         event->acceptProposedAction();
129     }
130 }
131
132 void VideoArea::dropEvent(QDropEvent *event) {
133     const VideoMimeData *videoMimeData = qobject_cast<const VideoMimeData *>(event->mimeData());
134     if (!videoMimeData) return;
135
136     QVector<Video *> droppedVideos = videoMimeData->getVideos();
137     if (droppedVideos.isEmpty()) return;
138     Video *video = droppedVideos.at(0);
139     int row = listModel->rowForVideo(video);
140     if (row != -1) listModel->setActiveRow(row);
141     event->acceptProposedAction();
142 }
143
144 void VideoArea::showContextMenu(const QPoint &point) {
145     QMenu *menu = MainWindow::instance()->getMenu("video");
146     menu->exec(mapToGlobal(point));
147 }