From 6e332683b1c9bc00592268b1ce5a270ecdef2e4e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 16 Oct 2014 03:25:50 +0200 Subject: [PATCH] refs #335, updated dock widget * removed unused methods * added toggleVisibility * renamed slot --- src/blackgui/dockwidget.cpp | 34 ++++++++++++++++++++-------------- src/blackgui/dockwidget.h | 18 ++++++++++++------ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/blackgui/dockwidget.cpp b/src/blackgui/dockwidget.cpp index b082370fb..f4387b52d 100644 --- a/src/blackgui/dockwidget.cpp +++ b/src/blackgui/dockwidget.cpp @@ -24,7 +24,8 @@ namespace BlackGui // connect connect(this, &QDockWidget::topLevelChanged, this, &CDockWidget::ps_onTopLevelChanged); - connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &CDockWidget::onStyleSheetsChanged); + connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &CDockWidget::ps_onStyleSheetsChanged); + connect(this, &QDockWidget::visibilityChanged, this, &CDockWidget::ps_onVisibilityChanged); // context menu this->setContextMenuPolicy(Qt::CustomContextMenu); @@ -74,6 +75,18 @@ namespace BlackGui this->setFloating(!this->isFloating()); } + void CDockWidget::toggleVisibility() + { + if (this->isVisible()) + { + this->hide(); + } + else + { + this->show(); + } + } + void CDockWidget::closeEvent(QCloseEvent *event) { if (this->isFloating()) @@ -93,18 +106,6 @@ namespace BlackGui CStyleSheetUtility::useStyleSheetInDerivedWidget(this); } - void CDockWidget::hideEvent(QHideEvent *event) - { - // qDebug() << "hide" << this->objectName() << "v:" << isVisible() << "h:" << isHidden(); - QDockWidget::hideEvent(event); - } - - void CDockWidget::showEvent(QShowEvent *event) - { - // qDebug() << "show" << this->objectName() << "v:" << isVisible() << "h:" << isHidden(); - QDockWidget::showEvent(event); - } - void CDockWidget::addToContextMenu(QMenu *contextMenu) const { if (this->isFloating()) @@ -180,7 +181,12 @@ namespace BlackGui Q_UNUSED(selectedItem); } - void CDockWidget::onStyleSheetsChanged() + void CDockWidget::ps_onVisibilityChanged(bool visible) + { + this->m_dockWidgetVisible = visible; + } + + void CDockWidget::ps_onStyleSheetsChanged() { // void, for further extensions } diff --git a/src/blackgui/dockwidget.h b/src/blackgui/dockwidget.h index 61da101e0..33a3e2c38 100644 --- a/src/blackgui/dockwidget.h +++ b/src/blackgui/dockwidget.h @@ -64,6 +64,10 @@ namespace BlackGui //! Selected when tabbed bool isSelected() const { return this->m_selected; } + //! Is widget visible? Not to be confused with \sa QWidget::isVisbible + //! \remarks Logical vsibility as in \sa QDockWidget::visibilityChanged + bool isWidgetVisible() const { return this->m_dockWidgetVisible && this->isVisible(); } + //! Show the window title when docked void showTitleWhenDocked(bool show); @@ -83,6 +87,9 @@ namespace BlackGui //! Toggle floating void toggleFloating(); + //! Toggle visibility + void toggleVisibility(); + //! Set title and internally keep a backup void setWindowTitle(const QString &title); @@ -100,12 +107,6 @@ namespace BlackGui //! \copydoc QWidget::paintEvent virtual void paintEvent(QPaintEvent *event) override; - //! \copydoc QWidget::hideEvent - void hideEvent(QHideEvent *event) override; - - //! \copydoc QWidget::showEvent - void showEvent(QShowEvent *event) override; - //! Contribute to menu virtual void addToContextMenu(QMenu *contextMenu) const; @@ -125,6 +126,9 @@ namespace BlackGui //! Context menu virtual void ps_showContextMenu(const QPoint &pos); + //! Visibility has changed + virtual void ps_onVisibilityChanged(bool visible); + private: QWidget *m_emptyTitleBar = nullptr; //!< replacing default title bar QWidget *m_titleBarOriginal = nullptr; //!< the original title bar @@ -136,9 +140,11 @@ namespace BlackGui bool m_windowTitleWhenDocked = true; bool m_wasAlreadyFloating = false; bool m_selected = false; //!< selected when tabbed + bool m_dockWidgetVisible = false; //!< logical visible, not to be confused with QDockWidget::isVisible() //! Empty widget with no size void initTitleBarWidgets(); + }; } // namespace