2018-10-07 03:40:25 +00:00
|
|
|
#pragma once
|
2018-07-18 07:39:26 +00:00
|
|
|
|
2019-08-28 00:51:38 +00:00
|
|
|
#include <tuple>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <QAction>
|
2018-08-10 06:19:23 +00:00
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
#include <QTableView>
|
2019-08-28 00:51:38 +00:00
|
|
|
#include <QToolButton>
|
|
|
|
|
|
|
|
#include "EditorWidget.hpp"
|
|
|
|
#include "ProjectModel.hpp"
|
|
|
|
|
|
|
|
#include <amuse/AudioGroupProject.hpp>
|
|
|
|
#include <amuse/Common.hpp>
|
|
|
|
#include <amuse/Voice.hpp>
|
2018-07-18 07:39:26 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class SFXObjectDelegate : public BaseObjectDelegate {
|
|
|
|
Q_OBJECT
|
2018-08-26 04:57:02 +00:00
|
|
|
protected:
|
2019-08-25 04:37:47 +00:00
|
|
|
ProjectModel::INode* getNode(const QAbstractItemModel* model, const QModelIndex& index) const override;
|
2018-12-08 05:20:09 +00:00
|
|
|
|
2018-08-10 06:19:23 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit SFXObjectDelegate(QObject* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~SFXObjectDelegate() override;
|
|
|
|
|
2019-08-25 04:37:47 +00:00
|
|
|
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
|
|
|
void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
|
|
|
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
2019-08-28 00:51:38 +00:00
|
|
|
|
2018-08-10 06:19:23 +00:00
|
|
|
private slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void objIndexChanged();
|
2018-08-10 06:19:23 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class SFXModel : public QAbstractTableModel {
|
|
|
|
Q_OBJECT
|
|
|
|
friend class SoundGroupEditor;
|
|
|
|
friend class SFXObjectDelegate;
|
|
|
|
friend class SFXTableView;
|
|
|
|
amuse::ObjToken<ProjectModel::SoundGroupNode> m_node;
|
|
|
|
struct Iterator {
|
|
|
|
using ItTp = std::unordered_map<amuse::SFXId, amuse::SFXGroupIndex::SFXEntry>::iterator;
|
|
|
|
ItTp m_it;
|
|
|
|
Iterator(ItTp it) : m_it(it) {}
|
|
|
|
ItTp::pointer operator->() const { return m_it.operator->(); }
|
|
|
|
bool operator<(const Iterator& other) const {
|
|
|
|
return amuse::SFXId::CurNameDB->resolveNameFromId(m_it->first) <
|
|
|
|
amuse::SFXId::CurNameDB->resolveNameFromId(other.m_it->first);
|
|
|
|
}
|
|
|
|
bool operator<(amuse::SongId other) const {
|
|
|
|
return amuse::SFXId::CurNameDB->resolveNameFromId(m_it->first) <
|
|
|
|
amuse::SFXId::CurNameDB->resolveNameFromId(other);
|
|
|
|
}
|
|
|
|
bool operator<(const std::string& name) const {
|
|
|
|
return amuse::SFXId::CurNameDB->resolveNameFromId(m_it->first) < name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
std::vector<Iterator> m_sorted;
|
|
|
|
std::unordered_map<amuse::SFXId, amuse::SFXGroupIndex::SFXEntry>& _getMap() const;
|
|
|
|
void _buildSortedList();
|
|
|
|
QModelIndex _indexOfSFX(amuse::SFXId sfx) const;
|
|
|
|
int _hypotheticalIndexOfSFX(const std::string& sfxName) const;
|
|
|
|
|
2018-08-10 06:19:23 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit SFXModel(QObject* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~SFXModel() override;
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
void loadData(ProjectModel::SoundGroupNode* node);
|
|
|
|
void unloadData();
|
2018-08-10 06:19:23 +00:00
|
|
|
|
2019-08-25 04:37:47 +00:00
|
|
|
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;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
2018-08-10 06:19:23 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
int _insertRow(const std::tuple<amuse::SFXId, std::string, amuse::SFXGroupIndex::SFXEntry>& data);
|
|
|
|
std::tuple<amuse::SFXId, std::string, amuse::SFXGroupIndex::SFXEntry> _removeRow(amuse::SFXId sfx);
|
2018-08-10 06:19:23 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class SFXTableView : public QTableView {
|
|
|
|
Q_OBJECT
|
|
|
|
SFXObjectDelegate m_sfxDelegate;
|
|
|
|
RangedValueFactory<0, 127> m_127Factory;
|
|
|
|
RangedValueFactory<0, 255> m_255Factory;
|
|
|
|
QStyledItemDelegate m_127Delegate, m_255Delegate;
|
|
|
|
|
2018-08-10 06:19:23 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit SFXTableView(QWidget* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~SFXTableView() override;
|
|
|
|
|
2019-08-25 04:37:47 +00:00
|
|
|
void setModel(QAbstractItemModel* model) override;
|
2018-12-08 05:20:09 +00:00
|
|
|
void deleteSelection();
|
2018-08-10 06:19:23 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class SFXPlayerWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
QAction m_playAction;
|
|
|
|
QToolButton m_button;
|
|
|
|
QModelIndex m_index;
|
|
|
|
amuse::GroupId m_groupId;
|
|
|
|
amuse::SFXId m_sfxId;
|
|
|
|
amuse::ObjToken<amuse::Voice> m_vox;
|
|
|
|
|
2018-08-10 06:19:23 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit SFXPlayerWidget(QModelIndex index, amuse::GroupId gid, amuse::SFXId id, QWidget* parent = Q_NULLPTR);
|
2019-08-25 04:37:47 +00:00
|
|
|
~SFXPlayerWidget() override;
|
2018-12-08 05:20:09 +00:00
|
|
|
amuse::SongId sfxId() const { return m_sfxId; }
|
|
|
|
amuse::Voice* voice() const { return m_vox.get(); }
|
|
|
|
void stopped();
|
2019-08-25 04:37:47 +00:00
|
|
|
void resizeEvent(QResizeEvent* event) override;
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent* event) override;
|
|
|
|
void mousePressEvent(QMouseEvent* event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event) override { event->ignore(); }
|
2018-08-10 06:19:23 +00:00
|
|
|
public slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void clicked();
|
2018-08-10 06:19:23 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class SoundGroupEditor : public EditorWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
SFXModel m_sfxs;
|
|
|
|
SFXTableView* m_sfxTable;
|
|
|
|
AddRemoveButtons m_addRemoveButtons;
|
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit SoundGroupEditor(QWidget* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~SoundGroupEditor() override;
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
bool loadData(ProjectModel::SoundGroupNode* node);
|
2019-08-25 04:37:47 +00:00
|
|
|
void unloadData() override;
|
|
|
|
ProjectModel::INode* currentNode() const override;
|
|
|
|
void setEditorEnabled(bool en) override {}
|
|
|
|
void resizeEvent(QResizeEvent* ev) override;
|
2018-12-08 05:20:09 +00:00
|
|
|
QTableView* getSFXListView() const { return m_sfxTable; }
|
2019-08-25 04:37:47 +00:00
|
|
|
AmuseItemEditFlags itemEditFlags() const override;
|
2019-08-28 00:51:38 +00:00
|
|
|
|
2018-08-30 20:34:10 +00:00
|
|
|
private slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void rowsInserted(const QModelIndex& parent, int first, int last);
|
|
|
|
void rowsMoved(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row);
|
|
|
|
void doAdd();
|
|
|
|
void doSelectionChanged();
|
|
|
|
void sfxDataChanged();
|
2019-08-25 04:37:47 +00:00
|
|
|
void itemDeleteAction() override;
|
2018-08-10 06:19:23 +00:00
|
|
|
};
|