19#include "TabWidgetWidget_p.h"
22#include "../Frame_p.h"
23#include "../TitleBar_p.h"
24#include "../DockRegistry_p.h"
29#include <QAbstractButton>
34TabWidgetWidget::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()));
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);
72TabBar *TabWidgetWidget::tabBar()
const
77int TabWidgetWidget::numDockWidgets()
const
84 removeTab(indexOf(dw));
87int TabWidgetWidget::indexOfDockWidget(
const DockWidgetBase *dw)
const
92void TabWidgetWidget::mouseDoubleClickEvent(
QMouseEvent *ev)
94 if (onMouseDoubleClick(ev->
pos())) {
101void TabWidgetWidget::mousePressEvent(
QMouseEvent *ev)
111void TabWidgetWidget::tabInserted(
int)
116void TabWidgetWidget::tabRemoved(
int)
121bool TabWidgetWidget::isPositionDraggable(
QPoint p)
const
124 qWarning() << Q_FUNC_INFO <<
"Not implemented yet. Only North is supported";
131void TabWidgetWidget::setCurrentDockWidget(
int index)
133 setCurrentIndex(index);
136bool TabWidgetWidget::insertDockWidget(
int index,
DockWidgetBase *dw,
139 insertTab(index, dw, icon, title);
143void TabWidgetWidget::setTabBarAutoHide(
bool b)
148void TabWidgetWidget::renameTab(
int index,
const QString &text)
150 setTabText(index, text);
153void TabWidgetWidget::changeTabIcon(
int index,
const QIcon &icon)
155 setTabIcon(index, icon);
160 return qobject_cast<DockWidgetBase *>(widget(index));
163int TabWidgetWidget::currentIndex()
const
168void TabWidgetWidget::setupTabBarButtons()
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())
204void 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));
211void TabWidgetWidget::showContextMenu(
QPoint pos)
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));
Application-wide config to tune certain behaviours of the framework.
bool contains(const QRect &rectangle, bool proper) const const
int tabAt(const QPoint &position) const const