12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
71 Q_DECLARE_PUBLIC(QQuickTabBar)
88#if QT_CONFIG(wheelevent)
95 Q_DECLARE_PUBLIC(QQuickTabBarAttached)
111 QQuickTabButton *button = qobject_cast<QQuickTabButton *>(contentModel->get(currentIndex));
113 button->setChecked(
true);
119 QQuickTabButton *button = qobject_cast<QQuickTabButton *>(q->sender());
120 if (button && button->isChecked())
121 q->setCurrentIndex(contentModel->indexOf(button,
nullptr));
127 const int count = contentModel->count();
128 if (count <= 0 || !contentItem)
131 qreal reservedWidth = 0;
132 int resizableCount = 0;
134 QList<QQuickItem *> allItems;
135 allItems.reserve(count);
137 for (
int i = 0; i < count; ++i) {
138 QQuickItem *item = q->itemAt(i);
140 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
141 if (!p->widthValid())
144 reservedWidth += item->width();
149 const qreal totalSpacing = qMax(0, count - 1) * spacing;
150 const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / qMax(1, resizableCount);
153 for (QQuickItem *item : std::as_const(allItems)) {
154 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
155 if (!p->widthValid()) {
156 item->setWidth(itemWidth);
157 p->widthValidFlag =
false;
159 if (!p->heightValid()) {
160 item->setHeight(contentHeight);
161 p->heightValidFlag =
false;
163 item->setY((contentHeight - item->height()) / 2);
174 Q_Q(
const QQuickTabBar);
175 const int count = contentModel->count();
176 qreal totalWidth = qMax(0, count - 1) * spacing;
177 for (
int i = 0; i < count; ++i) {
178 QQuickItem *item = q->itemAt(i);
180 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
181 if (!p->widthValid())
182 totalWidth += item->implicitWidth();
184 totalWidth += item->width();
192 if (hasContentHeight)
193 return contentHeight;
195 Q_Q(
const QQuickTabBar);
196 const int count = contentModel->count();
198 for (
int i = 0; i < count; ++i) {
199 QQuickItem *item = q->itemAt(i);
201 maxHeight = qMax(maxHeight, item->implicitHeight());
208 QQuickContainerPrivate::itemGeometryChanged(item, change, diff);
210 if (change.sizeChange())
211 updateImplicitContentSize();
218 QQuickContainerPrivate::itemImplicitWidthChanged(item);
219 if (item != contentItem)
220 updateImplicitContentWidth();
225 QQuickContainerPrivate::itemImplicitHeightChanged(item);
226 if (item != contentItem)
227 updateImplicitContentHeight();
230QQuickTabBar::QQuickTabBar(QQuickItem *parent)
231 : QQuickContainer(*(
new QQuickTabBarPrivate), parent)
234 d->changeTypes |= QQuickItemPrivate::Geometry | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight;
235 setFlag(ItemIsFocusScope);
236 QObjectPrivate::connect(
this, &QQuickTabBar::currentIndexChanged, d, &QQuickTabBarPrivate::updateCurrentItem);
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255QQuickTabBar::Position QQuickTabBar::position()
const
257 Q_D(
const QQuickTabBar);
261void QQuickTabBar::setPosition(Position position)
264 if (d->position == position)
267 d->position = position;
268 emit positionChanged();
272
273
274
275
276
277
278
279
280
281
282
285
286
287
288
289
290
291
292
293
294
295
297QQuickTabBarAttached *QQuickTabBar::qmlAttachedProperties(QObject *object)
299 return new QQuickTabBarAttached(object);
302void QQuickTabBar::updatePolish()
305 QQuickContainer::updatePolish();
309void QQuickTabBar::componentComplete()
312 QQuickContainer::componentComplete();
313 d->updateCurrentItem();
317void QQuickTabBar::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
320 QQuickContainer::geometryChange(newGeometry, oldGeometry);
324bool QQuickTabBar::isContent(QQuickItem *item)
const
326 return qobject_cast<QQuickTabButton *>(item);
329void QQuickTabBar::itemAdded(
int index, QQuickItem *item)
333 QQuickItemPrivate::get(item)->setCulled(
true);
334 if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item))
335 QObjectPrivate::connect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex);
336 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
338 QQuickTabBarAttachedPrivate::get(attached)->update(
this, index);
339 d->updateImplicitContentSize();
340 if (isComponentComplete())
344void QQuickTabBar::itemMoved(
int index, QQuickItem *item)
346 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
348 QQuickTabBarAttachedPrivate::get(attached)->update(
this, index);
351void QQuickTabBar::itemRemoved(
int index, QQuickItem *item)
355 if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item))
356 QObjectPrivate::disconnect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex);
357 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
359 QQuickTabBarAttachedPrivate::get(attached)->update(
nullptr, -1);
360 d->updateImplicitContentSize();
361 if (isComponentComplete())
365#if QT_CONFIG(wheelevent)
366void QQuickTabBar::wheelEvent(QWheelEvent *event)
369 QQuickContainer::wheelEvent(event);
370 if (d->wheelEnabled) {
371 d->accumulatedAngleDelta += event->angleDelta();
372 int xSteps = d->accumulatedAngleDelta.x() / QWheelEvent::DefaultDeltasPerStep;
373 int ySteps = d->accumulatedAngleDelta.y() / QWheelEvent::DefaultDeltasPerStep;
374 if (xSteps > 0 || ySteps > 0) {
375 decrementCurrentIndex();
376 d->accumulatedAngleDelta = QPoint();
377 }
else if (xSteps < 0 || ySteps < 0) {
378 incrementCurrentIndex();
379 d->accumulatedAngleDelta = QPoint();
385QFont QQuickTabBar::defaultFont()
const
387 return QQuickTheme::font(QQuickTheme::TabBar);
390#if QT_CONFIG(accessibility)
391QAccessible::Role QQuickTabBar::accessibleRole()
const
393 return QAccessible::PageTabList;
398
399
400
401
402
403
404
405
408
409
410
411
412
413
414
415
418
419
420
421
422
423
424
425
426
427
428
429
433 Q_Q(QQuickTabBarAttached);
434 const int oldIndex = index;
435 const QQuickTabBar *oldTabBar = tabBar;
436 const QQuickTabBar::Position oldPos = q->position();
441 if (oldTabBar != newTabBar) {
443 QObject::disconnect(oldTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged);
445 QObject::connect(newTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged);
446 emit q->tabBarChanged();
449 if (oldIndex != newIndex)
450 emit q->indexChanged();
451 if (oldPos != q->position())
452 emit q->positionChanged();
455QQuickTabBarAttached::QQuickTabBarAttached(QObject *parent)
456 : QObject(*(
new QQuickTabBarAttachedPrivate), parent)
460int QQuickTabBarAttached::index()
const
462 Q_D(
const QQuickTabBarAttached);
466QQuickTabBar *QQuickTabBarAttached::tabBar()
const
468 Q_D(
const QQuickTabBarAttached);
472QQuickTabBar::Position QQuickTabBarAttached::position()
const
474 Q_D(
const QQuickTabBarAttached);
476 return QQuickTabBar::Header;
477 return d->tabBar->position();
482#include "moc_qquicktabbar_p.cpp"
Allows the user to switch between different views or subtasks.
void itemImplicitHeightChanged(QQuickItem *item) override
QPalette defaultPalette() const override
qreal getContentHeight() const override
void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override
void itemImplicitWidthChanged(QQuickItem *item) override
qreal getContentWidth() const override
void updateCurrentIndex()