From 0800a2002f27f58d4e8b0fdd0ee516cd6fec817e Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 1 Mar 2023 17:47:50 +0100 Subject: [PATCH] tying spinboxes and sliders --- examples/gallery/inputs/InputPage.cpp | 48 +++++++++++++++++++++------ examples/gallery/inputs/InputPage.h | 2 +- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/examples/gallery/inputs/InputPage.cpp b/examples/gallery/inputs/InputPage.cpp index 4dce94e7..15764d1e 100644 --- a/examples/gallery/inputs/InputPage.cpp +++ b/examples/gallery/inputs/InputPage.cpp @@ -18,12 +18,12 @@ namespace Slider( Qt::Orientation orientation, QQuickItem* parent = nullptr ) : QskSlider( orientation, parent ) { - setBoundaries( 0, 1000 ); - setValue( 300 ); + setBoundaries( 0, 100 ); + setValue( 30 ); setPageSize( 10 ); - setStepSize( 10 ); - setSnap( true ); + setStepSize( 1 ); + //setSnap( true ); #if 0 connect( this, &QskSlider::valueChanged, @@ -63,7 +63,7 @@ namespace } { - auto spinBox = new QskSpinBox( this ); + auto spinBox = new QskSpinBox( 10.0, 100.0, 1.0, this ); spinBox->setPageSize( 10 ); spinBox->setDecoration( QskSpinBox::NoDecoration ); spinBox->setValue( 50 ); @@ -74,11 +74,6 @@ namespace InputPage::InputPage( QQuickItem* parent ) : Page( Qt::Horizontal, parent ) -{ - populate(); -} - -void InputPage::populate() { auto sliderH = new Slider( Qt::Horizontal ); auto sliderV = new Slider( Qt::Vertical ); @@ -90,4 +85,37 @@ void InputPage::populate() gridBox->addItem( sliderV, 0, 0, -1, 1 ); gridBox->addItem( sliderH, 0, 1, 1, -1 ); gridBox->addItem( inputBox, 1, 1, -1, -1 ); + + auto inputs = findChildren< QskBoundedValueInput* >(); + + for ( auto input : inputs ) + { + connect( input, &QskBoundedValueInput::valueChanged, + this, &InputPage::syncValues ); + } +} + +void InputPage::syncValues( qreal value ) +{ + static bool blockUpdates = false; + + if ( blockUpdates ) + return; + + blockUpdates = true; + + if ( qobject_cast< const QskSlider* >( sender() ) ) + { + auto spinBoxes = findChildren< QskSpinBox* >(); + for ( auto spinBox : spinBoxes ) + spinBox->setValue( value ); + } + else + { + auto sliders = findChildren< QskSlider* >(); + for ( auto slider : sliders ) + slider->setValue( value ); + } + + blockUpdates = false; } diff --git a/examples/gallery/inputs/InputPage.h b/examples/gallery/inputs/InputPage.h index ce6da0b5..3e9f20e1 100644 --- a/examples/gallery/inputs/InputPage.h +++ b/examples/gallery/inputs/InputPage.h @@ -13,5 +13,5 @@ class InputPage : public Page InputPage( QQuickItem* = nullptr ); private: - void populate(); + void syncValues( qreal ); };