7#include "QskAnimationHint.h"
9#include "QskStackBox.h"
10#include "QskStackBoxAnimator.h"
12#include "QskTabButton.h"
19static inline Qt::Orientation qskTransposed( Qt::Orientation orientation )
21 return ( orientation == Qt::Vertical ) ? Qt::Horizontal : Qt::Vertical;
24class QskTabView::PrivateData
31QskTabView::QskTabView( QQuickItem* parent )
33 , m_data( new PrivateData() )
35 setPolishOnResize(
true );
40 m_data->stackBox->setObjectName( QStringLiteral(
"QskTabViewStackBox" ) );
43 const auto hint = animationHint( Page );
44 if ( hint.duration > 0 )
49 animator->setDuration( hint.duration );
50 animator->setEasingCurve( hint.type );
52 m_data->stackBox->setAnimator( animator );
56 connect( m_data->tabBar, &QskTabBar::currentIndexChanged,
57 m_data->stackBox, &QskStackBox::setCurrentIndex );
59 connect( m_data->tabBar, &QskTabBar::currentIndexChanged,
60 this, &QskTabView::currentIndexChanged );
62 connect( m_data->tabBar, &QskTabBar::countChanged,
63 this, &QskTabView::countChanged );
65 connect( m_data->tabBar, &QskTabBar::edgeChanged,
66 this, &QskTabView::tabBarEdgeChanged );
68 connect( m_data->tabBar, &QskTabBar::autoFitTabsChanged,
69 this, &QskTabView::autoFitTabsChanged );
72QskTabView::~QskTabView()
78 return m_data->tabBar;
81const QskTabBar* QskTabView::tabBar()
const
83 return m_data->tabBar;
86void QskTabView::setTabBarEdge( Qt::Edge edge )
88 m_data->tabBar->setEdge( edge );
91Qt::Edge QskTabView::tabBarEdge()
const
93 return m_data->tabBar->edge();
96void QskTabView::setAutoFitTabs(
bool on )
98 m_data->tabBar->setAutoFitTabs( on );
101bool QskTabView::autoFitTabs()
const
103 return m_data->tabBar->autoFitTabs();
106Qt::Orientation QskTabView::orientation()
const
108 return qskTransposed( m_data->tabBar->orientation() );
111int QskTabView::addTab(
const QString& text, QQuickItem* page )
113 return insertTab( -1, text, page );
116int QskTabView::insertTab(
int index,
const QString& text, QQuickItem* page )
118 index = m_data->tabBar->insertTab( index, text );
120 if ( page && page->parent() ==
nullptr )
121 page->setParent(
this );
123 m_data->stackBox->insertItem( index, page );
128void QskTabView::removeTab(
int index )
130 if ( index >= 0 && index < m_data->tabBar->count() )
132 QPointer< QQuickItem > page = m_data->stackBox->itemAtIndex( index );
139 m_data->stackBox->removeAt( index );
140 m_data->tabBar->removeTab( index );
144 if ( page->parent() ==
this )
147 page->setParentItem(
nullptr );
152void QskTabView::clear(
bool autoDelete )
154 m_data->tabBar->clear( autoDelete );
155 m_data->stackBox->clear( autoDelete );
158void QskTabView::setTabEnabled(
int index,
bool enabled )
160 m_data->tabBar->setTabEnabled( index, enabled );
161 if (
auto page = pageAt( index ) )
162 page->setEnabled( enabled );
165bool QskTabView::isTabEnabled(
int index )
const
167 return m_data->tabBar->isTabEnabled( index );
170QQuickItem* QskTabView::pageAt(
int index )
const
172 return m_data->stackBox->itemAtIndex( index );
175int QskTabView::pageIndex(
const QQuickItem* page )
177 return m_data->stackBox->indexOf( page );
180QQuickItem* QskTabView::currentPage()
const
182 return pageAt( currentIndex() );
185int QskTabView::currentIndex()
const
187 return m_data->tabBar->currentIndex();
190int QskTabView::count()
const
192 return m_data->tabBar->count();
197 return m_data->tabBar->effectiveVariation();
200QSizeF QskTabView::layoutSizeHint(
201 Qt::SizeHint which,
const QSizeF& constraint )
const
203 if ( which == Qt::MaximumSize )
206 const auto& tabBar = m_data->tabBar;
207 const auto& stackBox = m_data->stackBox;
216 const qreal minBarSize = 200;
221 if ( orientation() == Qt::Vertical )
223 barHint.setWidth( qMin( barHint.width(), minBarSize ) );
225 if ( constraint.width() >= 0.0 )
227 qreal w = qMax( constraint.width(), barHint.width() );
228 qreal h = stackBox->sizeConstraint( which, QSizeF( w, -1.0 ) ).height();
230 hint.rheight() = barHint.height() + h;
232 else if ( constraint.height() >= 0.0 )
234 qreal h = constraint.height() - barHint.height();
235 qreal w = stackBox->sizeConstraint( which, QSizeF( -1.0, h ) ).width();
237 hint.rwidth() = qMax( barHint.width(), w );
241 const auto boxHint = stackBox->sizeConstraint();
243 hint.rwidth() = qMax( barHint.width(), boxHint.width() );
244 hint.rheight() = barHint.height() + boxHint.height();
249 barHint.setHeight( qMin( barHint.height(), minBarSize ) );
251 if ( constraint.width() >= 0.0 )
253 qreal w = constraint.width() - barHint.width();
254 qreal h = stackBox->sizeConstraint( which, QSizeF( w, -1.0 ) ).height();
256 hint.rheight() = qMax( barHint.height(), h );
258 else if ( constraint.height() >= 0.0 )
260 qreal h = qMax( constraint.height(), barHint.height() );
261 qreal w = stackBox->sizeConstraint( which, QSizeF( -1.0, h ) ).width();
263 hint.rwidth() = barHint.width() + w;
267 const auto boxHint = stackBox->sizeConstraint( which );
269 hint.rwidth() = barHint.width() + boxHint.width();
270 hint.rheight() = qMax( barHint.height(), boxHint.height() );
277void QskTabView::setCurrentIndex(
int index )
279 m_data->tabBar->setCurrentIndex( index );
282bool QskTabView::event( QEvent* event )
284 if ( event->type() == QEvent::LayoutRequest )
291 return Inherited::event( event );
294void QskTabView::updateLayout()
312int QskTabView::addTab(
QskTabButton* button, QQuickItem* page )
314 return insertTab( -1, button, page );
317int QskTabView::insertTab(
int index,
QskTabButton* button, QQuickItem* page )
319 if ( page && page->parent() ==
nullptr )
320 page->setParent(
this );
322 index = m_data->tabBar->insertTab( index, button );
323 m_data->stackBox->insertItem( index, page );
330 return m_data->tabBar->buttonAt( index );
333int QskTabView::buttonIndex(
const QskTabButton* button )
335 return m_data->tabBar->indexOf( button );
340 return buttonAt( currentIndex() );
345#include "moc_QskTabView.cpp"
Variation
Some sort of variation.
QRectF subControlRect(QskAspect::Subcontrol) const
QRectF subControlContentsRect(QskAspect::Subcontrol) const
QRectF contentsRect() const
bool maybeUnresized() const
QskAspect::Variation effectiveVariation() const override