working on the QskTab classes redesign - initial API cleanup
This commit is contained in:
parent
d8b668603f
commit
75600b584d
@ -62,10 +62,10 @@ namespace
|
||||
setAutoFitTabs( true );
|
||||
}
|
||||
|
||||
void setTabsEnabled( bool on )
|
||||
void setPagesEnabled( bool on )
|
||||
{
|
||||
for ( int i = 0; i < count(); i++ )
|
||||
itemAt( i )->setEnabled( on );
|
||||
pageAt( i )->setEnabled( on );
|
||||
}
|
||||
|
||||
void addPage( const QString& tabText, QQuickItem* page )
|
||||
@ -232,7 +232,7 @@ namespace
|
||||
tabView->addPage( "Dialogs", new DialogPage() );
|
||||
|
||||
connect( header, &Header::enabledToggled,
|
||||
tabView, &TabView::setTabsEnabled );
|
||||
tabView, &TabView::setPagesEnabled );
|
||||
|
||||
setHeader( header );
|
||||
setBody( tabView );
|
||||
|
@ -113,7 +113,7 @@ void MainWindow::setDarknessMode( bool on )
|
||||
{
|
||||
for ( int i = 0; i < m_tabView->count(); i++ )
|
||||
{
|
||||
auto label = static_cast< GraphicLabel* >( m_tabView->itemAt( i ) );
|
||||
auto label = static_cast< GraphicLabel* >( m_tabView->pageAt( i ) );
|
||||
label->setDarknessMode( on );
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include <QskObjectCounter.h>
|
||||
#include <QskPushButton.h>
|
||||
#include <QskSkin.h>
|
||||
#include <QskTabButton.h>
|
||||
#include <QskTabBar.h>
|
||||
#include <QskTabView.h>
|
||||
#include <QskTextLabel.h>
|
||||
@ -92,7 +91,7 @@ class TabView : public QskTabView
|
||||
|
||||
}
|
||||
|
||||
buttonAt( 2 )->setEnabled( false );
|
||||
setTabEnabled( 2, false );
|
||||
setCurrentIndex( 4 );
|
||||
}
|
||||
|
||||
|
@ -108,54 +108,43 @@ Qt::Orientation QskTabView::orientation() const
|
||||
return qskTransposed( m_data->tabBar->orientation() );
|
||||
}
|
||||
|
||||
int QskTabView::addTab( QskTabButton* button, QQuickItem* item )
|
||||
int QskTabView::addTab( const QString& text, QQuickItem* page )
|
||||
{
|
||||
return insertTab( -1, button, item );
|
||||
return insertTab( -1, text, page );
|
||||
}
|
||||
|
||||
int QskTabView::insertTab( int index, QskTabButton* button, QQuickItem* item )
|
||||
int QskTabView::insertTab( int index, const QString& text, QQuickItem* page )
|
||||
{
|
||||
// multiple insertion ???
|
||||
index = m_data->tabBar->insertTab( index, text );
|
||||
|
||||
if ( item && item->parent() == nullptr )
|
||||
item->setParent( this );
|
||||
if ( page && page->parent() == nullptr )
|
||||
page->setParent( this );
|
||||
|
||||
index = m_data->tabBar->insertTab( index, button );
|
||||
m_data->stackBox->insertItem( index, item );
|
||||
m_data->stackBox->insertItem( index, page );
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
int QskTabView::addTab( const QString& tabText, QQuickItem* item )
|
||||
{
|
||||
return insertTab( -1, tabText, item );
|
||||
}
|
||||
|
||||
int QskTabView::insertTab( int index, const QString& tabText, QQuickItem* item )
|
||||
{
|
||||
return insertTab( index, new QskTabButton( tabText ), item );
|
||||
}
|
||||
|
||||
void QskTabView::removeTab( int index )
|
||||
{
|
||||
if ( index >= 0 && index < m_data->tabBar->count() )
|
||||
{
|
||||
QPointer< QQuickItem > tabItem = m_data->stackBox->itemAtIndex( index );
|
||||
QPointer< QQuickItem > page = m_data->stackBox->itemAtIndex( index );
|
||||
|
||||
/*
|
||||
We have to remove the item from the stackBox first. Removing
|
||||
We have to remove the page from the stackBox first. Removing
|
||||
the tab then will result in a currentIndexChanged, where the stack
|
||||
box will be resynced.
|
||||
*/
|
||||
m_data->stackBox->removeAt( index );
|
||||
m_data->tabBar->removeTab( index );
|
||||
|
||||
if ( tabItem )
|
||||
if ( page )
|
||||
{
|
||||
if ( tabItem->parent() == this )
|
||||
delete tabItem;
|
||||
if ( page->parent() == this )
|
||||
delete page;
|
||||
else
|
||||
tabItem->setParentItem( nullptr );
|
||||
page->setParentItem( nullptr );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,34 +155,31 @@ void QskTabView::clear( bool autoDelete )
|
||||
m_data->stackBox->clear( autoDelete );
|
||||
}
|
||||
|
||||
QskTabButton* QskTabView::buttonAt( int index ) const
|
||||
void QskTabView::setTabEnabled( int index, bool enabled )
|
||||
{
|
||||
return m_data->tabBar->buttonAt( index );
|
||||
m_data->tabBar->setTabEnabled( index, enabled );
|
||||
if ( auto page = pageAt( index ) )
|
||||
page->setEnabled( enabled );
|
||||
}
|
||||
|
||||
QQuickItem* QskTabView::itemAt( int index ) const
|
||||
bool QskTabView::isTabEnabled( int index ) const
|
||||
{
|
||||
return m_data->tabBar->isTabEnabled( index );
|
||||
}
|
||||
|
||||
QQuickItem* QskTabView::pageAt( int index ) const
|
||||
{
|
||||
return m_data->stackBox->itemAtIndex( index );
|
||||
}
|
||||
|
||||
int QskTabView::itemIndex( const QQuickItem* item )
|
||||
int QskTabView::pageIndex( const QQuickItem* page )
|
||||
{
|
||||
return m_data->stackBox->indexOf( item );
|
||||
return m_data->stackBox->indexOf( page );
|
||||
}
|
||||
|
||||
int QskTabView::buttonIndex( const QskTabButton* button )
|
||||
QQuickItem* QskTabView::currentPage() const
|
||||
{
|
||||
return m_data->tabBar->indexOf( button );
|
||||
}
|
||||
|
||||
QQuickItem* QskTabView::currentItem() const
|
||||
{
|
||||
return itemAt( currentIndex() );
|
||||
}
|
||||
|
||||
QskTabButton* QskTabView::currentButton() const
|
||||
{
|
||||
return buttonAt( currentIndex() );
|
||||
return pageAt( currentIndex() );
|
||||
}
|
||||
|
||||
int QskTabView::currentIndex() const
|
||||
@ -316,4 +302,44 @@ void QskTabView::updateLayout()
|
||||
m_data->stackBox->setGeometry( subControlContentsRect( cr, Page ) );
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
||||
/*
|
||||
QskTabBar will do scene graph node composition and QskTabButton will go away
|
||||
see: https://github.com/uwerat/qskinny/issues/283
|
||||
*/
|
||||
|
||||
int QskTabView::addTab( QskTabButton* button, QQuickItem* page )
|
||||
{
|
||||
return insertTab( -1, button, page );
|
||||
}
|
||||
|
||||
int QskTabView::insertTab( int index, QskTabButton* button, QQuickItem* page )
|
||||
{
|
||||
if ( page && page->parent() == nullptr )
|
||||
page->setParent( this );
|
||||
|
||||
index = m_data->tabBar->insertTab( index, button );
|
||||
m_data->stackBox->insertItem( index, page );
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
QskTabButton* QskTabView::buttonAt( int index ) const
|
||||
{
|
||||
return m_data->tabBar->buttonAt( index );
|
||||
}
|
||||
|
||||
int QskTabView::buttonIndex( const QskTabButton* button )
|
||||
{
|
||||
return m_data->tabBar->indexOf( button );
|
||||
}
|
||||
|
||||
QskTabButton* QskTabView::currentButton() const
|
||||
{
|
||||
return buttonAt( currentIndex() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include "moc_QskTabView.cpp"
|
||||
|
@ -50,23 +50,16 @@ class QSK_EXPORT QskTabView : public QskControl
|
||||
|
||||
Qt::Orientation orientation() const;
|
||||
|
||||
int addTab( QskTabButton*, QQuickItem* );
|
||||
int insertTab( int index, QskTabButton*, QQuickItem* );
|
||||
|
||||
Q_INVOKABLE int addTab( const QString&, QQuickItem* );
|
||||
Q_INVOKABLE int insertTab( int index, const QString&, QQuickItem* );
|
||||
|
||||
Q_INVOKABLE void removeTab( int index );
|
||||
Q_INVOKABLE void clear( bool autoDelete = false );
|
||||
|
||||
QQuickItem* itemAt( int index ) const;
|
||||
QskTabButton* buttonAt( int index ) const;
|
||||
QQuickItem* pageAt( int index ) const;
|
||||
int pageIndex( const QQuickItem* );
|
||||
|
||||
int itemIndex( const QQuickItem* );
|
||||
int buttonIndex( const QskTabButton* );
|
||||
|
||||
QQuickItem* currentItem() const;
|
||||
QskTabButton* currentButton() const;
|
||||
QQuickItem* currentPage() const;
|
||||
|
||||
int currentIndex() const;
|
||||
int count() const;
|
||||
@ -75,6 +68,20 @@ class QSK_EXPORT QskTabView : public QskControl
|
||||
|
||||
QskAspect::Variation effectiveVariation() const override;
|
||||
|
||||
void setTabEnabled( int , bool );
|
||||
bool isTabEnabled( int index ) const;
|
||||
|
||||
#if 1
|
||||
// see: https://github.com/uwerat/qskinny/issues/283
|
||||
|
||||
int addTab( QskTabButton*, QQuickItem* );
|
||||
int insertTab( int index, QskTabButton*, QQuickItem* );
|
||||
|
||||
QskTabButton* buttonAt( int index ) const;
|
||||
int buttonIndex( const QskTabButton* );
|
||||
QskTabButton* currentButton() const;
|
||||
#endif
|
||||
|
||||
public Q_SLOTS:
|
||||
void setCurrentIndex( int index );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user