2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
2023-04-06 09:23:37 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2017-07-21 18:21:34 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "DynamicConstraintsPage.h"
|
|
|
|
|
|
|
|
#include <QskAspect.h>
|
|
|
|
#include <QskControl.h>
|
|
|
|
#include <QskLinearBox.h>
|
|
|
|
#include <QskPushButton.h>
|
|
|
|
#include <QskRgbValue.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2018-07-31 17:32:25 +02:00
|
|
|
class Control final : public QskControl
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-07-21 18:21:34 +02:00
|
|
|
Control( const char* colorName, QQuickItem* parent = nullptr );
|
|
|
|
Control( const char* colorName, qreal aspectRatio, QQuickItem* parent = nullptr );
|
|
|
|
|
|
|
|
void transpose();
|
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
protected:
|
2020-12-29 09:45:00 +01:00
|
|
|
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
2019-09-10 17:01:47 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
private:
|
2017-07-21 18:21:34 +02:00
|
|
|
qreal m_aspectRatio;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Box : public QskLinearBox
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-07-21 18:21:34 +02:00
|
|
|
Box( QQuickItem* parent = nullptr );
|
|
|
|
|
|
|
|
void flip();
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
private:
|
2017-07-21 18:21:34 +02:00
|
|
|
void addControl( Control* );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
Control::Control( const char* colorName, QQuickItem* parent )
|
|
|
|
: QskControl( parent )
|
|
|
|
, m_aspectRatio( 1.0 )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setObjectName( colorName );
|
|
|
|
|
|
|
|
setBackgroundColor( colorName );
|
|
|
|
|
|
|
|
setSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Fixed );
|
|
|
|
setPreferredSize( 80, 100 );
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
Control::Control( const char* colorName, qreal aspectRatio, QQuickItem* parent )
|
|
|
|
: QskControl( parent )
|
|
|
|
, m_aspectRatio( aspectRatio )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setObjectName( colorName );
|
|
|
|
|
|
|
|
setBackgroundColor( colorName );
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
// setSizePolicy( QskSizePolicy::Constrained, QskSizePolicy::Ignored );
|
2017-07-21 18:21:34 +02:00
|
|
|
setSizePolicy( QskSizePolicy::Constrained, QskSizePolicy::Fixed );
|
|
|
|
setPreferredHeight( 100 );
|
|
|
|
}
|
|
|
|
|
2020-12-29 09:45:00 +01:00
|
|
|
QSizeF Control::layoutSizeHint(
|
2019-09-10 17:01:47 +02:00
|
|
|
Qt::SizeHint which, const QSizeF& constraint ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-09-10 17:01:47 +02:00
|
|
|
if ( which == Qt::PreferredSize )
|
|
|
|
{
|
|
|
|
if ( constraint.width() >= 0.0 )
|
|
|
|
return QSizeF( -1.0, constraint.width() / m_aspectRatio );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
if ( constraint.height() >= 0.0 )
|
|
|
|
return QSizeF( constraint.height() * m_aspectRatio, -1.0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return QSizeF();
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Control::transpose()
|
|
|
|
{
|
|
|
|
m_aspectRatio = 1.0 / m_aspectRatio;
|
|
|
|
setPreferredSize( preferredSize().transposed() );
|
|
|
|
|
|
|
|
setSizePolicy( sizePolicy().verticalPolicy(), sizePolicy().horizontalPolicy() );
|
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
Box::Box( QQuickItem* parent )
|
|
|
|
: QskLinearBox( Qt::Horizontal, 2, parent )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setObjectName( "Box" );
|
|
|
|
|
|
|
|
setBackgroundColor( Qt::white );
|
2019-09-05 10:46:42 +02:00
|
|
|
setDefaultAlignment( Qt::AlignCenter );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
setMargins( 10 );
|
|
|
|
setSpacing( 5 );
|
|
|
|
|
|
|
|
addControl( new Control( "Cyan", 2.0 / 3.0 ) );
|
|
|
|
addControl( new Control( "DarkCyan" ) );
|
|
|
|
|
|
|
|
addControl( new Control( "Blue", 1.0 ) );
|
|
|
|
addControl( new Control( "DarkBlue" ) );
|
|
|
|
|
|
|
|
addControl( new Control( "Red", 3.0 / 2.0 ) );
|
|
|
|
addControl( new Control( "DarkRed" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Box::flip()
|
|
|
|
{
|
2020-11-11 10:31:39 +01:00
|
|
|
for ( int i = 0; i < elementCount(); i++ )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-06-19 14:08:45 +02:00
|
|
|
if ( auto control = dynamic_cast< Control* >( itemAtIndex( i ) ) )
|
2017-07-21 18:21:34 +02:00
|
|
|
control->transpose();
|
|
|
|
}
|
|
|
|
|
|
|
|
transpose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Box::addControl( Control* control )
|
|
|
|
{
|
2019-09-05 10:46:42 +02:00
|
|
|
addItem( control );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
DynamicConstraintsPage::DynamicConstraintsPage( QQuickItem* parent )
|
|
|
|
: QskLinearBox( Qt::Vertical, parent )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setMargins( 10 );
|
2020-08-15 13:29:17 +02:00
|
|
|
setBackgroundColor( QskRgb::LightSteelBlue );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-02-26 21:49:39 +01:00
|
|
|
auto box = new Box();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-02-26 21:49:39 +01:00
|
|
|
auto button = new QskPushButton( "Flip" );
|
2017-07-21 18:21:34 +02:00
|
|
|
button->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
|
2019-09-05 10:46:42 +02:00
|
|
|
button->setLayoutAlignmentHint( Qt::AlignTop | Qt::AlignLeft );
|
2019-02-26 21:49:39 +01:00
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QObject::connect( button, &QskPushButton::clicked, box, &Box::flip );
|
|
|
|
|
2019-09-05 10:46:42 +02:00
|
|
|
addItem( button );
|
2017-07-21 18:21:34 +02:00
|
|
|
addItem( box );
|
|
|
|
}
|