From 1788678732dcac965702e5d6ee3b0a2de9f40f0d Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Tue, 18 Aug 2015 23:12:48 +0200 Subject: [PATCH] EditDialog: Set position to center of parent dialog when opening dialog See issues #342 and #394. --- src/EditDialog.cpp | 12 ++++++++++++ src/EditDialog.h | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 7f84cd1b..99c6325a 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -49,6 +49,18 @@ void EditDialog::closeEvent(QCloseEvent*) emit goingAway(); } +void EditDialog::showEvent(QShowEvent*) +{ + // Whenever the dialog is shown, position it at the center of the parent dialog + QPoint center = mapToGlobal(rect().center()); + QDialog* parentDialog = qobject_cast(parent()); + if(parentDialog) + { + QPoint parentCenter = parentDialog->window()->mapToGlobal(parentDialog->window()->rect().center()); + move(parentCenter - center); + } +} + void EditDialog::loadText(const QByteArray& data, int row, int col) { curRow = row; diff --git a/src/EditDialog.h b/src/EditDialog.h index 4b605d96..8566c908 100644 --- a/src/EditDialog.h +++ b/src/EditDialog.h @@ -25,8 +25,11 @@ public slots: virtual void reset(); virtual void loadText(const QByteArray& data, int row, int col); +protected: + virtual void closeEvent(QCloseEvent* ev); + virtual void showEvent(QShowEvent* ev); + private slots: - virtual void closeEvent(QCloseEvent*); virtual void importData(); virtual void exportData(); virtual void clearData();