From 06ba85605b16dd201c91227ccd9844add5b21582 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 23 Feb 2023 14:37:49 +0100 Subject: [PATCH] QskSpinBox work in progress --- examples/gallery/spinbox/SpinBoxPage.cpp | 8 +- skins/material3/QskMaterial3Skin.cpp | 42 ++-- src/controls/QskSpinBox.cpp | 249 +++++++++++++++-------- src/controls/QskSpinBox.h | 55 +++-- src/controls/QskSpinBoxSkinlet.cpp | 136 ++++--------- src/controls/QskSpinBoxSkinlet.h | 23 +-- 6 files changed, 259 insertions(+), 254 deletions(-) diff --git a/examples/gallery/spinbox/SpinBoxPage.cpp b/examples/gallery/spinbox/SpinBoxPage.cpp index 6610670e..e4930f1e 100644 --- a/examples/gallery/spinbox/SpinBoxPage.cpp +++ b/examples/gallery/spinbox/SpinBoxPage.cpp @@ -53,8 +53,8 @@ void SpinBoxPage::populate() spinboxes << spinbox; } - const auto strutInc = spinboxes[ 0 ]->strutSizeHint( QskSpinBox::IncrementPanel ); - const auto strutDec = spinboxes[ 0 ]->strutSizeHint( QskSpinBox::DecrementPanel ); + const auto strutInc = spinboxes[ 0 ]->strutSizeHint( QskSpinBox::UpPanel ); + const auto strutDec = spinboxes[ 0 ]->strutSizeHint( QskSpinBox::DownPanel ); auto* const columnIncW = new QskLinearBox( Qt::Vertical, this ); auto* const sliderIncW = new QskSlider( Qt::Vertical, columnIncW ); @@ -93,8 +93,8 @@ void SpinBoxPage::populate() const auto decSize = QSizeF{ sliderDecW->value(), sliderDecH->value() }; for ( auto* spinbox : spinboxes ) { - spinbox->setStrutSizeHint( QskSpinBox::IncrementPanel, incSize ); - spinbox->setStrutSizeHint( QskSpinBox::DecrementPanel, decSize ); + spinbox->setStrutSizeHint( QskSpinBox::UpPanel, incSize ); + spinbox->setStrutSizeHint( QskSpinBox::DownPanel, decSize ); } }; diff --git a/skins/material3/QskMaterial3Skin.cpp b/skins/material3/QskMaterial3Skin.cpp index 11181f65..5f716cbc 100644 --- a/skins/material3/QskMaterial3Skin.cpp +++ b/skins/material3/QskMaterial3Skin.cpp @@ -818,39 +818,37 @@ void Editor::setupSpinBox() setSpacing( Q::Panel, 4_dp ); setStrutSize( Q::TextPanel, 80_dp, 40_dp ); - setStrutSize( Q::IncrementPanel, 40_dp,40_dp ); - setStrutSize( Q::DecrementPanel, 40_dp, 40_dp ); + setStrutSize( Q::UpPanel, 40_dp,40_dp ); + setStrutSize( Q::DownPanel, 40_dp, 40_dp ); setAlignment( Q::Panel, Qt::AlignHCenter ); setAlignment( Q::Text, Qt::AlignCenter ); - for( const auto& state : { Q::DecrementPanel, Q::IncrementPanel, Q::TextPanel } ) + for( const auto subControl : { Q::DownPanel, Q::UpPanel, Q::TextPanel } ) { - setBoxShape( state, 4_dp ); - setBoxBorderMetrics( state, 1_dp ); + setBoxShape( subControl, 4_dp ); + setBoxBorderMetrics( subControl, 1_dp ); } - for( const auto& state : { Q::DecrementPanel, Q::IncrementPanel } ) + for( const auto subControl : { Q::DownPanel, Q::UpPanel } ) { - setGradient( state, m_pal.primary ); - setGradient( state | Q::Disabled, m_pal.onSurface12 ); + setGradient( subControl, m_pal.primary ); + setGradient( subControl | Q::Disabled, m_pal.onSurface12 ); + } + { const auto focusColor = flattenedColor( m_pal.onPrimary, m_pal.primary, 0.12 ); - setGradient( state | Q::Focused, focusColor ); - setGradient( state | Q::Pressed, focusColor ); - const auto hoverColor = flattenedColor( m_pal.onPrimary, m_pal.primary, 0.08 ); - setGradient( state | Q::Hovered, hoverColor ); - setShadowMetrics( state | Q::Hovered, m_pal.elevation1 ); - setShadowColor( state | Q::Hovered, m_pal.shadow ); + setGradient( Q::DownPanel | Q::Decreasing, focusColor ); + setGradient( Q::UpPanel | Q::Increasing, focusColor ); } - for( const auto& state : { Q::DecrementIndicator, Q::IncrementIndicator } ) + for( const auto subControl : { Q::DownIndicator, Q::UpIndicator } ) { - setColor( state, m_pal.onPrimary ); - setColor( state | Q::Disabled, m_pal.onSurface38 ); - setAlignment(state, Qt::AlignCenter ); - setFontRole( state, QskMaterial3Skin::M3LabelLarge ); + setColor( subControl, m_pal.onPrimary ); + setColor( subControl | Q::Disabled, m_pal.onSurface38 ); + setAlignment( subControl, Qt::AlignCenter ); + setFontRole( subControl, QskMaterial3Skin::M3LabelLarge ); } setColor( Q::Text, m_pal.onBackground ); @@ -864,12 +862,6 @@ void Editor::setupSpinBox() setBoxBorderMetrics( Q::TextPanel | Q::Focused, 0, 0, 0, 2_dp ); setBoxBorderColors( Q::TextPanel | Q::Focused, m_pal.primary ); -// setBoxBorderMetrics( Q::TextPanel | Q::Editing, 0, 0, 0, 2_dp ); -// setBoxBorderColors( Q::TextPanel | Q::Editing, m_pal.primary ); - - setBoxBorderMetrics( Q::TextPanel | Q::Hovered, 0, 0, 0, 1_dp ); - setBoxBorderColors( Q::TextPanel | Q::Hovered, m_pal.onSurface ); - setGradient( Q::TextPanel, m_pal.surfaceVariant ); const auto c1 = QskRgb::toTransparentF( m_pal.onSurface, 0.04 ); diff --git a/src/controls/QskSpinBox.cpp b/src/controls/QskSpinBox.cpp index d6f8a93d..9c593e3f 100644 --- a/src/controls/QskSpinBox.cpp +++ b/src/controls/QskSpinBox.cpp @@ -4,77 +4,111 @@ *****************************************************************************/ #include "QskSpinBox.h" -#include "QskIntervalF.h" #include "QskEvent.h" +#include + QSK_SUBCONTROL( QskSpinBox, Panel ) QSK_SUBCONTROL( QskSpinBox, TextPanel ) QSK_SUBCONTROL( QskSpinBox, Text ) -QSK_SUBCONTROL( QskSpinBox, IncrementPanel ) -QSK_SUBCONTROL( QskSpinBox, IncrementIndicator ) +QSK_SUBCONTROL( QskSpinBox, UpPanel ) +QSK_SUBCONTROL( QskSpinBox, UpIndicator ) -QSK_SUBCONTROL( QskSpinBox, DecrementPanel ) -QSK_SUBCONTROL( QskSpinBox, DecrementIndicator ) +QSK_SUBCONTROL( QskSpinBox, DownPanel ) +QSK_SUBCONTROL( QskSpinBox, DownIndicator ) -QSK_SYSTEM_STATE( QskSpinBox, Pressed, ( QskAspect::QskAspect::FirstSystemState << 0 ) ) +QSK_SYSTEM_STATE( QskSpinBox, Increasing, ( QskAspect::FirstSystemState << 2 ) ) +QSK_SYSTEM_STATE( QskSpinBox, Decreasing, ( QskAspect::FirstSystemState << 3 ) ) namespace { - enum + inline QskAspect::Subcontrol buttonAt( const QskSpinBox* spinBox, const QPointF& pos ) { - ButtonDecrement = -1, - ButtonNone = 0, - ButtonIncrement = 1 - }; + if ( spinBox->subControlRect( QskSpinBox::UpPanel ).contains( pos ) ) + return QskSpinBox::UpPanel; - inline int buttonAt( const QskSpinBox* spinBox, const QPointF& pos ) - { - if ( spinBox->subControlRect( QskSpinBox::IncrementPanel ).contains( pos ) ) - return ButtonIncrement; + if ( spinBox->subControlRect( QskSpinBox::DownPanel ).contains( pos ) ) + return QskSpinBox::DownPanel; - if ( spinBox->subControlRect( QskSpinBox::DecrementPanel ).contains( pos ) ) - return ButtonDecrement; - - return ButtonNone; + return QskAspect::NoSubcontrol; } } class QskSpinBox::PrivateData { public: - inline void setPressed( QskSpinBox* spinBox, int button ) + PrivateData() + : buttons( true ) + , tracking( true ) + , wrapping( false ) + , accelerating( false ) { - if ( pressedButton != button ) - { - pressedButton = button; - spinBox->update(); - } } - inline void setHovered( QskSpinBox* spinBox, int button ) + inline void setAutoRepeat( QskSpinBox* spinBox, qreal offset ) { - if ( hoveredButton != button ) + this->autoRepeatIncrement = offset; + this->key = Qt::Key_unknown; + + if( offset < 0.0 ) { - hoveredButton = button; - spinBox->update(); + if ( spinBox->hasSkinState( QskSpinBox::Increasing ) ) + spinBox->setSkinStateFlag( QskSpinBox::Increasing, false ); + + if ( !spinBox->hasSkinState( QskSpinBox::Decreasing ) ) + { + spinBox->setSkinStateFlag( QskSpinBox::Decreasing, true ); + this->repeatTimer.start( autoRepeatDelay, spinBox ); + } + + return; } + + if ( offset > 0.0 ) + { + if ( spinBox->hasSkinState( QskSpinBox::Decreasing ) ) + spinBox->setSkinStateFlag( QskSpinBox::Decreasing, false ); + + if ( !spinBox->hasSkinState( QskSpinBox::Increasing ) ) + { + spinBox->setSkinStateFlag( QskSpinBox::Increasing, true ); + this->repeatTimer.start( autoRepeatDelay, spinBox ); + } + + return; + } + + spinBox->setSkinStateFlag( QskSpinBox::Decreasing, false ); + spinBox->setSkinStateFlag( QskSpinBox::Increasing, false ); + + this->repeatTimer.stop(); } - int pressedButton = ButtonNone; - int hoveredButton = ButtonNone; + int autoRepeatDelay = 300; + int autoRepeatInterval = 100; - // int decimals; ??? + qreal autoRepeatIncrement = 0.0; + + QBasicTimer repeatTimer; + + int key = Qt::Key_unknown; + + bool buttons : 1; + bool tracking : 1; + bool wrapping : 1; + bool accelerating : 1; // not yet implemented: TODO ... }; -QskSpinBox::QskSpinBox( QQuickItem* const parent ) +QskSpinBox::QskSpinBox( QQuickItem* parent ) : Inherited( parent ) , m_data( new PrivateData ) { + initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed ); + setBoundaries( 0.0, 99.99 ); // this is what QDoubleSpinBox does - setAcceptHoverEvents( true ); setAcceptedMouseButtons( Qt::LeftButton ); setFocusPolicy( Qt::StrongFocus ); } @@ -83,29 +117,80 @@ QskSpinBox::~QskSpinBox() { } -void QskSpinBox::hoverEnterEvent( QHoverEvent* ) +void QskSpinBox::setButtons( bool on ) { + if ( on != m_data->buttons ) + { + m_data->buttons = on; + Q_EMIT buttonsChanged( on ); + } } -void QskSpinBox::hoverLeaveEvent( QHoverEvent* ) +bool QskSpinBox::hasButtons() const { - m_data->setHovered( this, ButtonNone ); + return m_data->buttons; } -void QskSpinBox::hoverMoveEvent( QHoverEvent* event ) +void QskSpinBox::setTracking( bool on ) { - const auto button = buttonAt( this, qskHoverPosition( event ) ); - m_data->setHovered( this, button ); + if ( on != m_data->tracking ) + { + m_data->tracking = on; + Q_EMIT trackingChanged( on ); + } +} + +bool QskSpinBox::isTracking() const +{ + return m_data->tracking; +} + +void QskSpinBox::setWrapping( bool on ) +{ + if ( on != m_data->wrapping ) + { + m_data->wrapping = on; + Q_EMIT wrappingChanged( on ); + } +} + +bool QskSpinBox::isWrapping() const +{ + return m_data->wrapping; +} + +void QskSpinBox::setAccelerating( bool on ) +{ + if ( on != m_data->accelerating ) + { + m_data->accelerating = on; + Q_EMIT acceleratingChanged( on ); + } +} + +bool QskSpinBox::isAccelerating() const +{ + return m_data->accelerating; } void QskSpinBox::mousePressEvent( QMouseEvent* event ) { - if ( const auto button = buttonAt( this, qskMousePosition( event ) ) ) + if ( !isReadOnly() ) { - m_data->setPressed( this, button ); - increment( stepSize() * button ); + if ( auto subcontrol = buttonAt( this, qskMousePosition( event ) ) ) + { + if ( !m_data->repeatTimer.isActive() ) + { + auto increment = ( event->modifiers() == Qt::ControlModifier ) + ? stepSize() : pageSize(); - return; + if ( subcontrol == QskSpinBox::DownPanel ) + increment = -increment; + + m_data->setAutoRepeat( this, increment ); + } + return; + } } Inherited::mousePressEvent( event ); @@ -113,65 +198,55 @@ void QskSpinBox::mousePressEvent( QMouseEvent* event ) void QskSpinBox::mouseReleaseEvent( QMouseEvent* ) { - m_data->setPressed( this, ButtonNone ); + m_data->setAutoRepeat( this, 0.0 ); } -void QskSpinBox::keyPressEvent( QKeyEvent* const event ) +void QskSpinBox::keyPressEvent( QKeyEvent* event ) { - switch ( event->key() ) + if ( !isReadOnly() && !m_data->repeatTimer.isActive() ) { - case Qt::Key_Minus: - case Qt::Key_Down: - case Qt::Key_Left: + const auto offset = incrementForKey( event ); + if ( offset != 0.0 ) { - increment( -stepSize() ); - m_data->setPressed( this, ButtonDecrement ); + if ( !m_data->repeatTimer.isActive() ) + { + increment( offset ); + + m_data->setAutoRepeat( this, offset ); + m_data->key = event->key(); + } return; } - - case Qt::Key_Plus: - case Qt::Key_Up: - case Qt::Key_Right: - { - increment( +stepSize() ); - m_data->setPressed( this, ButtonIncrement ); - return; - } - -#if 1 - case Qt::Key_Select: - case Qt::Key_Space: - - /* - All keys to navigate along the focus tab chain are not valid - for a spin box, as it accepts number inputs only. Guess this is why - QSpinBox goes straight into edit mode when receiving the focus - - So once setting values by keyboard is implemented we have to decide - how to do it here. TODO ... - */ - return; -#endif - - default: - break; } Inherited::keyPressEvent( event ); } -void QskSpinBox::keyReleaseEvent( QKeyEvent* const event ) +void QskSpinBox::keyReleaseEvent( QKeyEvent* event ) { - m_data->setPressed( this, ButtonNone ); + if ( m_data->key == event->key() ) + { + m_data->setAutoRepeat( this, 0.0 ); + return; + } + Inherited::keyReleaseEvent( event ); } -int QskSpinBox::pressedButton() const +void QskSpinBox::timerEvent( QTimerEvent* event ) { - return m_data->pressedButton; + if ( event->timerId() == m_data->repeatTimer.timerId() ) + { + if ( skinStates() & ( QskSpinBox::Increasing | QskSpinBox::Decreasing ) ) + { + increment( m_data->autoRepeatIncrement ); + m_data->repeatTimer.start( m_data->autoRepeatInterval, this ); + } + + return; + } + + Inherited::timerEvent( event ); } -int QskSpinBox::hoveredButton() const -{ - return m_data->hoveredButton; -} +#include "moc_QskSpinBox.cpp" diff --git a/src/controls/QskSpinBox.h b/src/controls/QskSpinBox.h index 39f7f99c..aa30db60 100644 --- a/src/controls/QskSpinBox.h +++ b/src/controls/QskSpinBox.h @@ -13,36 +13,53 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput Q_OBJECT using Inherited = QskBoundedValueInput; + Q_PROPERTY( bool wrapping READ isWrapping + WRITE setWrapping NOTIFY wrappingChanged ) + + Q_PROPERTY( bool tracking READ isTracking + WRITE setTracking NOTIFY trackingChanged ) + + Q_PROPERTY( bool accelerating READ isAccelerating + WRITE setAccelerating NOTIFY acceleratingChanged ) + + Q_PROPERTY( bool buttons READ hasButtons + WRITE setButtons NOTIFY buttonsChanged ) + public: - QSK_SUBCONTROLS( Panel, TextPanel, Text, - IncrementPanel, IncrementIndicator, DecrementPanel, DecrementIndicator ) + UpPanel, UpIndicator, DownPanel, DownIndicator ) - QSK_STATES( Pressed ) + QSK_STATES( Decreasing, Increasing ) QskSpinBox( QQuickItem* parent = nullptr ); ~QskSpinBox() override; -#if 1 - /* - -1: decrease - 0: none - 1: increment - */ - int pressedButton() const; - int hoveredButton() const; -#endif + void setButtons( bool ); + bool hasButtons() const; + + void setWrapping( bool ); + bool isWrapping() const; + + void setTracking( bool ); + bool isTracking() const; + + void setAccelerating( bool ); + bool isAccelerating() const; + + Q_SIGNALS: + void trackingChanged( bool ); + void wrappingChanged( bool ); + void acceleratingChanged( bool ); + void buttonsChanged( bool ); private: - void hoverEnterEvent( QHoverEvent* event ) override; - void hoverLeaveEvent( QHoverEvent* event ) override; - void hoverMoveEvent( QHoverEvent* event ) override; + void timerEvent( QTimerEvent* ) override; - void mouseReleaseEvent( QMouseEvent* event ) override; - void mousePressEvent( QMouseEvent* event ) override; + void mouseReleaseEvent( QMouseEvent* ) override; + void mousePressEvent( QMouseEvent* ) override; - void keyPressEvent( QKeyEvent* event ) override; - void keyReleaseEvent( QKeyEvent* event ) override; + void keyPressEvent( QKeyEvent* ) override; + void keyReleaseEvent( QKeyEvent* ) override; class PrivateData; std::unique_ptr< PrivateData > m_data; diff --git a/src/controls/QskSpinBoxSkinlet.cpp b/src/controls/QskSpinBoxSkinlet.cpp index 5f7cd61b..742ed4d3 100644 --- a/src/controls/QskSpinBoxSkinlet.cpp +++ b/src/controls/QskSpinBoxSkinlet.cpp @@ -8,70 +8,10 @@ #include -namespace -{ - inline QPointF cursorPosSkinHint( const QskSpinBox& spinbox ) - { - const auto aspect = QskSpinBox::Panel | QskAspect::Metric | QskAspect::Position; - return spinbox.effectiveSkinHint( aspect ).toPointF(); - } - - enum - { - Dec = 0, - Txt = 1, - Inc = 2, - Count - }; -} - QskSpinBoxSkinlet::QskSpinBoxSkinlet( QskSkin* ) { - setNodeRoles( { IncrementPanel, DecrementPanel, TextPanel, - IncrementIndicator, DecrementIndicator, Text } ); -} - -int QskSpinBoxSkinlet::sampleCount( - const QskSkinnable*, QskAspect::Subcontrol ) const -{ - return 1; -} - -QRectF QskSpinBoxSkinlet::sampleRect( const QskSkinnable* skinnable, const QRectF& rect, - QskAspect::Subcontrol subControl, int index ) const -{ - if ( index == Dec || index == Inc || index == Txt ) - { - return subControlRect( skinnable, rect, subControl ); - } - - return Inherited::sampleRect( skinnable, rect, subControl, index ); -} - -QskAspect::States QskSpinBoxSkinlet::sampleStates( - const QskSkinnable* const skinnable, QskAspect::Subcontrol subControl, int index ) const -{ - using S = QskSpinBox; - - auto states = Inherited::sampleStates( skinnable, subControl, index ); - - if ( subControl == S::DecrementPanel || subControl == S::IncrementPanel || - subControl == S::TextPanel ) - { - const auto* const spinbox = static_cast< const S* >( skinnable ); - const auto cursorPos = cursorPosSkinHint( *spinbox ); - const QPointF cursorPosAbs{ qAbs( cursorPos.x() ), qAbs( cursorPos.y() ) }; - const auto subControlRect = spinbox->subControlRect( subControl ); - - const auto contain = !cursorPosAbs.isNull() && subControlRect.contains( cursorPosAbs ); - const auto pressed = contain && ( cursorPos.x() < 0 || cursorPos.y() < 0 ); - const auto hovered = contain && !pressed; - - states.setFlag( QskControl::Hovered, hovered ); - states.setFlag( QskSpinBox::Pressed, pressed ); - } - - return states; + setNodeRoles( { UpPanel, DownPanel, TextPanel, + UpIndicator, DownIndicator, Text } ); } QSizeF QskSpinBoxSkinlet::sizeHint( const QskSkinnable* skinnable, @@ -80,16 +20,16 @@ QSizeF QskSpinBoxSkinlet::sizeHint( const QskSkinnable* skinnable, if ( which != Qt::PreferredSize ) return QSizeF(); - using S = QskSpinBox; + using Q = QskSpinBox; const auto spinbox = static_cast< const QskSpinBox* >( skinnable ); - const auto layout = spinbox->alignmentHint( S::Panel ); - const auto spacing = spinbox->spacingHint( S::Panel ); + const auto layout = spinbox->alignmentHint( Q::Panel ); + const auto spacing = spinbox->spacingHint( Q::Panel ); - const auto strutInc = spinbox->strutSizeHint( S::IncrementPanel ); - const auto strutDec = spinbox->strutSizeHint( S::DecrementPanel ); - const auto strutTxt = spinbox->strutSizeHint( S::TextPanel ); + const auto strutInc = spinbox->strutSizeHint( Q::UpPanel ); + const auto strutDec = spinbox->strutSizeHint( Q::DownPanel ); + const auto strutTxt = spinbox->strutSizeHint( Q::TextPanel ); if ( layout == Qt::AlignTop || layout == Qt::AlignBottom || layout == Qt::AlignVCenter ) { @@ -118,7 +58,7 @@ QSizeF QskSpinBoxSkinlet::sizeHint( const QskSkinnable* skinnable, } if ( layout == ( Qt::AlignTop | Qt::AlignHCenter ) || - layout == ( Qt::AlignTop | Qt::AlignHCenter ) ) + layout == ( Qt::AlignBottom | Qt::AlignHCenter ) ) { const auto w = qMax( strutTxt.width(), strutInc.width() + strutDec.width() ); const auto h = strutTxt.height() + qMax( strutInc.height(), strutDec.height() ); @@ -134,11 +74,11 @@ QRectF QskSpinBoxSkinlet::subControlRect( const QskSkinnable* skinnable, { using Q = QskSpinBox; - if ( subControl == Q::DecrementIndicator ) - return skinnable->subControlContentsRect( contentsRect, Q::DecrementPanel ); + if ( subControl == Q::DownIndicator ) + return skinnable->subControlContentsRect( contentsRect, Q::DownPanel ); - if ( subControl == Q::IncrementIndicator ) - return skinnable->subControlContentsRect( contentsRect, Q::IncrementPanel ); + if ( subControl == Q::UpIndicator ) + return skinnable->subControlContentsRect( contentsRect, Q::UpPanel ); if ( subControl == Q::Text ) return skinnable->subControlContentsRect( contentsRect, Q::TextPanel ); @@ -148,10 +88,18 @@ QRectF QskSpinBoxSkinlet::subControlRect( const QskSkinnable* skinnable, const auto layout = spinbox->alignmentHint( Q::Panel ); const auto spacing = spinbox->spacingHint( Q::Panel ); + enum + { + Dec = 0, + Txt = 1, + Inc = 2, + Count + }; + std::array< QRectF, Count > rects = { - QRectF{ QPointF(), spinbox->strutSizeHint( Q::DecrementPanel ) }, + QRectF{ QPointF(), spinbox->strutSizeHint( Q::DownPanel ) }, QRectF{ QPointF(), spinbox->strutSizeHint( Q::TextPanel ) }, - QRectF{ QPointF(), spinbox->strutSizeHint( Q::IncrementPanel ) }, + QRectF{ QPointF(), spinbox->strutSizeHint( Q::UpPanel ) }, }; const auto center = contentsRect.center(); @@ -238,13 +186,13 @@ QRectF QskSpinBoxSkinlet::subControlRect( const QskSkinnable* skinnable, { center.x() + spacing * 0.5, rects[ Txt ].top() - spacing - rects[ Inc ].height() } ); } - if ( subControl == Q::DecrementPanel ) + if ( subControl == Q::DownPanel ) return rects[ Dec ]; if ( subControl == Q::TextPanel ) return rects[ Txt ]; - if ( subControl == Q::IncrementPanel ) + if ( subControl == Q::UpPanel ) return rects[ Inc ]; return Inherited::subControlRect( skinnable, contentsRect, subControl ); @@ -257,26 +205,26 @@ QSGNode* QskSpinBoxSkinlet::updateSubNode( switch( nodeRole ) { - case IncrementPanel: - return updateSeriesNode( skinnable, Q::IncrementPanel, node ); + case UpPanel: + return updateBoxNode( skinnable, node, Q::UpPanel ); - case DecrementPanel: - return updateSeriesNode( skinnable, Q::DecrementPanel, node ); + case DownPanel: + return updateBoxNode( skinnable, node, Q::DownPanel ); - case IncrementIndicator: + case UpIndicator: { return updateTextNode( skinnable, node, - QStringLiteral( "+" ), Q::IncrementIndicator ); + QStringLiteral( "+" ), Q::UpIndicator ); } - case DecrementIndicator: + case DownIndicator: { return updateTextNode( skinnable, node, - QStringLiteral( "-" ), Q::DecrementIndicator ); + QStringLiteral( "-" ), Q::DownIndicator ); } case TextPanel: - return updateSeriesNode( skinnable, Q::TextPanel, node ); + return updateBoxNode( skinnable, node, Q::TextPanel ); case Text: { @@ -289,19 +237,3 @@ QSGNode* QskSpinBoxSkinlet::updateSubNode( return Inherited::updateSubNode( skinnable, nodeRole, node ); } - -QSGNode* QskSpinBoxSkinlet::updateSampleNode( const QskSkinnable* skinnable, - QskAspect::Subcontrol subControl, const int index, QSGNode* const node ) const -{ - using Q = QskSpinBox; - const auto* const spinbox = static_cast< const QskSpinBox* >( skinnable ); - - if ( subControl == Q::DecrementPanel || subControl == Q::IncrementPanel || - subControl == Q::TextPanel ) - { - const auto rect = sampleRect( spinbox, spinbox->contentsRect(), subControl, index ); - return updateBoxNode( skinnable, node, rect, subControl ); - } - - return Inherited::updateSampleNode( skinnable, subControl, index, node ); -} diff --git a/src/controls/QskSpinBoxSkinlet.h b/src/controls/QskSpinBoxSkinlet.h index a6e1a03e..83e624e2 100644 --- a/src/controls/QskSpinBoxSkinlet.h +++ b/src/controls/QskSpinBoxSkinlet.h @@ -18,14 +18,15 @@ class QSK_EXPORT QskSpinBoxSkinlet : public QskSkinlet enum NodeRole { - IncrementPanel, - DecrementPanel, TextPanel, - - IncrementIndicator, - DecrementIndicator, Text, + UpPanel, + UpIndicator, + + DownPanel, + DownIndicator, + RoleCount }; @@ -35,21 +36,9 @@ class QSK_EXPORT QskSpinBoxSkinlet : public QskSkinlet QSizeF sizeHint( const QskSkinnable* skinnable, Qt::SizeHint, const QSizeF& ) const override; - int sampleCount( - const QskSkinnable* skinnable, QskAspect::Subcontrol subControl ) const override; - - QRectF sampleRect( const QskSkinnable* skinnable, const QRectF& rect, - QskAspect::Subcontrol subControl, int index ) const override; - - QskAspect::States sampleStates( const QskSkinnable*, - QskAspect::Subcontrol, int index ) const override; - protected: QSGNode* updateSubNode( const QskSkinnable* skinnable, quint8 role, QSGNode* node ) const override; - - QSGNode* updateSampleNode( const QskSkinnable*, QskAspect::Subcontrol, - int index, QSGNode* node ) const override; }; #endif