Skip to content

Commit

Permalink
Merge pull request #4037 from Holzhaus/qml-sidebar
Browse files Browse the repository at this point in the history
Basic QML Sidebar placeholder
  • Loading branch information
Swiftb0y authored Jul 9, 2021
2 parents 787b8aa + e367e61 commit fce26e2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
35 changes: 34 additions & 1 deletion res/skins/QMLDemo/Library.qml
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import "." as Skin
import Mixxx 0.1 as Mixxx
import QtQuick 2.12
import QtQuick.Controls 1.4
import "Theme"

Item {
Rectangle {
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
Expand Down
5 changes: 5 additions & 0 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/library/sidebarmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ namespace {
// been chosen as a compromise between usability and responsiveness.
const int kPressedUntilClickedTimeoutMillis = 300;

const QHash<int, QByteArray> kRoleNames = {
// Only roles that are useful in QML are added here.
{Qt::DisplayRole, "display"},
{Qt::ToolTipRole, "tooltip"},
{SidebarModel::IconNameRole, "iconName"},
};

} // anonymous namespace

SidebarModel::SidebarModel(
Expand Down Expand Up @@ -270,6 +277,10 @@ QVariant SidebarModel::data(const QModelIndex& index, int role) const {
}
}

QHash<int, QByteArray> SidebarModel::roleNames() const {
return kRoleNames;
}

void SidebarModel::startPressedUntilClickedTimer(const QModelIndex& pressedIndex) {
m_pressedIndex = pressedIndex;
m_pressedUntilClickedTimer->start(kPressedUntilClickedTimeoutMillis);
Expand Down
1 change: 1 addition & 0 deletions src/library/sidebarmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, QByteArray> roleNames() const override;
bool dropAccept(const QModelIndex& index, const QList<QUrl>& urls, QObject* pSource);
bool dragMoveAccept(const QModelIndex& index, const QUrl& url);
bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
Expand Down
5 changes: 5 additions & 0 deletions src/skin/qml/qmllibraryproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QAbstractItemModel>

#include "library/library.h"
#include "library/sidebarmodel.h"

namespace mixxx {
namespace skin {
Expand All @@ -14,6 +15,10 @@ QmlLibraryProxy::QmlLibraryProxy(std::shared_ptr<Library> pLibrary, QObject* par
m_pModel(make_parented<QmlLibraryTrackListModel>(m_pLibrary->trackTableModel(), this)) {
}

QAbstractItemModel* QmlLibraryProxy::getSidebarModel() {
return m_pLibrary->sidebarModel();
}

} // namespace qml
} // namespace skin
} // namespace mixxx
5 changes: 5 additions & 0 deletions src/skin/qml/qmllibraryproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "util/parented_ptr.h"

class Library;
class SidebarModel;

QT_FORWARD_DECLARE_CLASS(QAbstractItemModel);

namespace mixxx {
namespace skin {
Expand All @@ -20,6 +23,8 @@ class QmlLibraryProxy : public QObject {
public:
explicit QmlLibraryProxy(std::shared_ptr<Library> pLibrary, QObject* parent = nullptr);

Q_INVOKABLE QAbstractItemModel* getSidebarModel();

private:
std::shared_ptr<Library> m_pLibrary;
parented_ptr<QmlLibraryTrackListModel> m_pModel;
Expand Down

0 comments on commit fce26e2

Please sign in to comment.