segmented bar: Make API similar to QskMenu
This commit is contained in:
parent
afdfa7b24e
commit
5a78a365e3
@ -31,7 +31,7 @@ namespace
|
|||||||
auto bar = new QskSegmentedBar( orientation, this );
|
auto bar = new QskSegmentedBar( orientation, this );
|
||||||
|
|
||||||
for ( const auto text: texts )
|
for ( const auto text: texts )
|
||||||
bar->addText( text );
|
bar->addOption( {}, text );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -45,7 +45,7 @@ namespace
|
|||||||
|
|
||||||
auto bar = new QskSegmentedBar( orientation, this );
|
auto bar = new QskSegmentedBar( orientation, this );
|
||||||
for ( uint i = 0; i < sizeof( icons ) / sizeof( icons[ 0 ] ); ++i )
|
for ( uint i = 0; i < sizeof( icons ) / sizeof( icons[ 0 ] ); ++i )
|
||||||
bar->addGraphicAndText( QUrl( QString( icons[ i ] ) ), texts[ i ] );
|
bar->addOption( QUrl( QString( icons[ i ] ) ), texts[ i ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
setExtraSpacingAt( Qt::LeftEdge | Qt::BottomEdge );
|
setExtraSpacingAt( Qt::LeftEdge | Qt::BottomEdge );
|
||||||
|
@ -137,35 +137,13 @@ QskTextOptions QskSegmentedBar::textOptions() const
|
|||||||
return textOptionsHint( Text );
|
return textOptionsHint( Text );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskSegmentedBar::addText( const QString& text )
|
int QskSegmentedBar::addOption( const QUrl& graphicSource, const QString& text )
|
||||||
{
|
|
||||||
m_data->addOption( this, Option( QUrl(), text ) );
|
|
||||||
return count() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QskSegmentedBar::addGraphic( const QUrl& graphicSource )
|
|
||||||
{
|
|
||||||
m_data->addOption( this, Option( graphicSource, QString() ) );
|
|
||||||
return count() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QskSegmentedBar::addGraphicAndText( const QUrl& graphicSource, const QString& text )
|
|
||||||
{
|
{
|
||||||
m_data->addOption( this, Option( graphicSource, text ) );
|
m_data->addOption( this, Option( graphicSource, text ) );
|
||||||
return count() - 1;
|
return count() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QskSegmentedBar::textAt( int index ) const
|
QVariantList QskSegmentedBar::optionAt( int index ) const
|
||||||
{
|
|
||||||
return m_data->options.at( index ).text;
|
|
||||||
}
|
|
||||||
|
|
||||||
QskGraphic QskSegmentedBar::graphicAt( int index ) const
|
|
||||||
{
|
|
||||||
return m_data->options.at( index ).graphic;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant QskSegmentedBar::optionAt( int index ) const
|
|
||||||
{
|
{
|
||||||
const auto& options = m_data->options;
|
const auto& options = m_data->options;
|
||||||
|
|
||||||
@ -174,14 +152,11 @@ QVariant QskSegmentedBar::optionAt( int index ) const
|
|||||||
|
|
||||||
const auto& option = options[ index ];
|
const auto& option = options[ index ];
|
||||||
|
|
||||||
QVariant value;
|
QVariantList list;
|
||||||
|
list += QVariant::fromValue( option.graphic );
|
||||||
|
list += QVariant::fromValue( option.text );
|
||||||
|
|
||||||
if ( option.graphicSource.isValid() )
|
return list;
|
||||||
value = QVariant::fromValue( option.graphic );
|
|
||||||
else
|
|
||||||
value = QVariant::fromValue( option.text );
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QskAspect::Placement QskSegmentedBar::effectivePlacement() const
|
QskAspect::Placement QskSegmentedBar::effectivePlacement() const
|
||||||
|
@ -46,12 +46,7 @@ class QSK_EXPORT QskSegmentedBar : public QskControl
|
|||||||
void setTextOptions( const QskTextOptions& );
|
void setTextOptions( const QskTextOptions& );
|
||||||
QskTextOptions textOptions() const;
|
QskTextOptions textOptions() const;
|
||||||
|
|
||||||
int addText( const QString& );
|
int addOption( const QUrl&, const QString& );
|
||||||
int addGraphic( const QUrl& );
|
|
||||||
int addGraphicAndText( const QUrl&, const QString& );
|
|
||||||
|
|
||||||
QString textAt( int ) const;
|
|
||||||
QskGraphic graphicAt( int ) const;
|
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
@ -60,7 +55,7 @@ class QSK_EXPORT QskSegmentedBar : public QskControl
|
|||||||
|
|
||||||
int count() const;
|
int count() const;
|
||||||
|
|
||||||
QVariant optionAt( int ) const;
|
QVariantList optionAt( int ) const;
|
||||||
|
|
||||||
void setSegmentEnabled( int, bool );
|
void setSegmentEnabled( int, bool );
|
||||||
bool isSegmentEnabled( int ) const;
|
bool isSegmentEnabled( int ) const;
|
||||||
|
@ -18,6 +18,28 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
#if 1 // unify with the implementation from QskMenu
|
||||||
|
template< class T >
|
||||||
|
static inline QVariant qskSampleAt( const QskSegmentedBar* bar, int index )
|
||||||
|
{
|
||||||
|
const auto list = bar->optionAt( index );
|
||||||
|
for ( const auto& value : list )
|
||||||
|
{
|
||||||
|
if ( value.canConvert< T >() )
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
template< class T >
|
||||||
|
static inline T qskValueAt( const QskSegmentedBar* bar, int index )
|
||||||
|
{
|
||||||
|
const auto sample = qskSampleAt< T >( bar, index );
|
||||||
|
return sample.template value< T >();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
QskGraphic graphicAt( const QskSegmentedBar* bar, const int index )
|
QskGraphic graphicAt( const QskSegmentedBar* bar, const int index )
|
||||||
{
|
{
|
||||||
// note: It is a Material 3 peculiarity that the selected element
|
// note: It is a Material 3 peculiarity that the selected element
|
||||||
@ -26,7 +48,7 @@ namespace
|
|||||||
// subclass.
|
// subclass.
|
||||||
const auto graphic = ( bar->selectedIndex() == index )
|
const auto graphic = ( bar->selectedIndex() == index )
|
||||||
? bar->effectiveSkin()->symbol( QskStandardSymbol::SegmentedBarCheckMark )
|
? bar->effectiveSkin()->symbol( QskStandardSymbol::SegmentedBarCheckMark )
|
||||||
: bar->graphicAt( index );
|
: qskValueAt< QskGraphic >( bar, index );
|
||||||
|
|
||||||
return graphic;
|
return graphic;
|
||||||
}
|
}
|
||||||
@ -40,7 +62,7 @@ namespace
|
|||||||
setSpacing( bar->spacingHint( QskSegmentedBar::Panel ) );
|
setSpacing( bar->spacingHint( QskSegmentedBar::Panel ) );
|
||||||
|
|
||||||
setGraphicTextElements( bar,
|
setGraphicTextElements( bar,
|
||||||
QskSegmentedBar::Text, bar->textAt( index ),
|
QskSegmentedBar::Text, qskValueAt< QString >( bar, index ),
|
||||||
QskSegmentedBar::Graphic, graphicAt( bar, index ).defaultSize() );
|
QskSegmentedBar::Graphic, graphicAt( bar, index ).defaultSize() );
|
||||||
|
|
||||||
if( bar->orientation() == Qt::Horizontal )
|
if( bar->orientation() == Qt::Horizontal )
|
||||||
@ -211,7 +233,7 @@ QSizeF QskSegmentedBarSkinlet::segmentSizeHint( const QskSegmentedBar* bar, Qt::
|
|||||||
// We want to know how big the element can grow when it is selected,
|
// We want to know how big the element can grow when it is selected,
|
||||||
// i.e. when it has the checkmark symbol:
|
// i.e. when it has the checkmark symbol:
|
||||||
layoutEngine.setGraphicTextElements( bar,
|
layoutEngine.setGraphicTextElements( bar,
|
||||||
QskSegmentedBar::Text, bar->textAt( i ),
|
QskSegmentedBar::Text, qskValueAt< QString >( bar, i ),
|
||||||
QskSegmentedBar::Graphic, graphic.defaultSize() );
|
QskSegmentedBar::Graphic, graphic.defaultSize() );
|
||||||
|
|
||||||
const auto size = layoutEngine.sizeHint( which, QSizeF() );
|
const auto size = layoutEngine.sizeHint( which, QSizeF() );
|
||||||
@ -345,7 +367,7 @@ QSGNode* QskSegmentedBarSkinlet::updateSampleNode( const QskSkinnable* skinnable
|
|||||||
|
|
||||||
if ( subControl == Q::Text )
|
if ( subControl == Q::Text )
|
||||||
{
|
{
|
||||||
const auto text = bar->textAt( index );
|
const auto text = qskValueAt< QString >( bar, index );
|
||||||
|
|
||||||
if( !text.isEmpty() )
|
if( !text.isEmpty() )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user