qskinny/src/controls/QskSwitchButton.cpp

84 lines
1.7 KiB
C++
Raw Normal View History

2021-08-02 13:22:37 +02:00
#include "QskSwitchButton.h"
2021-08-02 19:17:04 +02:00
QSK_SUBCONTROL( QskSwitchButton, Handle )
2021-08-02 13:22:37 +02:00
QSK_SUBCONTROL( QskSwitchButton, Groove )
struct QskSwitchButton::PrivateData
{
2021-08-02 19:17:04 +02:00
PrivateData( Qt::Orientation orientation )
: orientation( orientation )
2021-08-02 13:22:37 +02:00
{
}
2021-08-02 19:17:04 +02:00
bool inverted = false;
2021-08-02 13:22:37 +02:00
Qt::Orientation orientation;
};
QskSwitchButton::QskSwitchButton( QQuickItem* parent )
2021-08-02 19:17:04 +02:00
: QskSwitchButton( Qt::Horizontal, parent )
2021-08-02 13:22:37 +02:00
{
}
2021-08-02 19:17:04 +02:00
QskSwitchButton::QskSwitchButton( Qt::Orientation orientation, QQuickItem* parent )
: QskAbstractButton( parent )
, m_data( new PrivateData( orientation ) )
2021-08-04 09:31:16 +02:00
{
2021-08-02 19:17:04 +02:00
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
2021-08-02 13:22:37 +02:00
}
2021-08-02 19:17:04 +02:00
QskSwitchButton::~QskSwitchButton()
{
}
2021-08-02 13:22:37 +02:00
bool QskSwitchButton::isCheckable() const
{
return true;
}
2021-08-02 13:22:37 +02:00
Qt::Orientation QskSwitchButton::orientation() const
{
return m_data->orientation;
}
2021-08-02 19:17:04 +02:00
void QskSwitchButton::setOrientation( Qt::Orientation orientation )
2021-08-02 13:22:37 +02:00
{
2021-08-02 19:17:04 +02:00
if( m_data->orientation != orientation )
2021-08-02 13:22:37 +02:00
{
m_data->orientation = orientation;
2021-08-02 19:17:04 +02:00
resetImplicitSize();
2021-08-02 13:22:37 +02:00
update();
2021-08-02 19:17:04 +02:00
2021-08-02 13:22:37 +02:00
Q_EMIT orientationChanged( orientation );
}
}
2021-08-02 19:17:04 +02:00
bool QskSwitchButton::isInverted() const
2021-08-02 13:22:37 +02:00
{
2021-08-02 19:17:04 +02:00
return m_data->inverted;
2021-08-02 13:22:37 +02:00
}
2021-08-02 19:17:04 +02:00
void QskSwitchButton::setInverted( bool on )
2021-08-02 13:22:37 +02:00
{
2021-08-02 19:17:04 +02:00
if( m_data->inverted != on )
2021-08-02 13:22:37 +02:00
{
2021-08-02 19:17:04 +02:00
m_data->inverted = on;
resetImplicitSize(); // in case the size hints depend on it
2021-08-02 13:22:37 +02:00
update();
2021-08-02 19:17:04 +02:00
Q_EMIT invertedChanged( on );
2021-08-02 13:22:37 +02:00
}
}
2021-08-02 19:17:04 +02:00
QskAspect::Placement QskSwitchButton::effectivePlacement() const
2021-08-04 09:31:16 +02:00
{
2021-08-02 19:17:04 +02:00
/*
So you can define different hints depending on the orientation,
but what about the layoutDirection ???
*/
return static_cast< QskAspect::Placement >( m_data->orientation );
}
2021-08-02 13:22:37 +02:00
#include "moc_QskSwitchButton.cpp"