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"
22 #include "loadingwidget.h"
23 #include "mainwindow.h"
24 #include "playlistmodel.h"
26 #include "videomimedata.h"
30 #include "snapshotpreview.h"
31 #include "fontutils.h"
35 class MessageWidget : public QWidget {
37 MessageWidget(QWidget *parent = nullptr) : QWidget(parent) {
38 QPalette p = palette();
39 p.setColor(QPalette::Window, Qt::black);
40 p.setColor(QPalette::WindowText, Qt::darkGray);
41 p.setColor(QPalette::Base, Qt::black);
42 p.setColor(QPalette::Text, Qt::darkGray);
44 setAutoFillBackground(true);
46 QBoxLayout *l = new QHBoxLayout(this);
49 l->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
51 QLabel *arrowLabel = new QLabel("←");
52 arrowLabel->setFont(FontUtils::light(64));
53 arrowLabel->setPalette(p);
54 l->addWidget(arrowLabel);
56 QLabel *msgLabel = new QLabel(tr("Pick a video"));
57 msgLabel->setFont(FontUtils::light(32));
58 msgLabel->setPalette(p);
59 l->addWidget(msgLabel);
64 VideoAreaWidget::VideoAreaWidget(QWidget *parent)
65 : QWidget(parent), videoWidget(0), messageWidget(0) {
66 setAttribute(Qt::WA_OpaquePaintEvent);
68 QBoxLayout *layout = new QVBoxLayout(this);
70 layout->setSpacing(0);
72 // hidden message widget
73 messageLabel = new QLabel(this);
74 messageLabel->setOpenExternalLinks(true);
75 messageLabel->setMargin(7);
76 messageLabel->setBackgroundRole(QPalette::ToolTipBase);
77 messageLabel->setForegroundRole(QPalette::ToolTipText);
78 messageLabel->setAutoFillBackground(true);
79 messageLabel->setWordWrap(true);
81 layout->addWidget(messageLabel);
83 stackedLayout = new QStackedLayout();
84 layout->addLayout(stackedLayout);
87 snapshotPreview = new SnapshotPreview();
88 connect(stackedLayout, SIGNAL(currentChanged(int)), snapshotPreview, SLOT(hide()));
92 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
94 setContextMenuPolicy(Qt::CustomContextMenu);
95 connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
96 SLOT(showContextMenu(const QPoint &)));
99 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
100 this->videoWidget = videoWidget;
101 stackedLayout->addWidget(videoWidget);
104 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
105 this->loadingWidget = loadingWidget;
106 stackedLayout->addWidget(loadingWidget);
107 stackedLayout->setCurrentWidget(loadingWidget);
110 void VideoAreaWidget::showVideo() {
111 if (videoWidget) stackedLayout->setCurrentWidget(videoWidget);
112 loadingWidget->clear();
115 void VideoAreaWidget::showError(const QString &message) {
116 messageLabel->setText(message);
117 messageLabel->show();
118 stackedLayout->setCurrentWidget(loadingWidget);
121 void VideoAreaWidget::showPickMessage() {
122 if (!messageWidget) {
123 messageWidget = new MessageWidget();
124 stackedLayout->addWidget(messageWidget);
126 stackedLayout->setCurrentWidget(messageWidget);
129 void VideoAreaWidget::showLoading(Video *video) {
130 messageLabel->hide();
131 messageLabel->clear();
132 stackedLayout->setCurrentWidget(loadingWidget);
133 loadingWidget->setVideo(video);
137 void VideoAreaWidget::showSnapshotPreview(const QPixmap &pixmap) {
138 bool soundOnly = false;
140 soundOnly = MainWindow::instance()->isReallyFullScreen();
142 snapshotPreview->start(videoWidget, pixmap, soundOnly);
145 void VideoAreaWidget::hideSnapshotPreview() {}
148 void VideoAreaWidget::clear() {
149 loadingWidget->clear();
150 messageLabel->hide();
151 messageLabel->clear();
152 stackedLayout->setCurrentWidget(loadingWidget);
155 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
156 if (event->button() == Qt::LeftButton) emit doubleClicked();
159 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
160 // qDebug() << event->mimeData()->formats();
161 if (event->mimeData()->hasFormat("application/x-minitube-video")) {
162 event->acceptProposedAction();
166 void VideoAreaWidget::dropEvent(QDropEvent *event) {
167 const VideoMimeData *videoMimeData = qobject_cast<const VideoMimeData *>(event->mimeData());
168 if (!videoMimeData) return;
170 QVector<Video *> droppedVideos = videoMimeData->getVideos();
171 if (droppedVideos.isEmpty()) return;
172 Video *video = droppedVideos.at(0);
173 int row = listModel->rowForVideo(video);
174 if (row != -1) listModel->setActiveRow(row);
175 event->acceptProposedAction();
178 void VideoAreaWidget::showContextMenu(const QPoint &point) {
179 QMenu *menu = MainWindow::instance()->getMenu("video");
180 menu->exec(mapToGlobal(point));