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");
185 return m_floatButtonVisible;
190 return m_maximizeButtonVisible;
237#ifdef DOCKS_TESTING_METHODS
238bool TitleBar::isFloatButtonVisible()
const
243bool TitleBar::isCloseButtonVisible()
const
248bool TitleBar::isCloseButtonEnabled()
const
256 return !m_icon.isNull();
266 return m_floatingWindow;
275 m_group->FocusScope::focus(reason);
276 }
else if (m_floatingWindow) {
277 m_floatingWindow->
focus(reason);
285 updateMaximizeButton();
289 updateAutoHideButton();
292void TitleBar::updateAutoHideButton()
294 const bool visible = m_supportsAutoHide;
302 d->autoHideButtonChanged.emit(visible,
true,
type);
305void TitleBar::updateMaximizeButton()
307 m_maximizeButtonVisible =
false;
311 m_maximizeButtonType =
316 d->maximizeButtonChanged.emit(m_maximizeButtonVisible,
true, m_maximizeButtonType);
319void TitleBar::updateCloseButton()
321 const bool anyNonClosable =
group()
330 if (!m_floatingWindow)
346 if (enabled != m_closeButtonEnabled) {
347 m_closeButtonEnabled = enabled;
348 d->closeButtonEnabledChanged.emit(enabled);
354 if (visible != m_floatButtonVisible) {
355 m_floatButtonVisible = visible;
356 d->floatButtonVisibleChanged.emit(visible);
360void TitleBar::setFloatButtonToolTip(
const QString &tip)
362 if (tip != m_floatButtonToolTip) {
363 m_floatButtonToolTip = tip;
364 d->floatButtonToolTipChanged.emit(tip);
370 if (
title != m_title) {
373 d->titleChanged.emit();
380 d->iconChanged.emit();
388 if (closeOnlyCurrentTab) {
393 KDDW_ERROR(
"Frame with no dock widgets");
397 m_group->
view()->
d->closeRootView();
402 }
else if (m_floatingWindow) {
404 if (closeOnlyCurrentTab) {
406 if (
DockWidget *dw = f->currentDockWidget()) {
410 KDDW_ERROR(
"Frame with no dock widgets");
418 }
else if (m_isStandalone) {
419 view()->
d->closeRootView();
430 KDDW_ERROR(
"TitleBar::onFloatClicked: empty list. Shouldn't happen");
457 dock->dptr()->m_lastPosition->m_tabIndex = i;
458 dock->setFloating(
false);
487 if (!m_floatingWindow)
503 KDDW_ERROR(
"Minimize not supported on floating windows");
510 KDDW_ERROR(
"TitleBar::onAutoHideClicked: There can only be a single dock widget per titlebar overlayed");
519 auto dw = dockwidgets.first();
521 auto sideBarGroup = groupedAutoHide ? registry->sideBarGroupingFor(dw) :
DockWidget::List();
522 if (sideBarGroup.isEmpty()) {
526 for (
auto it = sideBarGroup.rbegin(); it != sideBarGroup.rend(); ++it) {
529 dw->setAsCurrentTab();
530 registry->removeSideBarGrouping(sideBarGroup);
534 registry->addSideBarGrouping(dockwidgets);
537 if (groupedAutoHide || dw == currentDw)
545 return m_closeButtonEnabled;
559 KDDW_ERROR(
"TitleBar::makeWindow shouldn't be called on invisible title bar this={}, root.isVisible={}", (
void * )
this,
view()->rootView()->
isVisible());
561 KDDW_ERROR(
"this={}; actual={}", (
void * )
this, (
void * )m_group->
actualTitleBar());
562 }
else if (m_floatingWindow) {
563 KDDW_ERROR(
"Has floating window with titlebar={}, isVisible={}", (
void * )m_floatingWindow->
titleBar(), m_floatingWindow->
isVisible());
570 if (m_floatingWindow) {
572 return std::make_unique<WindowBeingDragged>(m_floatingWindow,
this);
578 KDDW_DEBUG(
"TitleBar::makeWindow no detach needed");
579 return std::make_unique<WindowBeingDragged>(fw,
this);
590 auto draggable = KDDockWidgets::usesNativeTitleBar() ?
static_cast<Draggable *
>(
floatingWindow)
591 :
static_cast<Draggable *
>(
this);
592 return std::make_unique<WindowBeingDragged>(
floatingWindow, draggable);
597 return m_floatingWindow !=
nullptr;
602 if (m_floatingWindow) {
604 const auto groups = m_floatingWindow->
groups();
617 KDDW_ERROR(
"TitleBar::dockWidget: shouldn't happen");
629 if (m_floatingWindow)
638 KDDW_ERROR(
"TitleBar::isFloating: shouldn't happen");
646 else if (m_floatingWindow)
648 else if (m_isStandalone)
654void TitleBar::updateFloatButton()
656 setFloatButtonToolTip(
floatingWindow() ? tr(
"Dock window") : tr(
"Undock window"));
662 return m_floatButtonToolTip;
672 KDDW_ERROR(
"Expected a group");
675 }
else if (m_group) {
684 return m_maximizeButtonType;
689 return m_isStandalone;
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.