From 1faf2e091c76ee729029057a533fe6841d767978 Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Fri, 17 Feb 2023 15:22:40 +0100 Subject: [PATCH] clang-format + clang-tidy improvements --- src/controls/QskSpinBox.cpp | 670 +++++++++++++++++------------ src/controls/QskSpinBox.h | 60 +-- src/controls/QskSpinBoxSkinlet.cpp | 467 +++++++++++--------- src/controls/QskSpinBoxSkinlet.h | 44 +- 4 files changed, 721 insertions(+), 520 deletions(-) diff --git a/src/controls/QskSpinBox.cpp b/src/controls/QskSpinBox.cpp index 3eabea92..1ed352b0 100644 --- a/src/controls/QskSpinBox.cpp +++ b/src/controls/QskSpinBox.cpp @@ -4,351 +4,463 @@ *****************************************************************************/ #include "QskSpinBox.h" -#include -#include -#include +#include #include -#include +#include #include #include -#include +#include #include -#include -#include -#include +#include #include +#include +#include +#include +#include #include -QSK_SUBCONTROL(QskSpinBox, IncrementPanel) -QSK_SUBCONTROL(QskSpinBox, DecrementPanel) -QSK_SUBCONTROL(QskSpinBox, IncrementText) -QSK_SUBCONTROL(QskSpinBox, DecrementText) -QSK_SUBCONTROL(QskSpinBox, Text) -QSK_SUBCONTROL(QskSpinBox, TextPanel) -QSK_SUBCONTROL(QskSpinBox, Layout) +QSK_SUBCONTROL( QskSpinBox, IncrementPanel ) +QSK_SUBCONTROL( QskSpinBox, DecrementPanel ) +QSK_SUBCONTROL( QskSpinBox, IncrementText ) +QSK_SUBCONTROL( QskSpinBox, DecrementText ) +QSK_SUBCONTROL( QskSpinBox, Text ) +QSK_SUBCONTROL( QskSpinBox, TextPanel ) +QSK_SUBCONTROL( QskSpinBox, Layout ) -QSK_SYSTEM_STATE(QskSpinBox, Pressed, ( QskAspect::QskAspect::FirstSystemState << 0)) +QSK_SYSTEM_STATE( QskSpinBox, Pressed, ( QskAspect::QskAspect::FirstSystemState << 0 ) ) namespace aliased_enum { - constexpr auto D = QskSpinBox::Decrement; - constexpr auto T = QskSpinBox::Textbox; - constexpr auto I = QskSpinBox::Increment; - constexpr auto N = QskSpinBox::None; + constexpr auto D = QskSpinBox::Decrement; + constexpr auto T = QskSpinBox::Textbox; + constexpr auto I = QskSpinBox::Increment; + constexpr auto N = QskSpinBox::None; } class QskSpinBox::PrivateData { -public: - - explicit PrivateData(QskSpinBox* const parent) : q(parent) - { - } - - FocusIndeces defaultFocusIndex() const - { - const auto layout = q->alignmentHint(QskSpinBox::Layout); - - if(layout == Qt::AlignLeft) return QskSpinBox::Textbox; - if(layout == Qt::AlignRight) return QskSpinBox::Decrement; - if(layout == Qt::AlignHCenter) return QskSpinBox::Decrement; - if(layout == Qt::AlignTop) return QskSpinBox::Textbox; - if(layout == Qt::AlignBottom) return QskSpinBox::Increment; - if(layout == Qt::AlignVCenter) return QskSpinBox::Increment; - if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return QskSpinBox::Textbox; - if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return QskSpinBox::Increment; - if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return QskSpinBox::Textbox; - if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return QskSpinBox::Decrement; - - return None; - } - - FocusIndeces nextFocusIndex() const - { - const auto layout = q->alignmentHint(QskSpinBox::Layout); - using namespace aliased_enum; - - // [0][1][2][3] := index - // [D][T][I][N] := control - using LUT = std::array; - if(layout == Qt::AlignLeft) return LUT{I,D,N,T}[m_focusIndex]; - if(layout == Qt::AlignRight) return LUT{I,N,T,D}[m_focusIndex]; - if(layout == Qt::AlignHCenter) return LUT{T,I,N,D}[m_focusIndex]; - if(layout == Qt::AlignTop) return LUT{N,I,D,T}[m_focusIndex]; - if(layout == Qt::AlignBottom) return LUT{T,N,D,I}[m_focusIndex]; - if(layout == Qt::AlignVCenter) return LUT{N,D,T,I}[m_focusIndex]; - if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return LUT{N,I,D,T}[m_focusIndex]; - if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return LUT{T,N,D,I}[m_focusIndex]; - if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return LUT{I,D,N,T}[m_focusIndex]; - if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return LUT{I,N,T,D}[m_focusIndex]; - - return None; - } - - FocusIndeces previousFocusIndex() const - { - const auto layout = q->alignmentHint(QskSpinBox::Layout); - using namespace aliased_enum; - - // [0][1][2][3] := index - // [D][T][I][N] := control - using LUT = std::array; - if(layout == Qt::AlignLeft) return LUT{T,N,D,I}[m_focusIndex]; - if(layout == Qt::AlignRight) return LUT{N,I,D,T}[m_focusIndex]; - if(layout == Qt::AlignHCenter) return LUT{N,D,T,I}[m_focusIndex]; - if(layout == Qt::AlignTop) return LUT{I,N,T,D}[m_focusIndex]; - if(layout == Qt::AlignBottom) return LUT{I,D,N,T}[m_focusIndex]; - if(layout == Qt::AlignVCenter) return LUT{T,I,N,D}[m_focusIndex]; - if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return LUT{I,N,T,D}[m_focusIndex]; - if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return LUT{I,D,N,T}[m_focusIndex]; - if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return LUT{T,N,D,I}[m_focusIndex]; - if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return LUT{N,I,D,T}[m_focusIndex]; - - return None; - } - - FocusIndeces focusIndex() const - { - return m_focusIndex; - } - - void focusNext() - { - const auto index = nextFocusIndex(); - setFocus(index); - } - - void focusPrevious() - { - const auto index = previousFocusIndex(); - setFocus(index); - } - - void focusDefault() - { - const auto index = defaultFocusIndex(); - setFocus(index); - } - - void setFocus(const FocusIndeces index) - { - using namespace aliased_enum; - Q_ASSERT(index == D || index == T || index == I || index == N); - if(index == D || index == T || index == I || index == N) + public: + explicit PrivateData( QskSpinBox* const parent ) + : q( parent ) { - m_focusIndex = index; - Q_EMIT q->focusIndexChanged(m_focusIndex); - q->update(); } - } - QRectF focusIndicatorRect() const - { - using namespace aliased_enum; - if(m_focusIndex == D) return q->subControlRect(QskSpinBox::DecrementPanel); - if(m_focusIndex == I) return q->subControlRect(QskSpinBox::IncrementPanel); - if(m_focusIndex == T) return q->subControlRect(QskSpinBox::TextPanel); - return {}; - } + FocusIndeces defaultFocusIndex() const + { + const auto layout = q->alignmentHint( QskSpinBox::Layout ); - void saveMousePosition(const QPointF& pos) - { - q->setSkinHint(QskSpinBox::Layout | QskAspect::Metric | QskAspect::Position, pos ); - } + if ( layout == Qt::AlignLeft ) + { + return QskSpinBox::Textbox; + } + if ( layout == Qt::AlignRight ) + { + return QskSpinBox::Decrement; + } + if ( layout == Qt::AlignHCenter ) + { + return QskSpinBox::Decrement; + } + if ( layout == Qt::AlignTop ) + { + return QskSpinBox::Textbox; + } + if ( layout == Qt::AlignBottom ) + { + return QskSpinBox::Increment; + } + if ( layout == Qt::AlignVCenter ) + { + return QskSpinBox::Increment; + } + if ( layout == ( Qt::AlignLeft | Qt::AlignVCenter ) ) + { + return QskSpinBox::Textbox; + } + if ( layout == ( Qt::AlignRight | Qt::AlignVCenter ) ) + { + return QskSpinBox::Increment; + } + if ( layout == ( Qt::AlignTop | Qt::AlignHCenter ) ) + { + return QskSpinBox::Textbox; + } + if ( layout == ( Qt::AlignBottom | Qt::AlignHCenter ) ) + { + return QskSpinBox::Decrement; + } -private: - QskSpinBox* const q; - FocusIndeces m_focusIndex = FocusIndeces::None; + return None; + } + + FocusIndeces nextFocusIndex() const + { + const auto layout = q->alignmentHint( QskSpinBox::Layout ); + using namespace aliased_enum; + + // [0][1][2][3] := index + // [D][T][I][N] := control + using LUT = std::array< QskSpinBox::FocusIndeces, 4 >; + if ( layout == Qt::AlignLeft ) + { + return LUT{ I, D, N, T }[ m_focusIndex ]; + } + if ( layout == Qt::AlignRight ) + { + return LUT{ I, N, T, D }[ m_focusIndex ]; + } + if ( layout == Qt::AlignHCenter ) + { + return LUT{ T, I, N, D }[ m_focusIndex ]; + } + if ( layout == Qt::AlignTop ) + { + return LUT{ N, I, D, T }[ m_focusIndex ]; + } + if ( layout == Qt::AlignBottom ) + { + return LUT{ T, N, D, I }[ m_focusIndex ]; + } + if ( layout == Qt::AlignVCenter ) + { + return LUT{ N, D, T, I }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignLeft | Qt::AlignVCenter ) ) + { + return LUT{ N, I, D, T }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignRight | Qt::AlignVCenter ) ) + { + return LUT{ T, N, D, I }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignTop | Qt::AlignHCenter ) ) + { + return LUT{ I, D, N, T }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignBottom | Qt::AlignHCenter ) ) + { + return LUT{ I, N, T, D }[ m_focusIndex ]; + } + + return None; + } + + FocusIndeces previousFocusIndex() const + { + const auto layout = q->alignmentHint( QskSpinBox::Layout ); + using namespace aliased_enum; + + // [0][1][2][3] := index + // [D][T][I][N] := control + using LUT = std::array< FocusIndeces, 4 >; + if ( layout == Qt::AlignLeft ) + { + return LUT{ T, N, D, I }[ m_focusIndex ]; + } + if ( layout == Qt::AlignRight ) + { + return LUT{ N, I, D, T }[ m_focusIndex ]; + } + if ( layout == Qt::AlignHCenter ) + { + return LUT{ N, D, T, I }[ m_focusIndex ]; + } + if ( layout == Qt::AlignTop ) + { + return LUT{ I, N, T, D }[ m_focusIndex ]; + } + if ( layout == Qt::AlignBottom ) + { + return LUT{ I, D, N, T }[ m_focusIndex ]; + } + if ( layout == Qt::AlignVCenter ) + { + return LUT{ T, I, N, D }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignLeft | Qt::AlignVCenter ) ) + { + return LUT{ I, N, T, D }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignRight | Qt::AlignVCenter ) ) + { + return LUT{ I, D, N, T }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignTop | Qt::AlignHCenter ) ) + { + return LUT{ T, N, D, I }[ m_focusIndex ]; + } + if ( layout == ( Qt::AlignBottom | Qt::AlignHCenter ) ) + { + return LUT{ N, I, D, T }[ m_focusIndex ]; + } + + return None; + } + + FocusIndeces focusIndex() const + { + return m_focusIndex; + } + + void focusNext() + { + const auto index = nextFocusIndex(); + setFocus( index ); + } + + void focusPrevious() + { + const auto index = previousFocusIndex(); + setFocus( index ); + } + + void focusDefault() + { + const auto index = defaultFocusIndex(); + setFocus( index ); + } + + void setFocus( const FocusIndeces index ) + { + using namespace aliased_enum; + Q_ASSERT( index == D || index == T || index == I || index == N ); + if ( index == D || index == T || index == I || index == N ) + { + m_focusIndex = index; + Q_EMIT q->focusIndexChanged( m_focusIndex ); + q->update(); + } + } + + QRectF focusIndicatorRect() const + { + if ( m_focusIndex == QskSpinBox::Decrement ) + { + return q->subControlRect( QskSpinBox::DecrementPanel ); + } + if ( m_focusIndex == QskSpinBox::Increment ) + { + return q->subControlRect( QskSpinBox::IncrementPanel ); + } + if ( m_focusIndex == QskSpinBox::Textbox ) + { + return q->subControlRect( QskSpinBox::TextPanel ); + } + return {}; + } + + void saveMousePosition( const QPointF& pos ) + { + q->setSkinHint( QskSpinBox::Layout | QskAspect::Metric | QskAspect::Position, pos ); + } + + bool focusNow() const + { + const auto focusOnClick = ( q->focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus; + const auto focusOnTouchRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease(); + return focusOnClick && !focusOnTouchRelease; + } + + private: + QskSpinBox* const q; + FocusIndeces m_focusIndex = FocusIndeces::None; }; using S = QskSpinBox; -QskSpinBox::QskSpinBox(QQuickItem* const parent) - : Inherited(parent) - , m_data(std::make_unique(this)) +QskSpinBox::QskSpinBox( QQuickItem* const parent ) + : Inherited( parent ) + , m_data( std::make_unique< PrivateData >( this ) ) { - setBoundaries(0.0,1.0); - setAcceptHoverEvents(true); - setAcceptedMouseButtons(Qt::LeftButton); - setFocusPolicy( Qt::StrongFocus ); + setBoundaries( 0.0, 1.0 ); + setAcceptHoverEvents( true ); + setAcceptedMouseButtons( Qt::LeftButton ); + setFocusPolicy( Qt::StrongFocus ); - connect( this, &S::focusIndexChanged, this, &S::focusIndicatorRectChanged ); + connect( this, &S::focusIndexChanged, this, &S::focusIndicatorRectChanged ); } QskSpinBox::~QskSpinBox() = default; -void QskSpinBox::hoverEnterEvent(QHoverEvent* event) +void QskSpinBox::hoverEnterEvent( QHoverEvent* const event ) { - m_data->saveMousePosition( qskHoverPosition( event ) ); + m_data->saveMousePosition( qskHoverPosition( event ) ); } -void QskSpinBox::hoverLeaveEvent(QHoverEvent* event) +void QskSpinBox::hoverLeaveEvent( QHoverEvent* /*const event */ ) { - m_data->saveMousePosition( {} ); + m_data->saveMousePosition( {} ); } -void QskSpinBox::hoverMoveEvent(QHoverEvent *event) +void QskSpinBox::hoverMoveEvent( QHoverEvent* const event ) { - m_data->saveMousePosition( qskHoverPosition( event ) ); + m_data->saveMousePosition( qskHoverPosition( event ) ); } -void QskSpinBox::mouseReleaseEvent(QMouseEvent *event) +void QskSpinBox::mouseReleaseEvent( QMouseEvent* const event ) { - m_data->saveMousePosition( qskMousePosition( event ) ); + m_data->saveMousePosition( qskMousePosition( event ) ); - const auto focus = ( focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus && !QGuiApplication::styleHints()->setFocusOnTouchRelease(); + const auto focus = m_data->focusNow(); - if(subControlRect(QskSpinBox::IncrementPanel).contains( event->pos() )) - { - increment(+stepSize()); - - if( focus ) + if ( subControlRect( QskSpinBox::IncrementPanel ).contains( event->pos() ) ) { - m_data->setFocus(Increment); - } + increment( +stepSize() ); - return; - } - - if(subControlRect(QskSpinBox::DecrementPanel).contains( event->pos() )) - { - increment(-stepSize()); - - if( focus ) - { - m_data->setFocus(Decrement); - } - - return; - } - - if(subControlRect(QskSpinBox::TextPanel).contains( event->pos() )) - { - if( focus ) - { - m_data->setFocus(Textbox); - } - - return; - } - - event->ignore(); -} - -void QskSpinBox::mousePressEvent(QMouseEvent *event) -{ - m_data->saveMousePosition( -1 * qskMousePosition( event ) ); - - const auto focus = ( focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus && !QGuiApplication::styleHints()->setFocusOnTouchRelease(); - - if(subControlRect(QskSpinBox::IncrementPanel).contains( event->pos() )) - { - if( focus ) - { - m_data->setFocus(QskSpinBox::Increment); - } - return; - } - - if(subControlRect(QskSpinBox::DecrementPanel).contains( event->pos() )) - { - if( focus ) - { - m_data->setFocus(QskSpinBox::Decrement); - } - return; - } - - event->ignore(); -} - -void QskSpinBox::keyPressEvent(QKeyEvent *event) -{ - switch( event->key() ) - { - case Qt::Key_Plus: - case Qt::Key_Up: - case Qt::Key_Right: - increment(+stepSize()); - return; - case Qt::Key_Minus: - case Qt::Key_Down: - case Qt::Key_Left: - increment(-stepSize()); - return; - case Qt::Key_Select: - case Qt::Key_Space: - if(focusIndex() == Increment) increment(+stepSize()); - if(focusIndex() == Decrement) increment(-stepSize()); - return; - default: - { - const int steps = qskFocusChainIncrement( event ); - - if(steps < 0) - { - for(int i = 0; i < qAbs(steps); ++i) + if ( focus ) { - m_data->focusPrevious(); + m_data->setFocus( Increment ); } - } - if(steps > 0) - { - for(int i = 0; i < steps; ++i) - { - m_data->focusNext(); - } - } - - if(steps != 0 && m_data->focusIndex() != None) - { return; - } } - } - Inherited::keyPressEvent( event ); + + if ( subControlRect( QskSpinBox::DecrementPanel ).contains( event->pos() ) ) + { + increment( -stepSize() ); + + if ( focus ) + { + m_data->setFocus( Decrement ); + } + + return; + } + + if ( subControlRect( QskSpinBox::TextPanel ).contains( event->pos() ) ) + { + if ( focus ) + { + m_data->setFocus( Textbox ); + } + + return; + } + + event->ignore(); } -void QskSpinBox::keyReleaseEvent( QKeyEvent* event ) +void QskSpinBox::mousePressEvent( QMouseEvent* const event ) { - if( event->key() == Qt::Key_Select || event->key() == Qt::Key_Space ) - { - return; - } + m_data->saveMousePosition( -1 * qskMousePosition( event ) ); - Inherited::keyReleaseEvent( event ); + const auto focus = m_data->focusNow(); + + if ( subControlRect( QskSpinBox::IncrementPanel ).contains( event->pos() ) ) + { + if ( focus ) + { + m_data->setFocus( QskSpinBox::Increment ); + } + return; + } + + if ( subControlRect( QskSpinBox::DecrementPanel ).contains( event->pos() ) ) + { + if ( focus ) + { + m_data->setFocus( QskSpinBox::Decrement ); + } + return; + } + + event->ignore(); } -void QskSpinBox::focusInEvent(QFocusEvent *event) +void QskSpinBox::keyPressEvent( QKeyEvent* const event ) { - switch( event->reason() ) - { - case Qt::TabFocusReason: - m_data->focusNext(); - break; + switch ( event->key() ) + { + case Qt::Key_Plus: + case Qt::Key_Up: + case Qt::Key_Right: + increment( +stepSize() ); + return; + case Qt::Key_Minus: + case Qt::Key_Down: + case Qt::Key_Left: + increment( -stepSize() ); + return; + case Qt::Key_Select: + case Qt::Key_Space: + if ( focusIndex() == Increment ) + { + increment( +stepSize() ); + } + if ( focusIndex() == Decrement ) + { + increment( -stepSize() ); + } + return; + default: + break; + } - case Qt::BacktabFocusReason: - m_data->focusPrevious(); - break; + const int steps = qskFocusChainIncrement( event ); - default: - if(m_data->focusIndex() == QskSpinBox::None) - { + if ( steps < 0 ) + { + for ( int i = 0; i < qAbs( steps ); ++i ) + { + m_data->focusPrevious(); + } + } + + if ( steps > 0 ) + { + for ( int i = 0; i < steps; ++i ) + { + m_data->focusNext(); + } + } + + if ( steps != 0 && m_data->focusIndex() != None ) + { + return; + } + + Inherited::keyPressEvent( event ); +} + +void QskSpinBox::keyReleaseEvent( QKeyEvent* const event ) +{ + if ( event->key() == Qt::Key_Select || event->key() == Qt::Key_Space ) + { + return; + } + + Inherited::keyReleaseEvent( event ); +} + +void QskSpinBox::focusInEvent( QFocusEvent* const event ) +{ + if ( event->reason() == Qt::TabFocusReason ) + { + m_data->focusNext(); + return; + } + + if ( event->reason() == Qt::BacktabFocusReason ) + { + m_data->focusPrevious(); + return; + } + + if ( m_data->focusIndex() == QskSpinBox::None ) + { m_data->focusDefault(); return; - } - } - Inherited::focusInEvent( event ); + } + + Inherited::focusInEvent( event ); } QRectF QskSpinBox::focusIndicatorRect() const { - auto rect = m_data->focusIndicatorRect(); - return rect; + return m_data->focusIndicatorRect(); } QskSpinBox::FocusIndeces QskSpinBox::focusIndex() const { - return m_data->focusIndex(); + return m_data->focusIndex(); } diff --git a/src/controls/QskSpinBox.h b/src/controls/QskSpinBox.h index 2d4e7efd..f0318815 100644 --- a/src/controls/QskSpinBox.h +++ b/src/controls/QskSpinBox.h @@ -5,43 +5,51 @@ #pragma once +#include #include #include -#include class QSK_EXPORT QskSpinBox : public QskBoundedValueInput { - Q_OBJECT - using Inherited = QskBoundedValueInput; -public: - enum FocusIndeces : int { Decrement = 0, Textbox = 1, Increment = 2, None = 3 }; - Q_ENUM(FocusIndeces) + Q_OBJECT + using Inherited = QskBoundedValueInput; - Q_PROPERTY(FocusIndeces focusIndex READ focusIndex NOTIFY focusIndexChanged) - QSK_SUBCONTROLS(IncrementPanel, DecrementPanel, IncrementText, DecrementText, TextPanel, Text, Layout) - QSK_STATES( Pressed ) + public: + enum FocusIndeces : int + { + Decrement = 0, + Textbox = 1, + Increment = 2, + None = 3 + }; + Q_ENUM( FocusIndeces ) - explicit QskSpinBox( QQuickItem* parent = nullptr ); - ~QskSpinBox() override; - FocusIndeces focusIndex() const; + Q_PROPERTY( FocusIndeces focusIndex READ focusIndex NOTIFY focusIndexChanged ) + QSK_SUBCONTROLS( + IncrementPanel, DecrementPanel, IncrementText, DecrementText, TextPanel, Text, Layout ) + QSK_STATES( Pressed ) -Q_SIGNALS: - void focusIndexChanged(int index); + explicit QskSpinBox( QQuickItem* parent = nullptr ); + ~QskSpinBox() override; + FocusIndeces focusIndex() const; -private: - void hoverEnterEvent( QHoverEvent* event) override; - void hoverLeaveEvent( QHoverEvent* event) override; - void hoverMoveEvent( QHoverEvent* event) override; + Q_SIGNALS: + void focusIndexChanged( int index ); - void mouseReleaseEvent(QMouseEvent* event) override; - void mousePressEvent(QMouseEvent* event) override; + private: + void hoverEnterEvent( QHoverEvent* event ) override; + void hoverLeaveEvent( QHoverEvent* event ) override; + void hoverMoveEvent( QHoverEvent* event ) override; - void keyPressEvent( QKeyEvent* event ) override; - void keyReleaseEvent( QKeyEvent* event ) override; + void mouseReleaseEvent( QMouseEvent* event ) override; + void mousePressEvent( QMouseEvent* event ) override; - void focusInEvent(QFocusEvent* event) override; - QRectF focusIndicatorRect() const override; + void keyPressEvent( QKeyEvent* event ) override; + void keyReleaseEvent( QKeyEvent* event ) override; - class PrivateData; - std::unique_ptr m_data; + void focusInEvent( QFocusEvent* event ) override; + QRectF focusIndicatorRect() const override; + + class PrivateData; + std::unique_ptr< PrivateData > m_data; }; diff --git a/src/controls/QskSpinBoxSkinlet.cpp b/src/controls/QskSpinBoxSkinlet.cpp index 41b89832..15c2e1f2 100644 --- a/src/controls/QskSpinBoxSkinlet.cpp +++ b/src/controls/QskSpinBoxSkinlet.cpp @@ -8,222 +8,291 @@ #include #include -const auto INCREMENT_TEXT = QStringLiteral("+"); -const auto DECREMENT_TEXT = QStringLiteral("-"); - -enum SampleIndeces { Dec = 0, Txt = 1, Inc = 2, Count }; - -QskSpinBoxSkinlet::QskSpinBoxSkinlet(QskSkin *) +namespace { - setNodeRoles({IncPanel, IncText, DecPanel, DecText, TextPanel, TextText}); -} - -int QskSpinBoxSkinlet::sampleCount(const QskSkinnable *, QskAspect::Subcontrol) const -{ - return Count; -} - -QRectF QskSpinBoxSkinlet::sampleRect(const QskSkinnable* const 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(skinnable); - const auto cursorPos = spinbox->effectiveSkinHint(S::Layout | QskAspect::Metric | QskAspect::Position).toPointF(); - const QPointF cursorPosAbs{qAbs(cursorPos.x()), qAbs(cursorPos.y())}; - const auto focusIndex = spinbox->focusIndex(); - - const auto contain = !cursorPosAbs.isNull() && spinbox->subControlRect(subControl).contains(cursorPosAbs); - const auto pressed = contain && (cursorPos.x() < 0 || cursorPos.y() < 0); - const auto hovered = contain && !pressed; - const auto focused = ( subControl == S::IncrementPanel && focusIndex == S::Increment) || - ( subControl == S::DecrementPanel && focusIndex == S::Decrement) || - ( subControl == S::TextPanel && focusIndex == S::Textbox); - - states.setFlag(QskControl::Hovered, hovered); - states.setFlag(QskSpinBox::Pressed, pressed); - states.setFlag(QskControl::Focused, focused); - } - - return states; -} - -QSizeF QskSpinBoxSkinlet::sizeHint(const QskSkinnable* const skinnable, Qt::SizeHint sizeHint, const QSizeF& size) const -{ - using S = QskSpinBox; - const auto* const spinbox = static_cast(skinnable); - const auto layout = spinbox->alignmentHint(S::Layout); - const auto spacing = spinbox->spacingHint(S::Layout); - - const auto strutInc = spinbox->strutSizeHint(S::IncrementPanel); - const auto strutDec = spinbox->strutSizeHint(S::DecrementPanel); - const auto strutTxt = spinbox->strutSizeHint(S::TextPanel); - - if(sizeHint == Qt::MinimumSize || sizeHint == Qt::MaximumSize || Qt::PreferredSize) - { - if(layout == Qt::AlignTop || layout == Qt::AlignBottom || layout == Qt::AlignVCenter) + inline QPointF cursorPosSkinHint( const QskSpinBox& spinbox ) { - const auto w = qMax(strutDec.width(), qMax( strutTxt.width() , strutInc.width())); - const auto h = strutDec.height() + strutTxt.height() + strutInc.height(); - return {w,h + 2.0 * spacing}; + const auto aspect = QskSpinBox::Layout | QskAspect::Metric | QskAspect::Position; + return spinbox.effectiveSkinHint( aspect ).toPointF(); } - if(layout == Qt::AlignLeft || layout == Qt::AlignRight || layout == Qt::AlignHCenter) + + enum SampleIndeces { - const auto w = strutDec.width() + strutTxt.width() + strutInc.width(); - const auto h = qMax(strutDec.height(), qMax( strutTxt.height() , strutInc.height())); - return {w + 2.0 * spacing,h}; - } - if(layout == (Qt::AlignLeft | Qt::AlignVCenter) || layout == (Qt::AlignRight | Qt::AlignVCenter)) + Dec = 0, + Txt = 1, + Inc = 2, + Count + }; +} + +QskSpinBoxSkinlet::QskSpinBoxSkinlet( QskSkin* ) +{ + setNodeRoles( { IncPanel, IncText, DecPanel, DecText, TextPanel, TextText } ); +} + +int QskSpinBoxSkinlet::sampleCount( const QskSkinnable*, QskAspect::Subcontrol ) const +{ + return Count; +} + +QRectF QskSpinBoxSkinlet::sampleRect( const QskSkinnable* const skinnable, const QRectF& rect, + QskAspect::Subcontrol subControl, int index ) const +{ + if ( index == Dec || index == Inc || index == Txt ) { - const auto w = strutTxt.width() + qMax(strutInc.width(), strutDec.width()); - const auto h = qMax(2.0 * qMax(strutInc.height(), strutDec.height()), strutTxt.height()); - return {w + spacing ,h + spacing}; + return subControlRect( skinnable, rect, subControl ); } - if(layout == (Qt::AlignTop | Qt::AlignHCenter) || layout == (Qt::AlignTop | Qt::AlignHCenter)) + + 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 w = qMax(strutTxt.width() , strutInc.width() + strutDec.width()); - const auto h = strutTxt.height() + qMax(strutInc.height() , strutDec.height()); - return {w + spacing, h + spacing}; + 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 focusIndex = spinbox->focusIndex(); + 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; + const auto focused = ( subControl == S::IncrementPanel && focusIndex == S::Increment ) || + ( subControl == S::DecrementPanel && focusIndex == S::Decrement ) || + ( subControl == S::TextPanel && focusIndex == S::Textbox ); + + states.setFlag( QskControl::Hovered, hovered ); + states.setFlag( QskSpinBox::Pressed, pressed ); + states.setFlag( QskControl::Focused, focused ); } - } - return Inherited::sizeHint(skinnable, sizeHint, size); + + return states; } -QRectF QskSpinBoxSkinlet::subControlRect(const QskSkinnable* const skinnable, const QRectF& rect, QskAspect::Subcontrol subControl) const +QSizeF QskSpinBoxSkinlet::sizeHint( + const QskSkinnable* const skinnable, Qt::SizeHint sizeHint, const QSizeF& size ) const { - using S = QskSpinBox; + using S = QskSpinBox; + const auto* const spinbox = static_cast< const S* >( skinnable ); + const auto layout = spinbox->alignmentHint( S::Layout ); + const auto spacing = spinbox->spacingHint( S::Layout ); - if(subControl == S::DecrementText) return subControlRect(skinnable, rect, S::DecrementPanel); - if(subControl == S::IncrementText) return subControlRect(skinnable, rect, S::IncrementPanel); - if(subControl == S::Text) return subControlRect(skinnable, rect, S::TextPanel); + const auto strutInc = spinbox->strutSizeHint( S::IncrementPanel ); + const auto strutDec = spinbox->strutSizeHint( S::DecrementPanel ); + const auto strutTxt = spinbox->strutSizeHint( S::TextPanel ); - const auto* const spinbox = static_cast(skinnable); - const auto layout = spinbox->alignmentHint(S::Layout); - const auto spacing = spinbox->spacingHint(S::Layout); - - std::array rects = - { - QRectF{ QPointF{}, spinbox->strutSizeHint(S::DecrementPanel)}, - QRectF{ QPointF{}, spinbox->strutSizeHint(S::TextPanel)}, - QRectF{ QPointF{}, spinbox->strutSizeHint(S::IncrementPanel)}, - }; - - const auto center = rect.center(); - - // TODO center everything - - if(layout == Qt::AlignLeft) - { - rects[Txt].moveTopLeft({0.0 /************/, center.y() - rects[Txt].height() * 0.5}); - rects[Dec].moveTopLeft({rects[Txt].right() + spacing, center.y() - rects[Dec].height() * 0.5}); - rects[Inc].moveTopLeft({rects[Dec].right() + spacing, center.y() - rects[Inc].height() * 0.5}); - } - else if(layout == Qt::AlignRight) - { - rects[Dec].moveTopLeft({0.0 /************/, center.y() - rects[Dec].height() * 0.5}); - rects[Inc].moveTopLeft({rects[Dec].right() + spacing, center.y() - rects[Inc].height() * 0.5}); - rects[Txt].moveTopLeft({rects[Inc].right() + spacing, center.y() - rects[Txt].height() * 0.5}); - } - else if(layout == Qt::AlignTop) - { - rects[Txt].moveTopLeft({center.x() - rects[Txt].width() * 0.5, 0.0 }); - rects[Inc].moveTopLeft({center.x() - rects[Inc].width() * 0.5, rects[Txt].bottom() + spacing}); - rects[Dec].moveTopLeft({center.x() - rects[Dec].width() * 0.5, rects[Inc].bottom() + spacing}); - } - else if(layout == Qt::AlignBottom) - { - rects[Inc].moveTopLeft({center.x() - rects[Inc].width() * 0.5, 0.0}); - rects[Dec].moveTopLeft({center.x() - rects[Dec].width() * 0.5, rects[Inc].bottom() + spacing}); - rects[Txt].moveTopLeft({center.x() - rects[Txt].width() * 0.5, rects[Dec].bottom() + spacing}); - } - else if(layout == Qt::AlignHCenter) - { - rects[Dec].moveTopLeft({0.0 /************/, center.y() - rects[Dec].height() * 0.5}); - rects[Txt].moveTopLeft({rects[Dec].right() + spacing, center.y() - rects[Txt].height() * 0.5}); - rects[Inc].moveTopLeft({rects[Txt].right() + spacing, center.y() - rects[Inc].height() * 0.5}); - } - else if(layout == Qt::AlignVCenter) - { - rects[Inc].moveTopLeft({center.x() - rects[Inc].width() * 0.5, 0.0}); - rects[Txt].moveTopLeft({center.x() - rects[Txt].width() * 0.5, rects[Inc].bottom() + spacing}); - rects[Dec].moveTopLeft({center.x() - rects[Dec].width() * 0.5, rects[Txt].bottom() + spacing}); - } - else if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) - { - rects[Txt].moveTopLeft({0.0 /************/, center.y() - rects[Txt].height() * 0.5 }); - rects[Inc].moveTopLeft({rects[Txt].right() + spacing, center.y() - spacing * 0.5 - rects[Inc].height()}); - rects[Dec].moveTopLeft({rects[Txt].right() + spacing, center.y() + spacing * 0.5}); - } - else if(layout == (Qt::AlignRight | Qt::AlignVCenter)) - { - const auto dx = qMax(rects[Inc].width(), rects[Dec].width()); - rects[Inc].moveTopLeft({dx - rects[Inc].width(), center.y() - spacing * 0.5 - rects[Inc].height()}); - rects[Dec].moveTopLeft({dx - rects[Dec].width(), center.y() + spacing * 0.5}); - rects[Txt].moveTopLeft({dx + spacing, center.y() - rects[Txt].height() * 0.5 }); - } - else if(layout == (Qt::AlignTop | Qt::AlignHCenter)) - { - rects[Txt].moveTopLeft({center.x() - rects[Txt].width() * 0.5, 0.0 }); - rects[Dec].moveTopLeft({rects[Txt].center().x() - spacing * 0.5 - rects[Dec].width(), rects[Txt].bottom() + spacing }); - rects[Inc].moveTopLeft({rects[Txt].center().x() + spacing * 0.5, rects[Txt].bottom() + spacing }); - } - else if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) - { - rects[Txt].moveTopLeft({center.x() - rects[Txt].width() * 0.5, center.y() - rects[Txt].height() * 0.5}); - rects[Dec].moveTopLeft({center.x() - spacing * 0.5 - rects[Dec].width() , rects[Txt].top() - spacing - rects[Dec].height() }); - rects[Inc].moveTopLeft({center.x() + spacing * 0.5, rects[Txt].top() - spacing - rects[Inc].height() }); - } - - if(subControl == S::DecrementPanel) - { - return rects[Dec]; - } - if(subControl == S::TextPanel) - { - return rects[Txt]; - } - if(subControl == S::IncrementPanel) - { - return rects[Inc]; - } - - return Inherited::subControlRect(skinnable, rect, subControl); + if ( sizeHint == Qt::MinimumSize || sizeHint == Qt::MaximumSize || Qt::PreferredSize ) + { + if ( layout == Qt::AlignTop || layout == Qt::AlignBottom || layout == Qt::AlignVCenter ) + { + const auto w = qMax( strutDec.width(), qMax( strutTxt.width(), strutInc.width() ) ); + const auto h = strutDec.height() + strutTxt.height() + strutInc.height(); + return { w, h + 2.0 * spacing }; + } + if ( layout == Qt::AlignLeft || layout == Qt::AlignRight || layout == Qt::AlignHCenter ) + { + const auto w = strutDec.width() + strutTxt.width() + strutInc.width(); + const auto h = qMax( strutDec.height(), qMax( strutTxt.height(), strutInc.height() ) ); + return { w + 2.0 * spacing, h }; + } + if ( layout == ( Qt::AlignLeft | Qt::AlignVCenter ) || + layout == ( Qt::AlignRight | Qt::AlignVCenter ) ) + { + const auto w = strutTxt.width() + qMax( strutInc.width(), strutDec.width() ); + const auto h = + qMax( 2.0 * qMax( strutInc.height(), strutDec.height() ), strutTxt.height() ); + return { w + spacing, h + spacing }; + } + if ( layout == ( Qt::AlignTop | Qt::AlignHCenter ) || + layout == ( Qt::AlignTop | Qt::AlignHCenter ) ) + { + const auto w = qMax( strutTxt.width(), strutInc.width() + strutDec.width() ); + const auto h = strutTxt.height() + qMax( strutInc.height(), strutDec.height() ); + return { w + spacing, h + spacing }; + } + } + return Inherited::sizeHint( skinnable, sizeHint, size ); } -QSGNode* QskSpinBoxSkinlet::updateSubNode(const QskSkinnable* const skinnable, const quint8 nodeRole, QSGNode* const node) const +QRectF QskSpinBoxSkinlet::subControlRect( const QskSkinnable* const skinnable, const QRectF& rect, + QskAspect::Subcontrol subControl ) const { - using S = QskSpinBox; - if(nodeRole == IncPanel) { return updateSeriesNode( skinnable, S::IncrementPanel, node); } - if(nodeRole == DecPanel) { return updateSeriesNode( skinnable, S::DecrementPanel, node ); } - if(nodeRole == IncText) { return updateTextNode( skinnable, node, INCREMENT_TEXT, S::IncrementText); } - if(nodeRole == DecText) { return updateTextNode( skinnable, node, DECREMENT_TEXT, S::DecrementText ); } - if(nodeRole == TextPanel) { return updateSeriesNode( skinnable, S::TextPanel, node ); } - if(nodeRole == TextText) { return updateTextNode( skinnable, node, QString::number(static_cast(skinnable)->value()), S::Text ); } - return Inherited::updateSubNode(skinnable, nodeRole, node); + using S = QskSpinBox; + + if ( subControl == S::DecrementText ) + { + return subControlRect( skinnable, rect, S::DecrementPanel ); + } + if ( subControl == S::IncrementText ) + { + return subControlRect( skinnable, rect, S::IncrementPanel ); + } + if ( subControl == S::Text ) + { + return subControlRect( skinnable, rect, S::TextPanel ); + } + + const auto* const spinbox = static_cast< const S* >( skinnable ); + const auto layout = spinbox->alignmentHint( S::Layout ); + const auto spacing = spinbox->spacingHint( S::Layout ); + + std::array< QRectF, Count > rects = { + QRectF{ QPointF{}, spinbox->strutSizeHint( S::DecrementPanel ) }, + QRectF{ QPointF{}, spinbox->strutSizeHint( S::TextPanel ) }, + QRectF{ QPointF{}, spinbox->strutSizeHint( S::IncrementPanel ) }, + }; + + const auto center = rect.center(); + + if ( layout == Qt::AlignLeft ) + { + rects[ Txt ].moveTopLeft( { 0.0, center.y() - rects[ Txt ].height() * 0.5 } ); + rects[ Dec ].moveTopLeft( + { rects[ Txt ].right() + spacing, center.y() - rects[ Dec ].height() * 0.5 } ); + rects[ Inc ].moveTopLeft( + { rects[ Dec ].right() + spacing, center.y() - rects[ Inc ].height() * 0.5 } ); + } + else if ( layout == Qt::AlignRight ) + { + rects[ Dec ].moveTopLeft( { 0.0, center.y() - rects[ Dec ].height() * 0.5 } ); + rects[ Inc ].moveTopLeft( + { rects[ Dec ].right() + spacing, center.y() - rects[ Inc ].height() * 0.5 } ); + rects[ Txt ].moveTopLeft( + { rects[ Inc ].right() + spacing, center.y() - rects[ Txt ].height() * 0.5 } ); + } + else if ( layout == Qt::AlignTop ) + { + rects[ Txt ].moveTopLeft( { center.x() - rects[ Txt ].width() * 0.5, 0.0 } ); + rects[ Inc ].moveTopLeft( + { center.x() - rects[ Inc ].width() * 0.5, rects[ Txt ].bottom() + spacing } ); + rects[ Dec ].moveTopLeft( + { center.x() - rects[ Dec ].width() * 0.5, rects[ Inc ].bottom() + spacing } ); + } + else if ( layout == Qt::AlignBottom ) + { + rects[ Inc ].moveTopLeft( { center.x() - rects[ Inc ].width() * 0.5, 0.0 } ); + rects[ Dec ].moveTopLeft( + { center.x() - rects[ Dec ].width() * 0.5, rects[ Inc ].bottom() + spacing } ); + rects[ Txt ].moveTopLeft( + { center.x() - rects[ Txt ].width() * 0.5, rects[ Dec ].bottom() + spacing } ); + } + else if ( layout == Qt::AlignHCenter ) + { + rects[ Dec ].moveTopLeft( { 0.0, center.y() - rects[ Dec ].height() * 0.5 } ); + rects[ Txt ].moveTopLeft( + { rects[ Dec ].right() + spacing, center.y() - rects[ Txt ].height() * 0.5 } ); + rects[ Inc ].moveTopLeft( + { rects[ Txt ].right() + spacing, center.y() - rects[ Inc ].height() * 0.5 } ); + } + else if ( layout == Qt::AlignVCenter ) + { + rects[ Inc ].moveTopLeft( { center.x() - rects[ Inc ].width() * 0.5, 0.0 } ); + rects[ Txt ].moveTopLeft( + { center.x() - rects[ Txt ].width() * 0.5, rects[ Inc ].bottom() + spacing } ); + rects[ Dec ].moveTopLeft( + { center.x() - rects[ Dec ].width() * 0.5, rects[ Txt ].bottom() + spacing } ); + } + else if ( layout == ( Qt::AlignLeft | Qt::AlignVCenter ) ) + { + rects[ Txt ].moveTopLeft( { 0.0, center.y() - rects[ Txt ].height() * 0.5 } ); + rects[ Inc ].moveTopLeft( { rects[ Txt ].right() + spacing, + center.y() - spacing * 0.5 - rects[ Inc ].height() } ); + rects[ Dec ].moveTopLeft( { rects[ Txt ].right() + spacing, center.y() + spacing * 0.5 } ); + } + else if ( layout == ( Qt::AlignRight | Qt::AlignVCenter ) ) + { + const auto dx = qMax( rects[ Inc ].width(), rects[ Dec ].width() ); + rects[ Inc ].moveTopLeft( + { dx - rects[ Inc ].width(), center.y() - spacing * 0.5 - rects[ Inc ].height() } ); + rects[ Dec ].moveTopLeft( { dx - rects[ Dec ].width(), center.y() + spacing * 0.5 } ); + rects[ Txt ].moveTopLeft( { dx + spacing, center.y() - rects[ Txt ].height() * 0.5 } ); + } + else if ( layout == ( Qt::AlignTop | Qt::AlignHCenter ) ) + { + rects[ Txt ].moveTopLeft( { center.x() - rects[ Txt ].width() * 0.5, 0.0 } ); + rects[ Dec ].moveTopLeft( + { rects[ Txt ].center().x() - spacing * 0.5 - rects[ Dec ].width(), + rects[ Txt ].bottom() + spacing } ); + rects[ Inc ].moveTopLeft( + { rects[ Txt ].center().x() + spacing * 0.5, rects[ Txt ].bottom() + spacing } ); + } + else if ( layout == ( Qt::AlignBottom | Qt::AlignHCenter ) ) + { + rects[ Txt ].moveTopLeft( + { center.x() - rects[ Txt ].width() * 0.5, center.y() - rects[ Txt ].height() * 0.5 } ); + rects[ Dec ].moveTopLeft( { center.x() - spacing * 0.5 - rects[ Dec ].width(), + rects[ Txt ].top() - spacing - rects[ Dec ].height() } ); + rects[ Inc ].moveTopLeft( + { center.x() + spacing * 0.5, rects[ Txt ].top() - spacing - rects[ Inc ].height() } ); + } + + if ( subControl == S::DecrementPanel ) + { + return rects[ Dec ]; + } + if ( subControl == S::TextPanel ) + { + return rects[ Txt ]; + } + if ( subControl == S::IncrementPanel ) + { + return rects[ Inc ]; + } + + return Inherited::subControlRect( skinnable, rect, subControl ); } -QSGNode* QskSpinBoxSkinlet::updateSampleNode(const QskSkinnable* const skinnable, QskAspect::Subcontrol subControl, const int index, QSGNode* const node) const +QSGNode* QskSpinBoxSkinlet::updateSubNode( + const QskSkinnable* const skinnable, const quint8 nodeRole, QSGNode* const node ) const { - using S = QskSpinBox; - const auto* const spinbox = static_cast(skinnable); - - if ( subControl == S::DecrementPanel || subControl == S::IncrementPanel || subControl == S::TextPanel ) - { - const auto rect = sampleRect(spinbox, spinbox->contentsRect(), subControl, index); - return updateBoxNode( skinnable, node, rect, subControl ); - } - - return Inherited::updateSampleNode( skinnable, subControl, index, node ); + using S = QskSpinBox; + if ( nodeRole == IncPanel ) + { + return updateSeriesNode( skinnable, S::IncrementPanel, node ); + } + if ( nodeRole == DecPanel ) + { + return updateSeriesNode( skinnable, S::DecrementPanel, node ); + } + if ( nodeRole == IncText ) + { + return updateTextNode( skinnable, node, QStringLiteral( "+" ), S::IncrementText ); + } + if ( nodeRole == DecText ) + { + return updateTextNode( skinnable, node, QStringLiteral( "-" ), S::DecrementText ); + } + if ( nodeRole == TextPanel ) + { + return updateSeriesNode( skinnable, S::TextPanel, node ); + } + if ( nodeRole == TextText ) + { + const auto* const spinbox = static_cast< const S* >( skinnable ); + return updateTextNode( skinnable, node, QString::number( spinbox->value() ), S::Text ); + } + return Inherited::updateSubNode( skinnable, nodeRole, node ); +} + +QSGNode* QskSpinBoxSkinlet::updateSampleNode( const QskSkinnable* const skinnable, + QskAspect::Subcontrol subControl, const int index, QSGNode* const node ) const +{ + using S = QskSpinBox; + const auto* const spinbox = static_cast< const S* >( skinnable ); + + if ( subControl == S::DecrementPanel || subControl == S::IncrementPanel || + subControl == S::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 ab6cbf65..1013d942 100644 --- a/src/controls/QskSpinBoxSkinlet.h +++ b/src/controls/QskSpinBoxSkinlet.h @@ -9,20 +9,32 @@ class QSK_EXPORT QskSpinBoxSkinlet : public QskSkinlet { - Q_GADGET - using Inherited = QskSkinlet; -public: - enum NodeRole - { - IncPanel, IncText, DecPanel, DecText, TextPanel, TextText, RoleCount - }; - Q_INVOKABLE QskSpinBoxSkinlet( QskSkin* = nullptr ); -protected: - int sampleCount( const QskSkinnable*, QskAspect::Subcontrol ) const override; - QRectF sampleRect( const QskSkinnable*, const QRectF&, QskAspect::Subcontrol, int index ) const override; - QskAspect::States sampleStates(const QskSkinnable* skinnable, QskAspect::Subcontrol subControl, int index ) const override; - QSizeF sizeHint( const QskSkinnable*, Qt::SizeHint, const QSizeF& ) const override; - QRectF subControlRect( const QskSkinnable*, const QRectF&, QskAspect::Subcontrol ) const override; - QSGNode* updateSubNode( const QskSkinnable*, quint8 nodeRole, QSGNode* ) const override; - QSGNode* updateSampleNode( const QskSkinnable* skinnable, QskAspect::Subcontrol subControl, int index, QSGNode* node ) const override; + Q_GADGET + using Inherited = QskSkinlet; + + public: + enum NodeRole + { + IncPanel, + IncText, + DecPanel, + DecText, + TextPanel, + TextText, + RoleCount + }; + Q_INVOKABLE QskSpinBoxSkinlet( QskSkin* = nullptr ); + + protected: + int sampleCount( const QskSkinnable*, QskAspect::Subcontrol ) const override; + QRectF sampleRect( + const QskSkinnable*, const QRectF&, QskAspect::Subcontrol, int index ) const override; + QskAspect::States sampleStates( + const QskSkinnable* skinnable, QskAspect::Subcontrol subControl, int index ) const override; + QSizeF sizeHint( const QskSkinnable*, Qt::SizeHint, const QSizeF& ) const override; + QRectF subControlRect( + const QskSkinnable*, const QRectF&, QskAspect::Subcontrol ) const override; + QSGNode* updateSubNode( const QskSkinnable*, quint8 nodeRole, QSGNode* ) const override; + QSGNode* updateSampleNode( const QskSkinnable* skinnable, QskAspect::Subcontrol subControl, + int index, QSGNode* node ) const override; };