1 /* $BEGIN_LICENSE
2 
3 This file is part of Musique.
4 Copyright 2013, Flavio Tordini <flavio.tordini@gmail.com>
5 
6 Musique 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 Musique 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 Musique.  If not, see <http://www.gnu.org/licenses/>.
18 
19 $END_LICENSE */
20 
21 #include <QtWidgets>
22 #include "droparea.h"
23 #include "iconutils.h"
24 #include "trackmimedata.h"
25 #include "model/track.h"
26 #include "playlistmodel.h"
27 
DropArea(QWidget * parent)28 DropArea::DropArea(QWidget *parent) : QLabel(parent) {
29     setMargin(15);
30     setAlignment(Qt::AlignCenter);
31     setAcceptDrops(true);
32     setAutoFillBackground(true);
33     clear();
34 }
35 
dragEnterEvent(QDragEnterEvent * event)36 void DropArea::dragEnterEvent(QDragEnterEvent *event) {
37     setBackgroundRole(QPalette::Highlight);
38     setForegroundRole(QPalette::HighlightedText);
39 
40     event->acceptProposedAction();
41     emit changed(event->mimeData());
42 }
43 
dragMoveEvent(QDragMoveEvent * event)44 void DropArea::dragMoveEvent(QDragMoveEvent *event) {
45     event->acceptProposedAction();
46 }
47 
dropEvent(QDropEvent * event)48 void DropArea::dropEvent(QDropEvent *event) {
49     const QMimeData *mimeData = event->mimeData();
50     const TrackMimeData* trackMimeData = qobject_cast<const TrackMimeData*>(mimeData);
51     if (trackMimeData) {
52         QVector<Track*> tracks = trackMimeData->getTracks();
53         playlistModel->addTracks(tracks);
54         event->acceptProposedAction();
55     }
56 }
57 
dragLeaveEvent(QDragLeaveEvent * event)58 void DropArea::dragLeaveEvent(QDragLeaveEvent *event) {
59     clear();
60     event->accept();
61 }
62 
clear()63 void DropArea::clear() {
64     setText("<b>" + tr("Drop here to append to the playlist") + "</b>");
65     setPixmap(IconUtils::icon("list-add").pixmap(24, 24));
66     setBackgroundRole(QPalette::Base);
67     setForegroundRole(QPalette::Text);
68 
69     emit changed();
70 }
71