2019-06-20 12:02:28 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-07-26 17:54:25 +02:00
|
|
|
#include "ButtonBar.h"
|
|
|
|
#include "SkinFactory.h"
|
2020-12-15 07:21:12 +01:00
|
|
|
|
2017-07-26 17:54:25 +02:00
|
|
|
#include <QskGraphic.h>
|
|
|
|
#include <QskGraphicIO.h>
|
|
|
|
#include <QskGraphicLabel.h>
|
2020-12-15 07:21:12 +01:00
|
|
|
#include <QskMargins.h>
|
2017-07-26 17:54:25 +02:00
|
|
|
|
|
|
|
QSK_SUBCONTROL( ButtonBar, Indicator )
|
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
class IndicatorLabel final : public QskGraphicLabel
|
2017-07-26 17:54:25 +02:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
|
|
|
IndicatorLabel( QQuickItem* parentItem = nullptr )
|
|
|
|
: QskGraphicLabel( parentItem )
|
2017-07-26 17:54:25 +02:00
|
|
|
{
|
2017-08-22 20:15:11 +02:00
|
|
|
// so the skins are able to colorize them
|
|
|
|
setGraphicRole( SkinFactory::Indicator );
|
2017-07-26 17:54:25 +02:00
|
|
|
}
|
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
QskAspect::Subcontrol effectiveSubcontrol(
|
|
|
|
QskAspect::Subcontrol subControl ) const override
|
2017-07-26 17:54:25 +02:00
|
|
|
{
|
|
|
|
// so that we can set specific colors in the skin
|
|
|
|
|
|
|
|
if ( subControl == QskGraphicLabel::Graphic )
|
|
|
|
return ButtonBar::Indicator;
|
|
|
|
|
|
|
|
return subControl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
ButtonBar::ButtonBar( QQuickItem* parentItem )
|
|
|
|
: QskLinearBox( parentItem )
|
2017-07-26 17:54:25 +02:00
|
|
|
{
|
|
|
|
QColor c( Qt::black );
|
|
|
|
c.setAlphaF( 0.5 );
|
|
|
|
setBackgroundColor( c );
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
setMargins( QskMargins( 20, 15 ) );
|
2017-07-26 17:54:25 +02:00
|
|
|
setSpacing( 20 );
|
|
|
|
|
|
|
|
setSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::MinimumExpanding );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonBar::addIndicator( const char* name )
|
|
|
|
{
|
2019-02-26 21:49:39 +01:00
|
|
|
auto label = new IndicatorLabel( this );
|
2017-07-26 17:54:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
The label should adjust vertically and be stretched horizontally
|
|
|
|
according to its aspect ratio.
|
|
|
|
*/
|
|
|
|
|
|
|
|
label->setSizePolicy( QskSizePolicy::Constrained, QskSizePolicy::Ignored );
|
|
|
|
|
|
|
|
const QString fileName = QString( ":/qvg/%1.qvg" ).arg( name );
|
|
|
|
label->setGraphic( QskGraphicIO::read( fileName ) );
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
QSizeF ButtonBar::layoutSizeHint(
|
|
|
|
Qt::SizeHint which, const QSizeF& ) const
|
2017-07-26 17:54:25 +02:00
|
|
|
{
|
2019-09-10 17:01:47 +02:00
|
|
|
if ( which == Qt::PreferredSize )
|
|
|
|
return QSizeF( -1, 20 );
|
|
|
|
|
|
|
|
return QSizeF();
|
2017-07-26 17:54:25 +02:00
|
|
|
}
|