diff --git a/src/DockWidgetBase.cpp b/src/DockWidgetBase.cpp index 330f2ef6..0a7d2bcc 100644 --- a/src/DockWidgetBase.cpp +++ b/src/DockWidgetBase.cpp @@ -784,6 +784,51 @@ void DockWidgetBase::Private::forceClose() close(); } +DockWidgetBase::Private::Private(const QString &dockName, DockWidgetBase::Options options_, + LayoutSaverOptions layoutSaverOptions_, DockWidgetBase *qq) + + : name(dockName) + , title(dockName) + , q(qq) + , options(options_) + , layoutSaverOptions(layoutSaverOptions_) + , toggleAction(new QAction(q)) + , floatAction(new QAction(q)) +{ + q->connect(toggleAction, &QAction::toggled, q, [this](bool enabled) { + if (!m_updatingToggleAction) { // guard against recursiveness + toggleAction->blockSignals(true); // and don't emit spurious toggle. Like when a dock + // widget is inserted into a tab widget it might get + // hide events, ignore those. The Dock Widget is open. + m_processingToggleAction = true; + toggle(enabled); + toggleAction->blockSignals(false); + m_processingToggleAction = false; + } + }); + + q->connect(floatAction, &QAction::toggled, q, [this](bool checked) { + if (!m_updatingFloatAction) { // guard against recursiveness + q->setFloating(checked); + } + + Q_EMIT q->isFloatingChanged(checked); + + // When floating, we remove from the sidebar + if (checked && q->isOpen()) { + if (SideBar *sb = DockRegistry::self()->sideBarForDockWidget(q)) { + sb->mainWindow()->clearSideBarOverlay(/* deleteFrame=*/false); + sb->removeDockWidget(q); + } + } + }); + + toggleAction->setCheckable(true); + floatAction->setCheckable(true); + + qApp->installEventFilter(this); +} + void DockWidgetBase::Private::addPlaceholderItem(Layouting::Item *item) { Q_ASSERT(item); diff --git a/src/DockWidgetBase.h b/src/DockWidgetBase.h index 9e5c729e..821633c9 100644 --- a/src/DockWidgetBase.h +++ b/src/DockWidgetBase.h @@ -29,10 +29,6 @@ // clazy:excludeall=ctor-missing-parent-argument -QT_BEGIN_NAMESPACE -class QAction; -QT_END_NAMESPACE - class TestDocks; namespace KDDockWidgets { @@ -498,73 +494,4 @@ private: } Q_DECLARE_METATYPE(KDDockWidgets::Location) -#if defined(QT_WIDGETS_LIB) -# include -#else -// A QAction for QtQuick. Just so it compiles, for now -class QAction : public QObject -{ - Q_OBJECT -public: - using QObject::QObject; - - bool isChecked() const { - return m_isChecked ; - } - - void setCheckable(bool is) { - m_isCheckable = is; - } - - void setText(const QString &text) { - m_text = text; - } - - void setToolTip(const QString &text) { - m_toolTip = text; - } - - QString toolTip() const { - returm m_toolTip; - } - - bool enabled() const { - return m_enabled; - } - - void setEnabled(bool enabled) { - m_enabled = enabled; - } - - bool checked() const { - return m_checked; - } - - void setChecked(bool checked) { - m_checked = checked; - } - - bool isEnabled() const { - return m_enabled; - } - - void toggle() { - m_enabled = !m_enabled; - Q_EMIT toggled(m_enabled); - } - -Q_SIGNALS: - bool toggled(bool); -private: - QString m_text; - QString m_toolTip; - - bool m_isChecked = false; - bool m_isCheckable = false; - bool m_enabled = false; - bool m_checked = false; -}; - -#endif - #endif diff --git a/src/private/DockWidgetBase_p.h b/src/private/DockWidgetBase_p.h index 2ca803e7..558ff63d 100644 --- a/src/private/DockWidgetBase_p.h +++ b/src/private/DockWidgetBase_p.h @@ -22,52 +22,17 @@ #include #include +QT_BEGIN_NAMESPACE +class QAction; +QT_END_NAMESPACE + namespace KDDockWidgets { class DockWidgetBase::Private : public QObject { public: Private(const QString &dockName, DockWidgetBase::Options options_, - LayoutSaverOptions layoutSaverOptions_, DockWidgetBase *qq) - : name(dockName) - , title(dockName) - , q(qq) - , options(options_) - , layoutSaverOptions(layoutSaverOptions_) - , toggleAction(new QAction(q)) - , floatAction(new QAction(q)) - { - q->connect(toggleAction, &QAction::toggled, q, [this] (bool enabled) { - if (!m_updatingToggleAction) { // guard against recursiveness - toggleAction->blockSignals(true); // and don't emit spurious toggle. Like when a dock widget is inserted into a tab widget it might get hide events, ignore those. The Dock Widget is open. - m_processingToggleAction = true; - toggle(enabled); - toggleAction->blockSignals(false); - m_processingToggleAction = false; - } - }); - - q->connect(floatAction, &QAction::toggled, q, [this] (bool checked) { - if (!m_updatingFloatAction) { // guard against recursiveness - q->setFloating(checked); - } - - Q_EMIT q->isFloatingChanged(checked); - - // When floating, we remove from the sidebar - if (checked && q->isOpen()) { - if (SideBar *sb = DockRegistry::self()->sideBarForDockWidget(q)) { - sb->mainWindow()->clearSideBarOverlay(/* deleteFrame=*/false); - sb->removeDockWidget(q); - } - } - }); - - toggleAction->setCheckable(true); - floatAction->setCheckable(true); - - qApp->installEventFilter(this); - } + LayoutSaverOptions layoutSaverOptions_, DockWidgetBase *qq); void init() { @@ -190,4 +155,85 @@ public: } +#if defined(QT_WIDGETS_LIB) +#include +#else +// A QAction for QtQuick. Just so it compiles, for now +class QAction : public QObject +{ + Q_OBJECT +public: + using QObject::QObject; + + bool isChecked() const + { + return m_isChecked; + } + + void setCheckable(bool is) + { + m_isCheckable = is; + } + + void setText(const QString &text) + { + m_text = text; + } + + void setToolTip(const QString &text) + { + m_toolTip = text; + } + + QString toolTip() const + { + returm m_toolTip; + } + + bool enabled() const + { + return m_enabled; + } + + void setEnabled(bool enabled) + { + m_enabled = enabled; + } + + bool checked() const + { + return m_checked; + } + + void setChecked(bool checked) + { + m_checked = checked; + } + + bool isEnabled() const + { + return m_enabled; + } + + void toggle() + { + m_enabled = !m_enabled; + Q_EMIT toggled(m_enabled); + } + +Q_SIGNALS: + bool toggled(bool); + +private: + QString m_text; + QString m_toolTip; + + bool m_isChecked = false; + bool m_isCheckable = false; + bool m_enabled = false; + bool m_checked = false; +}; + +#endif + #endif