amuse/Editor/StudioSetupWidget.hpp

195 lines
5.4 KiB
C++
Raw Normal View History

2018-10-07 03:40:25 +00:00
#pragma once
2018-08-16 06:26:44 +00:00
#include "EditorWidget.hpp"
#include <QWidget>
#include <QTreeWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QLayoutItem>
#include <QStaticText>
#include <QPropertyAnimation>
#include <QScrollArea>
#include <QSplitter>
#include "amuse/Studio.hpp"
2018-08-19 00:28:52 +00:00
class EffectListing;
2018-12-08 05:20:09 +00:00
struct EffectIntrospection {
struct Field {
enum class Type { Invalid, UInt32, UInt32x8, Float };
Type m_tp;
2018-08-16 06:26:44 +00:00
std::string_view m_name;
2018-12-08 05:20:09 +00:00
float m_min, m_max, m_default;
};
amuse::EffectType m_tp;
std::string_view m_name;
std::string_view m_description;
Field m_fields[7];
2018-08-16 06:26:44 +00:00
};
2018-12-08 05:20:09 +00:00
class Uint32X8Popup : public QFrame {
Q_OBJECT
FieldSlider* m_sliders[8];
2018-08-19 00:28:52 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit Uint32X8Popup(int min, int max, QWidget* parent = Q_NULLPTR);
void setValue(int chanIdx, int val);
2018-08-19 00:28:52 +00:00
private slots:
2018-12-08 05:20:09 +00:00
void doValueChanged(int val);
2018-08-19 00:28:52 +00:00
signals:
2018-12-08 05:20:09 +00:00
void valueChanged(int chanIdx, int val);
2018-08-19 00:28:52 +00:00
};
2018-12-08 05:20:09 +00:00
class Uint32X8Button : public QPushButton {
Q_OBJECT
Uint32X8Popup* m_popup;
2018-08-19 00:28:52 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit Uint32X8Button(int min, int max, QWidget* parent = Q_NULLPTR);
void paintEvent(QPaintEvent* event);
Uint32X8Popup* popup() const { return m_popup; }
QStyleOptionComboBox comboStyleOption() const;
2018-08-19 00:28:52 +00:00
private slots:
2018-12-08 05:20:09 +00:00
void onPressed();
2018-08-19 00:28:52 +00:00
};
2018-08-16 06:26:44 +00:00
2018-12-08 05:20:09 +00:00
class EffectWidget : public QWidget {
Q_OBJECT
friend class EffectListing;
QFont m_numberFont;
QLabel m_titleLabel;
ListingDeleteButton m_deleteButton;
QStaticText m_numberText;
int m_index = -1;
amuse::EffectBaseTypeless* m_effect;
const EffectIntrospection* m_introspection;
void setIndex(int index);
2018-08-16 06:26:44 +00:00
private slots:
2018-12-08 05:20:09 +00:00
void numChanged(int);
void numChanged(double);
void chanNumChanged(int, int);
void deleteClicked();
2018-08-16 06:26:44 +00:00
private:
2018-12-08 05:20:09 +00:00
explicit EffectWidget(QWidget* parent, amuse::EffectBaseTypeless* effect, amuse::EffectType type);
2018-08-16 06:26:44 +00:00
public:
2018-12-08 05:20:09 +00:00
EffectListing* getParent() const;
explicit EffectWidget(QWidget* parent, amuse::EffectBaseTypeless* effect);
explicit EffectWidget(QWidget* parent, amuse::EffectType op);
void paintEvent(QPaintEvent* event);
QString getText() const { return m_titleLabel.text(); }
2018-08-16 06:26:44 +00:00
};
2018-12-08 05:20:09 +00:00
class EffectWidgetContainer : public QWidget {
Q_OBJECT
friend class EffectListing;
EffectWidget* m_effectWidget;
QPropertyAnimation* m_animation = nullptr;
void animateOpen();
void animateClosed();
void snapOpen();
void snapClosed();
2018-08-16 06:26:44 +00:00
private slots:
2018-12-08 05:20:09 +00:00
void animationDestroyed();
2018-08-16 06:26:44 +00:00
public:
2018-12-08 05:20:09 +00:00
template <class... _Args>
EffectWidgetContainer(QWidget* parent, _Args&&... args);
2018-08-16 06:26:44 +00:00
};
2018-12-08 05:20:09 +00:00
class EffectListing : public QWidget {
Q_OBJECT
friend class EffectWidget;
friend class StudioSetupWidget;
amuse::Submix* m_submix = nullptr;
QVBoxLayout* m_layout;
QLayoutItem* m_dragItem = nullptr;
int m_origIdx = -1;
int m_dragOpenIdx = -1;
EffectWidgetContainer* m_prevDragOpen = nullptr;
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(EffectWidget* widget);
void endDrag();
void cancelDrag();
void _moveDrag(int hoverIdx, const QPoint& pt, QWidget* source, QMouseEvent* event);
void moveDrag(EffectWidget* widget, const QPoint& pt, QWidget* source, QMouseEvent* event);
int moveInsertDrag(const QPoint& pt, QWidget* source, QMouseEvent* event);
void insertDragout();
void insert(amuse::EffectType type, const QString& text);
void deleteEffect(int index);
void reindex();
void clear();
2018-08-16 06:26:44 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit EffectListing(QWidget* parent = Q_NULLPTR);
bool loadData(amuse::Submix* submix);
void unloadData();
void timerEvent(QTimerEvent* event);
2018-08-16 06:26:44 +00:00
};
2018-12-08 05:20:09 +00:00
class EffectCatalogueItem : public QWidget {
Q_OBJECT
amuse::EffectType m_type;
QLabel m_iconLab;
QLabel m_label;
2018-08-16 06:26:44 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit EffectCatalogueItem(amuse::EffectType type, const QString& name, const QString& doc,
QWidget* parent = Q_NULLPTR);
explicit EffectCatalogueItem(const EffectCatalogueItem& other, QWidget* parent = Q_NULLPTR);
amuse::EffectType getType() const { return m_type; }
QString getText() const { return m_label.text(); }
2018-08-16 06:26:44 +00:00
};
2018-12-08 05:20:09 +00:00
class EffectCatalogue : public QTreeWidget {
Q_OBJECT
2018-08-16 06:26:44 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit EffectCatalogue(QWidget* parent = Q_NULLPTR);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
2018-08-16 06:26:44 +00:00
};
2018-12-08 05:20:09 +00:00
class StudioSetupWidget : public QWidget {
Q_OBJECT
friend class EffectCatalogue;
QSplitter* m_splitter;
QTabWidget* m_tabs;
EffectListing* m_listing[2];
EffectCatalogue* m_catalogue;
EffectWidget* m_draggedCmd = nullptr;
EffectCatalogueItem* m_draggedItem = nullptr;
QPoint m_draggedPt;
int m_dragInsertIdx = -1;
EffectListing* getCurrentListing() const;
void beginCommandDrag(EffectWidget* widget, const QPoint& eventPt, const QPoint& pt);
void beginCatalogueDrag(EffectCatalogueItem* item, const QPoint& eventPt, const QPoint& pt);
2018-08-16 06:26:44 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit StudioSetupWidget(QWidget* parent = Q_NULLPTR);
bool loadData(amuse::Studio* studio);
void unloadData();
2018-08-16 06:26:44 +00:00
2018-12-08 05:20:09 +00:00
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent* event);
2018-08-16 06:26:44 +00:00
2018-12-08 05:20:09 +00:00
void hideEvent(QHideEvent* event);
void showEvent(QShowEvent* event);
void updateWindowPosition();
2018-08-16 06:26:44 +00:00
public slots:
2018-12-08 05:20:09 +00:00
void catalogueDoubleClicked(QTreeWidgetItem* item, int column);
2018-08-16 06:26:44 +00:00
signals:
2018-12-08 05:20:09 +00:00
void hidden();
void shown();
2018-08-16 06:26:44 +00:00
};