refactor node gizmo release

This commit is contained in:
itsmattkc
2021-12-27 20:30:00 -08:00
parent 5223483e8e
commit f8ac3f4e40
12 changed files with 68 additions and 81 deletions
+1 -3
View File
@@ -233,13 +233,11 @@ void CropDistortNode::GizmoMove(const QPointF &p, const rational &time, const Qt
} }
} }
void CropDistortNode::GizmoRelease() void CropDistortNode::GizmoRelease(MultiUndoCommand *command)
{ {
MultiUndoCommand *command = new MultiUndoCommand();
for (NodeInputDragger& i : gizmo_dragger_) { for (NodeInputDragger& i : gizmo_dragger_) {
i.End(command); i.End(command);
} }
Core::instance()->undo_stack()->push(command);
gizmo_dragger_.clear(); gizmo_dragger_.clear();
gizmo_start_.clear(); gizmo_start_.clear();
+1 -1
View File
@@ -76,7 +76,7 @@ public:
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override; virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override;
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override; virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoRelease() override; virtual void GizmoRelease(MultiUndoCommand *command) override;
static const QString kTextureInput; static const QString kTextureInput;
static const QString kLeftInput; static const QString kLeftInput;
@@ -301,13 +301,11 @@ void TransformDistortNode::GizmoMove(const QPointF &p, const rational &time, con
} }
} }
void TransformDistortNode::GizmoRelease() void TransformDistortNode::GizmoRelease(MultiUndoCommand *command)
{ {
MultiUndoCommand *command = new MultiUndoCommand();
for (NodeInputDragger& i : gizmo_dragger_) { for (NodeInputDragger& i : gizmo_dragger_) {
i.End(command); i.End(command);
} }
Core::instance()->undo_stack()->push(command);
gizmo_dragger_.clear(); gizmo_dragger_.clear();
gizmo_start_.clear(); gizmo_start_.clear();
@@ -78,7 +78,7 @@ public:
virtual bool GizmoPress(const NodeValueRow &row, const NodeGlobals &globals, const QPointF &p) override; virtual bool GizmoPress(const NodeValueRow &row, const NodeGlobals &globals, const QPointF &p) override;
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override; virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoRelease() override; virtual void GizmoRelease(MultiUndoCommand *command) override;
enum AutoScaleType { enum AutoScaleType {
kAutoScaleNone, kAutoScaleNone,
+1 -3
View File
@@ -297,13 +297,11 @@ void ShapeNodeBase::GizmoMove(const QPointF &p, const rational &time, const Qt::
} }
} }
void ShapeNodeBase::GizmoRelease() void ShapeNodeBase::GizmoRelease(MultiUndoCommand *command)
{ {
MultiUndoCommand *command = new MultiUndoCommand();
for (NodeInputDragger& i : gizmo_dragger_) { for (NodeInputDragger& i : gizmo_dragger_) {
i.End(command); i.End(command);
} }
Core::instance()->undo_stack()->push(command);
gizmo_dragger_.clear(); gizmo_dragger_.clear();
} }
+1 -1
View File
@@ -49,7 +49,7 @@ public:
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override; virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF &p) override;
virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override; virtual void GizmoMove(const QPointF &p, const rational &time, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoRelease() override; virtual void GizmoRelease(MultiUndoCommand *command) override;
private: private:
static QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, int drag, QVector2D *pt); static QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, int drag, QVector2D *pt);
+1 -1
View File
@@ -1504,7 +1504,7 @@ void Node::GizmoMove(const QPointF &, const rational&, const Qt::KeyboardModifie
{ {
} }
void Node::GizmoRelease() void Node::GizmoRelease(MultiUndoCommand *)
{ {
} }
+1 -1
View File
@@ -855,7 +855,7 @@ public:
virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF& p); virtual bool GizmoPress(const NodeValueRow& row, const NodeGlobals &globals, const QPointF& p);
virtual void GizmoMove(const QPointF& p, const rational &time, const Qt::KeyboardModifiers &modifiers); virtual void GizmoMove(const QPointF& p, const rational &time, const Qt::KeyboardModifiers &modifiers);
virtual void GizmoRelease(); virtual void GizmoRelease(MultiUndoCommand *command);
const QString& GetLabel() const; const QString& GetLabel() const;
void SetLabel(const QString& s); void SetLabel(const QString& s);
+34 -7
View File
@@ -95,6 +95,40 @@ PanelManager *PanelManager::instance()
return instance_; return instance_;
} }
void PanelManager::RegisterPanel(PanelWidget *panel)
{
// Add panel to the bottom of the focus history
focus_history_.append(panel);
panel->SetMovementLocked(locked_);
// Get panel parent (it's assumed it has one)
QWidget *parent = panel->parentWidget();
// Sane default for panel size
panel->resize(parent->size() / 3);
// We're about to center the panel relative to the parent (usually the main window), but for some
// reason this requires the panel to be shown first.
panel->show();
// Center the panel relative to the parent
QPoint parent_center = panel->mapFromGlobal(parent->mapToGlobal(parent->rect().center()));
QPoint panel_center = panel->rect().center();
panel->move(parent_center - panel_center);
if (focus_history_.size() == 1) {
// This is the first panel, focus it
panel->SetBorderVisible(true);
emit FocusedPanelChanged(panel);
}
}
void PanelManager::UnregisterPanel(PanelWidget *panel)
{
focus_history_.removeOne(panel);
}
void PanelManager::FocusChanged(QWidget *old, QWidget *now) void PanelManager::FocusChanged(QWidget *old, QWidget *now)
{ {
Q_UNUSED(old) Q_UNUSED(old)
@@ -151,11 +185,4 @@ void PanelManager::SetPanelsLocked(bool locked)
locked_ = locked; locked_ = locked;
} }
void PanelManager::PanelDestroyed()
{
PanelWidget* panel = static_cast<PanelWidget*>(sender());
focus_history_.removeOne(panel);
}
} }
+10 -46
View File
@@ -84,12 +84,6 @@ public:
*/ */
T* MostRecentlyFocused(); T* MostRecentlyFocused();
template<class T>
/**
* @brief Create a panel
*/
T* CreatePanel(QWidget* parent);
/** /**
* @brief Get whether panels are currently prevented from moving * @brief Get whether panels are currently prevented from moving
*/ */
@@ -118,6 +112,16 @@ public:
*/ */
QList<T*> GetPanelsOfType(); QList<T*> GetPanelsOfType();
/**
* @brief Panel should call this upon construction so it can be kept track of
*/
void RegisterPanel(PanelWidget *panel);
/**
* @brief Panel should call this upon destruction so no invalid pointers will be kept for it
*/
void UnregisterPanel(PanelWidget *panel);
public slots: public slots:
/** /**
* @brief Connect this to a QApplication's SIGNAL(focusChanged()) * @brief Connect this to a QApplication's SIGNAL(focusChanged())
@@ -153,48 +157,8 @@ private:
*/ */
static PanelManager* instance_; static PanelManager* instance_;
private slots:
/**
* @brief Processing if a panel gets deleted
*/
void PanelDestroyed();
}; };
template<class T>
T *PanelManager::CreatePanel(QWidget *parent)
{
T* panel = new T(parent);
// Add panel to the bottom of the focus history
focus_history_.append(panel);
panel->SetMovementLocked(locked_);
// Sane default for panel size
panel->resize(parent->size() / 3);
// We're about to center the panel relative to the parent (usually the main window), but for some
// reason this requires the panel to be shown first.
panel->show();
// Center the panel relative to the parent
QPoint parent_center = panel->mapFromGlobal(parent->mapToGlobal(parent->rect().center()));
QPoint panel_center = panel->rect().center();
panel->move(parent_center - panel_center);
// Connect destroy signal so we can remove it from focus history
connect(panel, &PanelWidget::destroyed, this, &PanelManager::PanelDestroyed, Qt::DirectConnection);
if (focus_history_.size() == 1) {
// This is the first panel, focus it
panel->SetBorderVisible(true);
emit FocusedPanelChanged(panel);
}
return panel;
}
template<class T> template<class T>
T* PanelManager::MostRecentlyFocused() T* PanelManager::MostRecentlyFocused()
{ {
+3 -1
View File
@@ -271,7 +271,9 @@ void ViewerDisplayWidget::mouseReleaseEvent(QMouseEvent *event)
} else if (gizmo_click_) { } else if (gizmo_click_) {
// Handle gizmo // Handle gizmo
gizmos_->GizmoRelease(); MultiUndoCommand *command = new MultiUndoCommand();
gizmos_->GizmoRelease(command);
undo_stack()->pushIfHasChildren(command);
gizmo_click_ = false; gizmo_click_ = false;
} else { } else {
+13 -13
View File
@@ -78,17 +78,17 @@ MainWindow::MainWindow(QWidget *parent) :
setStatusBar(status_bar); setStatusBar(status_bar);
// Create standard panels // Create standard panels
node_panel_ = PanelManager::instance()->CreatePanel<NodePanel>(this); node_panel_ = new NodePanel(undo_stack_, this);
footage_viewer_panel_ = PanelManager::instance()->CreatePanel<FootageViewerPanel>(this); footage_viewer_panel_ = new FootageViewerPanel(undo_stack_, this);
param_panel_ = PanelManager::instance()->CreatePanel<ParamPanel>(this); param_panel_ = new ParamPanel(undo_stack_, this);
curve_panel_ = PanelManager::instance()->CreatePanel<CurvePanel>(this); curve_panel_ = new CurvePanel(undo_stack_, this);
sequence_viewer_panel_ = PanelManager::instance()->CreatePanel<SequenceViewerPanel>(this); sequence_viewer_panel_ = new SequenceViewerPanel(undo_stack_, this);
pixel_sampler_panel_ = PanelManager::instance()->CreatePanel<PixelSamplerPanel>(this); pixel_sampler_panel_ = new PixelSamplerPanel(undo_stack_, this);
AppendProjectPanel(); AppendProjectPanel();
tool_panel_ = PanelManager::instance()->CreatePanel<ToolPanel>(this); tool_panel_ = new ToolPanel(undo_stack_, this);
task_man_panel_ = PanelManager::instance()->CreatePanel<TaskManagerPanel>(this); task_man_panel_ = new TaskManagerPanel(undo_stack_, this);
AppendTimelinePanel(); AppendTimelinePanel();
audio_monitor_panel_ = PanelManager::instance()->CreatePanel<AudioMonitorPanel>(this); audio_monitor_panel_ = new AudioMonitorPanel(undo_stack_, this);
// Make node-related connections // Make node-related connections
connect(node_panel_, &NodePanel::NodesSelected, param_panel_, &ParamPanel::SelectNodes); connect(node_panel_, &NodePanel::NodesSelected, param_panel_, &ParamPanel::SelectNodes);
@@ -218,7 +218,7 @@ bool MainWindow::IsSequenceOpen(Sequence *sequence) const
void MainWindow::FolderOpen(Project* p, Folder *i, bool floating) void MainWindow::FolderOpen(Project* p, Folder *i, bool floating)
{ {
ProjectPanel* panel = PanelManager::instance()->CreatePanel<ProjectPanel>(this); ProjectPanel* panel = new ProjectPanel(undo_stack_, this);
panel->set_project(p); panel->set_project(p);
panel->set_root(i); panel->set_root(i);
@@ -256,7 +256,7 @@ void MainWindow::OpenNodeInViewer(ViewerOutput *node)
viewer_panels_.value(node)->raise(); viewer_panels_.value(node)->raise();
} else { } else {
// Create a viewer for this node // Create a viewer for this node
ViewerPanel* viewer = PanelManager::instance()->CreatePanel<ViewerPanel>(this); ViewerPanel* viewer = new ViewerPanel(undo_stack_, this);
viewer->SetSignalInsteadOfClose(true); viewer->SetSignalInsteadOfClose(true);
viewer->setFloating(true); viewer->setFloating(true);
@@ -816,7 +816,7 @@ void MainWindow::showEvent(QShowEvent *e)
template<typename T> template<typename T>
T *MainWindow::AppendPanelInternal(QList<T*>& list) T *MainWindow::AppendPanelInternal(QList<T*>& list)
{ {
T* panel = PanelManager::instance()->CreatePanel<T>(this); T* panel = new T(undo_stack_, this);
if (!list.isEmpty()) { if (!list.isEmpty()) {
tabifyDockWidget(list.last(), panel); tabifyDockWidget(list.last(), panel);
@@ -837,7 +837,7 @@ T *MainWindow::AppendPanelInternal(QList<T*>& list)
template<typename T> template<typename T>
T *MainWindow::AppendFloatingPanelInternal(QList<T *> &list) T *MainWindow::AppendFloatingPanelInternal(QList<T *> &list)
{ {
T* panel = PanelManager::instance()->CreatePanel<T>(this); T* panel = new T(undo_stack_, this);
panel->setFloating(true); panel->setFloating(true);
panel->show(); panel->show();