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
67
68
69
74 Q_DECLARE_PUBLIC(QQuickTabBar)
91#if QT_CONFIG(wheelevent)
98 Q_DECLARE_PUBLIC(QQuickTabBarAttached)
114 QQuickTabButton *button = qobject_cast<QQuickTabButton *>(contentModel->get(currentIndex));
116 button->setChecked(
true);
122 QQuickTabButton *button = qobject_cast<QQuickTabButton *>(q->sender());
123 if (button && button->isChecked())
124 q->setCurrentIndex(contentModel->indexOf(button,
nullptr));
130 const int count = contentModel->count();
131 if (count <= 0 || !contentItem)
134 qreal reservedWidth = 0;
135 int resizableCount = 0;
137 QList<QQuickItem *> allItems;
138 allItems.reserve(count);
140 for (
int i = 0; i < count; ++i) {
141 QQuickItem *item = q->itemAt(i);
143 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
144 if (!p->widthValid())
147 reservedWidth += item->width();
152 const qreal totalSpacing = qMax(0, count - 1) * spacing;
153 const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / qMax(1, resizableCount);
156 for (QQuickItem *item : std::as_const(allItems)) {
157 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
158 if (!p->widthValid()) {
159 item->setWidth(itemWidth);
160 p->widthValidFlag =
false;
162 if (!p->heightValid()) {
163 item->setHeight(contentHeight);
164 p->heightValidFlag =
false;
166 item->setY((contentHeight - item->height()) / 2);
177 Q_Q(
const QQuickTabBar);
178 const int count = contentModel->count();
179 qreal totalWidth = qMax(0, count - 1) * spacing;
180 for (
int i = 0; i < count; ++i) {
181 QQuickItem *item = q->itemAt(i);
183 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
184 if (!p->widthValid())
185 totalWidth += item->implicitWidth();
187 totalWidth += item->width();
195 if (hasContentHeight)
196 return contentHeight;
198 Q_Q(
const QQuickTabBar);
199 const int count = contentModel->count();
201 for (
int i = 0; i < count; ++i) {
202 QQuickItem *item = q->itemAt(i);
204 maxHeight = qMax(maxHeight, item->implicitHeight());
211 QQuickContainerPrivate::itemGeometryChanged(item, change, diff);
213 if (change.sizeChange())
214 updateImplicitContentSize();
221 QQuickContainerPrivate::itemImplicitWidthChanged(item);
222 if (item != contentItem)
223 updateImplicitContentWidth();
228 QQuickContainerPrivate::itemImplicitHeightChanged(item);
229 if (item != contentItem)
230 updateImplicitContentHeight();
233QQuickTabBar::QQuickTabBar(QQuickItem *parent)
234 : QQuickContainer(*(
new QQuickTabBarPrivate), parent)
237 d->changeTypes |= QQuickItemPrivate::Geometry | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight;
238 setFlag(ItemIsFocusScope);
239 QObjectPrivate::connect(
this, &QQuickTabBar::currentIndexChanged, d, &QQuickTabBarPrivate::updateCurrentItem);
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258QQuickTabBar::Position QQuickTabBar::position()
const
260 Q_D(
const QQuickTabBar);
264void QQuickTabBar::setPosition(Position position)
267 if (d->position == position)
270 d->position = position;
271 emit positionChanged();
275
276
277
278
279
280
281
282
283
284
285
288
289
290
291
292
293
294
295
296
297
298
300QQuickTabBarAttached *QQuickTabBar::qmlAttachedProperties(QObject *object)
302 return new QQuickTabBarAttached(object);
305void QQuickTabBar::updatePolish()
308 QQuickContainer::updatePolish();
312void QQuickTabBar::componentComplete()
315 QQuickContainer::componentComplete();
316 d->updateCurrentItem();
320void QQuickTabBar::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
323 QQuickContainer::geometryChange(newGeometry, oldGeometry);
327bool QQuickTabBar::isContent(QQuickItem *item)
const
329 return qobject_cast<QQuickTabButton *>(item);
332void QQuickTabBar::itemAdded(
int index, QQuickItem *item)
336 QQuickItemPrivate::get(item)->setCulled(
true);
337 if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item))
338 QObjectPrivate::connect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex);
339 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
341 QQuickTabBarAttachedPrivate::get(attached)->update(
this, index);
342 d->updateImplicitContentSize();
343 if (isComponentComplete())
347void QQuickTabBar::itemMoved(
int index, QQuickItem *item)
349 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
351 QQuickTabBarAttachedPrivate::get(attached)->update(
this, index);
354void QQuickTabBar::itemRemoved(
int index, QQuickItem *item)
358 if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item))
359 QObjectPrivate::disconnect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex);
360 QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item));
362 QQuickTabBarAttachedPrivate::get(attached)->update(
nullptr, -1);
363 d->updateImplicitContentSize();
364 if (isComponentComplete())
368#if QT_CONFIG(wheelevent)
369void QQuickTabBar::wheelEvent(QWheelEvent *event)
372 QQuickContainer::wheelEvent(event);
373 if (d->wheelEnabled) {
374 d->accumulatedAngleDelta += event->angleDelta();
375 int xSteps = d->accumulatedAngleDelta.x() / QWheelEvent::DefaultDeltasPerStep;
376 int ySteps = d->accumulatedAngleDelta.y() / QWheelEvent::DefaultDeltasPerStep;
377 if (xSteps > 0 || ySteps > 0) {
378 decrementCurrentIndex();
379 d->accumulatedAngleDelta = QPoint();
380 }
else if (xSteps < 0 || ySteps < 0) {
381 incrementCurrentIndex();
382 d->accumulatedAngleDelta = QPoint();
388QFont QQuickTabBar::defaultFont()
const
390 return QQuickTheme::font(QQuickTheme::TabBar);
393#if QT_CONFIG(accessibility)
394QAccessible::Role QQuickTabBar::accessibleRole()
const
396 return QAccessible::PageTabList;
401
402
403
404
405
406
407
408
411
412
413
414
415
416
417
418
421
422
423
424
425
426
427
428
429
430
431
432
436 Q_Q(QQuickTabBarAttached);
437 const int oldIndex = index;
438 const QQuickTabBar *oldTabBar = tabBar;
439 const QQuickTabBar::Position oldPos = q->position();
444 if (oldTabBar != newTabBar) {
446 QObject::disconnect(oldTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged);
448 QObject::connect(newTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged);
449 emit q->tabBarChanged();
452 if (oldIndex != newIndex)
453 emit q->indexChanged();
454 if (oldPos != q->position())
455 emit q->positionChanged();
458QQuickTabBarAttached::QQuickTabBarAttached(QObject *parent)
459 : QObject(*(
new QQuickTabBarAttachedPrivate), parent)
463int QQuickTabBarAttached::index()
const
465 Q_D(
const QQuickTabBarAttached);
469QQuickTabBar *QQuickTabBarAttached::tabBar()
const
471 Q_D(
const QQuickTabBarAttached);
475QQuickTabBar::Position QQuickTabBarAttached::position()
const
477 Q_D(
const QQuickTabBarAttached);
479 return QQuickTabBar::Header;
480 return d->tabBar->position();
485#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()
Combined button and popup list for selecting options.