From 04ab2bea6d8c95a3e1b080e8287aad9be094dbc7 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Wed, 26 May 2021 16:13:04 +0200 Subject: [PATCH 1/3] QML: Add some initial work on exposing the Library sidebar to QML --- src/library/library.h | 5 +++++ src/skin/qml/qmllibraryproxy.cpp | 5 +++++ src/skin/qml/qmllibraryproxy.h | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/library/library.h b/src/library/library.h index c38ffa9e765..fc6624cc354 100644 --- a/src/library/library.h +++ b/src/library/library.h @@ -76,6 +76,11 @@ class Library: public QObject { /// Needed for exposing models to QML LibraryTableModel* trackTableModel() const; + /// Needed for exposing sidebar to QML + SidebarModel* sidebarModel() const { + return m_pSidebarModel.get(); + } + int getTrackTableRowHeight() const { return m_iTrackTableRowHeight; } diff --git a/src/skin/qml/qmllibraryproxy.cpp b/src/skin/qml/qmllibraryproxy.cpp index 210e0611dbe..ba090be3638 100644 --- a/src/skin/qml/qmllibraryproxy.cpp +++ b/src/skin/qml/qmllibraryproxy.cpp @@ -3,6 +3,7 @@ #include #include "library/library.h" +#include "library/sidebarmodel.h" namespace mixxx { namespace skin { @@ -14,6 +15,10 @@ QmlLibraryProxy::QmlLibraryProxy(std::shared_ptr pLibrary, QObject* par m_pModel(make_parented(m_pLibrary->trackTableModel(), this)) { } +QAbstractItemModel* QmlLibraryProxy::getSidebarModel() { + return m_pLibrary->sidebarModel(); +} + } // namespace qml } // namespace skin } // namespace mixxx diff --git a/src/skin/qml/qmllibraryproxy.h b/src/skin/qml/qmllibraryproxy.h index f2cd72ad9eb..cf921ba1e45 100644 --- a/src/skin/qml/qmllibraryproxy.h +++ b/src/skin/qml/qmllibraryproxy.h @@ -6,6 +6,9 @@ #include "util/parented_ptr.h" class Library; +class SidebarModel; + +QT_FORWARD_DECLARE_CLASS(QAbstractItemModel); namespace mixxx { namespace skin { @@ -20,6 +23,8 @@ class QmlLibraryProxy : public QObject { public: explicit QmlLibraryProxy(std::shared_ptr pLibrary, QObject* parent = nullptr); + Q_INVOKABLE QAbstractItemModel* getSidebarModel(); + private: std::shared_ptr m_pLibrary; parented_ptr m_pModel; From d7230fcb6198bb416e9b534a988040744b763858 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 29 Jun 2021 14:30:15 +0200 Subject: [PATCH 2/3] QML: Add roleNames support to SidebarModel --- src/library/sidebarmodel.cpp | 11 +++++++++++ src/library/sidebarmodel.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/library/sidebarmodel.cpp b/src/library/sidebarmodel.cpp index 40faccd2514..73e8c48764b 100644 --- a/src/library/sidebarmodel.cpp +++ b/src/library/sidebarmodel.cpp @@ -18,6 +18,13 @@ namespace { // been chosen as a compromise between usability and responsiveness. const int kPressedUntilClickedTimeoutMillis = 300; +const QHash kRoleNames = { + // Only roles that are useful in QML are added here. + {Qt::DisplayRole, "display"}, + {Qt::ToolTipRole, "tooltip"}, + {SidebarModel::IconNameRole, "iconName"}, +}; + } // anonymous namespace SidebarModel::SidebarModel( @@ -270,6 +277,10 @@ QVariant SidebarModel::data(const QModelIndex& index, int role) const { } } +QHash SidebarModel::roleNames() const { + return kRoleNames; +} + void SidebarModel::startPressedUntilClickedTimer(const QModelIndex& pressedIndex) { m_pressedIndex = pressedIndex; m_pressedUntilClickedTimer->start(kPressedUntilClickedTimeoutMillis); diff --git a/src/library/sidebarmodel.h b/src/library/sidebarmodel.h index c6d05611ebb..6327fca1333 100644 --- a/src/library/sidebarmodel.h +++ b/src/library/sidebarmodel.h @@ -38,6 +38,7 @@ class SidebarModel : public QAbstractItemModel { int columnCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; bool dropAccept(const QModelIndex& index, const QList& urls, QObject* pSource); bool dragMoveAccept(const QModelIndex& index, const QUrl& url); bool hasChildren(const QModelIndex& parent = QModelIndex()) const override; From e367e61abc9b57041e6b5c05700798724ee84e2d Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sat, 5 Jun 2021 01:06:22 +0200 Subject: [PATCH 3/3] skins/QMLDemo: Add initial support for the sidebar --- res/skins/QMLDemo/Library.qml | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/res/skins/QMLDemo/Library.qml b/res/skins/QMLDemo/Library.qml index 1aca01955a4..1fe9921102d 100644 --- a/res/skins/QMLDemo/Library.qml +++ b/res/skins/QMLDemo/Library.qml @@ -1,6 +1,7 @@ import "." as Skin import Mixxx 0.1 as Mixxx import QtQuick 2.12 +import QtQuick.Controls 1.4 import "Theme" Item { @@ -8,8 +9,40 @@ Item { color: Theme.deckBackgroundColor anchors.fill: parent + TreeView { + id: sidebar + + anchors.top: parent.top + anchors.left: parent.left + anchors.bottom: parent.bottom + anchors.margins: 10 + width: 250 + model: Mixxx.Library.getSidebarModel() + + TableViewColumn { + title: "Icon" + role: "iconName" + width: 50 + + delegate: Image { + fillMode: Image.PreserveAspectFit + source: styleData.value ? "qrc:///images/library/ic_library_" + styleData.value + ".svg" : "" + } + + } + + TableViewColumn { + title: "Title" + role: "display" + } + + } + ListView { - anchors.fill: parent + anchors.top: parent.top + anchors.left: sidebar.right + anchors.right: parent.right + anchors.bottom: parent.bottom anchors.margins: 10 clip: true model: Mixxx.Library.model