1 #include "videoareawidget.h"
2 #include "videomimedata.h"
7 VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) {
8 QBoxLayout *vLayout = new QVBoxLayout(this);
10 vLayout->setSpacing(0);
12 QPalette p = palette();
13 p.setBrush(QPalette::Window, Qt::black);
15 setAutoFillBackground(true);
17 // hidden message widget
18 messageLabel = new QLabel(this);
19 messageLabel->setOpenExternalLinks(true);
20 messageLabel->setMargin(7);
21 messageLabel->setBackgroundRole(QPalette::ToolTipBase);
22 messageLabel->setForegroundRole(QPalette::ToolTipText);
23 messageLabel->setAutoFillBackground(true);
24 messageLabel->setWordWrap(true);
26 vLayout->addWidget(messageLabel);
28 stackedLayout = new QStackedLayout();
29 vLayout->addLayout(stackedLayout);
31 snapshotPreview = new QLabel(this);
32 stackedLayout->addWidget(snapshotPreview);
35 setMouseTracking(true);
38 void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) {
39 this->videoWidget = videoWidget;
40 videoWidget->setMouseTracking(true);
41 stackedLayout->addWidget(videoWidget);
44 void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) {
45 this->loadingWidget = loadingWidget;
46 stackedLayout->addWidget(loadingWidget);
49 void VideoAreaWidget::showVideo() {
50 stackedLayout->setCurrentWidget(videoWidget);
53 void VideoAreaWidget::showError(QString message) {
54 // loadingWidget->setError(message);
55 messageLabel->setText(message);
57 stackedLayout->setCurrentWidget(loadingWidget);
60 void VideoAreaWidget::showLoading(Video *video) {
61 stackedLayout->setCurrentWidget(loadingWidget);
62 this->loadingWidget->setVideo(video);
64 messageLabel->clear();
67 void VideoAreaWidget::showSnapshotPreview(QPixmap pixmap) {
68 snapshotPreview->setPixmap(pixmap);
69 stackedLayout->setCurrentWidget(snapshotPreview);
71 Extra::flashInWidget(snapshotPreview);
73 QTimer::singleShot(1500, this, SLOT(hideSnapshotPreview()));
76 void VideoAreaWidget::hideSnapshotPreview() {
77 stackedLayout->setCurrentWidget(videoWidget);
80 void VideoAreaWidget::clear() {
81 stackedLayout->setCurrentWidget(loadingWidget);
82 loadingWidget->clear();
84 messageLabel->clear();
85 snapshotPreview->clear();
88 void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) {
89 if (event->button() == Qt::LeftButton)
93 void VideoAreaWidget::mousePressEvent(QMouseEvent *event) {
94 QWidget::mousePressEvent(event);
96 if(event->button() == Qt::RightButton)
100 void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) {
101 // qDebug() << event->mimeData()->formats();
102 if (event->mimeData()->hasFormat("application/x-minitube-video")) {
103 event->acceptProposedAction();
107 void VideoAreaWidget::dropEvent(QDropEvent *event) {
109 const VideoMimeData* videoMimeData = dynamic_cast<const VideoMimeData*>( event->mimeData() );
110 if(!videoMimeData ) return;
112 QList<Video*> droppedVideos = videoMimeData->videos();
113 if (droppedVideos.isEmpty())
115 Video *video = droppedVideos.first();
116 int row = listModel->rowForVideo(video);
118 listModel->setActiveRow(row);
119 event->acceptProposedAction();