Skip to content

Commit

Permalink
ticks for F2 sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Nov 22, 2024
1 parent f4c2211 commit 494c370
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 114 deletions.
20 changes: 15 additions & 5 deletions designsystems/fluent2/QskFluent2Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,10 +1450,14 @@ void Editor::setupSliderMetrics()

setShadowMetrics( Q::Handle, { shadowSpread, 0.0 } );

setBoxBorderMetrics( Q::Handle, 5 );
setBoxBorderMetrics( Q::Handle | Q::Hovered, 4 );
setBoxBorderMetrics( Q::Handle | Q::Pressed, 6 );
setBoxBorderMetrics( Q::Handle | Q::Disabled, 6 );
setBoxBorderMetrics( Q::Handle, 5_px );
setBoxBorderMetrics( Q::Handle | Q::Hovered, 4_px );
setBoxBorderMetrics( Q::Handle | Q::Pressed, 6_px );
setBoxBorderMetrics( Q::Handle | Q::Disabled, 6_px );

setFlag( Q::Tick | A::Option, Qsk::Maybe );
setStrutSize( Q::Tick | A::Horizontal, 1_px, -1 );
setStrutSize( Q::Tick | A::Vertical, -1, 1_px );
}

void Editor::setupSliderColors(
Expand Down Expand Up @@ -1484,29 +1488,35 @@ void Editor::setupSliderColors(

for ( auto state : { A::NoState, Q::Hovered, Q::Pressed, Q::Disabled } )
{
QRgb grooveColor, handleColor;
QRgb grooveColor, fillColor, handleColor;

if ( state == A::NoState || state == Q::Hovered )
{
grooveColor = pal.fillColor.controlStrong.defaultColor;
fillColor = pal.fillColor.accent.defaultColor;
handleColor = pal.fillColor.accent.defaultColor;
}
else if ( state == Q::Pressed )
{
grooveColor = pal.fillColor.controlStrong.defaultColor;
handleColor = pal.fillColor.accent.tertiary;
fillColor = pal.fillColor.accent.defaultColor;
}
else if ( state == Q::Disabled )
{
grooveColor = pal.fillColor.controlStrong.disabled;
fillColor = pal.fillColor.accent.disabled;
handleColor = grooveColor;
}

grooveColor = rgbSolid( grooveColor, pal.background.solid.base );

setGradient( Q::Groove | section | state, grooveColor );
setGradient( Q::Fill | section | state, fillColor );
setGradient( Q::Handle | section | state, handleColor );
}

setGradient( Q::Tick, pal.fillColor.controlSolid.defaultColor );
}

void Editor::setupSpinBoxMetrics()
Expand Down
4 changes: 3 additions & 1 deletion designsystems/material3/QskMaterial3Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ void Editor::setupSlider()
{
using A = QskAspect;
using Q = QskSlider;
using SK = QskMaterial3SliderSkinlet;
using SK = QskSliderSkinlet;

const auto extentGroove = 16_dp;
const auto extentPanel = 44_dp;
Expand Down Expand Up @@ -937,6 +937,8 @@ void Editor::setupSlider()
{ QskStateCombination::CombinationNoState, Q::Focused | Q::Pressed } );
setGradient( Q::Tick | SK::Filled | Q::Disabled, m_pal.inverseOnSurface );

setFlag( Q::Tick | A::Option, Qsk::Maybe );

for ( const auto variation : { A::Horizontal, A::Vertical } )
{
QSizeF handleSize( extentGroove, extentPanel );
Expand Down
71 changes: 27 additions & 44 deletions designsystems/material3/QskMaterial3SliderSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
#include <QskClipNode.h>
#include <QskSGNode.h>

#include <qmath.h>

// the color of stop indicators is different, when being on top of the filling
QSK_SYSTEM_STATE( QskMaterial3SliderSkinlet, Filled, QskAspect::FirstUserState >> 1 )

using Q = QskSlider;

static inline bool qskHasBoundaryTicks( const QskSlider* slider )
Expand Down Expand Up @@ -92,7 +87,7 @@ int QskMaterial3SliderSkinlet::sampleCount( const QskSkinnable* skinnable,
{
const auto slider = static_cast< const QskSlider* >( skinnable );

if ( qskHasBoundaryTicks( slider ) )
if ( ( slider->graduationPolicy() == Qsk::Maybe ) && !slider->isSnapping() )
{
const bool hasOrigin = false;

Expand All @@ -104,54 +99,42 @@ int QskMaterial3SliderSkinlet::sampleCount( const QskSkinnable* skinnable,
return Inherited::sampleCount( skinnable, subControl );
}

QVariant QskMaterial3SliderSkinlet::sampleAt( const QskSkinnable* skinnable,
QskAspect::Subcontrol subControl, int index ) const
QVector< qreal > QskMaterial3SliderSkinlet::graduation( const QskSlider* slider ) const
{
if ( subControl == Q::Tick )
QVector< qreal > graduation;

if ( ( slider->graduationPolicy() == Qsk::Maybe ) && !slider->isSnapping() )
{
const auto slider = static_cast< const QskSlider* >( skinnable );
const bool hasOrigin = false;

if ( qskHasBoundaryTicks( slider ) )
if ( hasOrigin )
{
switch( index )
{
case 1:
return slider->minimum();

#if 0
case 2:
return slider->origin();
#endif

default:
return slider->maximum();
}

return QVariant();
graduation.reserve( 3 );
graduation += slider->minimum();
#if 1
graduation += slider->maximum(); // origin !!!
#endif
graduation += slider->maximum();
}
else
{
graduation.reserve( 1 );
graduation += slider->maximum();
}
}

return Inherited::sampleAt( skinnable, subControl, index );
}

QskAspect::States QskMaterial3SliderSkinlet::sampleStates(
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl, int index ) const
{
auto states = Inherited::sampleStates( skinnable, subControl, index );

if ( subControl == Q::Tick )
else
{
const auto tickValue = sampleAt( skinnable, subControl, index );
if ( tickValue.canConvert< qreal >() )
{
const auto slider = static_cast< const QskSlider* >( skinnable );
const auto g = Inherited::graduation( slider );

if ( tickValue.value< qreal >() <= slider->value() )
states |= QskMaterial3SliderSkinlet::Filled;
}
// adding the boundaries

graduation.reserve( g.count() + 2 );
graduation += slider->minimum();
graduation += g;
graduation += slider->maximum();
}

return states;
return graduation;
}

#include "moc_QskMaterial3SliderSkinlet.cpp"
10 changes: 2 additions & 8 deletions designsystems/material3/QskMaterial3SliderSkinlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@ class QskMaterial3SliderSkinlet : QskSliderSkinlet
using Inherited = QskSliderSkinlet;

public:
QSK_STATES( Filled )

Q_INVOKABLE QskMaterial3SliderSkinlet( QskSkin* = nullptr );

QRectF subControlRect( const QskSkinnable*,
const QRectF& rect, QskAspect::Subcontrol ) const override;

int sampleCount( const QskSkinnable*, QskAspect::Subcontrol ) const override;

QVariant sampleAt( const QskSkinnable*,
QskAspect::Subcontrol, int index ) const override;

QskAspect::States sampleStates( const QskSkinnable*,
QskAspect::Subcontrol, int ) const override;

protected:
QSGNode* updateSubNode( const QskSkinnable*,
quint8 nodeRole, QSGNode* ) const override;

QVector< qreal > graduation( const QskSlider* ) const override;
};

#endif
43 changes: 1 addition & 42 deletions src/controls/QskSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "QskIntervalF.h"
#include "QskEvent.h"

#include <qmath.h>

QSK_SUBCONTROL( QskSlider, Panel )
QSK_SUBCONTROL( QskSlider, Groove )
QSK_SUBCONTROL( QskSlider, Fill )
Expand All @@ -25,26 +23,6 @@ static inline QskAspect qskAspectGraduationPolicy()
return QskSlider::Tick | QskAspect::Option;
}

static inline bool qskHasGraduation( const QskSlider* slider )
{
if ( slider->stepSize() )
{
switch( slider->graduationPolicy() )
{
case Qsk::Always:
return true;

case Qsk::Maybe:
return slider->isSnapping();

case Qsk::Never:
return false;
}
}

return false;
}

class QskSlider::PrivateData
{
public:
Expand Down Expand Up @@ -131,26 +109,7 @@ void QskSlider::resetGraduationPolicy()

Qsk::Policy QskSlider::graduationPolicy() const
{
return flagHint< Qsk::Policy >( qskAspectGraduationPolicy(), Qsk::Maybe );
}

QVector< qreal > QskSlider::visualGraduation() const
{
QVector< qreal > graduation;

if ( qskHasGraduation( this ) )
{
const auto n = qCeil( boundaryLength() / stepSize() ) + 1;

graduation.reserve( n );

for ( int i = 0; i < n - 1; i++ )
graduation += minimum() + i * stepSize();

graduation += maximum();
}

return graduation;
return flagHint< Qsk::Policy >( qskAspectGraduationPolicy(), Qsk::Never );
}

void QskSlider::setTracking( bool on )
Expand Down
4 changes: 0 additions & 4 deletions src/controls/QskSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "QskBoundedValueInput.h"
#include "QskNamespace.h"

#include <qvector.h>

class QSK_EXPORT QskSlider : public QskBoundedValueInput
{
Q_OBJECT
Expand Down Expand Up @@ -49,8 +47,6 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput
void resetGraduationPolicy();
Qsk::Policy graduationPolicy() const;

virtual QVector< qreal > visualGraduation() const;

void setTracking( bool );
bool isTracking() const;

Expand Down
Loading

0 comments on commit 494c370

Please sign in to comment.