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
+34 -7
View File
@@ -95,6 +95,40 @@ PanelManager *PanelManager::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)
{
Q_UNUSED(old)
@@ -151,11 +185,4 @@ void PanelManager::SetPanelsLocked(bool 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();
template<class T>
/**
* @brief Create a panel
*/
T* CreatePanel(QWidget* parent);
/**
* @brief Get whether panels are currently prevented from moving
*/
@@ -118,6 +112,16 @@ public:
*/
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:
/**
* @brief Connect this to a QApplication's SIGNAL(focusChanged())
@@ -153,48 +157,8 @@ private:
*/
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>
T* PanelManager::MostRecentlyFocused()
{