2018-07-14 06:06:33 +00:00
|
|
|
#ifndef AMUSE_EDITOR_WIDGET_HPP
|
|
|
|
#define AMUSE_EDITOR_WIDGET_HPP
|
|
|
|
|
|
|
|
#include <QWidget>
|
2018-07-26 03:41:48 +00:00
|
|
|
#include <QUndoCommand>
|
|
|
|
#include <QApplication>
|
2018-08-06 04:20:42 +00:00
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QWheelEvent>
|
2018-08-09 07:42:17 +00:00
|
|
|
#include <QItemEditorFactory>
|
2018-07-18 07:39:26 +00:00
|
|
|
#include "ProjectModel.hpp"
|
2018-07-14 06:06:33 +00:00
|
|
|
|
|
|
|
class EditorWidget : public QWidget
|
|
|
|
{
|
2018-07-26 03:41:48 +00:00
|
|
|
Q_OBJECT
|
2018-07-14 06:06:33 +00:00
|
|
|
public:
|
|
|
|
explicit EditorWidget(QWidget* parent = Q_NULLPTR);
|
2018-07-18 07:39:26 +00:00
|
|
|
virtual bool valid() const { return true; }
|
2018-07-26 03:41:48 +00:00
|
|
|
virtual void unloadData() {}
|
2018-07-28 04:34:29 +00:00
|
|
|
virtual ProjectModel::INode* currentNode() const { return nullptr; }
|
2018-08-07 07:09:23 +00:00
|
|
|
public slots:
|
|
|
|
virtual bool isItemEditEnabled() const { return false; }
|
|
|
|
virtual void itemCutAction() {}
|
|
|
|
virtual void itemCopyAction() {}
|
|
|
|
virtual void itemPasteAction() {}
|
|
|
|
virtual void itemDeleteAction() {}
|
2018-07-14 06:06:33 +00:00
|
|
|
};
|
|
|
|
|
2018-07-26 03:41:48 +00:00
|
|
|
class EditorUndoCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
protected:
|
2018-07-30 06:20:03 +00:00
|
|
|
amuse::ObjToken<ProjectModel::INode> m_node;
|
2018-07-26 03:41:48 +00:00
|
|
|
enum class Id
|
|
|
|
{
|
|
|
|
SMChangeVal,
|
2018-08-03 03:45:48 +00:00
|
|
|
SampLoop,
|
2018-08-04 02:07:34 +00:00
|
|
|
SampPitch,
|
|
|
|
ADSRAttack,
|
|
|
|
ADSRDecay,
|
|
|
|
ADSRSustain,
|
|
|
|
ADSRAttackAndDecay,
|
|
|
|
ADSRDecayAndSustain,
|
|
|
|
ADSRRelease,
|
|
|
|
ADSRDLS,
|
|
|
|
ADSRVelToAttack,
|
2018-08-04 22:05:01 +00:00
|
|
|
ADSRKeyToDecay,
|
|
|
|
CurveEdit
|
2018-07-26 03:41:48 +00:00
|
|
|
};
|
|
|
|
public:
|
2018-07-30 06:20:03 +00:00
|
|
|
EditorUndoCommand(amuse::ObjToken<ProjectModel::INode> node,
|
2018-07-26 03:41:48 +00:00
|
|
|
const QString& text, QUndoCommand* parent = nullptr)
|
|
|
|
: QUndoCommand(text, parent), m_node(node) {}
|
|
|
|
void undo();
|
|
|
|
void redo();
|
|
|
|
};
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-08-06 04:20:42 +00:00
|
|
|
class FieldSpinBox : public QSpinBox
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit FieldSpinBox(QWidget* parent = Q_NULLPTR)
|
|
|
|
: QSpinBox(parent) {}
|
|
|
|
|
|
|
|
/* Don't scroll */
|
|
|
|
void wheelEvent(QWheelEvent* event) { event->ignore(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class FieldComboBox : public QComboBox
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit FieldComboBox(QWidget* parent = Q_NULLPTR)
|
|
|
|
: QComboBox(parent) {}
|
|
|
|
|
|
|
|
/* Don't scroll */
|
|
|
|
void wheelEvent(QWheelEvent* event) { event->ignore(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class FieldProjectNode : public FieldComboBox
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
ProjectModel::CollectionNode* m_collection;
|
|
|
|
public:
|
|
|
|
explicit FieldProjectNode(ProjectModel::CollectionNode* collection = Q_NULLPTR, QWidget* parent = Q_NULLPTR);
|
|
|
|
void setCollection(ProjectModel::CollectionNode* collection);
|
|
|
|
ProjectModel::CollectionNode* collection() const { return m_collection; }
|
|
|
|
};
|
|
|
|
|
2018-08-09 07:42:17 +00:00
|
|
|
class FieldPageObjectNode : public FieldComboBox
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
ProjectModel::GroupNode* m_group;
|
|
|
|
public:
|
|
|
|
explicit FieldPageObjectNode(ProjectModel::GroupNode* group = Q_NULLPTR, QWidget* parent = Q_NULLPTR);
|
|
|
|
void setGroup(ProjectModel::GroupNode* group);
|
|
|
|
ProjectModel::GroupNode* group() const { return m_group; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class EditorFieldNode : public T
|
|
|
|
{
|
|
|
|
bool m_deferPopupOpen = true;
|
|
|
|
public:
|
|
|
|
using T::T;
|
|
|
|
bool shouldPopupOpen()
|
|
|
|
{
|
|
|
|
bool ret = m_deferPopupOpen;
|
|
|
|
m_deferPopupOpen = false;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using EditorFieldProjectNode = EditorFieldNode<FieldProjectNode>;
|
|
|
|
using EditorFieldPageObjectNode = EditorFieldNode<FieldPageObjectNode>;
|
|
|
|
|
|
|
|
template <int MIN, int MAX>
|
|
|
|
class RangedValueFactory : public QItemEditorFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QWidget* createEditor(int userType, QWidget *parent) const
|
|
|
|
{
|
|
|
|
QSpinBox* sb = new QSpinBox(parent);
|
|
|
|
sb->setFrame(false);
|
|
|
|
sb->setMinimum(MIN);
|
|
|
|
sb->setMaximum(MAX);
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-14 06:06:33 +00:00
|
|
|
#endif //AMUSE_EDITOR_WIDGET_HPP
|