diff --git a/app/panel/panelmanager.cpp b/app/panel/panelmanager.cpp index 252deae05..53903f81e 100644 --- a/app/panel/panelmanager.cpp +++ b/app/panel/panelmanager.cpp @@ -35,12 +35,10 @@ PanelManager::PanelManager(QObject *parent) : void PanelManager::DeleteAllPanels() { - foreach (PanelWidget* panel, focus_history_) { - // We don't need to run this signal anymore since we're destroying and clearing everything - disconnect(panel, &PanelWidget::destroyed, this, &PanelManager::PanelDestroyed); - delete panel; - } + // Prevent any confusion regarding focus history by clearing it first + QList copy = focus_history_; focus_history_.clear(); + qDeleteAll(copy); } const QList &PanelManager::panels() diff --git a/app/panel/panelmanager.h b/app/panel/panelmanager.h index 9e773ec92..caa7bae07 100644 --- a/app/panel/panelmanager.h +++ b/app/panel/panelmanager.h @@ -175,18 +175,26 @@ T *PanelManager::CreatePanel(QWidget *parent) { T* panel = new T(parent); - panel->SetMovementLocked(locked_); - - // Sane default for panel geometry - panel->resize(parent->size() / 3); - panel->move(panel->mapFromGlobal(parent->mapToGlobal(parent->pos()))); - - // Connect destroy signal so we can remove it from focus history - connect(panel, &PanelWidget::destroyed, this, &PanelManager::PanelDestroyed); - // 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); + return panel; }