19 #include "TabWidgetWidget_p.h"
22 #include "../Frame_p.h"
23 #include "../TitleBar_p.h"
24 #include "../DockRegistry_p.h"
26 #include <QMouseEvent>
28 #include <QHBoxLayout>
29 #include <QAbstractButton>
33 TabWidgetWidget::TabWidgetWidget(Frame *parent)
35 , TabWidget(this, parent)
36 , m_tabBar(
Config::self().frameworkWidgetFactory()->createTabBar(this))
38 setTabBar(
static_cast<QTabBar *
>(m_tabBar->asWidget()));
39 setTabsClosable(Config::self().flags() & Config::Flag_TabsHaveCloseButton);
44 if (dw->options() & DockWidgetBase::Option_NotClosable) {
45 qWarning() <<
"QTabWidget::tabCloseRequested: Refusing to close dock widget with Option_NotClosable option. name=" << dw->uniqueName();
50 qWarning() <<
"QTabWidget::tabCloseRequested Couldn't find dock widget for index" << index <<
"; count=" << count();
55 onCurrentTabChanged(index);
56 Q_EMIT currentTabChanged(index);
57 Q_EMIT currentDockWidgetChanged(currentDockWidget());
61 setFocusProxy(
nullptr);
66 TabBar *TabWidgetWidget::tabBar()
const
71 int TabWidgetWidget::numDockWidgets()
const
78 removeTab(indexOf(dw));
81 int TabWidgetWidget::indexOfDockWidget(
const DockWidgetBase *dw)
const
86 void TabWidgetWidget::mouseDoubleClickEvent(
QMouseEvent *ev)
88 if (onMouseDoubleClick(ev->
pos())) {
95 void TabWidgetWidget::mousePressEvent(
QMouseEvent *ev)
99 if ((Config::self().flags() & Config::Flag_TitleBarIsFocusable) && !frame()->isFocused()) {
105 void TabWidgetWidget::tabInserted(
int)
110 void TabWidgetWidget::tabRemoved(
int)
115 bool TabWidgetWidget::isPositionDraggable(
QPoint p)
const
118 qWarning() << Q_FUNC_INFO <<
"Not implemented yet. Only North is supported";
125 void TabWidgetWidget::setCurrentDockWidget(
int index)
127 setCurrentIndex(index);
130 bool TabWidgetWidget::insertDockWidget(
int index,
DockWidgetBase *dw,
133 insertTab(index, dw, icon, title);
137 void TabWidgetWidget::setTabBarAutoHide(
bool b)
142 void TabWidgetWidget::renameTab(
int index,
const QString &text)
144 setTabText(index, text);
147 void TabWidgetWidget::changeTabIcon(
int index,
const QIcon &icon)
149 setTabIcon(index, icon);
154 return qobject_cast<DockWidgetBase *>(widget(index));
157 int TabWidgetWidget::currentIndex()
const
162 void TabWidgetWidget::setupTabBarButtons()
164 if (!(Config::self().flags() & Config::Flag_ShowButtonsOnTabBarIfTitleBarHidden))
167 auto factory = Config::self().frameworkWidgetFactory();
168 m_closeButton = factory->createTitleBarButton(
this, TitleBarButtonType::Close);
169 m_floatButton = factory->createTitleBarButton(
this, TitleBarButtonType::Float);
171 auto cornerWidget =
new QWidget(
this);
172 cornerWidget->setObjectName(QStringLiteral(
"Corner Widget"));
176 m_cornerWidgetLayout =
new QHBoxLayout(cornerWidget);
178 m_cornerWidgetLayout->addWidget(m_floatButton);
179 m_cornerWidgetLayout->addWidget(m_closeButton);
182 TitleBar *tb = frame()->titleBar();
183 tb->onFloatClicked();
187 TitleBar *tb = frame()->titleBar();
188 tb->onCloseClicked();
192 connect(DockRegistry::self(), &DockRegistry::windowChangedScreen,
this, [
this](
QWindow *w) {
193 if (w == window()->windowHandle())
198 void TabWidgetWidget::updateMargins()
200 const qreal factor = logicalDpiFactor(
this);
201 m_cornerWidgetLayout->setContentsMargins(
QMargins(0, 0, 2, 0) * factor);
202 m_cornerWidgetLayout->setSpacing(
int(2 * factor));