]> git.sur5r.net Git - minitube/blob - src/videoareawidget.cpp
Autohide mouse cursor in the video area
[minitube] / src / videoareawidget.cpp
1 #include "videoareawidget.h"
2 #include "videomimedata.h"
3
4 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) {
5     stackedLayout = new QStackedLayout(this);
6     setLayout(stackedLayout);
7     setAcceptDrops(true);
8
9     // mouse autohide
10     setMouseTracking(true);
11     mouseTimer = new QTimer(this);
12     mouseTimer->setInterval(5000);
13     mouseTimer->setSingleShot(true);
14     connect(mouseTimer, SIGNAL(timeout()), SLOT(hideMouse()));
15 }
16
17 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
18     this->videoWidget = videoWidget;
19     stackedLayout->addWidget(videoWidget);
20 }
21
22 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
23     this->loadingWidget = loadingWidget;
24     stackedLayout->addWidget(loadingWidget);
25 }
26
27 void VideoAreaWidget::showVideo() {
28     stackedLayout->setCurrentWidget(videoWidget);
29 }
30
31 void VideoAreaWidget::showError(QString message) {
32     loadingWidget->setError(message);
33     stackedLayout->setCurrentWidget(loadingWidget);
34 }
35
36 void VideoAreaWidget::showLoading(Video *video) {
37     this->loadingWidget->setVideo(video);
38     stackedLayout->setCurrentWidget(loadingWidget);
39 }
40
41 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
42     if (event->button() == Qt::LeftButton)
43         emit doubleClicked();
44 }
45
46 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
47     switch(event->button() == Qt::RightButton)
48             emit rightClicked();
49 }
50
51 void VideoAreaWidget::mouseMoveEvent(QMouseEvent * /* event */) {
52     // show the normal cursor
53     unsetCursor();
54     // then hide it again after a few seconds
55     mouseTimer->start();
56 }
57
58 void VideoAreaWidget::hideMouse() {
59     setCursor(QCursor(QBitmap(1,1)));
60 }
61
62 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
63     qDebug() << event->mimeData()->formats();
64     if (event->mimeData()->hasFormat("application/x-minitube-video")) {
65         event->acceptProposedAction();
66     }
67 }
68
69 void VideoAreaWidget::dropEvent(QDropEvent *event) {
70
71     const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
72     if(!videoMimeData ) return;
73
74     QList<Video*> droppedVideos = videoMimeData->videos();
75     foreach( Video *video, droppedVideos) {
76         int row = listModel->rowForVideo(video);
77         if (row != -1)
78             listModel->setActiveRow(row);
79     }
80     event->acceptProposedAction();
81 }