]> git.sur5r.net Git - minitube/blob - src/videoareawidget.cpp
Qt5 fixes
[minitube] / src / videoareawidget.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
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.
10
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.
15
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/>.
18
19 $END_LICENSE */
20
21 #include "videoareawidget.h"
22 #include "videomimedata.h"
23 #include "mainwindow.h"
24 #ifdef APP_EXTRA
25 #include "extra.h"
26 #endif
27 #ifdef Q_OS_MAC
28 #include "macutils.h"
29 #endif
30
31 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent), videoWidget(0) {
32     QBoxLayout *vLayout = new QVBoxLayout(this);
33     vLayout->setMargin(0);
34     vLayout->setSpacing(0);
35
36     QPalette p = palette();
37     p.setBrush(QPalette::Window, Qt::black);
38     setPalette(p);
39     setAutoFillBackground(true);
40
41     // hidden message widget
42     messageLabel = new QLabel(this);
43     messageLabel->setOpenExternalLinks(true);
44     messageLabel->setMargin(7);
45     messageLabel->setBackgroundRole(QPalette::ToolTipBase);
46     messageLabel->setForegroundRole(QPalette::ToolTipText);
47     messageLabel->setAutoFillBackground(true);
48     messageLabel->setWordWrap(true);
49     messageLabel->hide();
50     vLayout->addWidget(messageLabel);
51
52     stackedLayout = new QStackedLayout();
53     vLayout->addLayout(stackedLayout);
54
55     // snapshotPreview = new QLabel(this);
56     // stackedLayout->addWidget(snapshotPreview);
57     
58     setAcceptDrops(true);
59     setMouseTracking(true);
60     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
61 }
62
63 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
64     this->videoWidget = videoWidget;
65     videoWidget->setMouseTracking(true);
66     stackedLayout->addWidget(videoWidget);
67 }
68
69 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
70     this->loadingWidget = loadingWidget;
71     stackedLayout->addWidget(loadingWidget);
72     stackedLayout->setCurrentWidget(loadingWidget);
73 }
74
75 void VideoAreaWidget::showVideo() {
76     if (videoWidget)
77         stackedLayout->setCurrentWidget(videoWidget);
78     loadingWidget->clear();
79 }
80
81 void VideoAreaWidget::showError(QString message) {
82     // loadingWidget->setError(message);
83     messageLabel->setText(message);
84     messageLabel->show();
85     stackedLayout->setCurrentWidget(loadingWidget);
86 }
87
88 void VideoAreaWidget::showLoading(Video *video) {
89     messageLabel->hide();
90     messageLabel->clear();
91     stackedLayout->setCurrentWidget(loadingWidget);
92     loadingWidget->setVideo(video);
93 }
94
95 /*
96 void VideoAreaWidget::showSnapshotPreview(QPixmap pixmap) {
97     snapshotPreview->setPixmap(pixmap);
98     stackedLayout->setCurrentWidget(snapshotPreview);
99 #ifdef APP_EXTRA
100     Extra::flashInWidget(snapshotPreview);
101 #endif
102     QTimer::singleShot(1500, this, SLOT(hideSnapshotPreview()));
103 }
104
105 void VideoAreaWidget::hideSnapshotPreview() {
106     stackedLayout->setCurrentWidget(videoWidget);
107 }
108 */
109
110 void VideoAreaWidget::clear() {
111     loadingWidget->clear();
112     messageLabel->hide();
113     messageLabel->clear();
114     // snapshotPreview->clear();
115     stackedLayout->setCurrentWidget(loadingWidget);
116 }
117
118 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
119     if (event->button() == Qt::LeftButton)
120         emit doubleClicked();
121 }
122
123 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
124     QWidget::mousePressEvent(event);
125
126     if(event->button() == Qt::RightButton)
127         emit rightClicked();
128
129     else if (event->button() == Qt::LeftButton) {
130         bool isNormalWindow = !window()->isMaximized() &&
131                 !MainWindow::instance()->isReallyFullScreen();
132         if (isNormalWindow) {
133             dragPosition = event->globalPos() - window()->frameGeometry().topLeft();
134             event->accept();
135         }
136     }
137 }
138
139 void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
140     bool isNormalWindow = !window()->isMaximized() &&
141             !MainWindow::instance()->isReallyFullScreen();
142     if (event->buttons() & Qt::LeftButton && isNormalWindow) {
143         QPoint p = event->globalPos() - dragPosition;
144 #ifdef Q_OS_MAC
145         mac::moveWindowTo(window()->winId(), p.x(), p.y());
146 #else
147         window()->move(p);
148 #endif
149         event->accept();
150     }
151 }
152
153 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
154     // qDebug() << event->mimeData()->formats();
155     if (event->mimeData()->hasFormat("application/x-minitube-video")) {
156         event->acceptProposedAction();
157     }
158 }
159
160 void VideoAreaWidget::dropEvent(QDropEvent *event) {
161     
162     const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
163     if(!videoMimeData ) return;
164     
165     QList<Video*> droppedVideos = videoMimeData->videos();
166     if (droppedVideos.isEmpty())
167         return;
168     Video *video = droppedVideos.first();
169     int row = listModel->rowForVideo(video);
170     if (row != -1)
171         listModel->setActiveRow(row);
172     event->acceptProposedAction();
173 }