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, TabWidgetOptions options)
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);
72 TabBar *TabWidgetWidget::tabBar()
const
77 int TabWidgetWidget::numDockWidgets()
const
84 removeTab(indexOf(dw));
87 int TabWidgetWidget::indexOfDockWidget(
const DockWidgetBase *dw)
const
92 void TabWidgetWidget::mouseDoubleClickEvent(
QMouseEvent *ev)
94 if (onMouseDoubleClick(ev->
pos())) {
101 void TabWidgetWidget::mousePressEvent(
QMouseEvent *ev)
105 if ((Config::self().flags() & Config::Flag_TitleBarIsFocusable) && !frame()->isFocused()) {
111 void TabWidgetWidget::tabInserted(
int)
116 void TabWidgetWidget::tabRemoved(
int)
121 bool TabWidgetWidget::isPositionDraggable(
QPoint p)
const
124 qWarning() << Q_FUNC_INFO <<
"Not implemented yet. Only North is supported";
131 void TabWidgetWidget::setCurrentDockWidget(
int index)
133 setCurrentIndex(index);
136 bool TabWidgetWidget::insertDockWidget(
int index,
DockWidgetBase *dw,
139 insertTab(index, dw, icon, title);
143 void TabWidgetWidget::setTabBarAutoHide(
bool b)
148 void TabWidgetWidget::renameTab(
int index,
const QString &text)
150 setTabText(index, text);
153 void TabWidgetWidget::changeTabIcon(
int index,
const QIcon &icon)
155 setTabIcon(index, icon);
160 return qobject_cast<DockWidgetBase *>(widget(index));
163 int TabWidgetWidget::currentIndex()
const
168 void TabWidgetWidget::setupTabBarButtons()
170 if (!(Config::self().flags() & Config::Flag_ShowButtonsOnTabBarIfTitleBarHidden))
173 auto factory = Config::self().frameworkWidgetFactory();
174 m_closeButton = factory->createTitleBarButton(
this, TitleBarButtonType::Close);
175 m_floatButton = factory->createTitleBarButton(
this, TitleBarButtonType::Float);
177 auto cornerWidget =
new QWidget(
this);
178 cornerWidget->setObjectName(QStringLiteral(
"Corner Widget"));
182 m_cornerWidgetLayout =
new QHBoxLayout(cornerWidget);
184 m_cornerWidgetLayout->addWidget(m_floatButton);
185 m_cornerWidgetLayout->addWidget(m_closeButton);
188 TitleBar *tb = frame()->titleBar();
189 tb->onFloatClicked();
193 TitleBar *tb = frame()->titleBar();
194 tb->onCloseClicked();
198 connect(DockRegistry::self(), &DockRegistry::windowChangedScreen,
this, [
this](
QWindow *w) {
199 if (w == window()->windowHandle())
204 void TabWidgetWidget::updateMargins()
206 const qreal factor = logicalDpiFactor(
this);
207 m_cornerWidgetLayout->setContentsMargins(
QMargins(0, 0, 2, 0) * factor);
208 m_cornerWidgetLayout->setSpacing(
int(2 * factor));
211 void TabWidgetWidget::showContextMenu(
QPoint pos)
213 if (!(Config::self().flags() & Config::Flag_AllowSwitchingTabsViaMenu))
218 if (tabBar->
count() <= 1)
222 if (tabBar->
tabAt(pos) >= 0)
227 tabAreaRect.
setWidth(this->width());
232 for (
int i = 0; i < tabBar->
count(); ++i) {
233 QAction *action = menu.addAction(tabText(i),
this, [
this, i] {
236 if (i == currentIndex())
239 menu.exec(mapToGlobal(pos));