display fixes; initial conversion of sample list to treeview
parent
208d515de0
commit
2db0f5b4ee
|
@ -615,7 +615,7 @@
|
|||
<property name="handleWidth">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QListView" name="sampleList">
|
||||
<widget class="QTreeView" name="sampleList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>1</horstretch>
|
||||
|
@ -637,6 +637,9 @@
|
|||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DropOnly</enum>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="sampleViewPane" native="true">
|
||||
<property name="sizePolicy">
|
||||
|
|
|
@ -193,7 +193,7 @@ void BeatPad::initUI(NodeUIScene* scene) {
|
|||
if (auto f = cfg.find(i); f != cfg.end()) {
|
||||
auto c = f->second;
|
||||
QString n;
|
||||
if (auto smp = c->smp.lock(); smp) n = smp->name;
|
||||
if (auto smp = c->smp.lock(); smp) n = smp->name.section('/', -1, -1);
|
||||
v.push_back({ f->first, qs("%1 %2").arg(Util::noteName(i)).arg(n) });
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ void BeatPad::initUI(NodeUIScene* scene) {
|
|||
auto smp = state->cfg->smp.lock();
|
||||
sampleSelector->setSample(smp);
|
||||
|
||||
noteSelector->setEntry({n, qs("%1 %2").arg(Util::noteName(n)).arg(smp ? smp->name : "")}, false);
|
||||
noteSelector->setEntry({n, qs("%1 %2").arg(Util::noteName(n)).arg(smp ? smp->name.section('/', -1, -1) : "")}, false);
|
||||
};
|
||||
state->setSample = [=](std::shared_ptr<Sample> smp) {
|
||||
state->cfg->smp = smp;
|
||||
|
|
|
@ -21,7 +21,10 @@ DirectoryNode::~DirectoryNode() {
|
|||
void DirectoryNode::sortChildren() {
|
||||
QCollator col;
|
||||
col.setNumericMode(true);
|
||||
std::sort(children.begin(), children.end(), [&col](auto a, auto b) { if (a->isDirectory() && !b->isDirectory()) return true; return col.compare(a->name, b->name) < 0; });
|
||||
std::sort(children.begin(), children.end(), [&col](auto a, auto b) {
|
||||
if (a->isDirectory() != b->isDirectory()) return a->isDirectory();
|
||||
return col.compare(a->name, b->name) < 0;
|
||||
});
|
||||
}
|
||||
|
||||
void DirectoryNode::sortTree() {
|
||||
|
|
|
@ -71,7 +71,7 @@ void SampleSelectorGadget::paint(QPainter* p, const QStyleOptionGraphicsItem* op
|
|||
QString name = qs("(no sample selected)");
|
||||
|
||||
// draw waveforms
|
||||
auto aa = p->renderHints() & QPainter::Antialiasing;
|
||||
//auto aa = p->renderHints() & QPainter::Antialiasing;
|
||||
p->setRenderHint(QPainter::Antialiasing, false);
|
||||
p->setPen(QPen(Config::colorScheme.waveformFgPrimary));
|
||||
if (auto smp = currentSample.lock(); smp) {
|
||||
|
@ -94,7 +94,7 @@ void SampleSelectorGadget::paint(QPainter* p, const QStyleOptionGraphicsItem* op
|
|||
// draw label
|
||||
QFont font("Arcon Rounded", 8);
|
||||
QFontMetrics fm(font);
|
||||
name = fm.elidedText(name, Qt::ElideRight, static_cast<int>(r.width() - 4));
|
||||
name = fm.elidedText(name.section('/', -1, -1), Qt::ElideRight, static_cast<int>(r.width() - 4));
|
||||
QPainterPath path;
|
||||
path.addText(r.bottomLeft() + QPointF(2, -fm.descent()), font, name);
|
||||
|
||||
|
@ -129,13 +129,6 @@ void SampleSelectorGadget::buildSubmenu(DirectoryNode* dir, QMenu* menu) {
|
|||
|
||||
void SampleSelectorGadget::mousePressEvent(QGraphicsSceneMouseEvent* e) {
|
||||
if (!project) return;
|
||||
/*std::vector<std::shared_ptr<Sample>> displayOrder;
|
||||
displayOrder.reserve(static_cast<size_t>(project->samples.size()));
|
||||
for (auto s : project->samples) displayOrder.push_back(s);
|
||||
std::sort(displayOrder.begin(), displayOrder.end(), [](std::shared_ptr<Sample> a, std::shared_ptr<Sample> b) {
|
||||
if (a->name == b->name) return a->uuid < b->uuid;
|
||||
return a->name < b->name;
|
||||
});*/
|
||||
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
auto smp = currentSample.lock();
|
||||
|
@ -149,19 +142,6 @@ void SampleSelectorGadget::mousePressEvent(QGraphicsSceneMouseEvent* e) {
|
|||
root.sortTree();
|
||||
|
||||
buildSubmenu(&root, m);
|
||||
|
||||
/*for (auto s : displayOrder) {
|
||||
auto wa = new QWidgetAction(m);
|
||||
auto wfp = new WaveformPreviewWidget(m);
|
||||
wa->setDefaultWidget(wfp);
|
||||
wfp->showName = true;
|
||||
wfp->highlightable = true;
|
||||
wfp->setSample(s);
|
||||
wfp->setMinimumSize(192, 48);
|
||||
m->addAction(wa);
|
||||
if (s == smp) wa->setDisabled(true);
|
||||
else connect(wa, &QWidgetAction::triggered, [this, s] { setSample(s); });
|
||||
}*/
|
||||
}
|
||||
m->setAttribute(Qt::WA_DeleteOnClose);
|
||||
m->popup(e->screenPos());
|
||||
|
|
|
@ -23,7 +23,7 @@ using namespace Xybrid::Editing;
|
|||
|
||||
#include "mainwindow.h"
|
||||
|
||||
SampleListModel::SampleListModel(QObject* parent, MainWindow* window) : QAbstractListModel (parent) {
|
||||
SampleListModel::SampleListModel(QObject* parent, MainWindow* window) : QAbstractItemModel (parent) {
|
||||
this->window = window;
|
||||
auto view = static_cast<QListView*>(parent);
|
||||
|
||||
|
@ -60,7 +60,7 @@ std::shared_ptr<Sample> SampleListModel::itemAt(const QModelIndex& ind) {
|
|||
}
|
||||
|
||||
void SampleListModel::refresh() {
|
||||
auto view = static_cast<QListView*>(parent());
|
||||
auto view = static_cast<QListView*>(QObject::parent());
|
||||
auto ind = view->currentIndex();
|
||||
QUuid uuid;
|
||||
if (ind.isValid()) uuid = displayOrder[static_cast<size_t>(ind.row())]->uuid;
|
||||
|
@ -80,11 +80,12 @@ void SampleListModel::refresh() {
|
|||
view->setCurrentIndex(index(-1, -1));
|
||||
for (size_t i = 0; i < displayOrder.size(); i++) {
|
||||
auto s = displayOrder[i];
|
||||
if (s->uuid == uuid) { view->setCurrentIndex(index(static_cast<int>(i))); break; }
|
||||
if (s->uuid == uuid) { view->setCurrentIndex(index(static_cast<int>(i), 0)); break; }
|
||||
}
|
||||
}
|
||||
|
||||
int SampleListModel::rowCount(const QModelIndex &parent [[maybe_unused]]) const {
|
||||
if (parent.isValid()) return 0;
|
||||
auto* project = window->getProject().get();
|
||||
if (!project) return 0;
|
||||
return static_cast<int>(project->samples.size());
|
||||
|
@ -122,7 +123,15 @@ bool SampleListModel::setData(const QModelIndex &index, const QVariant &value, i
|
|||
}
|
||||
|
||||
Qt::ItemFlags SampleListModel::flags(const QModelIndex &index) const {
|
||||
return Qt::ItemIsEditable | Qt::ItemIsDropEnabled | QAbstractListModel::flags(index);
|
||||
return Qt::ItemIsEditable | Qt::ItemIsDropEnabled | QAbstractItemModel::flags(index);
|
||||
}
|
||||
|
||||
QModelIndex SampleListModel::index(int row, int column, const QModelIndex &parent) const {
|
||||
return createIndex(row, column);
|
||||
}
|
||||
|
||||
QModelIndex SampleListModel::parent(const QModelIndex& index) const {
|
||||
return this->index(-1, -1);
|
||||
}
|
||||
|
||||
Qt::DropActions SampleListModel::supportedDropActions() const {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
#include "data/project.h"
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace Xybrid::Data {
|
|||
}
|
||||
|
||||
namespace Xybrid::UI {
|
||||
class SampleListModel : public QAbstractListModel {
|
||||
class SampleListModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
// raw pointer because the model's lifetime is dependent on the window
|
||||
|
@ -27,9 +27,11 @@ namespace Xybrid::UI {
|
|||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
|
||||
Qt::ItemFlags flags(const QModelIndex & index) const override;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex& index) const override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
QStringList mimeTypes() const override;
|
||||
|
|
Loading…
Reference in New Issue