Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spin box: Improve for M3 #440

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions designsystems/material3/QskMaterial3Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ void Editor::setupSpinBox()

setHint( Q::Panel | QskAspect::Style, Q::ButtonsLeftAndRight );

setStrutSize( Q::Panel, -1.0, 48_dp );
setBoxShape( Q::Panel, 4_dp );
setBoxBorderMetrics( Q::Panel, 1_dp );

Expand All @@ -909,21 +910,25 @@ void Editor::setupSpinBox()
setSpacing( Q::Panel, 4_dp );

setStrutSize( Q::TextPanel, 80_dp, 40_dp );
setStrutSize( Q::UpPanel, 40_dp,40_dp );
setStrutSize( Q::UpPanel, 40_dp, 40_dp );
setStrutSize( Q::DownPanel, 40_dp, 40_dp );

setAlignment( Q::Text, Qt::AlignCenter );

for( const auto subControl : { Q::DownPanel, Q::UpPanel, Q::TextPanel } )
{
setBoxShape( subControl, 4_dp );
setBoxBorderMetrics( subControl, 1_dp );
}

setBoxShape( Q::TextPanel, 4_dp );

setBoxShape( Q::DownPanel, 100, Qt::RelativeSize );
setBoxShape( Q::UpPanel, 100, Qt::RelativeSize );

for( const auto subControl : { Q::DownPanel, Q::UpPanel } )
{
setGradient( subControl | Q::Hovered, m_pal.primary8 );
setPadding( subControl, 10 );
setPadding( subControl, 11_dp );
}

{
Expand Down
32 changes: 32 additions & 0 deletions src/controls/QskSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ QskSpinBox::QskSpinBox( qreal min, qreal max, qreal stepSize, QQuickItem* parent
setBoundaries( min, max );
setStepSize( stepSize );

setAcceptHoverEvents( true );

setAcceptedMouseButtons( Qt::LeftButton );
setFocusPolicy( Qt::StrongFocus );

Expand Down Expand Up @@ -302,6 +304,36 @@ void QskSpinBox::mouseUngrabEvent()
m_data->setAutoRepeat( this, 0.0 );
}

void QskSpinBox::hoverEnterEvent( QHoverEvent* event )
{
using A = QskAspect;

setSkinHint( UpPanel | Hovered | A::Metric | A::Position, qskHoverPosition( event ) );
setSkinHint( DownPanel | Hovered | A::Metric | A::Position, qskHoverPosition( event ) );

update();
}

void QskSpinBox::hoverMoveEvent( QHoverEvent* event )
{
using A = QskAspect;

setSkinHint( UpPanel | Hovered | A::Metric | A::Position, qskHoverPosition( event ) );
setSkinHint( DownPanel | Hovered | A::Metric | A::Position, qskHoverPosition( event ) );

update();
}

void QskSpinBox::hoverLeaveEvent( QHoverEvent* )
{
using A = QskAspect;

setSkinHint( UpPanel | Hovered | A::Metric | A::Position, QPointF() );
setSkinHint( DownPanel | Hovered | A::Metric | A::Position, QPointF() );

update();
}

void QskSpinBox::keyPressEvent( QKeyEvent* event )
{
if ( !isReadOnly() && !m_data->repeatTimer.isActive() )
Expand Down
4 changes: 4 additions & 0 deletions src/controls/QskSpinBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
void mousePressEvent( QMouseEvent* ) override;
void mouseUngrabEvent() override;

void hoverEnterEvent( QHoverEvent* ) override;
void hoverMoveEvent( QHoverEvent* ) override;
void hoverLeaveEvent( QHoverEvent* ) override;

void keyPressEvent( QKeyEvent* ) override;
void keyReleaseEvent( QKeyEvent* ) override;

Expand Down
26 changes: 20 additions & 6 deletions src/controls/QskSpinBoxSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,39 @@ static inline QskAspect::States qskButtonStates(
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
{
using Q = QskSpinBox;
using A = QskAspect;

auto spinBox = static_cast< const QskSpinBox* >( skinnable );

auto states = spinBox->skinStates();

if ( spinBox->isEnabled() && !spinBox->isWrapping() )
if ( spinBox->isEnabled() )
{
if ( subControl == Q::DownIndicator || subControl == Q::DownPanel )
{
if ( spinBox->value() <= spinBox->minimum() )
if ( !spinBox->isWrapping() && spinBox->value() <= spinBox->minimum() )
states |= QskControl::Disabled;

const auto cursorPos = spinBox->effectiveSkinHint(
Q::DownPanel | Q::Hovered | A::Metric | A::Position ).toPointF();

if( !cursorPos.isNull() && spinBox->subControlRect( Q::DownPanel ).contains( cursorPos ) )
{
states |= Q::Hovered;
}
}
else if ( subControl == Q::UpIndicator || subControl == Q::UpPanel )
{
if ( spinBox->value() >= spinBox->maximum() )
if ( !spinBox->isWrapping() && spinBox->value() >= spinBox->maximum() )
states |= QskControl::Disabled;

const auto cursorPos = spinBox->effectiveSkinHint(
Q::UpPanel | Q::Hovered | A::Metric | A::Position ).toPointF();

if( !cursorPos.isNull() && spinBox->subControlRect( Q::UpPanel ).contains( cursorPos ) )
{
states |= Q::Hovered;
}
}
}

Expand All @@ -47,9 +64,6 @@ QRectF QskSpinBoxSkinlet::subControlRect( const QskSkinnable* skinnable,
{
using Q = QskSpinBox;

QskSkinStateChanger stateChanger( skinnable );
stateChanger.setStates( qskButtonStates( skinnable, subControl ) );

if ( subControl == Q::Panel )
return contentsRect;

Expand Down
Loading