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 "videomimedata.h"
23 #include "mainwindow.h"
31 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent), videoWidget(0) {
32 QBoxLayout *vLayout = new QVBoxLayout(this);
33 vLayout->setMargin(0);
34 vLayout->setSpacing(0);
36 QPalette p = palette();
37 p.setBrush(QPalette::Window, Qt::black);
39 setAutoFillBackground(true);
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);
50 vLayout->addWidget(messageLabel);
52 stackedLayout = new QStackedLayout();
53 vLayout->addLayout(stackedLayout);
55 // snapshotPreview = new QLabel(this);
56 // stackedLayout->addWidget(snapshotPreview);
59 setMouseTracking(true);
60 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
63 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
64 this->videoWidget = videoWidget;
65 videoWidget->setMouseTracking(true);
66 stackedLayout->addWidget(videoWidget);
69 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
70 this->loadingWidget = loadingWidget;
71 stackedLayout->addWidget(loadingWidget);
72 stackedLayout->setCurrentWidget(loadingWidget);
75 void VideoAreaWidget::showVideo() {
77 stackedLayout->setCurrentWidget(videoWidget);
78 loadingWidget->clear();
81 void VideoAreaWidget::showError(QString message) {
82 // loadingWidget->setError(message);
83 messageLabel->setText(message);
85 stackedLayout->setCurrentWidget(loadingWidget);
88 void VideoAreaWidget::showLoading(Video *video) {
90 messageLabel->clear();
91 stackedLayout->setCurrentWidget(loadingWidget);
92 loadingWidget->setVideo(video);
96 void VideoAreaWidget::showSnapshotPreview(QPixmap pixmap) {
97 snapshotPreview->setPixmap(pixmap);
98 stackedLayout->setCurrentWidget(snapshotPreview);
100 Extra::flashInWidget(snapshotPreview);
102 QTimer::singleShot(1500, this, SLOT(hideSnapshotPreview()));
105 void VideoAreaWidget::hideSnapshotPreview() {
106 stackedLayout->setCurrentWidget(videoWidget);
110 void VideoAreaWidget::clear() {
111 loadingWidget->clear();
112 messageLabel->hide();
113 messageLabel->clear();
114 // snapshotPreview->clear();
115 stackedLayout->setCurrentWidget(loadingWidget);
118 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
119 if (event->button() == Qt::LeftButton)
120 emit doubleClicked();
123 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
124 QWidget::mousePressEvent(event);
126 if(event->button() == Qt::RightButton)
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();
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;
145 mac::moveWindowTo(window()->winId(), p.x(), p.y());
153 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
154 // qDebug() << event->mimeData()->formats();
155 if (event->mimeData()->hasFormat("application/x-minitube-video")) {
156 event->acceptProposedAction();
160 void VideoAreaWidget::dropEvent(QDropEvent *event) {
162 const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
163 if(!videoMimeData ) return;
165 QList<Video*> droppedVideos = videoMimeData->videos();
166 if (droppedVideos.isEmpty())
168 Video *video = droppedVideos.first();
169 int row = listModel->rowForVideo(video);
171 listModel->setActiveRow(row);
172 event->acceptProposedAction();