2018-10-07 03:40:25 +00:00
|
|
|
#pragma once
|
2018-07-14 06:06:33 +00:00
|
|
|
|
|
|
|
#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-08-10 06:19:23 +00:00
|
|
|
#include <QToolButton>
|
|
|
|
#include <QAction>
|
2018-08-16 06:26:44 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QLabel>
|
2018-08-26 04:57:02 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QStyledItemDelegate>
|
2018-07-18 07:39:26 +00:00
|
|
|
#include "ProjectModel.hpp"
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class EditorWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
2018-07-14 06:06:33 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit EditorWidget(QWidget* parent = Q_NULLPTR);
|
|
|
|
virtual bool valid() const { return true; }
|
|
|
|
virtual void unloadData() {}
|
|
|
|
virtual ProjectModel::INode* currentNode() const { return nullptr; }
|
|
|
|
virtual void setEditorEnabled(bool en) { setEnabled(en); }
|
|
|
|
virtual AmuseItemEditFlags itemEditFlags() const { return AmuseItemNone; }
|
2018-08-10 06:19:23 +00:00
|
|
|
public slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
virtual void itemCutAction() {}
|
|
|
|
virtual void itemCopyAction() {}
|
|
|
|
virtual void itemPasteAction() {}
|
|
|
|
virtual void itemDeleteAction() {}
|
2018-07-14 06:06:33 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class EditorUndoCommand : public QUndoCommand {
|
2018-07-26 03:41:48 +00:00
|
|
|
protected:
|
2018-12-08 05:20:09 +00:00
|
|
|
amuse::ObjToken<ProjectModel::INode> m_node;
|
|
|
|
enum class Id {
|
|
|
|
SMChangeVal,
|
|
|
|
SampLoop,
|
|
|
|
SampPitch,
|
|
|
|
ADSRAttack,
|
|
|
|
ADSRDecay,
|
|
|
|
ADSRSustain,
|
|
|
|
ADSRAttackAndDecay,
|
|
|
|
ADSRDecayAndSustain,
|
|
|
|
ADSRRelease,
|
|
|
|
ADSRDLS,
|
|
|
|
ADSRVelToAttack,
|
|
|
|
ADSRKeyToDecay,
|
|
|
|
CurveEdit
|
|
|
|
};
|
|
|
|
|
2018-07-26 03:41:48 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
EditorUndoCommand(amuse::ObjToken<ProjectModel::INode> node, const QString& text, QUndoCommand* parent = nullptr)
|
|
|
|
: QUndoCommand(text, parent), m_node(node) {}
|
2019-08-25 04:37:47 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2018-07-26 03:41:48 +00:00
|
|
|
};
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class FieldSpinBox : public QSpinBox {
|
|
|
|
Q_OBJECT
|
2018-08-06 04:20:42 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit FieldSpinBox(QWidget* parent = Q_NULLPTR) : QSpinBox(parent) {}
|
2018-08-06 04:20:42 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
/* Don't scroll */
|
2019-08-25 04:37:47 +00:00
|
|
|
void wheelEvent(QWheelEvent* event) override { event->ignore(); }
|
2018-08-06 04:20:42 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class FieldSlider : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
QSlider m_slider;
|
|
|
|
QLabel m_value;
|
|
|
|
|
2018-08-16 06:26:44 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit FieldSlider(QWidget* parent = Q_NULLPTR);
|
2018-08-16 06:26:44 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
/* Don't scroll */
|
2019-08-25 04:37:47 +00:00
|
|
|
void wheelEvent(QWheelEvent* event) override { event->ignore(); }
|
2018-08-16 06:26:44 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
int value() const { return m_slider.value(); }
|
|
|
|
void setValue(int value) {
|
|
|
|
m_slider.setValue(value);
|
|
|
|
doValueChanged(value);
|
|
|
|
}
|
|
|
|
void setRange(int min, int max) { m_slider.setRange(min, max); }
|
2018-08-16 06:26:44 +00:00
|
|
|
|
|
|
|
private slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void doValueChanged(int value);
|
2018-08-16 06:26:44 +00:00
|
|
|
signals:
|
2018-12-08 05:20:09 +00:00
|
|
|
void valueChanged(int value);
|
2018-08-16 06:26:44 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class FieldDoubleSlider : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
QSlider m_slider;
|
|
|
|
QLabel m_value;
|
|
|
|
double m_min = 0.0;
|
|
|
|
double m_max = 1.0;
|
|
|
|
|
2018-08-16 06:26:44 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit FieldDoubleSlider(QWidget* parent = Q_NULLPTR);
|
2018-08-16 06:26:44 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
/* Don't scroll */
|
2019-08-25 04:37:47 +00:00
|
|
|
void wheelEvent(QWheelEvent* event) override { event->ignore(); }
|
2018-08-16 06:26:44 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
double value() const;
|
|
|
|
void setValue(double value);
|
|
|
|
void setRange(double min, double max);
|
2018-08-16 06:26:44 +00:00
|
|
|
|
|
|
|
private slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void doValueChanged(int value);
|
2018-08-16 06:26:44 +00:00
|
|
|
signals:
|
2018-12-08 05:20:09 +00:00
|
|
|
void valueChanged(double value);
|
2018-08-16 06:26:44 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class FieldComboBox : public QComboBox {
|
|
|
|
Q_OBJECT
|
2018-08-06 04:20:42 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit FieldComboBox(QWidget* parent = Q_NULLPTR) : QComboBox(parent) {}
|
2018-08-06 04:20:42 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
/* Don't scroll */
|
2019-08-25 04:37:47 +00:00
|
|
|
void wheelEvent(QWheelEvent* event) override { event->ignore(); }
|
2018-08-06 04:20:42 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class FieldProjectNode : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
ProjectModel::CollectionNode* m_collection;
|
|
|
|
FieldComboBox m_comboBox;
|
|
|
|
QPushButton m_button;
|
|
|
|
|
2018-08-06 04:20:42 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit FieldProjectNode(ProjectModel::CollectionNode* collection = Q_NULLPTR, QWidget* parent = Q_NULLPTR);
|
|
|
|
void setCollection(ProjectModel::CollectionNode* collection);
|
|
|
|
ProjectModel::CollectionNode* collection() const { return m_collection; }
|
|
|
|
int currentIndex() const { return m_comboBox.currentIndex(); }
|
|
|
|
void setCurrentIndex(int index) { m_comboBox.setCurrentIndex(index); }
|
|
|
|
void showPopup() { m_comboBox.showPopup(); }
|
|
|
|
ProjectModel::BasePoolObjectNode* currentNode() const;
|
2019-08-25 04:37:47 +00:00
|
|
|
bool event(QEvent* ev) override;
|
2018-08-25 08:34:04 +00:00
|
|
|
private slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void _currentIndexChanged(int);
|
2018-08-25 08:34:04 +00:00
|
|
|
public slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void openCurrent();
|
2018-08-25 08:34:04 +00:00
|
|
|
signals:
|
2018-12-08 05:20:09 +00:00
|
|
|
void currentIndexChanged(int);
|
2018-08-06 04:20:42 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class FieldPageObjectNode : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
ProjectModel::GroupNode* m_group;
|
|
|
|
FieldComboBox m_comboBox;
|
|
|
|
QPushButton m_button;
|
|
|
|
|
2018-08-09 07:42:17 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit FieldPageObjectNode(ProjectModel::GroupNode* group = Q_NULLPTR, QWidget* parent = Q_NULLPTR);
|
|
|
|
void setGroup(ProjectModel::GroupNode* group);
|
|
|
|
ProjectModel::GroupNode* group() const { return m_group; }
|
|
|
|
int currentIndex() const { return m_comboBox.currentIndex(); }
|
|
|
|
void setCurrentIndex(int index) { m_comboBox.setCurrentIndex(index); }
|
|
|
|
QModelIndex rootModelIndex() const { return m_comboBox.rootModelIndex(); }
|
|
|
|
void showPopup() { m_comboBox.showPopup(); }
|
|
|
|
ProjectModel::BasePoolObjectNode* currentNode() const;
|
2019-08-25 04:37:47 +00:00
|
|
|
bool event(QEvent* ev) override;
|
2018-08-25 08:34:04 +00:00
|
|
|
private slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void _currentIndexChanged(int);
|
2018-08-25 08:34:04 +00:00
|
|
|
public slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void openCurrent();
|
2018-08-25 08:34:04 +00:00
|
|
|
signals:
|
2018-12-08 05:20:09 +00:00
|
|
|
void currentIndexChanged(int);
|
2018-08-09 07:42:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
2018-12-08 05:20:09 +00:00
|
|
|
class EditorFieldNode : public T {
|
|
|
|
bool m_deferPopupOpen = true;
|
|
|
|
|
2018-08-09 07:42:17 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
using T::T;
|
|
|
|
bool shouldPopupOpen() {
|
|
|
|
bool ret = m_deferPopupOpen;
|
|
|
|
m_deferPopupOpen = false;
|
|
|
|
return ret;
|
|
|
|
}
|
2018-08-09 07:42:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using EditorFieldProjectNode = EditorFieldNode<FieldProjectNode>;
|
|
|
|
using EditorFieldPageObjectNode = EditorFieldNode<FieldPageObjectNode>;
|
|
|
|
|
|
|
|
template <int MIN, int MAX>
|
2018-12-08 05:20:09 +00:00
|
|
|
class RangedValueFactory : public QItemEditorFactory {
|
2018-08-09 07:42:17 +00:00
|
|
|
public:
|
2019-08-25 04:37:47 +00:00
|
|
|
QWidget* createEditor(int userType, QWidget* parent) const override {
|
2018-12-08 05:20:09 +00:00
|
|
|
QSpinBox* sb = new QSpinBox(parent);
|
|
|
|
sb->setFrame(false);
|
|
|
|
sb->setMinimum(MIN);
|
|
|
|
sb->setMaximum(MAX);
|
|
|
|
return sb;
|
|
|
|
}
|
2018-08-09 07:42:17 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class AddRemoveButtons : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
QAction m_addAction;
|
|
|
|
QToolButton m_addButton;
|
|
|
|
QAction m_removeAction;
|
|
|
|
QToolButton m_removeButton;
|
|
|
|
|
2018-08-10 06:19:23 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit AddRemoveButtons(QWidget* parent = Q_NULLPTR);
|
|
|
|
QAction* addAction() { return &m_addAction; }
|
|
|
|
QAction* removeAction() { return &m_removeAction; }
|
2018-08-10 06:19:23 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class ListingDeleteButton : public QPushButton {
|
|
|
|
Q_OBJECT
|
2018-08-16 06:26:44 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit ListingDeleteButton(QWidget* parent = Q_NULLPTR);
|
2019-08-25 04:37:47 +00:00
|
|
|
void enterEvent(QEvent* event) override;
|
|
|
|
void leaveEvent(QEvent* event) override;
|
2018-08-16 06:26:44 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class ContextMenu : public QMenu {
|
2018-08-26 04:57:02 +00:00
|
|
|
public:
|
2019-08-25 04:37:47 +00:00
|
|
|
void hideEvent(QHideEvent* ev) override {
|
2018-12-08 05:20:09 +00:00
|
|
|
QMenu::hideEvent(ev);
|
|
|
|
deleteLater();
|
|
|
|
}
|
2018-08-26 04:57:02 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class BaseObjectDelegate : public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
2018-08-26 04:57:02 +00:00
|
|
|
protected:
|
2018-12-08 05:20:09 +00:00
|
|
|
virtual ProjectModel::INode* getNode(const QAbstractItemModel* model, const QModelIndex& index) const = 0;
|
|
|
|
|
2018-08-26 04:57:02 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit BaseObjectDelegate(QObject* parent = Q_NULLPTR) : QStyledItemDelegate(parent) {}
|
|
|
|
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
|
2019-08-25 04:37:47 +00:00
|
|
|
const QModelIndex& index) override;
|
2018-08-26 04:57:02 +00:00
|
|
|
private slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void doOpenEditor();
|
|
|
|
void doFindUsages();
|
2018-08-26 04:57:02 +00:00
|
|
|
};
|