]> git.sur5r.net Git - minitube/blob - src/videoareawidget.cpp
Enhanced fullscreen mode
[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     switch(event->button() == Qt::RightButton)
72             emit rightClicked();
73 }
74
75 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
76     // qDebug() << event->mimeData()->formats();
77     if (event->mimeData()->hasFormat("application/x-minitube-video")) {
78         event->acceptProposedAction();
79     }
80 }
81
82 void VideoAreaWidget::dropEvent(QDropEvent *event) {
83     
84     const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
85     if(!videoMimeData ) return;
86     
87     QList<Video*> droppedVideos = videoMimeData->videos();
88     if (droppedVideos.isEmpty())
89         return;
90     Video *video = droppedVideos.first();
91     int row = listModel->rowForVideo(video);
92     if (row != -1)
93         listModel->setActiveRow(row);
94     event->acceptProposedAction();
95 }
96
97 void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
98     // qDebug() << "VideoAreaWidget::mouseMoveEvent" << event->pos();
99
100     QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(qApp->topLevelWidgets().first());
101     bool visible = event->pos().y() <= 0;
102     bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible));
103     if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed";
104
105     visible = event->pos().x() <= 0;
106     ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible));
107     if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed";
108 }