From 62cdaab2700c1827e5357a078b9045cbf2d23514 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 14 Apr 2015 14:29:03 -0700 Subject: [PATCH] Dock widget no longer supports floating mode Action passed in in order to make X in title bar close work --- src/QGCDockWidget.cc | 16 ++++++++++++---- src/QGCDockWidget.h | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/QGCDockWidget.cc b/src/QGCDockWidget.cc index b087abbba..7fce8d785 100644 --- a/src/QGCDockWidget.cc +++ b/src/QGCDockWidget.cc @@ -25,15 +25,23 @@ #include -QGCDockWidget::QGCDockWidget(const QString& title, QWidget *parent, Qt::WindowFlags flags) : - QDockWidget(title, parent, flags) +QGCDockWidget::QGCDockWidget(const QString& title, QAction* action, QWidget *parent, Qt::WindowFlags flags) : + QDockWidget(title, parent, flags), + _action(action) { - + QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetMovable; + + if (action) { + features |= QDockWidget::DockWidgetClosable; + } + setFeatures(features); } // Instead of destroying the widget just hide it void QGCDockWidget::closeEvent(QCloseEvent* event) { + Q_ASSERT(_action); + event->ignore(); - setVisible(false); + _action->trigger(); } diff --git a/src/QGCDockWidget.h b/src/QGCDockWidget.h index ffc2fb135..24f6e6a77 100644 --- a/src/QGCDockWidget.h +++ b/src/QGCDockWidget.h @@ -25,6 +25,7 @@ #define QGCDockWidget_h #include +#include /// @file /// @brief Subclass of QDockWidget so we can intercept the closeEvent. @@ -35,9 +36,12 @@ class QGCDockWidget : public QDockWidget { Q_OBJECT public: - QGCDockWidget(const QString& title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + QGCDockWidget(const QString& title, QAction* action, QWidget *parent = 0, Qt::WindowFlags flags = 0); void closeEvent(QCloseEvent* event); + +private: + QAction* _action; }; -- 2.22.0