2018-07-09 18:05:31 +00:00
|
|
|
#ifndef AMUSE_LAYERS_EDITOR_HPP
|
|
|
|
#define AMUSE_LAYERS_EDITOR_HPP
|
|
|
|
|
2018-07-14 06:06:33 +00:00
|
|
|
#include "EditorWidget.hpp"
|
2018-08-07 07:09:23 +00:00
|
|
|
#include <QAbstractTableModel>
|
|
|
|
#include <QTableView>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QToolButton>
|
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
|
|
|
|
class SoundMacroDelegate : public QStyledItemDelegate
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit SoundMacroDelegate(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 smIndexChanged();
|
|
|
|
};
|
|
|
|
|
|
|
|
class LayersModel : public QAbstractTableModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
friend class LayersEditor;
|
|
|
|
friend class SoundMacroDelegate;
|
2018-08-14 08:36:02 +00:00
|
|
|
friend class LayersTableView;
|
2018-08-07 07:09:23 +00:00
|
|
|
amuse::ObjToken<ProjectModel::LayersNode> m_node;
|
|
|
|
public:
|
|
|
|
explicit LayersModel(QObject* parent = Q_NULLPTR);
|
|
|
|
void loadData(ProjectModel::LayersNode* 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;
|
|
|
|
Qt::DropActions supportedDropActions() const;
|
|
|
|
Qt::DropActions supportedDragActions() const;
|
|
|
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|
|
|
int row, int column, const QModelIndex &parent);
|
|
|
|
|
|
|
|
bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
|
|
|
bool moveRows(const QModelIndex& sourceParent, int sourceRow, int count,
|
|
|
|
const QModelIndex& destinationParent, int destinationChild);
|
|
|
|
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
2018-08-14 08:36:02 +00:00
|
|
|
|
|
|
|
void _insertRow(int row, const amuse::LayerMapping& data);
|
|
|
|
amuse::LayerMapping _removeRow(int row);
|
2018-08-07 07:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class LayersTableView : public QTableView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-08-09 07:42:17 +00:00
|
|
|
SoundMacroDelegate m_smDelegate;
|
|
|
|
RangedValueFactory<-128, 127> m_signedFactory;
|
|
|
|
RangedValueFactory<0, 127> m_unsignedFactory;
|
|
|
|
QStyledItemDelegate m_signedDelegate, m_unsignedDelegate;
|
2018-08-07 07:09:23 +00:00
|
|
|
public:
|
|
|
|
explicit LayersTableView(QWidget* parent = Q_NULLPTR);
|
2018-08-09 07:42:17 +00:00
|
|
|
void setModel(QAbstractItemModel* model);
|
2018-08-07 07:09:23 +00:00
|
|
|
void deleteSelection();
|
|
|
|
};
|
2018-07-09 18:05:31 +00:00
|
|
|
|
2018-07-14 06:06:33 +00:00
|
|
|
class LayersEditor : public EditorWidget
|
2018-07-09 18:05:31 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-08-14 08:36:02 +00:00
|
|
|
friend class LayersModel;
|
2018-08-07 07:09:23 +00:00
|
|
|
LayersModel m_model;
|
|
|
|
LayersTableView m_tableView;
|
2018-08-10 06:19:23 +00:00
|
|
|
AddRemoveButtons m_addRemoveButtons;
|
2018-07-09 18:05:31 +00:00
|
|
|
public:
|
2018-07-26 03:41:48 +00:00
|
|
|
explicit LayersEditor(QWidget* parent = Q_NULLPTR);
|
|
|
|
bool loadData(ProjectModel::LayersNode* node);
|
2018-08-07 07:09:23 +00:00
|
|
|
void unloadData();
|
|
|
|
ProjectModel::INode* currentNode() const;
|
|
|
|
void resizeEvent(QResizeEvent* ev);
|
2018-08-25 08:34:04 +00:00
|
|
|
AmuseItemEditFlags itemEditFlags() const;
|
2018-08-07 07:09:23 +00:00
|
|
|
public slots:
|
|
|
|
void doAdd();
|
2018-08-10 06:19:23 +00:00
|
|
|
void doSelectionChanged();
|
2018-08-07 07:09:23 +00:00
|
|
|
void itemDeleteAction();
|
|
|
|
};
|
2018-07-09 18:05:31 +00:00
|
|
|
|
|
|
|
#endif //AMUSE_LAYERS_EDITOR_HPP
|