QskTabBar::autoFitTabs added
This commit is contained in:
parent
f257ad8f95
commit
416759f3c6
@ -366,6 +366,7 @@ class TabView : public QskTabView
|
|||||||
: QskTabView( parentItem )
|
: QskTabView( parentItem )
|
||||||
{
|
{
|
||||||
setMargins( 10 );
|
setMargins( 10 );
|
||||||
|
setAutoFitTabs( true );
|
||||||
|
|
||||||
auto* tab1 = new QskLinearBox( Qt::Horizontal, 5 );
|
auto* tab1 = new QskLinearBox( Qt::Horizontal, 5 );
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <QskPushButton.h>
|
#include <QskPushButton.h>
|
||||||
#include <QskSkin.h>
|
#include <QskSkin.h>
|
||||||
#include <QskTabButton.h>
|
#include <QskTabButton.h>
|
||||||
|
#include <QskTabBar.h>
|
||||||
#include <QskTabView.h>
|
#include <QskTabView.h>
|
||||||
#include <QskTextLabel.h>
|
#include <QskTextLabel.h>
|
||||||
#include <QskWindow.h>
|
#include <QskWindow.h>
|
||||||
@ -82,15 +83,25 @@ int main( int argc, char* argv[] )
|
|||||||
auto tabView = new TabView();
|
auto tabView = new TabView();
|
||||||
|
|
||||||
auto rotateButton = new QskPushButton( "Rotate" );
|
auto rotateButton = new QskPushButton( "Rotate" );
|
||||||
rotateButton->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
|
||||||
rotateButton->setFocus( true );
|
rotateButton->setFocus( true );
|
||||||
QObject::connect( rotateButton, &QskPushButton::clicked, tabView, &TabView::rotate );
|
QObject::connect( rotateButton, &QskPushButton::clicked,
|
||||||
|
tabView, &TabView::rotate );
|
||||||
|
|
||||||
|
auto autoFitButton = new QskPushButton( "Fit Tabs" );
|
||||||
|
autoFitButton->setCheckable( true );
|
||||||
|
QObject::connect( autoFitButton, &QskPushButton::toggled,
|
||||||
|
tabView, &QskTabView::setAutoFitTabs );
|
||||||
|
|
||||||
|
auto buttonBox = new QskLinearBox( Qt::Horizontal );
|
||||||
|
buttonBox->addItem( rotateButton );
|
||||||
|
buttonBox->addItem( autoFitButton );
|
||||||
|
buttonBox->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||||
|
|
||||||
auto layoutBox = new QskLinearBox( Qt::Vertical );
|
auto layoutBox = new QskLinearBox( Qt::Vertical );
|
||||||
layoutBox->setDefaultAlignment( Qt::AlignLeft );
|
layoutBox->setDefaultAlignment( Qt::AlignLeft );
|
||||||
layoutBox->setMargins( 5 );
|
layoutBox->setMargins( 5 );
|
||||||
layoutBox->setSpacing( 10 );
|
layoutBox->setSpacing( 10 );
|
||||||
layoutBox->addItem( rotateButton );
|
layoutBox->addItem( buttonBox );
|
||||||
layoutBox->addItem( tabView );
|
layoutBox->addItem( tabView );
|
||||||
|
|
||||||
auto focusIndicator = new QskFocusIndicator();
|
auto focusIndicator = new QskFocusIndicator();
|
||||||
@ -98,7 +109,7 @@ int main( int argc, char* argv[] )
|
|||||||
focusIndicator->setBoxBorderColorsHint( QskFocusIndicator::Panel, Qt::red );
|
focusIndicator->setBoxBorderColorsHint( QskFocusIndicator::Panel, Qt::red );
|
||||||
|
|
||||||
QskWindow window;
|
QskWindow window;
|
||||||
window.resize( 600, 400 );
|
window.resize( 800, 600 );
|
||||||
window.addItem( layoutBox );
|
window.addItem( layoutBox );
|
||||||
window.addItem( focusIndicator );
|
window.addItem( focusIndicator );
|
||||||
|
|
||||||
|
@ -4,7 +4,10 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "QskSizePolicy.h"
|
#include "QskSizePolicy.h"
|
||||||
#include <algorithm>
|
|
||||||
|
#ifndef QT_NO_DEBUG
|
||||||
|
#include <qdebug.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
QskSizePolicy::Policy QskSizePolicy::policy( Qt::Orientation orientation ) const
|
QskSizePolicy::Policy QskSizePolicy::policy( Qt::Orientation orientation ) const
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,11 @@ static inline Qt::Orientation qskOrientation( int position )
|
|||||||
return Qt::Vertical;
|
return Qt::Vertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void qskTransposeSizePolicy( QskControl* control )
|
||||||
|
{
|
||||||
|
control->setSizePolicy( control->sizePolicy().transposed() );
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class ButtonBox final : public QskLinearBox
|
class ButtonBox final : public QskLinearBox
|
||||||
@ -270,9 +275,11 @@ void QskTabBar::setPosition( Qsk::Position position )
|
|||||||
|
|
||||||
if ( orientation != m_data->buttonBox->orientation() )
|
if ( orientation != m_data->buttonBox->orientation() )
|
||||||
{
|
{
|
||||||
setSizePolicy( sizePolicy().transposed() );
|
qskTransposeSizePolicy( this );
|
||||||
|
|
||||||
m_data->buttonBox->setOrientation( orientation );
|
m_data->buttonBox->setOrientation( orientation );
|
||||||
|
qskTransposeSizePolicy( m_data->buttonBox );
|
||||||
|
|
||||||
m_data->scrollBox->setOrientation( orientation );
|
m_data->scrollBox->setOrientation( orientation );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,6 +315,34 @@ bool QskTabBar::autoScrollFocusButton() const
|
|||||||
return m_data->scrollBox->autoScrollFocusItem();
|
return m_data->scrollBox->autoScrollFocusItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskTabBar::setAutoFitTabs( bool on )
|
||||||
|
{
|
||||||
|
const auto orientation = qskOrientation( m_data->position );
|
||||||
|
int policy = m_data->buttonBox->sizePolicy( orientation );
|
||||||
|
|
||||||
|
if ( ( policy & QskSizePolicy::GrowFlag ) != on )
|
||||||
|
{
|
||||||
|
if ( on )
|
||||||
|
policy |= QskSizePolicy::GrowFlag;
|
||||||
|
else
|
||||||
|
policy &= ~QskSizePolicy::GrowFlag;
|
||||||
|
|
||||||
|
// we need operators for QskSizePolicy::Policy: TODO ...
|
||||||
|
m_data->buttonBox->setSizePolicy(
|
||||||
|
orientation, static_cast< QskSizePolicy::Policy >( policy ) );
|
||||||
|
|
||||||
|
polish();
|
||||||
|
|
||||||
|
Q_EMIT autoFitTabsChanged( on );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QskTabBar::autoFitTabs() const
|
||||||
|
{
|
||||||
|
const auto policy = m_data->buttonBox->sizePolicy( orientation() );
|
||||||
|
return ( policy & QskSizePolicy::GrowFlag );
|
||||||
|
}
|
||||||
|
|
||||||
void QskTabBar::setTextOptions( const QskTextOptions& options )
|
void QskTabBar::setTextOptions( const QskTextOptions& options )
|
||||||
{
|
{
|
||||||
if ( options != m_data->textOptions )
|
if ( options != m_data->textOptions )
|
||||||
|
@ -23,6 +23,9 @@ class QSK_EXPORT QskTabBar : public QskBox
|
|||||||
Q_PROPERTY( bool autoScrollFocusButton READ autoScrollFocusButton
|
Q_PROPERTY( bool autoScrollFocusButton READ autoScrollFocusButton
|
||||||
WRITE setAutoScrollFocusedButton NOTIFY autoScrollFocusedButtonChanged FINAL )
|
WRITE setAutoScrollFocusedButton NOTIFY autoScrollFocusedButtonChanged FINAL )
|
||||||
|
|
||||||
|
Q_PROPERTY( bool autoFitTabs READ autoFitTabs
|
||||||
|
WRITE setAutoFitTabs NOTIFY autoFitTabsChanged FINAL )
|
||||||
|
|
||||||
Q_PROPERTY( int count READ count NOTIFY countChanged FINAL )
|
Q_PROPERTY( int count READ count NOTIFY countChanged FINAL )
|
||||||
|
|
||||||
Q_PROPERTY( int currentIndex READ currentIndex
|
Q_PROPERTY( int currentIndex READ currentIndex
|
||||||
@ -46,9 +49,12 @@ class QSK_EXPORT QskTabBar : public QskBox
|
|||||||
|
|
||||||
Qt::Orientation orientation() const;
|
Qt::Orientation orientation() const;
|
||||||
|
|
||||||
void setAutoScrollFocusedButton( bool on );
|
void setAutoScrollFocusedButton( bool );
|
||||||
bool autoScrollFocusButton() const;
|
bool autoScrollFocusButton() const;
|
||||||
|
|
||||||
|
void setAutoFitTabs( bool );
|
||||||
|
bool autoFitTabs() const;
|
||||||
|
|
||||||
void ensureButtonVisible( const QskTabButton* );
|
void ensureButtonVisible( const QskTabButton* );
|
||||||
|
|
||||||
void setTextOptions( const QskTextOptions& );
|
void setTextOptions( const QskTextOptions& );
|
||||||
@ -95,6 +101,7 @@ class QSK_EXPORT QskTabBar : public QskBox
|
|||||||
void textOptionsChanged( const QskTextOptions& );
|
void textOptionsChanged( const QskTextOptions& );
|
||||||
void positionChanged( Qsk::Position );
|
void positionChanged( Qsk::Position );
|
||||||
void autoScrollFocusedButtonChanged( bool );
|
void autoScrollFocusedButtonChanged( bool );
|
||||||
|
void autoFitTabsChanged( bool );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void componentComplete() override;
|
void componentComplete() override;
|
||||||
|
@ -45,7 +45,8 @@ QskTabButton::QskTabButton( const QString& text, QQuickItem* parent )
|
|||||||
if ( parent )
|
if ( parent )
|
||||||
m_data->tabBar = qskFindTabBar( this );
|
m_data->tabBar = qskFindTabBar( this );
|
||||||
|
|
||||||
initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed );
|
initSizePolicy( QskSizePolicy::MinimumExpanding,
|
||||||
|
QskSizePolicy::QskSizePolicy::MinimumExpanding );
|
||||||
|
|
||||||
setCheckable( true );
|
setCheckable( true );
|
||||||
setExclusive( true );
|
setExclusive( true );
|
||||||
|
@ -71,6 +71,9 @@ QskTabView::QskTabView( Qsk::Position tabPosition, QQuickItem* parent )
|
|||||||
|
|
||||||
connect( m_data->tabBar, &QskTabBar::positionChanged,
|
connect( m_data->tabBar, &QskTabBar::positionChanged,
|
||||||
this, &QskTabView::tabPositionChanged );
|
this, &QskTabView::tabPositionChanged );
|
||||||
|
|
||||||
|
connect( m_data->tabBar, &QskTabBar::autoFitTabsChanged,
|
||||||
|
this, &QskTabView::autoFitTabsChanged );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskTabView::~QskTabView()
|
QskTabView::~QskTabView()
|
||||||
@ -103,6 +106,16 @@ Qsk::Position QskTabView::tabPosition() const
|
|||||||
return m_data->tabBar->position();
|
return m_data->tabBar->position();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskTabView::setAutoFitTabs( bool on )
|
||||||
|
{
|
||||||
|
m_data->tabBar->setAutoFitTabs( on );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QskTabView::autoFitTabs() const
|
||||||
|
{
|
||||||
|
return m_data->tabBar->autoFitTabs();
|
||||||
|
}
|
||||||
|
|
||||||
Qt::Orientation QskTabView::orientation() const
|
Qt::Orientation QskTabView::orientation() const
|
||||||
{
|
{
|
||||||
return qskTransposed( m_data->tabBar->orientation() );
|
return qskTransposed( m_data->tabBar->orientation() );
|
||||||
|
@ -21,6 +21,9 @@ class QSK_EXPORT QskTabView : public QskControl
|
|||||||
Q_PROPERTY( Qsk::Position tabPosition READ tabPosition
|
Q_PROPERTY( Qsk::Position tabPosition READ tabPosition
|
||||||
WRITE setTabPosition NOTIFY tabPositionChanged FINAL )
|
WRITE setTabPosition NOTIFY tabPositionChanged FINAL )
|
||||||
|
|
||||||
|
Q_PROPERTY( bool autoFitTabs READ autoFitTabs
|
||||||
|
WRITE setAutoFitTabs NOTIFY autoFitTabsChanged FINAL )
|
||||||
|
|
||||||
Q_PROPERTY( Qt::Orientation orientation READ orientation )
|
Q_PROPERTY( Qt::Orientation orientation READ orientation )
|
||||||
|
|
||||||
Q_PROPERTY( int count READ count NOTIFY countChanged FINAL )
|
Q_PROPERTY( int count READ count NOTIFY countChanged FINAL )
|
||||||
@ -44,6 +47,9 @@ class QSK_EXPORT QskTabView : public QskControl
|
|||||||
void setTabPosition( Qsk::Position );
|
void setTabPosition( Qsk::Position );
|
||||||
Qsk::Position tabPosition() const;
|
Qsk::Position tabPosition() const;
|
||||||
|
|
||||||
|
void setAutoFitTabs( bool );
|
||||||
|
bool autoFitTabs() const;
|
||||||
|
|
||||||
Qt::Orientation orientation() const;
|
Qt::Orientation orientation() const;
|
||||||
|
|
||||||
int addTab( QskTabButton*, QQuickItem* );
|
int addTab( QskTabButton*, QQuickItem* );
|
||||||
@ -76,6 +82,7 @@ class QSK_EXPORT QskTabView : public QskControl
|
|||||||
void currentIndexChanged( int index );
|
void currentIndexChanged( int index );
|
||||||
void countChanged( int );
|
void countChanged( int );
|
||||||
void tabPositionChanged( Qsk::Position );
|
void tabPositionChanged( Qsk::Position );
|
||||||
|
void autoFitTabsChanged( bool );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event( QEvent* event ) override;
|
bool event( QEvent* event ) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user