]> git.sur5r.net Git - minitube/blob - src/videoareawidget.cpp
Imported Upstream version 1.4.1
[minitube] / src / videoareawidget.cpp
1 #include "videoareawidget.h"
2 #include "videomimedata.h"
3
4 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) {
5     QBoxLayout *vLayout = new QVBoxLayout(this);
6     vLayout->setMargin(0);
7     vLayout->setSpacing(0);
8     
9     // hidden message widget
10     messageLabel = new QLabel(this);
11     messageLabel->setOpenExternalLinks(true);
12     messageLabel->setMargin(7);
13     messageLabel->setBackgroundRole(QPalette::ToolTipBase);
14     messageLabel->setForegroundRole(QPalette::ToolTipText);
15     messageLabel->setAutoFillBackground(true);
16     messageLabel->setWordWrap(true);
17     messageLabel->hide();
18     vLayout->addWidget(messageLabel);
19     
20     stackedLayout = new QStackedLayout();
21     vLayout->addLayout(stackedLayout);
22     
23     setLayout(vLayout);
24     setAcceptDrops(true);
25     
26     setMouseTracking(true);
27 }
28
29 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
30     this->videoWidget = videoWidget;
31     videoWidget->setMouseTracking(true);
32     stackedLayout->addWidget(videoWidget);
33 }
34
35 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
36     this->loadingWidget = loadingWidget;
37     stackedLayout->addWidget(loadingWidget);
38 }
39
40 void VideoAreaWidget::showVideo() {
41     stackedLayout->setCurrentWidget(videoWidget);
42 }
43
44 void VideoAreaWidget::showError(QString message) {
45     // loadingWidget->setError(message);
46     messageLabel->setText(message);
47     messageLabel->show();
48     stackedLayout->setCurrentWidget(loadingWidget);
49 }
50
51 void VideoAreaWidget::showLoading(Video *video) {
52     this->loadingWidget->setVideo(video);
53     stackedLayout->setCurrentWidget(loadingWidget);
54     messageLabel->hide();
55     messageLabel->clear();
56 }
57
58 void VideoAreaWidget::clear() {
59     stackedLayout->setCurrentWidget(loadingWidget);
60     loadingWidget->clear();
61     messageLabel->hide();
62     messageLabel->clear();
63 }
64
65 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
66     if (event->button() == Qt::LeftButton)
67         emit doubleClicked();
68 }
69
70 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
71     QWidget::mousePressEvent(event);
72
73     if(event->button() == Qt::RightButton)
74         emit rightClicked();
75 }
76
77 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
78     // qDebug() << event->mimeData()->formats();
79     if (event->mimeData()->hasFormat("application/x-minitube-video")) {
80         event->acceptProposedAction();
81     }
82 }
83
84 void VideoAreaWidget::dropEvent(QDropEvent *event) {
85     
86     const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
87     if(!videoMimeData ) return;
88     
89     QList<Video*> droppedVideos = videoMimeData->videos();
90     if (droppedVideos.isEmpty())
91         return;
92     Video *video = droppedVideos.first();
93     int row = listModel->rowForVideo(video);
94     if (row != -1)
95         listModel->setActiveRow(row);
96     event->acceptProposedAction();
97 }
98
99 void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
100     QWidget::mouseMoveEvent(event);
101
102     QWidget* mainWindow = window();
103     if (!mainWindow->isFullScreen()) return;
104
105     // qDebug() << "VideoAreaWidget::mouseMoveEvent" << event->pos();
106
107     const int x = event->pos().x();
108     const int y = event->pos().y();
109
110     bool visible = y <= 10;
111     bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible));
112     if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed";
113
114     visible = x <= 10;
115     ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible));
116     if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed";
117 }