20 #include "TabWidget_p.h"
22 #include "DockWidgetBase_p.h"
23 #include "DragController_p.h"
24 #include "FloatingWindow_p.h"
27 #include "Logging_p.h"
29 #include "WindowBeingDragged_p.h"
41 , m_tabWidget(tabWidget)
42 , m_thisWidget(thisWidget)
48 if (index < 0 || index >= numDockWidgets())
51 return m_tabWidget->dockwidgetAt(index);
56 return dockWidgetAt(tabAt(localPos));
59 std::unique_ptr<WindowBeingDragged> TabBar::makeWindow()
61 auto dock = m_lastPressedDockWidget;
62 m_lastPressedDockWidget =
nullptr;
64 const bool hideTitleBarWhenTabsVisible = Config::self().flags() & Config::Flag_HideTitleBarWhenTabsVisible;
65 const bool alwaysShowTabs = Config::self().flags() & Config::Flag_AlwaysShowTabs;
67 if (hideTitleBarWhenTabsVisible) {
69 if (alwaysShowTabs && hasSingleDockWidget()) {
71 return m_tabWidget->makeWindow();
76 return m_tabWidget->makeWindow();
79 if (dock && hasSingleDockWidget() && alwaysShowTabs) {
88 FloatingWindow *floatingWindow = frame()->detachTab(dock);
92 auto draggable = KDDockWidgets::usesNativeTitleBar() ?
static_cast<Draggable *
>(floatingWindow)
94 return std::unique_ptr<WindowBeingDragged>(
new WindowBeingDragged(floatingWindow, draggable));
97 bool TabBar::isWindow()
const
100 return m_tabWidget->isWindow();
103 void TabBar::onMousePress(
QPoint localPos)
105 m_lastPressedDockWidget = dockWidgetAt(localPos);
106 Frame *frame = this->frame();
107 if ((Config::self().flags() & Config::Flag_TitleBarIsFocusable) && !frame->isFocused()) {
114 void TabBar::onMouseDoubleClick(
QPoint localPos)
117 dw->setFloating(
true);
120 bool TabBar::hasSingleDockWidget()
const
122 return numDockWidgets() == 1;
125 int TabBar::numDockWidgets()
const
127 return m_tabWidget->numDockWidgets();
137 return m_tabWidget->singleDockWidget();
140 bool TabBar::isMDI()
const
143 return f && f->isMDI();
146 Frame *TabBar::frame()
const
148 return m_tabWidget->frame();
154 , m_thisWidget(thisWidget)
160 setCurrentDockWidget(indexOfDockWidget(dw));
165 return dockwidgetAt(currentIndex());
170 insertDockWidget(dock, numDockWidgets());
176 qCDebug(addwidget) << Q_FUNC_INFO << dock <<
"; count before=" << numDockWidgets();
180 if (index > numDockWidgets())
181 index = numDockWidgets();
183 if (contains(dock)) {
184 qWarning() << Q_FUNC_INFO <<
"Refusing to add already existing widget";
189 insertDockWidget(index, dock, dock->
icon(DockWidgetBase::IconPlace::TabBar), dock->
title());
190 setCurrentDockWidget(index);
192 if (oldFrame && oldFrame->beingDeletedLater()) {
209 return indexOfDockWidget(dw) != -1;
217 Frame *TabWidget::frame()
const
222 std::unique_ptr<WindowBeingDragged> TabWidget::makeWindow()
226 if (
auto floatingWindow = qobject_cast<FloatingWindow *>(asWidget()->window())) {
227 if (floatingWindow->hasSingleFrame()) {
230 return std::unique_ptr<WindowBeingDragged>(
new WindowBeingDragged(floatingWindow,
this));
234 QRect r = m_frame->QWidgetAdapter::geometry();
236 const QPoint globalPoint = m_thisWidget->mapToGlobal(
QPoint(0, 0));
238 auto floatingWindow = Config::self().frameworkWidgetFactory()->createFloatingWindow(m_frame);
241 floatingWindow->show();
243 return std::unique_ptr<WindowBeingDragged>(
new WindowBeingDragged(floatingWindow,
this));
246 bool TabWidget::isWindow()
const
248 if (
auto floatingWindow = qobject_cast<FloatingWindow *>(asWidget()->window())) {
250 return floatingWindow->hasSingleFrame();
258 if (m_frame->hasSingleDockWidget())
259 return m_frame->dockWidgets().first();
264 bool TabWidget::isMDI()
const
266 return m_frame && m_frame->isMDI();
269 void TabWidget::onTabInserted()
271 m_frame->onDockWidgetCountChanged();
274 void TabWidget::onTabRemoved()
276 m_frame->onDockWidgetCountChanged();
279 void TabWidget::onCurrentTabChanged(
int index)
284 bool TabWidget::onMouseDoubleClick(
QPoint localPos)
289 if (!(Config::self().flags() & Config::Flag_HideTitleBarWhenTabsVisible) || tabBar()->dockWidgetAt(localPos))
292 Frame *frame = this->frame();
295 if (frame->isCentralFrame())
298 if (FloatingWindow *fw = frame->floatingWindow()) {
299 if (!fw->hasSingleFrame()) {
303 }
else if (frame->isInMainWindow()) {