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 "videoarea.h"
22 #include "loadingwidget.h"
23 #include "mainwindow.h"
24 #include "playlistmodel.h"
26 #include "videomimedata.h"
30 #include "fontutils.h"
31 #include "snapshotpreview.h"
35 class PickMessage : public QWidget {
37 PickMessage(QWidget *parent = nullptr) : QWidget(parent) {
38 setAutoFillBackground(true);
40 QBoxLayout *l = new QHBoxLayout(this);
43 l->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
45 QLabel *arrowLabel = new QLabel("←");
46 arrowLabel->setFont(FontUtils::light(64));
47 l->addWidget(arrowLabel);
49 QLabel *msgLabel = new QLabel(tr("Pick a video"));
50 msgLabel->setFont(FontUtils::light(32));
51 l->addWidget(msgLabel);
56 VideoArea::VideoArea(QWidget *parent)
57 : QWidget(parent), videoWidget(nullptr), messageWidget(nullptr) {
58 setAttribute(Qt::WA_OpaquePaintEvent);
60 QBoxLayout *layout = new QVBoxLayout(this);
62 layout->setSpacing(0);
64 stackedLayout = new QStackedLayout();
65 layout->addLayout(stackedLayout);
68 snapshotPreview = new SnapshotPreview();
69 connect(stackedLayout, SIGNAL(currentChanged(int)), snapshotPreview, SLOT(hide()));
73 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
75 setContextMenuPolicy(Qt::CustomContextMenu);
76 connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
77 SLOT(showContextMenu(const QPoint &)));
80 void VideoArea::setVideoWidget(QWidget *videoWidget) {
81 this->videoWidget = videoWidget;
82 stackedLayout->addWidget(videoWidget);
85 void VideoArea::setLoadingWidget(LoadingWidget *loadingWidget) {
86 this->loadingWidget = loadingWidget;
87 stackedLayout->addWidget(loadingWidget);
88 stackedLayout->setCurrentWidget(loadingWidget);
91 void VideoArea::showVideo() {
92 if (videoWidget) stackedLayout->setCurrentWidget(videoWidget);
93 loadingWidget->clear();
96 void VideoArea::showPickMessage() {
98 messageWidget = new PickMessage();
99 stackedLayout->addWidget(messageWidget);
101 stackedLayout->setCurrentWidget(messageWidget);
104 void VideoArea::showLoading(Video *video) {
105 loadingWidget->setVideo(video);
106 stackedLayout->setCurrentWidget(loadingWidget);
110 void VideoArea::showSnapshotPreview(const QPixmap &pixmap) {
111 bool soundOnly = MainWindow::instance()->isReallyFullScreen();
112 snapshotPreview->start(videoWidget, pixmap, soundOnly);
116 void VideoArea::clear() {
117 loadingWidget->clear();
118 stackedLayout->setCurrentWidget(loadingWidget);
121 void VideoArea::mouseDoubleClickEvent(QMouseEvent *event) {
122 if (event->button() == Qt::LeftButton) emit doubleClicked();
125 void VideoArea::dragEnterEvent(QDragEnterEvent *event) {
126 // qDebug() << event->mimeData()->formats();
127 if (event->mimeData()->hasFormat("application/x-minitube-video")) {
128 event->acceptProposedAction();
132 void VideoArea::dropEvent(QDropEvent *event) {
133 const VideoMimeData *videoMimeData = qobject_cast<const VideoMimeData *>(event->mimeData());
134 if (!videoMimeData) return;
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();
144 void VideoArea::showContextMenu(const QPoint &point) {
145 QMenu *menu = MainWindow::instance()->getMenu("video");
146 menu->exec(mapToGlobal(point));