qskinny/examples/gallery/inputs/InputPage.cpp

167 lines
4.2 KiB
C++
Raw Normal View History

2023-02-27 09:56:41 +01:00
/******************************************************************************
2024-01-17 14:31:45 +01:00
* QSkinny - Copyright (C) The authors
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2023-02-27 09:56:41 +01:00
*****************************************************************************/
#include "InputPage.h"
#include <QskGridBox.h>
#include <QskSlider.h>
#include <QskTextInput.h>
#include <QskSpinBox.h>
namespace
{
class Slider : public QskSlider
{
public:
2024-10-22 15:45:09 +02:00
enum Style
{
Continous,
Discrete,
Centered
};
2024-10-22 13:10:38 +02:00
Slider( Qt::Orientation orientation,
2024-10-22 15:45:09 +02:00
Style style, QQuickItem* parent = nullptr )
2023-02-27 09:56:41 +01:00
: QskSlider( orientation, parent )
{
2023-03-01 17:47:50 +01:00
setBoundaries( 0, 100 );
setValue( 30 );
2023-02-27 09:56:41 +01:00
2024-10-22 15:45:09 +02:00
switch( style )
2024-10-22 13:10:38 +02:00
{
2024-10-22 15:45:09 +02:00
case Discrete:
{
setSnap( true );
setStepSize( 5 );
setPageSteps( 4 );
break;
}
case Continous:
{
setSnap( false );
setStepSize( 1 );
setPageSteps( 10 );
break;
}
case Centered:
{
// TODO
break;
}
2024-10-22 13:10:38 +02:00
}
2023-02-27 09:56:41 +01:00
#if 0
connect( this, &QskSlider::valueChanged,
[]( qreal value ) { qDebug() << value; } );
#endif
}
};
class InputBox : public QskLinearBox
{
public:
InputBox( QQuickItem* parent = nullptr )
2024-10-22 13:10:38 +02:00
: QskLinearBox( Qt::Horizontal, parent )
2023-02-27 09:56:41 +01:00
{
setSpacing( 20 );
{
new QskTextInput( "Edit Me", this );
}
{
auto input = new QskTextInput( "Only Read Me", this );
input->setReadOnly( true );
input->setSizePolicy( Qt::Horizontal, QskSizePolicy::MinimumExpanding );
2023-02-27 09:56:41 +01:00
}
{
auto input = new QskTextInput( "12345", this );
input->setMaxLength( 5 );
input->setEchoMode( QskTextInput::PasswordEchoOnEdit );
#if 1
input->setFixedWidth( 80 );
#endif
2023-02-27 09:56:41 +01:00
}
}
};
}
InputPage::InputPage( QQuickItem* parent )
: Page( Qt::Horizontal, parent )
{
2024-10-22 15:45:09 +02:00
struct
{
Slider* continous;
2024-10-23 08:44:00 +02:00
Slider* discrete;
2024-10-22 15:45:09 +02:00
} sliders[2];
for ( int i = 0; i < 2; i++ )
{
const auto orientation = static_cast< Qt::Orientation >( i + 1 );
2024-10-22 13:10:38 +02:00
2024-10-22 15:45:09 +02:00
sliders[i].continous = new Slider( orientation, Slider::Continous );
2024-10-23 08:44:00 +02:00
sliders[i].discrete = new Slider( orientation, Slider::Discrete );
2024-10-22 15:45:09 +02:00
}
2024-10-22 13:10:38 +02:00
auto spinBox = new QskSpinBox( 0.0, 100.0, 1.0 );
spinBox->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
2023-02-27 09:56:41 +01:00
auto inputBox = new InputBox();
2024-10-22 13:10:38 +02:00
inputBox->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );
auto vBox = new QskLinearBox( Qt::Vertical );
vBox->setSpacing( 30 );
vBox->setExtraSpacingAt( Qt::RightEdge | Qt::BottomEdge );
2023-02-27 09:56:41 +01:00
2024-10-22 15:45:09 +02:00
vBox->addItem( sliders[0].continous );
2024-10-23 08:44:00 +02:00
vBox->addItem( sliders[0].discrete );
2024-10-22 13:10:38 +02:00
vBox->addItem( inputBox );
vBox->addItem( spinBox );
2023-02-27 09:56:41 +01:00
2024-10-22 13:10:38 +02:00
auto mainBox = new QskLinearBox( Qt::Horizontal, this );
mainBox->setSpacing( 30 );
2024-10-22 15:45:09 +02:00
mainBox->addItem( sliders[1].continous );
2024-10-23 08:44:00 +02:00
mainBox->addItem( sliders[1].discrete );
2024-10-22 13:10:38 +02:00
mainBox->addItem( vBox );
2023-03-01 17:47:50 +01:00
auto inputs = findChildren< QskBoundedValueInput* >();
for ( auto input : inputs )
{
connect( input, &QskBoundedValueInput::valueChanged,
this, &InputPage::syncValues );
}
2024-10-23 08:44:00 +02:00
spinBox->setValue( 30.0 );
2023-03-01 17:47:50 +01:00
}
void InputPage::syncValues( qreal value )
{
static bool blockUpdates = false;
if ( blockUpdates )
return;
blockUpdates = true;
2024-10-22 13:10:38 +02:00
2023-03-01 17:47:50 +01:00
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;
2023-02-27 09:56:41 +01:00
}