qskinny/examples/layouts/LinearLayoutPage.cpp

101 lines
2.7 KiB
C++
Raw Normal View History

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 "LinearLayoutPage.h"
#include "ButtonBox.h"
2018-08-03 08:15:28 +02:00
#include "TestRectangle.h"
2017-07-21 18:21:34 +02:00
#include <QskAspect.h>
#include <QskLinearBox.h>
#include <QskRgbValue.h>
namespace
{
class Box : public QskLinearBox
{
2018-08-03 08:15:28 +02:00
public:
Box( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, parent )
2017-07-21 18:21:34 +02:00
{
setObjectName( "Box" );
setBackgroundColor( Qt::white );
setMargins( 10 );
setSpacing( 5 );
setDefaultAlignment( Qt::AlignCenter );
2017-07-21 18:21:34 +02:00
addRectangle( "LightSalmon" );
addRectangle( "Salmon" );
addRectangle( "DarkSalmon" );
addRectangle( "LightCoral" );
addRectangle( "IndianRed" );
addRectangle( "Crimson" );
addRectangle( "FireBrick" );
addRectangle( "DarkRed" );
insertSpacer( 5, 30 );
}
void mirror()
{
setLayoutMirroring( !layoutMirroring() );
}
void rotate()
{
const int index = 0;
2019-07-09 14:27:50 +02:00
if ( auto item = itemAtIndex( index ) )
2017-07-21 18:21:34 +02:00
{
2019-07-09 14:27:50 +02:00
removeAt( index );
addItem( item );
2017-07-21 18:21:34 +02:00
}
else
{
2019-07-09 14:27:50 +02:00
const auto spacing = spacingAtIndex( index );
removeAt( index );
addSpacer( spacing );
2017-07-21 18:21:34 +02:00
}
}
void incrementSpacing( int spacing )
{
setSpacing( this->spacing() + spacing );
}
2018-08-03 08:15:28 +02:00
private:
2017-07-21 18:21:34 +02:00
void addRectangle( const char* colorName )
{
2019-02-26 21:49:39 +01:00
auto rect = new TestRectangle( colorName );
2020-11-11 10:31:39 +01:00
rect->setText( QString::number( elementCount() + 1 ) );
2017-07-21 18:21:34 +02:00
addItem( rect );
2017-07-21 18:21:34 +02:00
}
};
}
2018-08-03 08:15:28 +02:00
LinearLayoutPage::LinearLayoutPage( 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 buttonBox = new ButtonBox();
buttonBox->setLayoutAlignmentHint( Qt::AlignTop | Qt::AlignLeft );
2017-12-14 09:41:41 +01:00
buttonBox->addButton( "Flip", [ box ]() { box->transpose(); } );
buttonBox->addButton( "Mirror", [ box ]() { box->mirror(); } );
buttonBox->addButton( "Rotate", [ box ]() { box->rotate(); } );
buttonBox->addButton( "Spacing+", [ box ]() { box->incrementSpacing( +1 ); }, true );
buttonBox->addButton( "Spacing-", [ box ]() { box->incrementSpacing( -1 ); }, true );
2017-07-21 18:21:34 +02:00
addItem( buttonBox );
2017-07-21 18:21:34 +02:00
addItem( box );
}