amuse/Editor/SoundMacroEditor.hpp

219 lines
6.5 KiB
C++
Raw Normal View History

#ifndef AMUSE_SOUND_MACRO_EDITOR_HPP
#define AMUSE_SOUND_MACRO_EDITOR_HPP
#include "EditorWidget.hpp"
#include <QStaticText>
2018-07-22 03:45:47 +00:00
#include <QVBoxLayout>
#include <QPropertyAnimation>
#include <QSplitter>
#include <QLabel>
#include <QMouseEvent>
#include <QSpinBox>
2018-07-25 06:01:01 +00:00
#include <QComboBox>
#include <QTreeWidget>
#include <QPushButton>
2018-07-22 03:45:47 +00:00
2018-07-28 04:34:29 +00:00
class SoundMacroEditor;
2018-07-22 03:45:47 +00:00
class SoundMacroListing;
class CatalogueItem;
class FieldSpinBox : public QSpinBox
{
Q_OBJECT
public:
2018-07-28 04:34:29 +00:00
explicit FieldSpinBox(QWidget* parent = Q_NULLPTR)
2018-07-22 03:45:47 +00:00
: QSpinBox(parent) {}
/* Don't scroll */
void wheelEvent(QWheelEvent* event) { event->ignore(); }
};
2018-07-25 06:01:01 +00:00
class FieldComboBox : public QComboBox
{
2018-07-28 04:34:29 +00:00
Q_OBJECT
2018-07-25 06:01:01 +00:00
public:
2018-07-28 04:34:29 +00:00
explicit FieldComboBox(QWidget* parent = Q_NULLPTR)
2018-07-25 06:01:01 +00:00
: QComboBox(parent) {}
/* Don't scroll */
void wheelEvent(QWheelEvent* event) { event->ignore(); }
};
2018-07-28 04:34:29 +00:00
class FieldProjectNode : public FieldComboBox
{
Q_OBJECT
ProjectModel::CollectionNode* m_collection;
public:
explicit FieldProjectNode(ProjectModel::CollectionNode* collection, QWidget* parent = Q_NULLPTR);
ProjectModel::CollectionNode* collection() const { return m_collection; }
};
class TargetButton : public QPushButton
{
Q_OBJECT
public:
explicit TargetButton(QWidget* parent = Q_NULLPTR);
void mouseReleaseEvent(QMouseEvent* event) { event->ignore(); }
void mouseMoveEvent(QMouseEvent* event) { event->ignore(); }
};
class FieldSoundMacroStep : public QWidget
{
friend class CommandWidget;
Q_OBJECT
FieldProjectNode* m_macroField;
FieldSpinBox m_spinBox;
TargetButton m_targetButton;
SoundMacroEditor* getEditor() const;
SoundMacroListing* getListing() const;
signals:
void valueChanged(int);
public slots:
void targetPressed();
void updateMacroField();
public:
explicit FieldSoundMacroStep(FieldProjectNode* macroField = Q_NULLPTR, QWidget* parent = Q_NULLPTR);
~FieldSoundMacroStep();
void setIndex(int index);
void cancel();
};
class CommandWidget : public QWidget
{
2018-07-22 03:45:47 +00:00
Q_OBJECT
friend class SoundMacroListing;
QFont m_numberFont;
QLabel m_titleLabel;
QPushButton m_deleteButton;
QStaticText m_numberText;
int m_index = -1;
2018-07-22 03:45:47 +00:00
amuse::SoundMacro::ICmd* m_cmd;
const amuse::SoundMacro::CmdIntrospection* m_introspection;
2018-07-28 04:34:29 +00:00
FieldSoundMacroStep* m_stepField = nullptr;
2018-07-22 03:45:47 +00:00
void setIndex(int index);
SoundMacroListing* getParent() const;
2018-07-22 03:45:47 +00:00
private slots:
void boolChanged(int);
void numChanged(int);
2018-07-28 04:34:29 +00:00
void nodeChanged(int);
void deleteClicked();
2018-07-22 03:45:47 +00:00
private:
2018-07-28 04:34:29 +00:00
CommandWidget(amuse::SoundMacro::ICmd* cmd, amuse::SoundMacro::CmdOp op, SoundMacroListing* listing);
public:
2018-07-28 04:34:29 +00:00
CommandWidget(amuse::SoundMacro::ICmd* cmd, SoundMacroListing* listing);
CommandWidget(amuse::SoundMacro::CmdOp op, SoundMacroListing* listing);
void paintEvent(QPaintEvent* event);
QString getText() const { return m_titleLabel.text(); }
};
class CommandWidgetContainer : public QWidget
{
Q_OBJECT
friend class SoundMacroListing;
CommandWidget* m_commandWidget;
QPropertyAnimation* m_animation = nullptr;
void animateOpen();
void animateClosed();
void snapOpen();
void snapClosed();
private slots:
void animationDestroyed();
public:
CommandWidgetContainer(CommandWidget* child, QWidget* parent = Q_NULLPTR);
2018-07-22 03:45:47 +00:00
};
class SoundMacroListing : public QWidget
{
Q_OBJECT
friend class CommandWidget;
friend class SoundMacroEditor;
2018-07-30 06:20:03 +00:00
amuse::ObjToken<ProjectModel::SoundMacroNode> m_node;
2018-07-22 03:45:47 +00:00
QVBoxLayout* m_layout;
QLayoutItem* m_dragItem = nullptr;
int m_origIdx = -1;
int m_dragOpenIdx = -1;
CommandWidgetContainer* m_prevDragOpen = nullptr;
2018-07-22 03:45:47 +00:00
int m_autoscrollTimer = -1;
int m_autoscrollDelta = 0;
QWidget* m_autoscrollSource = nullptr;
QMouseEvent m_autoscrollEvent = {{}, {}, {}, {}, {}};
void startAutoscroll(QWidget* source, QMouseEvent* event, int delta);
void stopAutoscroll();
bool beginDrag(CommandWidget* widget);
void endDrag();
2018-07-22 03:45:47 +00:00
void cancelDrag();
void _moveDrag(int hoverIdx, const QPoint& pt, QWidget* source, QMouseEvent* event);
void moveDrag(CommandWidget* widget, const QPoint& pt, QWidget* source, QMouseEvent* event);
int moveInsertDrag(const QPoint& pt, QWidget* source, QMouseEvent* event);
void insertDragout();
void insert(amuse::SoundMacro::CmdOp op, const QString& text);
void deleteCommand(int index);
2018-07-22 03:45:47 +00:00
void reindex();
void clear();
2018-07-22 03:45:47 +00:00
public:
explicit SoundMacroListing(QWidget* parent = Q_NULLPTR);
bool loadData(ProjectModel::SoundMacroNode* node);
void unloadData();
2018-07-28 04:34:29 +00:00
ProjectModel::INode* currentNode() const;
2018-07-22 03:45:47 +00:00
void timerEvent(QTimerEvent* event);
};
class CatalogueItem : public QWidget
{
Q_OBJECT
amuse::SoundMacro::CmdOp m_op;
QLabel m_iconLab;
QLabel m_label;
2018-07-22 03:45:47 +00:00
public:
explicit CatalogueItem(amuse::SoundMacro::CmdOp op, const QString& name,
const QString& doc, QWidget* parent = Q_NULLPTR);
explicit CatalogueItem(const CatalogueItem& other, QWidget* parent = Q_NULLPTR);
amuse::SoundMacro::CmdOp getCmdOp() const { return m_op; }
QString getText() const { return m_label.text(); }
2018-07-22 03:45:47 +00:00
};
2018-07-25 06:01:01 +00:00
class SoundMacroCatalogue : public QTreeWidget
2018-07-22 03:45:47 +00:00
{
Q_OBJECT
public:
explicit SoundMacroCatalogue(QWidget* parent = Q_NULLPTR);
2018-07-25 06:01:01 +00:00
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
};
class SoundMacroEditor : public EditorWidget
{
Q_OBJECT
2018-07-25 06:01:01 +00:00
friend class SoundMacroCatalogue;
2018-07-28 04:34:29 +00:00
friend class FieldSoundMacroStep;
2018-07-22 03:45:47 +00:00
QSplitter* m_splitter;
SoundMacroListing* m_listing;
SoundMacroCatalogue* m_catalogue;
CommandWidget* m_draggedCmd = nullptr;
CatalogueItem* m_draggedItem = nullptr;
2018-07-28 04:34:29 +00:00
FieldSoundMacroStep* m_targetField = nullptr;
2018-07-22 03:45:47 +00:00
QPoint m_draggedPt;
int m_dragInsertIdx = -1;
void beginCommandDrag(CommandWidget* widget, const QPoint& eventPt, const QPoint& pt);
void beginCatalogueDrag(CatalogueItem* item, const QPoint& eventPt, const QPoint& pt);
2018-07-28 04:34:29 +00:00
void beginStepTarget(FieldSoundMacroStep* stepField);
void endStepTarget();
public:
explicit SoundMacroEditor(QWidget* parent = Q_NULLPTR);
bool loadData(ProjectModel::SoundMacroNode* node);
void unloadData();
2018-07-28 04:34:29 +00:00
ProjectModel::INode* currentNode() const;
2018-07-22 03:45:47 +00:00
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent* event);
2018-07-25 06:01:01 +00:00
public slots:
void catalogueDoubleClicked(QTreeWidgetItem* item, int column);
};
#endif //AMUSE_SOUND_MACRO_EDITOR_HPP