Code cleanup
This commit is contained in:
parent
4310ee3c34
commit
c3a4472587
|
@ -23,8 +23,7 @@ public:
|
||||||
|
|
||||||
QskRadioBox::QskRadioBox( QQuickItem* parent ) :
|
QskRadioBox::QskRadioBox( QQuickItem* parent ) :
|
||||||
Inherited( parent ),
|
Inherited( parent ),
|
||||||
m_data( new PrivateData{} )
|
m_data( new PrivateData{} ) {
|
||||||
{
|
|
||||||
setFocusPolicy( Qt::NoFocus );
|
setFocusPolicy( Qt::NoFocus );
|
||||||
setAcceptedMouseButtons( Qt::LeftButton );
|
setAcceptedMouseButtons( Qt::LeftButton );
|
||||||
|
|
||||||
|
@ -41,16 +40,13 @@ QskRadioBox::QskRadioBox( QQuickItem* parent ) :
|
||||||
}
|
}
|
||||||
|
|
||||||
QskRadioBox::QskRadioBox( const QStringList& list, QQuickItem* parent ) :
|
QskRadioBox::QskRadioBox( const QStringList& list, QQuickItem* parent ) :
|
||||||
QskRadioBox( parent )
|
QskRadioBox( parent ) {
|
||||||
{
|
|
||||||
setItems( list );
|
setItems( list );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskRadioBox::QskRadioBox( const QStringList& items,
|
QskRadioBox::QskRadioBox( const QStringList& items,
|
||||||
int selectedIndex,
|
int selectedIndex, QQuickItem* parent ) :
|
||||||
QQuickItem* parent ) :
|
QskRadioBox( items, parent ) {
|
||||||
QskRadioBox( items, parent )
|
|
||||||
{
|
|
||||||
if( selectedIndex >= 0 && selectedIndex < items.count() )
|
if( selectedIndex >= 0 && selectedIndex < items.count() )
|
||||||
{
|
{
|
||||||
m_data->selectedIndex = selectedIndex;
|
m_data->selectedIndex = selectedIndex;
|
||||||
|
@ -59,7 +55,6 @@ QskRadioBox::QskRadioBox( const QStringList& items,
|
||||||
|
|
||||||
QRectF QskRadioBox::focusIndicatorRect() const {
|
QRectF QskRadioBox::focusIndicatorRect() const {
|
||||||
if( m_data->focusedIndex > -1) {
|
if( m_data->focusedIndex > -1) {
|
||||||
|
|
||||||
auto textRect = effectiveSkinlet()->sampleRect( this,
|
auto textRect = effectiveSkinlet()->sampleRect( this,
|
||||||
contentsRect(), QskRadioBox::Text, m_data->focusedIndex );
|
contentsRect(), QskRadioBox::Text, m_data->focusedIndex );
|
||||||
|
|
||||||
|
@ -146,7 +141,8 @@ void QskRadioBox::keyPressEvent( QKeyEvent* event )
|
||||||
return;
|
return;
|
||||||
case Qt::Key_Down:
|
case Qt::Key_Down:
|
||||||
case Qt::Key_Right:
|
case Qt::Key_Right:
|
||||||
m_data->selectedIndex = qMin(m_data->selectedIndex + 1, items().size() - 1);
|
m_data->selectedIndex = qMin( m_data->selectedIndex + 1,
|
||||||
|
items().size() - 1 );
|
||||||
setFocusedIndex( m_data->selectedIndex );
|
setFocusedIndex( m_data->selectedIndex );
|
||||||
event->setAccepted( true );
|
event->setAccepted( true );
|
||||||
update();
|
update();
|
||||||
|
@ -174,8 +170,7 @@ void QskRadioBox::keyPressEvent( QKeyEvent* event )
|
||||||
const auto aspect = Ripple | QskAspect::Metric | QskAspect::Position;
|
const auto aspect = Ripple | QskAspect::Metric | QskAspect::Position;
|
||||||
auto hint = animationHint(aspect | skinStates());
|
auto hint = animationHint(aspect | skinStates());
|
||||||
if( hint.isValid()) {
|
if( hint.isValid()) {
|
||||||
startTransition( aspect,
|
startTransition( aspect, hint,
|
||||||
hint,
|
|
||||||
( float ) currentTabIndex, ( float ) nextTabIndex );
|
( float ) currentTabIndex, ( float ) nextTabIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,8 +230,9 @@ int QskRadioBox::indexAt( const QPointF& target ) const {
|
||||||
auto itemHeight = contentsRect().height() / items().size();
|
auto itemHeight = contentsRect().height() / items().size();
|
||||||
auto index = target.y() / itemHeight;
|
auto index = target.y() / itemHeight;
|
||||||
|
|
||||||
if( index < 0 || index >= items().size() )
|
if( index < 0 || index >= items().size() ) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,7 @@ QSizeF QskRadioBoxSkinlet::sizeHint( const QskSkinnable* skinnable,
|
||||||
|
|
||||||
auto spacing = radio->spacingHint( Q::Panel );
|
auto spacing = radio->spacingHint( Q::Panel );
|
||||||
return QSizeF( maxTextWidth + qMax( buttonWidth, symbolWidth ),
|
return QSizeF( maxTextWidth + qMax( buttonWidth, symbolWidth ),
|
||||||
( lineHeight( radio ) + spacing ) * radio->items().size()
|
( lineHeight( radio ) + spacing ) * radio->items().size() - spacing );
|
||||||
- spacing );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSGNode* QskRadioBoxSkinlet::updateSubNode( const QskSkinnable* skinnable,
|
QSGNode* QskRadioBoxSkinlet::updateSubNode( const QskSkinnable* skinnable,
|
||||||
|
@ -103,7 +102,8 @@ QSGNode* QskRadioBoxSkinlet::updateSubNode( const QskSkinnable* skinnable,
|
||||||
case RippleRole:
|
case RippleRole:
|
||||||
{
|
{
|
||||||
QskSkinStateChanger changer( radio );
|
QskSkinStateChanger changer( radio );
|
||||||
changer.setStates( statesForIndex( radio, radio->positionHint( Q::Ripple ) ) );
|
auto ripplePosition = radio->positionHint( Q::Ripple );
|
||||||
|
changer.setStates( statesForIndex( radio, ripplePosition ) );
|
||||||
|
|
||||||
return updateBoxNode( radio, node, Q::Ripple );
|
return updateBoxNode( radio, node, Q::Ripple );
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,7 @@ qreal QskRadioBoxSkinlet::lineHeight(const QskRadioBox* target) const {
|
||||||
return qMax( strutHight, fontHeight );
|
return qMax( strutHight, fontHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskRadioBoxSkinlet::sampleCount( const QskSkinnable* skinnable,
|
int QskRadioBoxSkinlet::sampleCount( const QskSkinnable* skinnable, QskAspect::Subcontrol ) const {
|
||||||
QskAspect::Subcontrol ) const {
|
|
||||||
const auto radio = static_cast< const QskRadioBox* >( skinnable );
|
const auto radio = static_cast< const QskRadioBox* >( skinnable );
|
||||||
return radio->items().count();
|
return radio->items().count();
|
||||||
}
|
}
|
||||||
|
@ -140,8 +139,7 @@ QSizeF QskRadioBoxSkinlet::buttonSymbolSize( const QskRadioBox* radio ) const {
|
||||||
qMax( buttonStrut.height(), symbolStrut.height() ) );
|
qMax( buttonStrut.height(), symbolStrut.height() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF QskRadioBoxSkinlet::rippleRect( const QskRadioBox* radio,
|
QRectF QskRadioBoxSkinlet::rippleRect( const QskRadioBox* radio, const QRectF& rect ) const {
|
||||||
const QRectF& rect ) const {
|
|
||||||
auto ripplePosition = radio->positionHint( Q::Ripple );
|
auto ripplePosition = radio->positionHint( Q::Ripple );
|
||||||
|
|
||||||
if( ripplePosition < 0 ) {
|
if( ripplePosition < 0 ) {
|
||||||
|
@ -157,8 +155,7 @@ QRectF QskRadioBoxSkinlet::rippleRect( const QskRadioBox* radio,
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF QskRadioBoxSkinlet::buttonRect( const QskRadioBox* radio,
|
QRectF QskRadioBoxSkinlet::buttonRect( const QskRadioBox* radio,
|
||||||
const QskAspect::Subcontrol target,
|
const QskAspect::Subcontrol target, const QRectF& rect, double index ) const {
|
||||||
const QRectF& rect, double index ) const {
|
|
||||||
if( index < 0 ) {
|
if( index < 0 ) {
|
||||||
return QRectF();
|
return QRectF();
|
||||||
}
|
}
|
||||||
|
@ -237,8 +234,8 @@ QRectF QskRadioBoxSkinlet::textRect( const QskRadioBox* radio,
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF QskRadioBoxSkinlet::sampleRect( const QskSkinnable* skinnable,
|
QRectF QskRadioBoxSkinlet::sampleRect( const QskSkinnable* skinnable,
|
||||||
const QRectF& rect, QskAspect::Subcontrol subcontrol,
|
const QRectF& rect, QskAspect::Subcontrol subcontrol, int index ) const {
|
||||||
int index ) const {
|
|
||||||
const auto radio = static_cast< const QskRadioBox* >( skinnable );
|
const auto radio = static_cast< const QskRadioBox* >( skinnable );
|
||||||
|
|
||||||
if( subcontrol == Q::Text ) {
|
if( subcontrol == Q::Text ) {
|
||||||
|
@ -250,6 +247,7 @@ QRectF QskRadioBoxSkinlet::sampleRect( const QskSkinnable* skinnable,
|
||||||
|
|
||||||
QskAspect::States QskRadioBoxSkinlet::sampleStates( const QskSkinnable* skinnable,
|
QskAspect::States QskRadioBoxSkinlet::sampleStates( const QskSkinnable* skinnable,
|
||||||
QskAspect::Subcontrol subControl, int index ) const {
|
QskAspect::Subcontrol subControl, int index ) const {
|
||||||
|
|
||||||
auto radio = static_cast< const QskRadioBox* >( skinnable );
|
auto radio = static_cast< const QskRadioBox* >( skinnable );
|
||||||
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
||||||
|
|
||||||
|
@ -258,23 +256,17 @@ QskAspect::States QskRadioBoxSkinlet::sampleStates( const QskSkinnable* skinnabl
|
||||||
|
|
||||||
QSGNode* QskRadioBoxSkinlet::updateSampleNode( const QskSkinnable* skinnable,
|
QSGNode* QskRadioBoxSkinlet::updateSampleNode( const QskSkinnable* skinnable,
|
||||||
QskAspect::Subcontrol subcontrol, int index, QSGNode* node ) const {
|
QskAspect::Subcontrol subcontrol, int index, QSGNode* node ) const {
|
||||||
|
|
||||||
auto radio = static_cast< const QskRadioBox* >( skinnable );
|
auto radio = static_cast< const QskRadioBox* >( skinnable );
|
||||||
|
|
||||||
auto rect = sampleRect( skinnable, radio->contentsRect(),
|
auto rect = sampleRect( skinnable, radio->contentsRect(),
|
||||||
subcontrol, index );
|
subcontrol, index );
|
||||||
|
|
||||||
if( subcontrol == Q::Text ) {
|
if( subcontrol == Q::Text ) {
|
||||||
return QskSkinlet::updateTextNode( radio,
|
return QskSkinlet::updateTextNode( radio, node, rect, Qt::AlignLeft,
|
||||||
node,
|
radio->items()[ index ], subcontrol );
|
||||||
rect,
|
|
||||||
Qt::AlignLeft,
|
|
||||||
radio->items()[index],
|
|
||||||
subcontrol);
|
|
||||||
} else if ( subcontrol == Q::Button ) {
|
} else if ( subcontrol == Q::Button ) {
|
||||||
return QskSkinlet::updateBoxNode( radio,
|
return QskSkinlet::updateBoxNode( radio, node, rect, subcontrol );
|
||||||
node,
|
|
||||||
rect,
|
|
||||||
subcontrol );
|
|
||||||
} else if( subcontrol == Q::Symbol ) {
|
} else if( subcontrol == Q::Symbol ) {
|
||||||
auto symbol = QskStandardSymbol::NoSymbol;
|
auto symbol = QskStandardSymbol::NoSymbol;
|
||||||
auto color = radio->color( subcontrol ).rgb();
|
auto color = radio->color( subcontrol ).rgb();
|
||||||
|
|
|
@ -39,7 +39,8 @@ class QSK_EXPORT QskRadioBoxSkinlet : public QskSkinlet
|
||||||
|
|
||||||
QSizeF buttonSymbolSize( const QskRadioBox* radio ) const;
|
QSizeF buttonSymbolSize( const QskRadioBox* radio ) const;
|
||||||
QRectF textRect( const QskRadioBox*, const QRectF&, int ) const;
|
QRectF textRect( const QskRadioBox*, const QRectF&, int ) const;
|
||||||
QRectF buttonRect( const QskRadioBox*, const QskAspect::Subcontrol target, const QRectF&, double ) const;
|
QRectF buttonRect( const QskRadioBox*, const QskAspect::Subcontrol target, const QRectF&,
|
||||||
|
double ) const;
|
||||||
QRectF rippleRect( const QskRadioBox*, const QRectF& ) const;
|
QRectF rippleRect( const QskRadioBox*, const QRectF& ) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue