140 const int count = contentModel->count();
141 if (count <= 0 || !contentItem)
144 const bool horizontal = orientation == Qt::Horizontal;
145 qreal reservedSize = 0;
146 int resizableCount = 0;
148 QList<QQuickItem *> allItems;
149 allItems.reserve(count);
151 for (
int i = 0; i < count; ++i) {
152 QQuickItem *item = q->itemAt(i);
154 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
155 const bool sizeValid = horizontal ? p->widthValid() : p->heightValid();
159 reservedSize += horizontal ? item->width() : item->height();
164 const qreal totalSpacing = qMax(0, count - 1) * spacing;
165 const qreal availableSize = horizontal ? contentItem->width() : contentItem->height();
166 const qreal itemSize = (availableSize - reservedSize - totalSpacing) / qMax(1, resizableCount);
169 for (QQuickItem *item : std::as_const(allItems)) {
170 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
172 if (!p->widthValid()) {
173 item->setWidth(itemSize);
174 p->widthValidFlag =
false;
176 if (!p->heightValid()) {
177 item->setHeight(contentHeight);
178 p->heightValidFlag =
false;
180 item->setY((contentHeight - item->height()) / 2);
183 if (!p->heightValid()) {
184 item->setHeight(itemSize);
185 p->heightValidFlag =
false;
187 if (!p->widthValid()) {
188 item->setWidth(contentWidth);
189 p->widthValidFlag =
false;
191 item->setX((contentWidth - item->width()) / 2);
203 Q_Q(
const QQuickTabBar);
204 const int count = contentModel->count();
205 if (orientation == Qt::Vertical) {
207 for (
int i = 0; i < count; ++i) {
208 QQuickItem *item = q->itemAt(i);
210 maxWidth = qMax(maxWidth, item->implicitWidth());
215 qreal totalWidth = qMax(0, count - 1) * spacing;
216 for (
int i = 0; i < count; ++i) {
217 QQuickItem *item = q->itemAt(i);
219 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
220 if (!p->widthValid())
221 totalWidth += item->implicitWidth();
223 totalWidth += item->width();
231 if (hasContentHeight)
232 return contentHeight;
234 Q_Q(
const QQuickTabBar);
235 const int count = contentModel->count();
236 if (orientation == Qt::Vertical) {
237 qreal totalHeight = qMax(0, count - 1) * spacing;
238 for (
int i = 0; i < count; ++i) {
239 QQuickItem *item = q->itemAt(i);
241 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
242 if (!p->heightValid())
243 totalHeight += item->implicitHeight();
245 totalHeight += item->height();
252 for (
int i = 0; i < count; ++i) {
253 QQuickItem *item = q->itemAt(i);
255 maxHeight = qMax(maxHeight, item->implicitHeight());
284QQuickTabBar::QQuickTabBar(QQuickItem *parent)
285 : QQuickContainer(*(
new QQuickTabBarPrivate), parent)
288 d->changeTypes |= QQuickItemPrivate::Geometry | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight;
289 setFlag(ItemIsFocusScope);
290 QObjectPrivate::connect(
this, &QQuickTabBar::currentIndexChanged, d, &QQuickTabBarPrivate::updateCurrentItem);
343void QQuickTabBar::setOrientation(Qt::Orientation orientation)
346 if (d->orientation == orientation)
349 d->orientation = orientation;
350 d->updateImplicitContentSize();
351 if (isComponentComplete())
353 emit orientationChanged();
444void QQuickTabBar::itemAdded(
int index, QQuickItem *item)
452 if (qobject_cast<QQuickItemView *>(d->contentItem))
453 QQuickItemPrivate::get(item)->setCulled(
true);
454 if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item))
455 QObjectPrivate::connect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex);
456 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
458 QQuickTabBarAttachedPrivate::get(attached)->update(
this, index);
459 d->updateImplicitContentSize();
460 if (isComponentComplete())
471void QQuickTabBar::itemRemoved(
int index, QQuickItem *item)
475 if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item))
476 QObjectPrivate::disconnect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex);
477 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
479 QQuickTabBarAttachedPrivate::get(attached)->update(
nullptr, -1);
480 d->updateImplicitContentSize();
481 if (isComponentComplete())
553 Q_Q(QQuickTabBarAttached);
554 const int oldIndex = index;
555 const QQuickTabBar *oldTabBar = tabBar;
556 const QQuickTabBar::Position oldPos = q->position();
561 if (oldTabBar != newTabBar) {
563 QObject::disconnect(oldTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged);
565 QObject::connect(newTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged);
566 emit q->tabBarChanged();
569 if (oldIndex != newIndex)
570 emit q->indexChanged();
571 if (oldPos != q->position())
572 emit q->positionChanged();