22#include "core/DockWidget_p.h"
23#include "kddockwidgets/core/TabBar.h"
24#include "kddockwidgets/core/Stack.h"
25#include "core/ScopedValueRollback_p.h"
26#include "core/TabBar_p.h"
27#include "core/Stack_p.h"
28#include "core/Logging_p.h"
37#include <unordered_map>
42class QtQuick::TabBar::Private
50 int m_hoveredTabIndex = -1;
56class DockWidgetModel::Private
69 std::unordered_map<Core::DockWidget *, KDBindings::ScopedConnection>
72 bool m_removeGuard =
false;
77 :
View(controller, Core::ViewType::
TabBar, parent)
78 , TabBarViewInterface(controller)
79 , d(new Private(controller, this))
82 [
controller] { controller->dptr()->countChanged.emit(); });
92 d->m_tabBarAutoHideChanged =
m_tabBar->
stack()->d->tabBarAutoHideChanged.connect(
102 if (!d->m_tabBarQmlItem) {
103 qWarning() << Q_FUNC_INFO <<
"No visual tab bar item yet";
107 const QPointF globalPos = d->m_tabBarQmlItem->mapToGlobal(localPt);
115 return index.
toInt();
122 return d->m_tabBarQmlItem;
127 if (d->m_tabBarQmlItem == item) {
128 qWarning() << Q_FUNC_INFO <<
"Should be called only once";
132 d->m_tabBarQmlItem = item;
138 if (QQuickItem *item =
tabAt(index))
139 return item->property(
"text").toString();
146 if (QQuickItem *item =
tabAt(index))
147 return item->boundingRect().toRect();
154 if (QQuickItem *item =
tabAt(index)) {
155 QRect r = item->boundingRect().toRect();
165 switch (ev->
type()) {
168 if (d->m_tabBarQmlItem) {
170 const int idx =
tabAt(me->pos());
172 d->m_tabBarQmlItem->setProperty(
"currentTabIndex", idx);
196 d->m_tabBarQmlItem,
"getTabAtIndex", Q_RETURN_ARG(
QVariant, result), Q_ARG(
QVariant, index));
199 return result.
value<QQuickItem *>();
201 qWarning() << Q_FUNC_INFO <<
"Could not find tab for index" << index;
223 qWarning() << Q_FUNC_INFO <<
"Unexpected null Stack_qtquick";
229 d->m_dockWidgetModel->setCurrentIndex(index);
234 if (
auto dw = d->m_dockWidgetModel->dockWidgetAt(index))
253 d->m_dockWidgetModel->remove(dw);
262 d->m_dockWidgetModel->insert(dw, index);
267 return d->m_dockWidgetModel;
273 setHoveredTabIndex(-1);
281 const int count = d->m_dockWidgetModel->count();
282 for (
int i = 0; i < count; i++) {
291void TabBar::setHoveredTabIndex(
int idx)
293 if (idx == d->m_hoveredTabIndex)
296 d->m_hoveredTabIndex = idx;
302 return d->m_hoveredTabIndex;
309 qWarning() << Q_FUNC_INFO <<
"Refusing to add null dock widget";
318 qWarning() << Q_FUNC_INFO <<
"No existing tab was found";
322 if (
auto dwi = qobject_cast<DockWidgetInstantiator *>(other)) {
325 }
else if (
auto dwView = qobject_cast<QtQuick::DockWidget *>(other)) {
327 }
else if (
auto dw = qobject_cast<Core::DockWidget *>(other)) {
328 dw->addDockWidgetAsTab(dw, opt);
330 qWarning() << Q_FUNC_INFO <<
"Could not understand what is" << other;
336 , d(new Private(tabBar))
347 return d->m_dockWidgets.size();
352 return parent.isValid() ? 0 : d->m_dockWidgets.size();
358 if (row < 0 || row >= d->m_dockWidgets.size())
371 if (index < 0 || index >= d->m_dockWidgets.size()) {
376 return d->m_dockWidgets.at(
index);
381 return d->m_dockWidgets.contains(dw);
386 return d->m_currentDockWidget;
392 if (d->m_currentDockWidget && !d->m_currentDockWidget->inDtor())
393 d->m_currentDockWidget->setVisible(
false);
395 d->m_currentDockWidget = dw;
397 if (d->m_currentDockWidget) {
398 ScopedValueRollback guard(d->m_currentDockWidget->d->m_isSettingCurrent,
true);
399 d->m_currentDockWidget->setVisible(
true);
412 qWarning() << Q_FUNC_INFO <<
"Couldn't find" << dw;
421 ScopedValueRollback guard(d->m_removeGuard,
true);
425 if (!d->m_removeGuard) {
428 qWarning() << Q_FUNC_INFO <<
"Nothing to remove"
429 <<
static_cast<void *
>(dw);
434 auto it = d->m_connections2.find(dw);
435 if (it != d->m_connections2.end())
436 d->m_connections2.erase(it);
439 d->m_dockWidgets.removeOne(dw);
454 if (!d->m_currentDockWidget)
457 const int index = d->m_dockWidgets.indexOf(d->m_currentDockWidget);
460 qWarning() << Q_FUNC_INFO <<
"Unexpected null index for" << d->m_currentDockWidget <<
this
461 <<
"; count=" <<
count();
470 if (d->m_currentDockWidget != dw) {
474 d->m_tabBar->setCurrentIndex(
index);
480 if (d->m_dockWidgets.contains(dw)) {
481 qWarning() << Q_FUNC_INFO <<
"Shouldn't happen";
490 d->m_connections[dw] = destroyedConnection;
491 d->m_connections2[dw] = std::move(titleChangedConnection);
494 d->m_dockWidgets.insert(
index, dw);
A ScopedConnection is a RAII-style way to make sure a Connection is disconnected.
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QEvent::Type type() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void destroyed(QObject *obj)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QObject * parent() const const
bool contains(const QRect &rectangle, bool proper) const const
void moveTopLeft(const QPoint &position)
QPoint topLeft() const const
int toInt(bool *ok) const const