13#include "TitleBar_p.h"
17#include "WindowBeingDragged_p.h"
23#include "DockWidget_p.h"
26#include "FloatingWindow_p.h"
32#ifdef KDDW_FRONTEND_QT
45 Config::self().viewFactory()->createTitleBar(this, parent ? parent->view() : nullptr))
49 , m_floatingWindow(nullptr)
50 , m_supportsAutoHide((
Config::self().flags() &
Config::Flag_AutoHideSupport) ==
Config::Flag_AutoHideSupport)
51 , m_isStandalone(false)
54 d->numDockWidgetsChangedConnection = m_group->
dptr()->numDockWidgetsChanged.connect([
this] {
56 d->numDockWidgetsChanged.emit();
59 d->isFocusedChangedConnection = m_group->
dptr()->isFocusedChanged.connect([
this] {
60 d->isFocusedChanged.emit();
63 d->isInMainWindowChangedConnection = m_group->
dptr()->isInMainWindowChanged.connect([
this] {
64 updateAutoHideButton();
71 Config::self().viewFactory()->createTitleBar(this, parent ? parent->view() : nullptr))
75 , m_floatingWindow(parent)
76 , m_supportsAutoHide((
Config::self().flags() &
Config::Flag_AutoHideSupport) ==
Config::Flag_AutoHideSupport)
77 , m_isStandalone(false)
80 auto fwPrivate = m_floatingWindow->
dptr();
81 fwPrivate->numGroupsChanged.connect([
this] {
updateButtons(); });
82 fwPrivate->numDockWidgetsChanged.connect([
this] { d->numDockWidgetsChanged.emit(); });
83 fwPrivate->windowStateChanged.connect([
this] { updateMaximizeButton(); });
84 fwPrivate->activatedChanged.connect([
this] { d->isFocusedChanged.emit(); });
89 , Draggable(view, false)
92 , m_floatingWindow(nullptr)
93 , m_supportsAutoHide(false)
94 , m_isStandalone(true)
102 d->isFocusedChanged.connect([
this] {
109#ifdef KDDW_FRONTEND_QT
129 if (m_floatingWindow || m_isStandalone)
135 KDDW_ERROR(
"null group and null floating window");
175 }
else if (supportsFloatUnfloat()) {
185 return m_floatButtonVisible;
190 return m_maximizeButtonVisible;
193bool TitleBar::supportsFloatUnfloat()
const
224 return supportsFloatUnfloat();
243#ifdef DOCKS_TESTING_METHODS
244bool TitleBar::isFloatButtonVisible()
const
249bool TitleBar::isCloseButtonVisible()
const
254bool TitleBar::isCloseButtonEnabled()
const
262 return !m_icon.isNull();
272 return m_floatingWindow;
281 m_group->FocusScope::focus(reason);
282 }
else if (m_floatingWindow) {
283 m_floatingWindow->
focus(reason);
291 updateMaximizeButton();
293 const bool isEnabled =
true;
295 d->minimizeButtonChanged.emit(minimizeVisible, isEnabled);
297 updateAutoHideButton();
300void TitleBar::updateAutoHideButton()
309 const bool isEnabled =
true;
311 d->autoHideButtonChanged.emit(visible, isEnabled,
type);
314void TitleBar::updateMaximizeButton()
316 m_maximizeButtonVisible =
false;
320 m_maximizeButtonType =
324 const bool isEnabled =
true;
325 m_maximizeButtonVisible = m_maximizeButtonVisible && !
buttonIsUserHidden(m_maximizeButtonType, isEnabled);
326 d->maximizeButtonChanged.emit(m_maximizeButtonVisible, isEnabled, m_maximizeButtonType);
329void TitleBar::updateCloseButton()
331 const bool anyNonClosable =
group()
335 const bool isEnabled = !anyNonClosable;
342 if (!m_floatingWindow)
358 if (enabled != m_closeButtonEnabled) {
359 m_closeButtonEnabled = enabled;
360 d->closeButtonChanged.emit(m_closeButtonVisible, enabled);
366 if (visible != m_closeButtonVisible) {
367 m_closeButtonVisible = visible;
368 d->closeButtonChanged.emit(m_closeButtonVisible, m_closeButtonEnabled);
374 if (visible != m_floatButtonVisible) {
375 m_floatButtonVisible = visible;
376 d->floatButtonVisibleChanged.emit(visible);
380void TitleBar::setFloatButtonToolTip(
const QString &tip)
382 if (tip != m_floatButtonToolTip) {
383 m_floatButtonToolTip = tip;
384 d->floatButtonToolTipChanged.emit(tip);
390 if (
title != m_title) {
393 d->titleChanged.emit();
400 d->iconChanged.emit();
410 if (closeOnlyCurrentTab) {
415 KDDW_ERROR(
"Group with no dock widgets");
419 m_group->
view()->
d->closeRootView();
424 }
else if (m_floatingWindow) {
426 if (closeOnlyCurrentTab) {
428 if (
DockWidget *dw = f->currentDockWidget()) {
432 KDDW_ERROR(
"Group with no dock widgets");
440 }
else if (m_isStandalone) {
441 view()->
d->closeRootView();
452 KDDW_ERROR(
"TitleBar::onFloatClicked: empty list. Shouldn't happen");
481 dock->dptr()->m_lastPosition->m_tabIndex = i;
482 dock->setFloating(
false);
512 if (!m_floatingWindow)
528 KDDW_ERROR(
"Minimize not supported on floating windows");
535 KDDW_ERROR(
"TitleBar::onAutoHideClicked: There can only be a single dock widget per titlebar overlayed");
544 auto dw = dockwidgets.first();
546 auto sideBarGroup = groupedAutoHide ? registry->sideBarGroupingFor(dw) :
DockWidget::List();
547 if (sideBarGroup.isEmpty()) {
551 for (
auto it = sideBarGroup.rbegin(); it != sideBarGroup.rend(); ++it) {
554 dw->setAsCurrentTab();
555 registry->removeSideBarGrouping(sideBarGroup);
559 registry->addSideBarGrouping(dockwidgets);
564 if (groupedAutoHide || dw == currentDw)
572 return m_closeButtonEnabled;
586 KDDW_ERROR(
"TitleBar::makeWindow shouldn't be called on invisible title bar this={}, root.isVisible={}", (
void * )
this,
view()->rootView()->
isVisible());
588 KDDW_ERROR(
"this={}; actual={}", (
void * )
this, (
void * )m_group->
actualTitleBar());
589 }
else if (m_floatingWindow) {
590 KDDW_ERROR(
"Has floating window with titlebar={}, isVisible={}", (
void * )m_floatingWindow->
titleBar(), m_floatingWindow->
isVisible());
597 if (m_floatingWindow) {
599 return std::make_unique<WindowBeingDragged>(m_floatingWindow,
this);
605 KDDW_DEBUG(
"TitleBar::makeWindow no detach needed");
606 return std::make_unique<WindowBeingDragged>(fw,
this);
617 auto draggable = KDDockWidgets::usesNativeTitleBar() ?
static_cast<Draggable *
>(
floatingWindow)
618 :
static_cast<Draggable *
>(
this);
619 return std::make_unique<WindowBeingDragged>(
floatingWindow, draggable);
624 return m_floatingWindow !=
nullptr;
629 if (m_floatingWindow) {
631 const auto groups = m_floatingWindow->
groups();
644 KDDW_ERROR(
"TitleBar::dockWidget: shouldn't happen");
656 if (m_floatingWindow)
665 KDDW_ERROR(
"TitleBar::isFloating: shouldn't happen");
673 else if (m_floatingWindow)
675 else if (m_isStandalone)
681void TitleBar::updateFloatButton()
683 setFloatButtonToolTip(
floatingWindow() ? tr(
"Dock window") : tr(
"Undock window"));
689 return m_floatButtonToolTip;
699 KDDW_ERROR(
"Expected a group");
702 }
else if (m_group) {
711 return m_maximizeButtonType;
716 return m_isStandalone;
721 return d->m_userHiddenButtonTypes &
type;
737 if (d->m_userHiddenButtonTypes != types) {
738 d->m_userHiddenButtonTypes = types;
750 if (d->m_buttonsToHideIfDisabled != types) {
751 d->m_buttonsToHideIfDisabled = types;
758 return d->m_buttonsToHideIfDisabled &
type;
Application-wide config to tune certain behaviours of the framework.
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
void restoreFromSideBar(KDDockWidgets::Core::DockWidget *dw)
Removes the dock widget from the sidebar and docks it into the main window again.
QMainWindow sub-class to enable KDDockWidgets support.