qskinny/examples/gallery/button/ButtonPage.cpp

118 lines
3.3 KiB
C++
Raw Normal View History

2022-04-01 14:54:31 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "ButtonPage.h"
#include <QskSwitchButton.h>
#include <QskPushButton.h>
#include <QskCheckBox.h>
2022-04-01 14:54:31 +02:00
#include <QskSeparator.h>
#include <QskLinearBox.h>
namespace
{
class ButtonBox : public QskLinearBox
{
public:
ButtonBox( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, 4, parent )
{
setSpacing( 20 );
setExtraSpacingAt( Qt::BottomEdge );
setDefaultAlignment( Qt::AlignCenter );
populate();
}
private:
void populate()
{
const char* texts[] = { "Press Me", "Check Me" };
for ( int i = 0; i < 6; i++ )
{
const int index = i % 2;
auto button = new QskPushButton( this );
button->setCheckable( index != 0 );
//button->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
if ( i > 1 )
{
auto src = QStringLiteral( "plus" );
2022-04-01 14:54:31 +02:00
button->setGraphicSource( src );
}
if ( i < 2 || i > 3 )
{
button->setText( texts[ index ] );
}
}
}
};
class SwitchButtonBox : public QskLinearBox
{
public:
SwitchButtonBox( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, parent )
{
setSpacing( 20 );
setExtraSpacingAt( Qt::LeftEdge | Qt::RightEdge | Qt::BottomEdge );
for ( auto orientation : { Qt::Vertical, Qt::Horizontal } )
{
(void) new QskSwitchButton( orientation, this );
auto button = new QskSwitchButton( orientation, this );
2022-04-03 16:37:36 +02:00
button->setChecked( true );
button = new QskSwitchButton( orientation, this );
button->setInverted( true );
button = new QskSwitchButton( orientation, this );
2022-04-01 14:54:31 +02:00
button->setInverted( true );
2022-04-03 16:37:36 +02:00
button->setChecked( true );
2022-04-01 14:54:31 +02:00
}
}
};
class CheckButtonBox : public QskLinearBox
{
public:
CheckButtonBox( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, 2, parent )
{
setSpacing( 40 );
setExtraSpacingAt( Qt::LeftEdge | Qt::RightEdge | Qt::BottomEdge );
auto button1 = new QskCheckBox( "Options 1", this );
button1->setChecked( true );
auto button2 = new QskCheckBox( "Options 2", this );
button2->setLayoutMirroring( true );
auto button3 = new QskCheckBox( "Error", this );
button3->setSkinStateFlag( QskCheckBox::Error );
}
};
2022-04-01 14:54:31 +02:00
}
ButtonPage::ButtonPage( QQuickItem* parent )
: Page( Qt::Vertical, parent )
{
setSpacing( 40 );
populate();
}
void ButtonPage::populate()
{
new ButtonBox( this );
new QskSeparator( Qt::Horizontal, this );
new SwitchButtonBox( this );
new QskSeparator( Qt::Horizontal, this );
new CheckButtonBox( this );
2022-04-01 14:54:31 +02:00
}