diff --git a/DrumMachine.pro b/DrumMachine.pro index 98bedcb..09cf081 100755 --- a/DrumMachine.pro +++ b/DrumMachine.pro @@ -26,6 +26,7 @@ SOURCES += \ loopstationjsonconverters.cpp \ loopstationpresets.cpp \ loopstationpresetsmodel.cpp \ + loopstationpresettagsmodel.cpp \ main.cpp \ midicontainers.cpp \ midiinwrapper.cpp \ @@ -37,6 +38,7 @@ SOURCES += \ widgets/drumpadsampleswidget.cpp \ widgets/drumpadsamplewidget.cpp \ widgets/drumpadwidget.cpp \ + widgets/loopstationpresetdetailwidget.cpp \ widgets/loopstationwidget.cpp \ widgets/mainwindow.cpp \ widgets/midibutton.cpp \ @@ -62,6 +64,7 @@ HEADERS += \ loopstationjsonconverters.h \ loopstationpresets.h \ loopstationpresetsmodel.h \ + loopstationpresettagsmodel.h \ midicontainers.h \ midiinwrapper.h \ midioutwrapper.h \ @@ -72,6 +75,7 @@ HEADERS += \ widgets/drumpadsampleswidget.h \ widgets/drumpadsamplewidget.h \ widgets/drumpadwidget.h \ + widgets/loopstationpresetdetailwidget.h \ widgets/loopstationwidget.h \ widgets/mainwindow.h \ widgets/midibutton.h \ @@ -88,6 +92,7 @@ FORMS += \ widgets/drumpadsampleswidget.ui \ widgets/drumpadsamplewidget.ui \ widgets/drumpadwidget.ui \ + widgets/loopstationpresetdetailwidget.ui \ widgets/loopstationwidget.ui \ widgets/mainwindow.ui \ widgets/sequencerwidget.ui \ diff --git a/drumpadpresettagsmodel.cpp b/drumpadpresettagsmodel.cpp index 1d71f8a..07fa38d 100644 --- a/drumpadpresettagsmodel.cpp +++ b/drumpadpresettagsmodel.cpp @@ -1,5 +1,7 @@ #include "drumpadpresettagsmodel.h" +#include "drumpadpresets.h" + DrumPadPresetTagsModel::DrumPadPresetTagsModel(QObject *parent) : QAbstractListModel{parent} { diff --git a/drumpadpresettagsmodel.h b/drumpadpresettagsmodel.h index b9be164..115dc8f 100644 --- a/drumpadpresettagsmodel.h +++ b/drumpadpresettagsmodel.h @@ -2,8 +2,6 @@ #include -#include "drumpadpresets.h" - namespace drumpad_presets { struct Preset; } class DrumPadPresetTagsModel : public QAbstractListModel diff --git a/loopstationpresets.cpp b/loopstationpresets.cpp index c633ae9..79fde15 100644 --- a/loopstationpresets.cpp +++ b/loopstationpresets.cpp @@ -1,2 +1 @@ #include "loopstationpresets.h" - diff --git a/loopstationpresettagsmodel.cpp b/loopstationpresettagsmodel.cpp new file mode 100644 index 0000000..4863057 --- /dev/null +++ b/loopstationpresettagsmodel.cpp @@ -0,0 +1,43 @@ +#include "loopstationpresettagsmodel.h" + +#include "loopstationpresets.h" + +LoopStationPresetTagsModel::LoopStationPresetTagsModel(QObject *parent) : + QAbstractListModel{parent} +{ +} + +void LoopStationPresetTagsModel::setPreset(const loopstation_presets::Preset &preset) +{ + beginResetModel(); + if (preset.tags) + m_tags = *preset.tags; + else + m_tags.clear(); + endResetModel(); +} + +int LoopStationPresetTagsModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return m_tags.size(); +} + +QVariant LoopStationPresetTagsModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return {}; + + if (index.row() < 0 || index.row() >= int(m_tags.size())) + return {}; + + switch (role) + { + case Qt::DisplayRole: + case Qt::EditRole: + return m_tags[index.row()]; + } + + return {}; +} diff --git a/loopstationpresettagsmodel.h b/loopstationpresettagsmodel.h new file mode 100644 index 0000000..58c92d9 --- /dev/null +++ b/loopstationpresettagsmodel.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace loopstation_presets { struct Preset; } + +class LoopStationPresetTagsModel : public QAbstractListModel +{ +public: + LoopStationPresetTagsModel(QObject *parent = nullptr); + + void setPreset(const loopstation_presets::Preset &preset); + + int rowCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + +private: + std::vector m_tags; +}; diff --git a/widgets/drumpadpresetdetailwidget.ui b/widgets/drumpadpresetdetailwidget.ui index a8d48f8..f408f47 100755 --- a/widgets/drumpadpresetdetailwidget.ui +++ b/widgets/drumpadpresetdetailwidget.ui @@ -128,6 +128,9 @@ tags: + + listViewTags + @@ -479,7 +482,11 @@ - + + + false + + diff --git a/widgets/loopstationpresetdetailwidget.cpp b/widgets/loopstationpresetdetailwidget.cpp new file mode 100644 index 0000000..77f3f6b --- /dev/null +++ b/widgets/loopstationpresetdetailwidget.cpp @@ -0,0 +1,50 @@ +#include "loopstationpresetdetailwidget.h" +#include "ui_loopstationpresetdetailwidget.h" + +#include "loopstationpresets.h" + +LoopStationPresetDetailWidget::LoopStationPresetDetailWidget(QWidget *parent) : + QScrollArea{parent}, + m_ui{std::make_unique()} +{ + m_ui->setupUi(this); + + m_ui->listViewTags->setModel(&m_tagsModel); +} + +LoopStationPresetDetailWidget::~LoopStationPresetDetailWidget() = default; + +void LoopStationPresetDetailWidget::setPreset(const loopstation_presets::Preset &preset) +{ + constexpr const auto applyField = [](QWidget *edit, const auto &field){ + edit->setEnabled(field.has_value()); + edit->setVisible(field.has_value()); + }; + constexpr const auto applyLineEdit = [applyField](QLineEdit *edit, const auto &field){ + applyField(edit, field); + edit->setText(field ? *field : QString{}); + }; + constexpr const auto applySpinBox = [applyField](QSpinBox *edit, const auto &field){ + applyField(edit, field); + edit->setValue(field ? *field : -1); + }; + constexpr const auto applyCheckBox = [applyField](QCheckBox *edit, const auto &field){ + applyField(edit, field); + edit->setChecked(field ? *field : false); + }; + + applyLineEdit(m_ui->lineEditId, preset.id); + applyLineEdit(m_ui->lineEditTitle, preset.title); + applyLineEdit(m_ui->lineEditAudioPreviewUrl, preset.audioPreviewUrl); + applyLineEdit(m_ui->lineEditAuthor, preset.author); + applySpinBox(m_ui->spinBoxBpm, preset.bpm); + // TODO lessons + applyLineEdit(m_ui->lineEditCoverUrl, preset.coverUrl); + applySpinBox(m_ui->spinBoxLoopLength, preset.loopLength); + applyLineEdit(m_ui->lineEditOrderBy, preset.orderBy); + // TODO pads + applyCheckBox(m_ui->checkBoxPremium, preset.premium); + applyCheckBox(m_ui->checkBoxDeleted, preset.DELETED); + + m_tagsModel.setPreset(preset); +} diff --git a/widgets/loopstationpresetdetailwidget.h b/widgets/loopstationpresetdetailwidget.h new file mode 100644 index 0000000..5eff07b --- /dev/null +++ b/widgets/loopstationpresetdetailwidget.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include + +#include "loopstationpresettagsmodel.h" + +namespace Ui { class LoopStationPresetDetailWidget; } +namespace loopstation_presets { struct Preset; } + +class LoopStationPresetDetailWidget : public QScrollArea +{ + Q_OBJECT + +public: + explicit LoopStationPresetDetailWidget(QWidget *parent = nullptr); + ~LoopStationPresetDetailWidget() override; + + void setPreset(const loopstation_presets::Preset &preset); + +private: + const std::unique_ptr m_ui; + + LoopStationPresetTagsModel m_tagsModel; +}; diff --git a/widgets/loopstationpresetdetailwidget.ui b/widgets/loopstationpresetdetailwidget.ui new file mode 100644 index 0000000..df351da --- /dev/null +++ b/widgets/loopstationpresetdetailwidget.ui @@ -0,0 +1,255 @@ + + + LoopStationPresetDetailWidget + + + + 0 + 0 + 431 + 640 + + + + true + + + + + 0 + 0 + 429 + 638 + + + + + + + id: + + + lineEditId + + + + + + + false + + + true + + + + + + + audioPreviewUrl: + + + lineEditAudioPreviewUrl + + + + + + + author: + + + lineEditAuthor + + + + + + + bpm: + + + spinBoxBpm + + + + + + + coverUrl: + + + lineEditCoverUrl + + + + + + + loopLength: + + + spinBoxLoopLength + + + + + + + orderBy: + + + lineEditOrderBy + + + + + + + premium: + + + checkBoxPremium + + + + + + + tags: + + + listViewTags + + + + + + + title: + + + lineEditTitle + + + + + + + DELETED: + + + checkBoxDeleted + + + + + + + false + + + true + + + + + + + false + + + true + + + + + + + false + + + true + + + + + + + false + + + + + + + false + + + true + + + + + + + false + + + + + + + false + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + false + + + CheckBox + + + + + + + false + + + + + + + false + + + CheckBox + + + + + + + + + diff --git a/widgets/loopstationwidget.cpp b/widgets/loopstationwidget.cpp index 547070e..a76e5c3 100644 --- a/widgets/loopstationwidget.cpp +++ b/widgets/loopstationwidget.cpp @@ -90,6 +90,8 @@ void LoopStationWidget::currentRowChanged(const QModelIndex ¤t) m_settings->setLoopstationLastPresetId(preset.id ? *preset.id : QString{}); else qWarning() << "no settings available"; + + m_ui->presetDetailWidget->setPreset(preset); } void LoopStationWidget::loadPresets() diff --git a/widgets/loopstationwidget.ui b/widgets/loopstationwidget.ui index 15364b2..c8704bd 100644 --- a/widgets/loopstationwidget.ui +++ b/widgets/loopstationwidget.ui @@ -75,6 +75,15 @@ + + + + + Properties + + + + @@ -99,6 +108,12 @@ QPushButton
widgets/midibutton.h
+ + LoopStationPresetDetailWidget + QWidget +
widgets/loopstationpresetdetailwidget.h
+ 1 +