Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 119 additions & 101 deletions res/qml/Library.qml
Original file line number Diff line number Diff line change
@@ -1,139 +1,157 @@
import Mixxx 1.0 as Mixxx
import QtQuick 2.12
import QtQuick.Controls
import "Theme"

Item {
Rectangle {
color: Theme.deckBackgroundColor
LibraryControl {
id: libraryControl

onMoveVertical: (offset) => {
listView.moveSelectionVertical(offset);
}
onLoadSelectedTrack: (group, play) => {
listView.loadSelectedTrack(group, play);
}
onLoadSelectedTrackIntoNextAvailableDeck: (play) => {
listView.loadSelectedTrackIntoNextAvailableDeck(play);
}
onFocusWidgetChanged: {
switch (focusWidget) {
case FocusedWidgetControl.WidgetKind.LibraryView:
listView.forceActiveFocus();
break;
}
}
}

SplitView {
anchors.fill: parent

LibraryControl {
id: libraryControl
Rectangle {
id: sidebarBox

onMoveVertical: (offset) => {
listView.moveSelectionVertical(offset);
}
onLoadSelectedTrack: (group, play) => {
listView.loadSelectedTrack(group, play);
}
onLoadSelectedTrackIntoNextAvailableDeck: (play) => {
listView.loadSelectedTrackIntoNextAvailableDeck(play);
}
onFocusWidgetChanged: {
switch (focusWidget) {
case FocusedWidgetControl.WidgetKind.LibraryView:
listView.forceActiveFocus();
break;
}
color: Theme.deckBackgroundColor

SplitView.preferredWidth: 200

LibrarySidebar {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like this component is missing - forgot to stage a QML file perhaps? :)

model: Mixxx.Library.sidebarModel
}
}

ListView {
id: listView
Rectangle {
id: tableBox

function moveSelectionVertical(value) {
if (value == 0)
return ;
color: Theme.deckBackgroundColor

const rowCount = model.rowCount();
if (rowCount == 0)
return ;
ListView {
id: listView

currentIndex = Mixxx.MathUtils.positiveModulo(currentIndex + value, rowCount);
}
function moveSelectionVertical(value) {
if (value == 0)
return ;

function loadSelectedTrackIntoNextAvailableDeck(play) {
const url = model.get(currentIndex).fileUrl;
if (!url)
return ;
const rowCount = model.rowCount();
if (rowCount == 0)
return ;

Mixxx.PlayerManager.loadLocationUrlIntoNextAvailableDeck(url, play);
}
currentIndex = Mixxx.MathUtils.positiveModulo(currentIndex + value, rowCount);
}

function loadSelectedTrack(group, play) {
const url = model.get(currentIndex).fileUrl;
if (!url)
return ;
function loadSelectedTrackIntoNextAvailableDeck(play) {
const url = model.get(currentIndex).fileUrl;
if (!url)
return ;

const player = Mixxx.PlayerManager.getPlayer(group);
if (!player)
return ;
Mixxx.PlayerManager.loadLocationUrlIntoNextAvailableDeck(url, play);
}

player.loadTrackFromLocationUrl(url, play);
}
function loadSelectedTrack(group, play) {
const url = model.get(currentIndex).fileUrl;
if (!url)
return ;

anchors.fill: parent
anchors.margins: 10
clip: true
keyNavigationWraps: true
highlightMoveDuration: 250
highlightResizeDuration: 50
model: Mixxx.Library.model
Keys.onPressed: (event) => {
switch (event.key) {
case Qt.Key_Enter:
case Qt.Key_Return:
listView.loadSelectedTrackIntoNextAvailableDeck(false);
break;
const player = Mixxx.PlayerManager.getPlayer(group);
if (!player)
return ;

player.loadTrackFromLocationUrl(url, play);
}
}

delegate: Item {
id: itemDlgt
anchors.fill: parent
anchors.margins: 10
clip: true
keyNavigationWraps: true
highlightMoveDuration: 250
highlightResizeDuration: 50
model: Mixxx.Library.model
Keys.onPressed: (event) => {
switch (event.key) {
case Qt.Key_Enter:
case Qt.Key_Return:
listView.loadSelectedTrackIntoNextAvailableDeck(false);
break;
}
}

required property int index
required property url fileUrl
required property string artist
required property string title
delegate: Item {
id: itemDlgt

implicitWidth: listView.width
implicitHeight: 30
required property int index
required property url fileUrl
required property string artist
required property string title

Text {
anchors.verticalCenter: parent.verticalCenter
text: itemDlgt.artist + " - " + itemDlgt.title
color: (listView.currentIndex == itemDlgt.index && listView.activeFocus) ? Theme.blue : Theme.deckTextColor
implicitWidth: listView.width
implicitHeight: 30

Behavior on color {
ColorAnimation {
duration: listView.highlightMoveDuration
Text {
anchors.verticalCenter: parent.verticalCenter
text: itemDlgt.artist + " - " + itemDlgt.title
color: (listView.currentIndex == itemDlgt.index && listView.activeFocus) ? Theme.blue : Theme.deckTextColor

Behavior on color {
ColorAnimation {
duration: listView.highlightMoveDuration
}
}
}
}

Image {
id: dragItem
Image {
id: dragItem

Drag.active: dragArea.drag.active
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.CopyAction
Drag.mimeData: {
"text/uri-list": itemDlgt.fileUrl,
"text/plain": itemDlgt.fileUrl
Drag.active: dragArea.drag.active
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.CopyAction
Drag.mimeData: {
"text/uri-list": itemDlgt.fileUrl,
"text/plain": itemDlgt.fileUrl
}
anchors.fill: parent
}
anchors.fill: parent
}

MouseArea {
id: dragArea

anchors.fill: parent
drag.target: dragItem
onPressed: {
listView.forceActiveFocus();
listView.currentIndex = itemDlgt.index;
parent.grabToImage((result) => {
dragItem.Drag.imageSource = result.url;
});
MouseArea {
id: dragArea

anchors.fill: parent
drag.target: dragItem
onPressed: {
listView.forceActiveFocus();
listView.currentIndex = itemDlgt.index;
parent.grabToImage((result) => {
dragItem.Drag.imageSource = result.url;
});
}
onDoubleClicked: listView.loadSelectedTrackIntoNextAvailableDeck(false)
}
onDoubleClicked: listView.loadSelectedTrackIntoNextAvailableDeck(false)
}
}

highlight: Rectangle {
border.color: listView.activeFocus ? Theme.blue : Theme.deckTextColor
border.width: 1
color: "transparent"
highlight: Rectangle {
border.color: listView.activeFocus ? Theme.blue : Theme.deckTextColor
border.width: 1
color: "transparent"
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,7 @@ LibraryTableModel* Library::trackTableModel() const {

return m_pMixxxLibraryFeature->trackTableModel();
}

SidebarModel* Library::sidebarModel() const {
return m_pSidebarModel.get();
}
1 change: 1 addition & 0 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Library: public QObject {

/// Needed for exposing models to QML
LibraryTableModel* trackTableModel() const;
SidebarModel* sidebarModel() const;

bool isTrackIdInCurrentLibraryView(const TrackId& trackId);

Expand Down
5 changes: 4 additions & 1 deletion src/qml/qmllibraryproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
#include <QAbstractItemModel>

#include "library/library.h"
#include "library/sidebarmodel.h"
#include "moc_qmllibraryproxy.cpp"
#include "qmllibraryproxy.h"

namespace mixxx {
namespace qml {

QmlLibraryProxy::QmlLibraryProxy(std::shared_ptr<Library> pLibrary, QObject* parent)
: QObject(parent),
m_pLibrary(pLibrary),
m_pModelProperty(new QmlLibraryTrackListModel(m_pLibrary->trackTableModel(), this)) {
m_pModelProperty(new QmlLibraryTrackListModel(m_pLibrary->trackTableModel(), this)),
m_pSidebarModelProperty(m_pLibrary->sidebarModel()) {
}

// static
Expand Down
3 changes: 3 additions & 0 deletions src/qml/qmllibraryproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "util/parented_ptr.h"

class Library;
class SidebarModel;

namespace mixxx {
namespace qml {
Expand All @@ -16,6 +17,7 @@ class QmlLibraryTrackListModel;
class QmlLibraryProxy : public QObject {
Q_OBJECT
Q_PROPERTY(mixxx::qml::QmlLibraryTrackListModel* model MEMBER m_pModelProperty CONSTANT)
Q_PROPERTY(SidebarModel* sidebarModel MEMBER m_pSidebarModelProperty CONSTANT)
QML_NAMED_ELEMENT(Library)
QML_SINGLETON

Expand All @@ -34,6 +36,7 @@ class QmlLibraryProxy : public QObject {

/// This needs to be a plain pointer because it's used as a `Q_PROPERTY` member variable.
QmlLibraryTrackListModel* m_pModelProperty;
SidebarModel* m_pSidebarModelProperty;
};

} // namespace qml
Expand Down