2021-04-29 07:49:08 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (C) 2021 Edelhirsch Software GmbH
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
#include "BoxWithButtons.h"
|
2021-08-04 18:55:18 +02:00
|
|
|
#include "RoundButton.h"
|
2021-04-26 06:22:35 +02:00
|
|
|
#include "RoundedIcon.h"
|
|
|
|
#include "Skin.h"
|
|
|
|
|
|
|
|
#include <QskTextLabel.h>
|
2021-08-04 18:55:18 +02:00
|
|
|
#include <QskLinearBox.h>
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2021-08-04 18:55:18 +02:00
|
|
|
QSK_SUBCONTROL( BoxWithButtons, ValueText )
|
|
|
|
QSK_SUBCONTROL( BoxWithButtons, ValuePanel )
|
2021-04-26 06:22:35 +02:00
|
|
|
QSK_SUBCONTROL( BoxWithButtons, Panel )
|
|
|
|
|
2021-08-04 18:55:18 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class UpAndDownBox : public QskLinearBox
|
2021-08-24 14:38:03 +02:00
|
|
|
{
|
2022-12-17 11:06:47 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2021-08-04 18:55:18 +02:00
|
|
|
public:
|
|
|
|
UpAndDownBox( QQuickItem* parent )
|
|
|
|
: QskLinearBox( Qt::Vertical, parent )
|
|
|
|
{
|
|
|
|
setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
|
|
|
|
setSpacing( 0 );
|
|
|
|
|
2022-12-17 11:06:47 +01:00
|
|
|
auto* const topButton = new RoundButton( QskAspect::Top, this );
|
|
|
|
connect( topButton, &QskPushButton::clicked, this, &UpAndDownBox::increase );
|
|
|
|
|
|
|
|
auto* const bottomButton = new RoundButton( QskAspect::Bottom, this );
|
|
|
|
connect( bottomButton, &QskPushButton::clicked, this, &UpAndDownBox::decrease );
|
2021-08-04 18:55:18 +02:00
|
|
|
}
|
2022-12-17 11:06:47 +01:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void increase();
|
|
|
|
void decrease();
|
2021-08-04 18:55:18 +02:00
|
|
|
};
|
|
|
|
}
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2022-12-17 11:06:47 +01:00
|
|
|
BoxWithButtons::BoxWithButtons( const QString& title, const QString &prefix,
|
|
|
|
const int initialValue, const QString &suffix,
|
|
|
|
bool isBright, QQuickItem* parent )
|
2021-08-04 15:06:04 +02:00
|
|
|
: Box( QString(), parent )
|
2022-12-17 11:06:47 +01:00
|
|
|
, m_prefix( prefix )
|
|
|
|
, m_suffix( suffix )
|
2021-04-26 06:22:35 +02:00
|
|
|
{
|
2021-08-04 15:06:04 +02:00
|
|
|
setSubcontrolProxy( QskBox::Panel, Panel );
|
|
|
|
|
2021-04-26 06:22:35 +02:00
|
|
|
setSizePolicy( Qt::Vertical, QskSizePolicy::Maximum );
|
|
|
|
|
2021-08-04 15:06:44 +02:00
|
|
|
auto* layout = new QskLinearBox( Qt::Horizontal, this );
|
2021-04-26 06:22:35 +02:00
|
|
|
layout->setSpacing( 20 );
|
|
|
|
|
2021-08-26 15:24:13 +02:00
|
|
|
auto iconLabel = new RoundedIcon( isBright, layout );
|
2022-12-17 11:26:26 +01:00
|
|
|
iconLabel->setGraphicSource( title );
|
|
|
|
iconLabel->setGraphicStrutSize( { 35.17, 35.17 } );
|
2021-08-26 15:24:13 +02:00
|
|
|
iconLabel->setFixedSize( 68, 68 );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2021-08-04 18:55:18 +02:00
|
|
|
auto titleAndValue = new QskLinearBox( Qt::Vertical, layout );
|
|
|
|
titleAndValue->setPanel( true );
|
|
|
|
titleAndValue->setSubcontrolProxy( QskBox::Panel, ValuePanel );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
|
|
|
auto* titleLabel = new QskTextLabel( title, titleAndValue );
|
|
|
|
titleLabel->setFontRole( Skin::TitleFont );
|
|
|
|
|
2022-12-17 11:06:47 +01:00
|
|
|
m_valueLabel = new QskTextLabel( titleAndValue );
|
|
|
|
m_valueLabel->setSubcontrolProxy( QskTextLabel::Text, ValueText );
|
|
|
|
setValue( initialValue );
|
2021-04-26 06:22:35 +02:00
|
|
|
|
2021-08-26 15:24:13 +02:00
|
|
|
layout->addStretch( 1 );
|
|
|
|
|
2022-12-17 11:06:47 +01:00
|
|
|
auto* const upAndDownBox = new UpAndDownBox( layout );
|
|
|
|
|
|
|
|
connect( upAndDownBox, &UpAndDownBox::increase, this, [this]()
|
|
|
|
{
|
|
|
|
setValue( m_value + 1 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
connect( upAndDownBox, &UpAndDownBox::decrease, this, [this]()
|
|
|
|
{
|
|
|
|
setValue( m_value - 1 );
|
|
|
|
} );
|
2021-04-26 06:22:35 +02:00
|
|
|
}
|
2022-12-17 11:06:47 +01:00
|
|
|
|
|
|
|
void BoxWithButtons::setValue( const int value )
|
|
|
|
{
|
|
|
|
m_value = qBound( 0, value, 100 );
|
|
|
|
const QString text = m_prefix + QString::number( m_value ) + m_suffix;
|
|
|
|
m_valueLabel->setText( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "BoxWithButtons.moc"
|