From a32e7f0e502eae624dba8e1ed1fbe3d769bc9531 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 29 Feb 2024 22:34:33 +0100 Subject: [PATCH] feat(qml): Add dummy QML library sidebar --- res/qml/Library.qml | 220 +++++++++++++++++++----------------- src/library/library.cpp | 4 + src/library/library.h | 1 + src/qml/qmllibraryproxy.cpp | 5 +- src/qml/qmllibraryproxy.h | 3 + 5 files changed, 131 insertions(+), 102 deletions(-) diff --git a/res/qml/Library.qml b/res/qml/Library.qml index 3f94320aac26..27d7033b9988 100644 --- a/res/qml/Library.qml +++ b/res/qml/Library.qml @@ -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 { + 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" + } } } } diff --git a/src/library/library.cpp b/src/library/library.cpp index 77bd315e1b4b..37910252902c 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -701,3 +701,7 @@ LibraryTableModel* Library::trackTableModel() const { return m_pMixxxLibraryFeature->trackTableModel(); } + +SidebarModel* Library::sidebarModel() const { + return m_pSidebarModel.get(); +} diff --git a/src/library/library.h b/src/library/library.h index fe9bf0056c13..80399620a75f 100644 --- a/src/library/library.h +++ b/src/library/library.h @@ -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); diff --git a/src/qml/qmllibraryproxy.cpp b/src/qml/qmllibraryproxy.cpp index fec3d21120c4..7a55e8fdddcf 100644 --- a/src/qml/qmllibraryproxy.cpp +++ b/src/qml/qmllibraryproxy.cpp @@ -3,7 +3,9 @@ #include #include "library/library.h" +#include "library/sidebarmodel.h" #include "moc_qmllibraryproxy.cpp" +#include "qmllibraryproxy.h" namespace mixxx { namespace qml { @@ -11,7 +13,8 @@ namespace qml { QmlLibraryProxy::QmlLibraryProxy(std::shared_ptr 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 diff --git a/src/qml/qmllibraryproxy.h b/src/qml/qmllibraryproxy.h index 56bb0f0783e7..6bad436765fd 100644 --- a/src/qml/qmllibraryproxy.h +++ b/src/qml/qmllibraryproxy.h @@ -7,6 +7,7 @@ #include "util/parented_ptr.h" class Library; +class SidebarModel; namespace mixxx { namespace qml { @@ -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 @@ -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