amuse/Editor/StudioSetupWidget.hpp

216 lines
5.7 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 <array>
#include <string>
2018-08-16 06:26:44 +00:00
#include <QLabel>
#include <QLayoutItem>
#include <QMouseEvent>
2018-08-16 06:26:44 +00:00
#include <QPropertyAnimation>
#include <QPushButton>
2018-08-16 06:26:44 +00:00
#include <QScrollArea>
#include <QSplitter>
#include <QStaticText>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <QWidget>
#include "EditorWidget.hpp"
2018-08-16 06:26:44 +00:00
namespace amuse {
class EffectBaseTypeless;
class Studio;
class Submix;
enum class EffectType;
} // namespace amuse
class EffectListing;
struct EffectIntrospection;
2018-08-16 06:26:44 +00:00
2018-12-08 05:20:09 +00:00
class Uint32X8Popup : public QFrame {
Q_OBJECT
2018-08-19 00:28:52 +00:00
public:
static constexpr int NumSliders = 8;
2018-12-08 05:20:09 +00:00
explicit Uint32X8Popup(int min, int max, QWidget* parent = Q_NULLPTR);
~Uint32X8Popup() override;
2018-12-08 05:20:09 +00:00
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);
private:
std::array<FieldSlider*, NumSliders> m_sliders;
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);
~Uint32X8Button() override;
void paintEvent(QPaintEvent* event) override;
2018-12-08 05:20:09 +00:00
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);
~EffectWidget() override;
2018-12-08 05:20:09 +00:00
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) override;
2018-12-08 05:20:09 +00:00
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);
~EffectWidgetContainer() override;
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);
~EffectListing() override;
2018-12-08 05:20:09 +00:00
bool loadData(amuse::Submix* submix);
void unloadData();
void timerEvent(QTimerEvent* event) override;
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);
~EffectCatalogueItem() override;
2018-12-08 05:20:09 +00:00
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) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
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;
std::array<EffectListing*, 2> m_listing{};
2018-12-08 05:20:09 +00:00
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);
~StudioSetupWidget() override;
2018-12-08 05:20:09 +00:00
bool loadData(amuse::Studio* studio);
void unloadData();
2018-08-16 06:26:44 +00:00
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
2018-08-16 06:26:44 +00:00
void hideEvent(QHideEvent* event) override;
void showEvent(QShowEvent* event) override;
2018-12-08 05:20:09 +00:00
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
};