segmented bar: Add separator subcontrol
This commit is contained in:
parent
8036d8ee69
commit
c465676642
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
QSK_SUBCONTROL( QskSegmentedBar, Panel )
|
QSK_SUBCONTROL( QskSegmentedBar, Panel )
|
||||||
QSK_SUBCONTROL( QskSegmentedBar, Segment )
|
QSK_SUBCONTROL( QskSegmentedBar, Segment )
|
||||||
|
QSK_SUBCONTROL( QskSegmentedBar, Separator )
|
||||||
QSK_SUBCONTROL( QskSegmentedBar, Cursor )
|
QSK_SUBCONTROL( QskSegmentedBar, Cursor )
|
||||||
QSK_SUBCONTROL( QskSegmentedBar, Text )
|
QSK_SUBCONTROL( QskSegmentedBar, Text )
|
||||||
QSK_SUBCONTROL( QskSegmentedBar, Graphic )
|
QSK_SUBCONTROL( QskSegmentedBar, Graphic )
|
||||||
|
@ -32,7 +32,7 @@ class QSK_EXPORT QskSegmentedBar : public QskControl
|
|||||||
using Inherited = QskControl;
|
using Inherited = QskControl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Panel, Segment, Cursor, Text, Graphic )
|
QSK_SUBCONTROLS( Panel, Segment, Separator, Cursor, Text, Graphic )
|
||||||
QSK_STATES( Selected, Minimum, Maximum )
|
QSK_STATES( Selected, Minimum, Maximum )
|
||||||
|
|
||||||
QskSegmentedBar( QQuickItem* parent = nullptr );
|
QskSegmentedBar( QQuickItem* parent = nullptr );
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
QskSegmentedBarSkinlet::QskSegmentedBarSkinlet( QskSkin* skin )
|
QskSegmentedBarSkinlet::QskSegmentedBarSkinlet( QskSkin* skin )
|
||||||
: Inherited( skin )
|
: Inherited( skin )
|
||||||
{
|
{
|
||||||
setNodeRoles( { PanelRole, SegmentRole, CursorRole, TextRole, GraphicRole } );
|
setNodeRoles( { PanelRole, SegmentRole, SeparatorRole, CursorRole, TextRole, GraphicRole } );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskSegmentedBarSkinlet::~QskSegmentedBarSkinlet() = default;
|
QskSegmentedBarSkinlet::~QskSegmentedBarSkinlet() = default;
|
||||||
@ -99,6 +99,34 @@ QRectF QskSegmentedBarSkinlet::segmentRect(
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF QskSegmentedBarSkinlet::separatorRect(
|
||||||
|
const QskSegmentedBar* bar, const QRectF& contentsRect, int index ) const
|
||||||
|
{
|
||||||
|
using Q = QskSegmentedBar;
|
||||||
|
|
||||||
|
auto rect = segmentRect( bar, contentsRect, index );
|
||||||
|
|
||||||
|
auto sh = bar->sizeHint();
|
||||||
|
|
||||||
|
const QSizeF strutSize = bar->strutSizeHint( Q::Separator );
|
||||||
|
|
||||||
|
if( bar->orientation() == Qt::Horizontal )
|
||||||
|
{
|
||||||
|
rect.setLeft( rect.right() );
|
||||||
|
rect.setSize( { strutSize.width(), sh.height() } );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rect.setTop( rect.bottom() );
|
||||||
|
rect.setSize( { sh.width(), strutSize.height() } );
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto padding = bar->paddingHint( Q::Separator );
|
||||||
|
rect = rect.marginsRemoved( padding );
|
||||||
|
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
QSGNode* QskSegmentedBarSkinlet::updateSubNode(
|
QSGNode* QskSegmentedBarSkinlet::updateSubNode(
|
||||||
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
||||||
{
|
{
|
||||||
@ -115,6 +143,9 @@ QSGNode* QskSegmentedBarSkinlet::updateSubNode(
|
|||||||
case SegmentRole:
|
case SegmentRole:
|
||||||
return updateSeriesNode( skinnable, Q::Segment, node );
|
return updateSeriesNode( skinnable, Q::Segment, node );
|
||||||
|
|
||||||
|
case SeparatorRole:
|
||||||
|
return updateSeriesNode( skinnable, Q::Separator, node );
|
||||||
|
|
||||||
case TextRole:
|
case TextRole:
|
||||||
return updateSeriesNode( skinnable, Q::Text, node );
|
return updateSeriesNode( skinnable, Q::Text, node );
|
||||||
|
|
||||||
@ -226,13 +257,18 @@ QRectF QskSegmentedBarSkinlet::sampleRect( const QskSkinnable* skinnable,
|
|||||||
const QRectF& contentsRect, QskAspect::Subcontrol subControl, int index ) const
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl, int index ) const
|
||||||
{
|
{
|
||||||
using Q = QskSegmentedBar;
|
using Q = QskSegmentedBar;
|
||||||
|
const auto bar = static_cast< const QskSegmentedBar* >( skinnable );
|
||||||
|
|
||||||
if ( subControl == Q::Segment )
|
if ( subControl == Q::Segment )
|
||||||
{
|
{
|
||||||
const auto bar = static_cast< const QskSegmentedBar* >( skinnable );
|
|
||||||
return segmentRect( bar, contentsRect, index );
|
return segmentRect( bar, contentsRect, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( subControl == Q::Separator )
|
||||||
|
{
|
||||||
|
return separatorRect( bar, contentsRect, index );
|
||||||
|
}
|
||||||
|
|
||||||
if ( subControl == Q::Text || subControl == Q::Graphic )
|
if ( subControl == Q::Text || subControl == Q::Graphic )
|
||||||
{
|
{
|
||||||
const auto rect = sampleRect( skinnable, contentsRect, Q::Segment, index );
|
const auto rect = sampleRect( skinnable, contentsRect, Q::Segment, index );
|
||||||
@ -281,6 +317,20 @@ QSGNode* QskSegmentedBarSkinlet::updateSampleNode( const QskSkinnable* skinnable
|
|||||||
return updateBoxNode( skinnable, node, rect, subControl );
|
return updateBoxNode( skinnable, node, rect, subControl );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( subControl == Q::Separator )
|
||||||
|
{
|
||||||
|
if( index == bar->count() - 1 )
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto rect = sampleRect( bar, bar->contentsRect(), subControl, index );
|
||||||
|
|
||||||
|
return updateBoxNode( skinnable, node, rect, subControl );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const auto alignment = bar->alignmentHint( subControl, Qt::AlignCenter );
|
const auto alignment = bar->alignmentHint( subControl, Qt::AlignCenter );
|
||||||
|
|
||||||
if ( subControl == Q::Text )
|
if ( subControl == Q::Text )
|
||||||
|
@ -21,6 +21,7 @@ class QSK_EXPORT QskSegmentedBarSkinlet : public QskSkinlet
|
|||||||
{
|
{
|
||||||
PanelRole,
|
PanelRole,
|
||||||
SegmentRole,
|
SegmentRole,
|
||||||
|
SeparatorRole,
|
||||||
CursorRole,
|
CursorRole,
|
||||||
|
|
||||||
TextRole,
|
TextRole,
|
||||||
@ -57,6 +58,7 @@ class QSK_EXPORT QskSegmentedBarSkinlet : public QskSkinlet
|
|||||||
QSizeF segmentSizeHint( const QskSegmentedBar* ) const;
|
QSizeF segmentSizeHint( const QskSegmentedBar* ) const;
|
||||||
|
|
||||||
QRectF segmentRect( const QskSegmentedBar*, const QRectF&, int index ) const;
|
QRectF segmentRect( const QskSegmentedBar*, const QRectF&, int index ) const;
|
||||||
|
QRectF separatorRect( const QskSegmentedBar*, const QRectF&, int index ) const;
|
||||||
QRectF cursorRect( const QskSegmentedBar*, const QRectF& ) const;
|
QRectF cursorRect( const QskSegmentedBar*, const QRectF& ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user