From a9965bf6dcd8d35d953ae013c2656a453d8ef548 Mon Sep 17 00:00:00 2001 From: Jan Krassnigg Date: Wed, 13 May 2020 08:04:50 +0200 Subject: [PATCH 1/4] Moved CTitleBarButton and CSpacerWidget declaration into DockAreaTitleBar.h This gets rid of the need to MOC DockAreaTitleBar.h and DockAreaTitleBar.cpp and it means that DockAreaTitleBar.cpp does not need to #include "DockAreaTitleBar.moc" anymore, which is a file that is generated by the build system and therefore may be named differently when using a custom build system. --- src/DockAreaTitleBar.cpp | 126 +++++++++++++-------------------------- src/DockAreaTitleBar.h | 52 ++++++++++++++++ 2 files changed, 94 insertions(+), 84 deletions(-) diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index ac9f345..62e9877 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -55,8 +55,6 @@ namespace ads { -using tTitleBarButton = QToolButton; - /** * Private data class of CDockAreaTitleBar class (pimpl) @@ -130,86 +128,6 @@ struct DockAreaTitleBarPrivate IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState); };// struct DockAreaTitleBarPrivate - -/** - * Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour - * according to various config flags such as: - * CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible - * CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled - */ -class CTitleBarButton : public tTitleBarButton -{ - Q_OBJECT - bool Visible = true; - bool HideWhenDisabled = false; -public: - using Super = tTitleBarButton; - CTitleBarButton(bool visible = true, QWidget* parent = nullptr) - : tTitleBarButton(parent), - Visible(visible), - HideWhenDisabled(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaHideDisabledButtons)) - {} - - - /** - * Adjust this visibility change request with our internal settings: - */ - virtual void setVisible(bool visible) override - { - // 'visible' can stay 'true' if and only if this button is configured to generaly visible: - visible = visible && this->Visible; - - // 'visible' can stay 'true' unless: this button is configured to be invisible when it is disabled and it is currently disabled: - if(visible && HideWhenDisabled) - { - visible = isEnabled(); - } - - Super::setVisible(visible); - } - -protected: - /** - * Handle EnabledChanged signal to set button invisible if the configured - */ - bool event(QEvent *ev) override - { - if(QEvent::EnabledChange == ev->type() && HideWhenDisabled) - { - // force setVisible() call - // Calling setVisible() directly here doesn't work well when button is expected to be shown first time - QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled())); - } - - return Super::event(ev); - } -}; - - -/** - * This spacer widget is here because of the following problem. - * The dock area title bar handles mouse dragging and moving the floating widget. - * The problem is, that if the title bar becomes invisible, i.e. if the dock - * area contains only one single dock widget and the dock area is moved - * into a floating widget, then mouse events are not handled anymore and dragging - * of the floating widget stops. - */ -class CSpacerWidget : public QWidget -{ - Q_OBJECT -public: - using Super = QWidget; - CSpacerWidget(QWidget* Parent = 0) - : Super(Parent) - { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - setStyleSheet("border: none; background: none;"); - } - virtual QSize sizeHint() const override {return QSize(0, 0);} - virtual QSize minimumSizeHint() const override {return QSize(0, 0);} -}; - - //============================================================================ DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) : _this(_public) @@ -674,10 +592,50 @@ int CDockAreaTitleBar::indexOf(QWidget *widget) const return d->Layout->indexOf(widget); } +//============================================================================ +CTitleBarButton::CTitleBarButton(bool visible /*= true*/, QWidget* parent /*= nullptr*/) : tTitleBarButton(parent), +Visible(visible), +HideWhenDisabled(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaHideDisabledButtons)) +{ + +} + +//============================================================================ +void CTitleBarButton::setVisible(bool visible) +{ + // 'visible' can stay 'true' if and only if this button is configured to generaly visible: + visible = visible && this->Visible; + + // 'visible' can stay 'true' unless: this button is configured to be invisible when it is disabled and it is currently disabled: + if (visible && HideWhenDisabled) + { + visible = isEnabled(); + } + + Super::setVisible(visible); +} + +//============================================================================ +bool CTitleBarButton::event(QEvent *ev) +{ + if (QEvent::EnabledChange == ev->type() && HideWhenDisabled) + { + // force setVisible() call + // Calling setVisible() directly here doesn't work well when button is expected to be shown first time + QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled())); + } + + return Super::event(ev); +} + +//============================================================================ +CSpacerWidget::CSpacerWidget(QWidget* Parent /*= 0*/) : Super(Parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setStyleSheet("border: none; background: none;"); +} } // namespace ads -#include "DockAreaTitleBar.moc" - //--------------------------------------------------------------------------- // EOF DockAreaTitleBar.cpp diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index cd28842..3efb8cc 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -31,6 +31,7 @@ // INCLUDES //============================================================================ #include +#include #include "ads_globals.h" @@ -155,6 +156,57 @@ signals: */ void tabBarClicked(int index); }; // class name + +using tTitleBarButton = QToolButton; + + /** + * Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour + * according to various config flags such as: + * CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible + * CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled + */ +class CTitleBarButton : public tTitleBarButton +{ + Q_OBJECT + + bool Visible = true; + bool HideWhenDisabled = false; + +public: + using Super = tTitleBarButton; + CTitleBarButton(bool visible = true, QWidget* parent = nullptr); + + /** + * Adjust this visibility change request with our internal settings: + */ + virtual void setVisible(bool visible) override; + +protected: + /** + * Handle EnabledChanged signal to set button invisible if the configured + */ + bool event(QEvent *ev) override; +}; + + +/** +* This spacer widget is here because of the following problem. +* The dock area title bar handles mouse dragging and moving the floating widget. +* The problem is, that if the title bar becomes invisible, i.e. if the dock +* area contains only one single dock widget and the dock area is moved +* into a floating widget, then mouse events are not handled anymore and dragging +* of the floating widget stops. +*/ +class CSpacerWidget : public QWidget +{ + Q_OBJECT +public: + using Super = QWidget; + CSpacerWidget(QWidget* Parent = 0); + virtual QSize sizeHint() const override {return QSize(0, 0);} + virtual QSize minimumSizeHint() const override {return QSize(0, 0);} +}; + } // namespace ads //----------------------------------------------------------------------------- From 115e67edc441c258b10d419ec38fd4ea798edcb5 Mon Sep 17 00:00:00 2001 From: Jan Krassnigg Date: Wed, 13 May 2020 16:40:43 +0200 Subject: [PATCH 2/4] Moved private classes into dedicated header --- src/DockAreaTitleBar.cpp | 1 + src/DockAreaTitleBar.h | 51 ---------------------- src/DockAreaTitleBar_p.h | 93 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 51 deletions(-) create mode 100644 src/DockAreaTitleBar_p.h diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 62e9877..aec4cc9 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -39,6 +39,7 @@ #include #include +#include "DockAreaTitleBar_p.h" #include "ads_globals.h" #include "FloatingDockContainer.h" #include "FloatingDragPreview.h" diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index 3efb8cc..2a4505f 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -31,7 +31,6 @@ // INCLUDES //============================================================================ #include -#include #include "ads_globals.h" @@ -157,56 +156,6 @@ signals: void tabBarClicked(int index); }; // class name -using tTitleBarButton = QToolButton; - - /** - * Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour - * according to various config flags such as: - * CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible - * CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled - */ -class CTitleBarButton : public tTitleBarButton -{ - Q_OBJECT - - bool Visible = true; - bool HideWhenDisabled = false; - -public: - using Super = tTitleBarButton; - CTitleBarButton(bool visible = true, QWidget* parent = nullptr); - - /** - * Adjust this visibility change request with our internal settings: - */ - virtual void setVisible(bool visible) override; - -protected: - /** - * Handle EnabledChanged signal to set button invisible if the configured - */ - bool event(QEvent *ev) override; -}; - - -/** -* This spacer widget is here because of the following problem. -* The dock area title bar handles mouse dragging and moving the floating widget. -* The problem is, that if the title bar becomes invisible, i.e. if the dock -* area contains only one single dock widget and the dock area is moved -* into a floating widget, then mouse events are not handled anymore and dragging -* of the floating widget stops. -*/ -class CSpacerWidget : public QWidget -{ - Q_OBJECT -public: - using Super = QWidget; - CSpacerWidget(QWidget* Parent = 0); - virtual QSize sizeHint() const override {return QSize(0, 0);} - virtual QSize minimumSizeHint() const override {return QSize(0, 0);} -}; - } // namespace ads //----------------------------------------------------------------------------- diff --git a/src/DockAreaTitleBar_p.h b/src/DockAreaTitleBar_p.h new file mode 100644 index 0000000..c159de2 --- /dev/null +++ b/src/DockAreaTitleBar_p.h @@ -0,0 +1,93 @@ +#ifndef DockAreaTitleBarPH +#define DockAreaTitleBarPH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaTitleBar_p.h +/// \author Uwe Kindler +/// \date 12.10.2018 +/// \brief Declaration of classes CTitleBarButton and CSpacerWidget +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include + +#include "ads_globals.h" + +namespace ads +{ +using tTitleBarButton = QToolButton; + + /** + * Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour + * according to various config flags such as: + * CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible + * CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled + */ +class CTitleBarButton : public tTitleBarButton +{ + Q_OBJECT + + bool Visible = true; + bool HideWhenDisabled = false; + +public: + using Super = tTitleBarButton; + CTitleBarButton(bool visible = true, QWidget* parent = nullptr); + + /** + * Adjust this visibility change request with our internal settings: + */ + virtual void setVisible(bool visible) override; + +protected: + /** + * Handle EnabledChanged signal to set button invisible if the configured + */ + bool event(QEvent *ev) override; +}; + + +/** +* This spacer widget is here because of the following problem. +* The dock area title bar handles mouse dragging and moving the floating widget. +* The problem is, that if the title bar becomes invisible, i.e. if the dock +* area contains only one single dock widget and the dock area is moved +* into a floating widget, then mouse events are not handled anymore and dragging +* of the floating widget stops. +*/ +class CSpacerWidget : public QWidget +{ + Q_OBJECT +public: + using Super = QWidget; + CSpacerWidget(QWidget* Parent = 0); + virtual QSize sizeHint() const override {return QSize(0, 0);} + virtual QSize minimumSizeHint() const override {return QSize(0, 0);} +}; + +} + // namespace ads +//----------------------------------------------------------------------------- +#endif // DockAreaTitleBarPH From 726d73b2c239818ed68c028f86a6094d902e64a3 Mon Sep 17 00:00:00 2001 From: Jan Krassnigg Date: Wed, 13 May 2020 16:47:43 +0200 Subject: [PATCH 3/4] Missing cmake change --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73a0b10..a246a97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(ads_INSTALL_INCLUDE src/ads_globals.h src/DockAreaTabBar.h src/DockAreaTitleBar.h + src/DockAreaTitleBar_p.h src/DockAreaWidget.h src/DockContainerWidget.h src/DockManager.h From d418d92ef48a101e2f7eb789663a0f522fea0bd9 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 13 May 2020 16:57:36 +0200 Subject: [PATCH 4/4] Added missing DockAreaTitleBar_p.h to src.pro --- src/DockAreaTitleBar_p.h | 19 ++++++++++--------- src/src.pro | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/DockAreaTitleBar_p.h b/src/DockAreaTitleBar_p.h index c159de2..b94a510 100644 --- a/src/DockAreaTitleBar_p.h +++ b/src/DockAreaTitleBar_p.h @@ -1,5 +1,5 @@ -#ifndef DockAreaTitleBarPH -#define DockAreaTitleBarPH +#ifndef DockAreaTitleBar_pH +#define DockAreaTitleBar_pH /******************************************************************************* ** Qt Advanced Docking System ** Copyright (C) 2017 Uwe Kindler @@ -39,16 +39,17 @@ namespace ads { using tTitleBarButton = QToolButton; - /** - * Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour - * according to various config flags such as: - * CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible - * CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled - */ +/** +* Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour +* according to various config flags such as: +* CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible +* CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled +*/ class CTitleBarButton : public tTitleBarButton { Q_OBJECT +private: bool Visible = true; bool HideWhenDisabled = false; @@ -90,4 +91,4 @@ public: } // namespace ads //----------------------------------------------------------------------------- -#endif // DockAreaTitleBarPH +#endif // DockAreaTitleBar_pH diff --git a/src/src.pro b/src/src.pro index 73367b0..f117495 100644 --- a/src/src.pro +++ b/src/src.pro @@ -41,6 +41,7 @@ HEADERS += \ FloatingDragPreview.h \ DockOverlay.h \ DockSplitter.h \ + DockAreaTitleBar_p.h \ DockAreaTitleBar.h \ ElidingLabel.h \ IconProvider.h \