Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dragging track from deck to deck #173

Merged
merged 8 commits into from
Feb 11, 2014
11 changes: 8 additions & 3 deletions src/skin/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,19 +782,22 @@ QWidget* LegacySkinParser::parseVisual(QDomElement node) {

QWidget* LegacySkinParser::parseText(QDomElement node) {
QString channelStr = lookupNodeGroup(node);
const char* pSafeChannelStr = safeChannelString(channelStr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is off topic and the rest of the code is also effected (not your fault):

IMHO it should be "save" = de:gespeichert not "safe" (security) = de:gesichert
The string is saved into heap, because channelStr will be deleted from stack after returning from parseText().
Maybe a native speaker can verify it.

Because of this, pSafeChannelStr should become pSavedChannelStr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safe in this case means "safe to use without crashing" not "save it for later" so I think the current wording is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then safe us from the work ;-)


BaseTrackPlayer* pPlayer = m_pPlayerManager->getPlayer(channelStr);

if (!pPlayer)
return NULL;

WTrackText* p = new WTrackText(m_pParent);
WTrackText* p = new WTrackText(pSafeChannelStr, m_pConfig, m_pParent);
setupLabelWidget(node, p);

connect(pPlayer, SIGNAL(newTrackLoaded(TrackPointer)),
p, SLOT(slotTrackLoaded(TrackPointer)));
connect(pPlayer, SIGNAL(unloadingTrack(TrackPointer)),
p, SLOT(slotTrackUnloaded(TrackPointer)));
connect(p, SIGNAL(trackDropped(QString,QString)),
m_pPlayerManager, SLOT(slotLoadToPlayer(QString,QString)));

TrackPointer pTrack = pPlayer->getLoadedTrack();
if (pTrack) {
Expand All @@ -806,20 +809,22 @@ QWidget* LegacySkinParser::parseText(QDomElement node) {

QWidget* LegacySkinParser::parseTrackProperty(QDomElement node) {
QString channelStr = lookupNodeGroup(node);

const char* pSafeChannelStr = safeChannelString(channelStr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a QString?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it looks like we usually use const char* for group names. nevermind.


BaseTrackPlayer* pPlayer = m_pPlayerManager->getPlayer(channelStr);

if (!pPlayer)
return NULL;

WTrackProperty* p = new WTrackProperty(m_pParent);
WTrackProperty* p = new WTrackProperty(pSafeChannelStr, m_pConfig, m_pParent);
setupLabelWidget(node, p);

connect(pPlayer, SIGNAL(newTrackLoaded(TrackPointer)),
p, SLOT(slotTrackLoaded(TrackPointer)));
connect(pPlayer, SIGNAL(unloadingTrack(TrackPointer)),
p, SLOT(slotTrackUnloaded(TrackPointer)));
connect(p, SIGNAL(trackDropped(QString,QString)),
m_pPlayerManager, SLOT(slotLoadToPlayer(QString,QString)));

TrackPointer pTrack = pPlayer->getLoadedTrack();
if (pTrack) {
Expand Down
11 changes: 7 additions & 4 deletions src/skin/tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ QList<QString>& Tooltips::add(QString id) {
}

void Tooltips::addStandardTooltips() {
QString dropTracksHere = tr("Drop tracks from library or external file manager here.");
QString dropTracksHere = tr("Drop tracks from library, external file manager, or other decks/samplers here.");
QString resetToDefault = tr("Reset to default value.");
QString leftClick = tr("Left-click");
QString rightClick = tr("Right-click");
Expand Down Expand Up @@ -406,12 +406,14 @@ void Tooltips::addStandardTooltips() {
add("track_artist")
<< tr("Track Artist")
<< tr("Displays the artist of the loaded track.")
<< trackTags;
<< trackTags
<< dropTracksHere;

add("track_title")
<< tr("Track Title")
<< tr("Displays the title of the loaded track.")
<< trackTags;
<< trackTags
<< dropTracksHere;

add("track_album")
<< tr("Track Album")
Expand All @@ -427,7 +429,8 @@ void Tooltips::addStandardTooltips() {
add("text")
<< tr("Track Artist/Title")
<< tr("Displays the artist and title of the loaded track.")
<< trackTags;
<< trackTags
<< dropTracksHere;

add("flanger")
<< tr("Flanger")
Expand Down
57 changes: 54 additions & 3 deletions src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#include "widget/wtrackproperty.h"

WTrackProperty::WTrackProperty(QWidget* pParent)
: WLabel(pParent) {
#include <QDebug>
#include <QUrl>

#include "controlobject.h"
#include "widget/wtrackproperty.h"

WTrackProperty::WTrackProperty(const char* group, ConfigObject<ConfigValue>* pConfig, QWidget* pParent)
: WLabel(pParent),
m_pGroup(group),
m_pConfig(pConfig) {
setAcceptDrops(true);
}

WTrackProperty::~WTrackProperty() {
Expand Down Expand Up @@ -41,3 +48,47 @@ void WTrackProperty::updateLabel(TrackInfoObject*) {
}
}
}

void WTrackProperty::mouseMoveEvent(QMouseEvent *event) {
if ((event->buttons() & Qt::LeftButton) && m_pCurrentTrack) {
QList<QUrl> locationUrls;
locationUrls.append(QUrl::fromLocalFile(m_pCurrentTrack->getLocation()));

QMimeData* mimeData = new QMimeData();
mimeData->setUrls(locationUrls);

QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(QPixmap(":images/library/ic_library_drag_and_drop.png"));
drag->exec(Qt::CopyAction);
}
}

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() &&
event->mimeData()->urls().size() > 0) {
QUrl url = event->mimeData()->urls().first();
QString filename = url.toLocalFile();
// If the file is on a network share, try just converting the URL to a string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment did not at additional information. You might want to explain why this will work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a question I had myself. I saw this was how it was done in

//If the file is on a network share, try just converting the URL to a string...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #169 I've created a helper class for this so I'll just update it to use that once it merges.

if (filename == "") {
filename = url.toString();
}
event->accept();
emit(trackDropped(filename, m_pGroup));
} else {
event->ignore();
}
}
20 changes: 17 additions & 3 deletions src/widget/wtrackproperty.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#ifndef WTRACKPROPERTY_H
#define WTRACKPROPERTY_H

#include "widget/wlabel.h"
#include "trackinfoobject.h"
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMouseEvent>

#include "configobject.h"
#include "skin/skincontext.h"
#include "trackinfoobject.h"
#include "widget/wlabel.h"

class WTrackProperty : public WLabel {
Q_OBJECT
public:
WTrackProperty(QWidget* pParent);
WTrackProperty(const char* group, ConfigObject<ConfigValue>* pConfig, QWidget* pParent);
virtual ~WTrackProperty();

void setup(QDomNode node, const SkinContext& context);

signals:
void trackDropped(QString filename, QString group);

public slots:
void slotTrackLoaded(TrackPointer track);
void slotTrackUnloaded(TrackPointer track);
Expand All @@ -21,6 +29,12 @@ class WTrackProperty : public WLabel {
void updateLabel(TrackInfoObject*);

private:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void mouseMoveEvent(QMouseEvent *event);

const char* m_pGroup;
ConfigObject<ConfigValue>* m_pConfig;
TrackPointer m_pCurrentTrack;
QString m_property;
};
Expand Down
57 changes: 53 additions & 4 deletions src/widget/wtracktext.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@

#include "widget/wtracktext.h"
#include <QDebug>
#include <QUrl>

WTrackText::WTrackText(QWidget* pParent)
: WLabel(pParent) {
#include "controlobject.h"
#include "widget/wtracktext.h"

WTrackText::WTrackText(const char *group, ConfigObject<ConfigValue> *pConfig, QWidget* pParent)
: WLabel(pParent),
m_pGroup(group),
m_pConfig(pConfig) {
setAcceptDrops(true);
}

WTrackText::~WTrackText() {

}

void WTrackText::slotTrackLoaded(TrackPointer track) {
Expand All @@ -33,3 +38,47 @@ void WTrackText::updateLabel(TrackInfoObject*) {
setText(m_pCurrentTrack->getInfo());
}
}

void WTrackText::mouseMoveEvent(QMouseEvent *event) {
if ((event->buttons() & Qt::LeftButton) && m_pCurrentTrack) {
QList<QUrl> locationUrls;
locationUrls.append(QUrl::fromLocalFile(m_pCurrentTrack->getLocation()));

QMimeData* mimeData = new QMimeData();
mimeData->setUrls(locationUrls);

QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(QPixmap(":images/library/ic_library_drag_and_drop.png"));
drag->exec(Qt::CopyAction);
}
}

void WTrackText::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 WTrackText::dropEvent(QDropEvent *event) {
if (event->mimeData()->hasUrls() &&
event->mimeData()->urls().size() > 0) {
QUrl url = event->mimeData()->urls().first();
QString fileName = url.toLocalFile();
// If the file is on a network share, try just converting the URL to a string
if (fileName == "") {
fileName = url.toString();
}
event->accept();
emit(trackDropped(fileName, m_pGroup));
} else {
event->ignore();
}
}
18 changes: 16 additions & 2 deletions src/widget/wtracktext.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#ifndef WTRACKTEXT_H
#define WTRACKTEXT_H

#include "widget/wlabel.h"
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMouseEvent>

#include "configobject.h"
#include "trackinfoobject.h"
#include "widget/wlabel.h"

class WTrackText : public WLabel {
Q_OBJECT
public:
WTrackText(QWidget *parent);
WTrackText(const char* group, ConfigObject<ConfigValue>* pConfig, QWidget *parent);
virtual ~WTrackText();
signals:
void trackDropped(QString fileName, QString group);

public slots:
void slotTrackLoaded(TrackPointer track);
Expand All @@ -18,7 +25,14 @@ class WTrackText : public WLabel {
void updateLabel(TrackInfoObject*);

private:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void mouseMoveEvent(QMouseEvent *event);

const char* m_pGroup;
ConfigObject<ConfigValue>* m_pConfig;
TrackPointer m_pCurrentTrack;
};


#endif /* WTRACKTEXT_H */