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) {
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() {
76 stackedLayout->setCurrentWidget(videoWidget);
77 loadingWidget->clear();
80 void VideoAreaWidget::showError(QString message) {
81 // loadingWidget->setError(message);
82 messageLabel->setText(message);
84 stackedLayout->setCurrentWidget(loadingWidget);
87 void VideoAreaWidget::showLoading(Video *video) {
89 messageLabel->clear();
90 stackedLayout->setCurrentWidget(loadingWidget);
91 loadingWidget->setVideo(video);
95 void VideoAreaWidget::showSnapshotPreview(QPixmap pixmap) {
96 snapshotPreview->setPixmap(pixmap);
97 stackedLayout->setCurrentWidget(snapshotPreview);
99 Extra::flashInWidget(snapshotPreview);
101 QTimer::singleShot(1500, this, SLOT(hideSnapshotPreview()));
104 void VideoAreaWidget::hideSnapshotPreview() {
105 stackedLayout->setCurrentWidget(videoWidget);
109 void VideoAreaWidget::clear() {
110 loadingWidget->clear();
111 messageLabel->hide();
112 messageLabel->clear();
113 // snapshotPreview->clear();
114 stackedLayout->setCurrentWidget(loadingWidget);
117 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
118 if (event->button() == Qt::LeftButton)
119 emit doubleClicked();
122 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
123 QWidget::mousePressEvent(event);
125 if(event->button() == Qt::RightButton)
128 else if (event->button() == Qt::LeftButton) {
129 bool isNormalWindow = !window()->isMaximized() &&
130 !MainWindow::instance()->isReallyFullScreen();
131 if (isNormalWindow) {
132 dragPosition = event->globalPos() - window()->frameGeometry().topLeft();
138 void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
139 bool isNormalWindow = !window()->isMaximized() &&
140 !MainWindow::instance()->isReallyFullScreen();
141 if (event->buttons() & Qt::LeftButton && isNormalWindow) {
142 QPoint p = event->globalPos() - dragPosition;
144 mac::moveWindowTo(window()->winId(), p.x(), p.y());
152 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
153 // qDebug() << event->mimeData()->formats();
154 if (event->mimeData()->hasFormat("application/x-minitube-video")) {
155 event->acceptProposedAction();
159 void VideoAreaWidget::dropEvent(QDropEvent *event) {
161 const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
162 if(!videoMimeData ) return;
164 QList<Video*> droppedVideos = videoMimeData->videos();
165 if (droppedVideos.isEmpty())
167 Video *video = droppedVideos.first();
168 int row = listModel->rowForVideo(video);
170 listModel->setActiveRow(row);
171 event->acceptProposedAction();