1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include <QDebug>
#include <QUrl>
#include "controlobject.h"
#include "widget/wtrackproperty.h"
#include "util/dnd.h"
WTrackProperty::WTrackProperty(const char* group,
ConfigObject<ConfigValue>* pConfig,
QWidget* pParent)
: WLabel(pParent),
m_pGroup(group),
m_pConfig(pConfig) {
setAcceptDrops(true);
}
WTrackProperty::~WTrackProperty() {
}
void WTrackProperty::setup(QDomNode node, const SkinContext& context) {
WLabel::setup(node, context);
m_property = context.selectString(node, "Property");
}
void WTrackProperty::slotTrackLoaded(TrackPointer track) {
if (track) {
m_pCurrentTrack = track;
connect(track.data(), SIGNAL(changed(TrackInfoObject*)),
this, SLOT(updateLabel(TrackInfoObject*)));
updateLabel(track.data());
}
}
void WTrackProperty::slotTrackUnloaded(TrackPointer track) {
Q_UNUSED(track);
if (m_pCurrentTrack) {
disconnect(m_pCurrentTrack.data(), 0, this, 0);
}
m_pCurrentTrack.clear();
setText("");
}
void WTrackProperty::updateLabel(TrackInfoObject*) {
if (m_pCurrentTrack) {
QVariant property = m_pCurrentTrack->property(m_property.toAscii().constData());
if (property.isValid() && qVariantCanConvert<QString>(property)) {
setText(property.toString());
}
}
}
void WTrackProperty::mouseMoveEvent(QMouseEvent *event) {
if ((event->buttons() & Qt::LeftButton) && m_pCurrentTrack) {
DragAndDropHelper::dragTrack(m_pCurrentTrack, this);
}
}
void WTrackProperty::dragEnterEvent(QDragEnterEvent *event) {
if (event->mimeData()->hasUrls() &&
event->mimeData()->urls().size() > 0) {
// Accept if the Deck isn't playing or the settings allow to interrupt a playing deck
if ((!ControlObject::get(ConfigKey(m_pGroup, "play")) ||
m_pConfig->getValueString(ConfigKey("[Controls]", "AllowTrackLoadToPlayingDeck")).toInt())) {
event->acceptProposedAction();
} else {
event->ignore();
}
}
}
void WTrackProperty::dropEvent(QDropEvent *event) {
if (event->mimeData()->hasUrls()) {
QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(
event->mimeData()->urls(), true, false);
if (!files.isEmpty()) {
event->accept();
emit(trackDropped(files.at(0).canonicalFilePath(), m_pGroup));
return;
}
}
event->ignore();
}
|