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>
34 TabWidgetWidget::TabWidgetWidget(Frame *parent)
36 , TabWidget(this, parent)
37 , m_tabBar(
Config::self().frameworkWidgetFactory()->createTabBar(this))
39 setTabBar(
static_cast<QTabBar *
>(m_tabBar->asWidget()));
40 setTabsClosable(Config::self().flags() & Config::Flag_TabsHaveCloseButton);
48 if (dw->options() & DockWidgetBase::Option_NotClosable) {
49 qWarning() <<
"QTabWidget::tabCloseRequested: Refusing to close dock widget with Option_NotClosable option. name=" << dw->uniqueName();
54 qWarning() <<
"QTabWidget::tabCloseRequested Couldn't find dock widget for index" << index <<
"; count=" << count();
59 onCurrentTabChanged(index);
60 Q_EMIT currentTabChanged(index);
61 Q_EMIT currentDockWidgetChanged(currentDockWidget());
65 setFocusProxy(
nullptr);
70 TabBar *TabWidgetWidget::tabBar()
const
75 int TabWidgetWidget::numDockWidgets()
const
82 removeTab(indexOf(dw));
85 int TabWidgetWidget::indexOfDockWidget(
const DockWidgetBase *dw)
const
90 void TabWidgetWidget::mouseDoubleClickEvent(
QMouseEvent *ev)
92 if (onMouseDoubleClick(ev->
pos())) {
99 void TabWidgetWidget::mousePressEvent(
QMouseEvent *ev)
103 if ((Config::self().flags() & Config::Flag_TitleBarIsFocusable) && !frame()->isFocused()) {
109 void TabWidgetWidget::tabInserted(
int)
114 void TabWidgetWidget::tabRemoved(
int)
119 bool TabWidgetWidget::isPositionDraggable(
QPoint p)
const
122 qWarning() << Q_FUNC_INFO <<
"Not implemented yet. Only North is supported";
129 void TabWidgetWidget::setCurrentDockWidget(
int index)
131 setCurrentIndex(index);
134 bool TabWidgetWidget::insertDockWidget(
int index,
DockWidgetBase *dw,
137 insertTab(index, dw, icon, title);
141 void TabWidgetWidget::setTabBarAutoHide(
bool b)
146 void TabWidgetWidget::renameTab(
int index,
const QString &text)
148 setTabText(index, text);
151 void TabWidgetWidget::changeTabIcon(
int index,
const QIcon &icon)
153 setTabIcon(index, icon);
158 return qobject_cast<DockWidgetBase *>(widget(index));
161 int TabWidgetWidget::currentIndex()
const
166 void TabWidgetWidget::setupTabBarButtons()
168 if (!(Config::self().flags() & Config::Flag_ShowButtonsOnTabBarIfTitleBarHidden))
171 auto factory = Config::self().frameworkWidgetFactory();
172 m_closeButton = factory->createTitleBarButton(
this, TitleBarButtonType::Close);
173 m_floatButton = factory->createTitleBarButton(
this, TitleBarButtonType::Float);
175 auto cornerWidget =
new QWidget(
this);
176 cornerWidget->setObjectName(QStringLiteral(
"Corner Widget"));
180 m_cornerWidgetLayout =
new QHBoxLayout(cornerWidget);
182 m_cornerWidgetLayout->addWidget(m_floatButton);
183 m_cornerWidgetLayout->addWidget(m_closeButton);
186 TitleBar *tb = frame()->titleBar();
187 tb->onFloatClicked();
191 TitleBar *tb = frame()->titleBar();
192 tb->onCloseClicked();
196 connect(DockRegistry::self(), &DockRegistry::windowChangedScreen,
this, [
this](
QWindow *w) {
197 if (w == window()->windowHandle())
202 void TabWidgetWidget::updateMargins()
204 const qreal factor = logicalDpiFactor(
this);
205 m_cornerWidgetLayout->setContentsMargins(
QMargins(0, 0, 2, 0) * factor);
206 m_cornerWidgetLayout->setSpacing(
int(2 * factor));
209 void TabWidgetWidget::showContextMenu(
QPoint pos)
211 if (!(Config::self().flags() & Config::Flag_AllowSwitchingTabsViaMenu))
216 if (tabBar->
count() <= 1)
220 if (tabBar->
tabAt(pos) >= 0)
225 tabAreaRect.
setWidth(this->width());
230 for (
int i = 0; i < tabBar->
count(); ++i) {
231 QAction *action = menu.addAction(tabText(i),
this, [
this, i] {
234 if (i == currentIndex())
237 menu.exec(mapToGlobal(pos));