-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HotcueButton: move drag info and dnd verification to separate file
- Loading branch information
Showing
7 changed files
with
149 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <widget/hotcuedrag.h> | ||
|
||
#include <QDragEnterEvent> | ||
#include <QMimeData> | ||
#include <QMouseEvent> | ||
#include <QString> | ||
|
||
#include "mixer/playerinfo.h" | ||
#include "track/track.h" | ||
|
||
namespace mixxx { | ||
|
||
namespace hotcuedrag { | ||
|
||
/// Check if the event is a valid hotcue drag or drop event. | ||
/// Event must be a QDragEnterEvent or a QDropEvent. | ||
/// In case of QDropEvent, the HotcueDragInfo is extracted and the pointer | ||
/// data is used by the caller (WHotcueButton) to swap hotuces. | ||
template<typename T> | ||
bool isValidHotcueDragOrDropEvent(T* pEvent, | ||
QObject* pTarget, | ||
const QString& group, | ||
int ignoreHotcueIndex, | ||
HotcueDragInfo* pDragData) { | ||
bool isDrag = std::same_as<QDragEnterEvent, T>; | ||
// Allow source == target in the drag case so we get the drag cursor | ||
// (i.e. not the 'drop rejected' cursor) when starting the drag and when | ||
// dragging over the source later on. | ||
// Same exception for hotcue index check below. | ||
if (!isDrag && pEvent->source() == pTarget) { | ||
return false; | ||
} | ||
TrackPointer pTrack = PlayerInfo::instance().getTrackInfo(group); | ||
if (!pTrack) { | ||
return false; | ||
} | ||
const QByteArray mimeDataBytes = pEvent->mimeData()->data(kDragMimeType); | ||
if (mimeDataBytes.isEmpty()) { | ||
return false; | ||
} | ||
const HotcueDragInfo dragData = HotcueDragInfo::fromByteArray(mimeDataBytes); | ||
if (dragData.isValid() && | ||
(isDrag || dragData.hotcue != ignoreHotcueIndex) && | ||
dragData.trackId == pTrack->getId()) { | ||
if (pDragData != nullptr) { | ||
*pDragData = dragData; | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
} // namespace hotcuedrag | ||
|
||
} // namespace mixxx | ||
|
||
template bool mixxx::hotcuedrag::isValidHotcueDragOrDropEvent<QDropEvent>( | ||
QDropEvent*, QObject*, const QString&, int, HotcueDragInfo*); | ||
template bool mixxx::hotcuedrag::isValidHotcueDragOrDropEvent<QDragEnterEvent>( | ||
QDragEnterEvent*, QObject*, const QString&, int, HotcueDragInfo*); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include <QBuffer> | ||
#include <QMimeData> | ||
#include <QString> | ||
|
||
#include "track/cue.h" | ||
#include "track/trackid.h" | ||
|
||
const QString kDragMimeType = QStringLiteral("hotcueDragInfo"); | ||
|
||
class TrackId; | ||
|
||
namespace mixxx { | ||
|
||
namespace hotcuedrag { | ||
|
||
struct HotcueDragInfo { | ||
HotcueDragInfo() {}; | ||
HotcueDragInfo(TrackId id, int cue) | ||
: trackId(id), | ||
hotcue(cue) {}; | ||
|
||
static HotcueDragInfo fromByteArray(const QByteArray& bytes) { | ||
QDataStream stream(bytes); | ||
TrackId trackId; | ||
int hotcue; | ||
stream >> trackId >> hotcue; | ||
return HotcueDragInfo(trackId, hotcue); | ||
}; | ||
|
||
QByteArray toByteArray() { | ||
QByteArray bytes; | ||
QDataStream dataStream(&bytes, QIODevice::WriteOnly); | ||
dataStream << trackId << hotcue; | ||
return bytes; | ||
}; | ||
|
||
bool isValid() const { | ||
return trackId.isValid() && hotcue != Cue::kNoHotCue; | ||
} | ||
|
||
TrackId trackId = TrackId(); | ||
int hotcue = Cue::kNoHotCue; | ||
}; | ||
|
||
/// Check if the event is a valid hotcue drag or drop event. | ||
/// Event must be a QDragEnterEvent or a QDropEvent. | ||
/// In case of QDropEvent, the HotcueDragInfo is extracted and the pointer | ||
/// data is used by the caller (WHotcueButton) to swap hotuces. | ||
template<typename T> | ||
bool isValidHotcueDragOrDropEvent(T* pEvent, | ||
QObject* pTarget, | ||
const QString& group, | ||
int ignoreHotcueIndex, | ||
HotcueDragInfo* pDragData = nullptr); | ||
|
||
} // namespace hotcuedrag | ||
|
||
} // namespace mixxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters