2018-10-07 03:40:25 +00:00
|
|
|
#pragma once
|
2018-07-18 07:39:26 +00:00
|
|
|
|
|
|
|
#include "EditorWidget.hpp"
|
2018-08-10 06:19:23 +00:00
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
#include <QTableView>
|
|
|
|
#include "amuse/Voice.hpp"
|
2018-07-18 07:39:26 +00:00
|
|
|
|
2018-08-26 04:57:02 +00:00
|
|
|
class SFXObjectDelegate : public BaseObjectDelegate
|
2018-08-10 06:19:23 +00:00
|
|
|
{
|
2018-08-25 08:34:04 +00:00
|
|
|
Q_OBJECT
|
2018-08-26 04:57:02 +00:00
|
|
|
protected:
|
|
|
|
ProjectModel::INode* getNode(const QAbstractItemModel* model, const QModelIndex& index) const;
|
2018-08-10 06:19:23 +00:00
|
|
|
public:
|
|
|
|
explicit SFXObjectDelegate(QObject* parent = Q_NULLPTR);
|
|
|
|
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
|
|
|
void setEditorData(QWidget* editor, const QModelIndex& index) const;
|
|
|
|
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
|
|
|
|
private slots:
|
|
|
|
void objIndexChanged();
|
|
|
|
};
|
|
|
|
|
|
|
|
class SFXModel : public QAbstractTableModel
|
|
|
|
{
|
2018-08-25 08:34:04 +00:00
|
|
|
Q_OBJECT
|
2018-08-10 06:19:23 +00:00
|
|
|
friend class SoundGroupEditor;
|
|
|
|
friend class SFXObjectDelegate;
|
2018-08-14 08:36:02 +00:00
|
|
|
friend class SFXTableView;
|
2018-08-10 06:19:23 +00:00
|
|
|
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) {}
|
2018-08-14 08:36:02 +00:00
|
|
|
ItTp::pointer operator->() const { return m_it.operator->(); }
|
2018-08-10 06:19:23 +00:00
|
|
|
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;
|
|
|
|
public:
|
|
|
|
explicit SFXModel(QObject* parent = Q_NULLPTR);
|
|
|
|
void loadData(ProjectModel::SoundGroupNode* node);
|
|
|
|
void unloadData();
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const;
|
|
|
|
|
2018-08-14 08:36:02 +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
|
|
|
};
|
|
|
|
|
|
|
|
class SFXTableView : public QTableView
|
|
|
|
{
|
2018-08-25 08:34:04 +00:00
|
|
|
Q_OBJECT
|
2018-08-10 06:19:23 +00:00
|
|
|
SFXObjectDelegate m_sfxDelegate;
|
|
|
|
RangedValueFactory<0, 127> m_127Factory;
|
|
|
|
RangedValueFactory<0, 255> m_255Factory;
|
|
|
|
QStyledItemDelegate m_127Delegate, m_255Delegate;
|
|
|
|
public:
|
|
|
|
explicit SFXTableView(QWidget* parent = Q_NULLPTR);
|
|
|
|
void setModel(QAbstractItemModel* model);
|
|
|
|
void deleteSelection();
|
|
|
|
};
|
|
|
|
|
|
|
|
class SFXPlayerWidget : public QWidget
|
2018-07-18 07:39:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-08-10 06:19:23 +00:00
|
|
|
QAction m_playAction;
|
|
|
|
QToolButton m_button;
|
|
|
|
QModelIndex m_index;
|
|
|
|
amuse::GroupId m_groupId;
|
|
|
|
amuse::SFXId m_sfxId;
|
|
|
|
amuse::ObjToken<amuse::Voice> m_vox;
|
|
|
|
public:
|
|
|
|
explicit SFXPlayerWidget(QModelIndex index, amuse::GroupId gid, amuse::SFXId id,
|
|
|
|
QWidget* parent = Q_NULLPTR);
|
|
|
|
~SFXPlayerWidget();
|
|
|
|
amuse::SongId sfxId() const { return m_sfxId; }
|
|
|
|
amuse::Voice* voice() const { return m_vox.get(); }
|
|
|
|
void stopped();
|
|
|
|
void resizeEvent(QResizeEvent* event);
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent* event);
|
2018-08-26 04:57:02 +00:00
|
|
|
void mousePressEvent(QMouseEvent* event);
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event) { event->ignore(); }
|
2018-08-10 06:19:23 +00:00
|
|
|
public slots:
|
|
|
|
void clicked();
|
|
|
|
};
|
|
|
|
|
|
|
|
class SoundGroupEditor : public EditorWidget
|
|
|
|
{
|
2018-08-25 08:34:04 +00:00
|
|
|
Q_OBJECT
|
2018-08-10 06:19:23 +00:00
|
|
|
SFXModel m_sfxs;
|
|
|
|
SFXTableView* m_sfxTable;
|
|
|
|
AddRemoveButtons m_addRemoveButtons;
|
2018-07-18 07:39:26 +00:00
|
|
|
public:
|
2018-07-26 03:41:48 +00:00
|
|
|
explicit SoundGroupEditor(QWidget* parent = Q_NULLPTR);
|
|
|
|
bool loadData(ProjectModel::SoundGroupNode* node);
|
2018-08-10 06:19:23 +00:00
|
|
|
void unloadData();
|
|
|
|
ProjectModel::INode* currentNode() const;
|
|
|
|
void setEditorEnabled(bool en) {}
|
|
|
|
void resizeEvent(QResizeEvent* ev);
|
|
|
|
QTableView* getSFXListView() const { return m_sfxTable; }
|
2018-08-25 08:34:04 +00:00
|
|
|
AmuseItemEditFlags itemEditFlags() const;
|
2018-08-30 20:34:10 +00:00
|
|
|
private slots:
|
|
|
|
void rowsInserted(const QModelIndex &parent, int first, int last);
|
|
|
|
void rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
|
2018-08-10 06:19:23 +00:00
|
|
|
void doAdd();
|
|
|
|
void doSelectionChanged();
|
|
|
|
void sfxDataChanged();
|
|
|
|
void itemDeleteAction();
|
|
|
|
};
|
2018-07-18 07:39:26 +00:00
|
|
|
|