code cleanup

This commit is contained in:
Uwe Rathmann 2019-02-28 08:06:44 +01:00
parent 4e00c73f92
commit f8016125b1
3 changed files with 11 additions and 39 deletions

View File

@ -51,27 +51,6 @@ MyToggleButton::MyToggleButton( QQuickItem* parent )
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
} }
MyToggleButton::MyToggleButton(
const QString& checkedIcon, const QString& uncheckedIcon, QQuickItem* parent )
: MyToggleButton( parent )
{
if ( !uncheckedIcon.isEmpty() )
{
auto& data = m_data->content[ UncheckedSection ];
data.iconSource = uncheckedIcon;
data.iconDirty = true;
}
if ( !checkedIcon.isEmpty() )
{
auto& data = m_data->content[ CheckedSection ];
data.iconSource = checkedIcon;
data.iconDirty = true;
}
}
MyToggleButton::~MyToggleButton() MyToggleButton::~MyToggleButton()
{ {
} }

View File

@ -19,17 +19,8 @@ class MyToggleButton : public QskAbstractButton
public: public:
QSK_SUBCONTROLS( Panel, Cursor, CheckedPanel, CheckedLabel, CheckedIcon, QSK_SUBCONTROLS( Panel, Cursor, CheckedPanel, CheckedLabel, CheckedIcon,
UncheckedPanel, UncheckedLabel, UncheckedIcon ) UncheckedPanel, UncheckedLabel, UncheckedIcon )
enum
{
UncheckedSection = 0,
CheckedSection = 1
};
MyToggleButton( QQuickItem* parent = nullptr ); MyToggleButton( QQuickItem* parent = nullptr );
MyToggleButton( const QString& ckeckedIcon, const QString& uncheckedIcon,
QQuickItem* parent = nullptr );
~MyToggleButton() override; ~MyToggleButton() override;
void setTextAt( int index, const QString& ); void setTextAt( int index, const QString& );

View File

@ -26,9 +26,11 @@ MyToggleButtonSkinlet::MyToggleButtonSkinlet( QskSkin* skin )
{ {
// sorted in stacking order // sorted in stacking order
setNodeRoles( { PanelRole, CursorRole, UncheckedPanelRole, UncheckedLabelRole, setNodeRoles(
{ PanelRole, CursorRole, UncheckedPanelRole, UncheckedLabelRole,
UncheckedIconRole, CheckedPanelRole, CheckedLabelRole, CheckedIconRole UncheckedIconRole, CheckedPanelRole, CheckedLabelRole, CheckedIconRole
} ); }
);
} }
QRectF MyToggleButtonSkinlet::subControlRect( QRectF MyToggleButtonSkinlet::subControlRect(
@ -44,12 +46,12 @@ QRectF MyToggleButtonSkinlet::subControlRect(
} }
else if( subControl == Q::UncheckedPanel ) else if( subControl == Q::UncheckedPanel )
{ {
auto rect = innerRect( skinnable, Q::Panel ); const auto rect = innerRect( skinnable, Q::Panel );
return sectionRect( rect, button->isInverted() ? 0 : 1 ); return sectionRect( rect, button->isInverted() ? 0 : 1 );
} }
else if( subControl == Q::CheckedPanel ) else if( subControl == Q::CheckedPanel )
{ {
auto rect = innerRect( skinnable, Q::Panel ); const auto rect = innerRect( skinnable, Q::Panel );
return sectionRect( rect, button->isInverted() ? 1 : 0 ); return sectionRect( rect, button->isInverted() ? 1 : 0 );
} }
else if( subControl == Q::CheckedLabel || subControl == Q::CheckedIcon ) else if( subControl == Q::CheckedLabel || subControl == Q::CheckedIcon )
@ -100,27 +102,27 @@ QSGNode* MyToggleButtonSkinlet::updateSubNode(
case CheckedLabelRole: case CheckedLabelRole:
{ {
return updateTextNode( return updateTextNode(
button, node, button->textAt( Q::CheckedSection ), button, node, button->textAt( 1 ),
button->textOptions(), Q::CheckedLabel ); button->textOptions(), Q::CheckedLabel );
} }
case UncheckedLabelRole: case UncheckedLabelRole:
{ {
return updateTextNode( return updateTextNode(
button, node, button->textAt( Q::UncheckedSection ), button, node, button->textAt( 0 ),
button->textOptions(), Q::UncheckedLabel ); button->textOptions(), Q::UncheckedLabel );
} }
case CheckedIconRole: case CheckedIconRole:
{ {
return updateGraphicNode( return updateGraphicNode(
button, node, button->graphicAt( Q::CheckedSection ), Q::CheckedIcon ); button, node, button->graphicAt( 1 ), Q::CheckedIcon );
} }
case UncheckedIconRole: case UncheckedIconRole:
{ {
return updateGraphicNode( return updateGraphicNode(
button, node, button->graphicAt( Q::UncheckedSection ), Q::UncheckedIcon ); button, node, button->graphicAt( 0 ), Q::UncheckedIcon );
} }
case CheckedPanelRole: case CheckedPanelRole: