2019-07-22 17:21:33 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "GridSkinny.h"
|
|
|
|
#include <QskControl.h>
|
|
|
|
#include <QskGridBox.h>
|
|
|
|
#include <QskQuick.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class Rectangle : public QskControl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Rectangle( const QByteArray& colorName )
|
|
|
|
: m_colorName( colorName )
|
|
|
|
{
|
|
|
|
setObjectName( colorName );
|
|
|
|
|
|
|
|
initSizePolicy( QskSizePolicy::Preferred, QskSizePolicy::Preferred );
|
|
|
|
setPreferredSize( 50, 50 );
|
|
|
|
|
|
|
|
setBackgroundColor( colorName.constData() );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void geometryChangeEvent( QskGeometryChangeEvent* event ) override
|
|
|
|
{
|
|
|
|
QskControl::geometryChangeEvent( event );
|
|
|
|
//qDebug() << colorName() << size();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QByteArray m_colorName;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
GridSkinny::GridSkinny( QWidget* parent )
|
|
|
|
: QQuickWidget( parent )
|
|
|
|
{
|
|
|
|
setContentsMargins( QMargins() );
|
|
|
|
setResizeMode( QQuickWidget::SizeRootObjectToView );
|
|
|
|
|
|
|
|
m_grid = new QskGridBox();
|
|
|
|
m_grid->setBackgroundColor( Qt::white );
|
|
|
|
m_grid->setMargins( 10 );
|
2019-07-25 18:39:50 +02:00
|
|
|
m_grid->setSpacing( 5 );
|
2019-07-22 17:21:33 +02:00
|
|
|
|
|
|
|
setContent( QUrl(), nullptr, m_grid );
|
|
|
|
}
|
|
|
|
|
|
|
|
GridSkinny::~GridSkinny()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridSkinny::insert( const QByteArray& colorName,
|
|
|
|
int row, int column, int rowSpan, int columnSpan )
|
|
|
|
{
|
|
|
|
m_grid->addItem( new Rectangle( colorName ),
|
|
|
|
row, column, rowSpan, columnSpan );
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridSkinny::setSpacing( Qt::Orientations orientations, int spacing )
|
|
|
|
{
|
|
|
|
m_grid->setSpacing( orientations, spacing );
|
|
|
|
}
|
|
|
|
|
2019-07-23 18:35:51 +02:00
|
|
|
void GridSkinny::setSizeHint(
|
|
|
|
int pos, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
2019-07-22 17:21:33 +02:00
|
|
|
{
|
2019-07-23 18:35:51 +02:00
|
|
|
if ( orientation == Qt::Vertical )
|
|
|
|
m_grid->setRowSizeHint( pos, which, hint );
|
|
|
|
else
|
|
|
|
m_grid->setColumnSizeHint( pos, which, hint );
|
2019-07-22 17:21:33 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 18:35:51 +02:00
|
|
|
void GridSkinny::setStretchFactor(
|
|
|
|
int pos, Qt::Orientation orientation, int stretch )
|
2019-07-22 17:21:33 +02:00
|
|
|
{
|
2019-07-23 18:35:51 +02:00
|
|
|
if ( orientation == Qt::Vertical )
|
|
|
|
m_grid->setRowStretchFactor( pos, stretch );
|
|
|
|
else
|
|
|
|
m_grid->setColumnStretchFactor( pos, stretch );
|
2019-07-22 17:21:33 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 18:35:51 +02:00
|
|
|
void GridSkinny::setSizeHintAt( int index, Qt::Orientation orientation,
|
2019-07-22 17:21:33 +02:00
|
|
|
Qt::SizeHint which, int hint )
|
|
|
|
{
|
|
|
|
if ( auto control = qobject_cast< QskControl* >( m_grid->itemAtIndex( index ) ) )
|
|
|
|
{
|
|
|
|
auto size = control->explicitSizeHint( which );
|
|
|
|
|
|
|
|
if ( orientation == Qt::Horizontal )
|
|
|
|
size.setWidth( hint );
|
|
|
|
else
|
|
|
|
size.setHeight( hint );
|
|
|
|
|
|
|
|
control->setExplicitSizeHint( which, size );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 18:35:51 +02:00
|
|
|
void GridSkinny::setSizePolicyAt(
|
2019-07-22 17:21:33 +02:00
|
|
|
int index, Qt::Orientation orientation, int policy )
|
|
|
|
{
|
|
|
|
if ( auto control = qobject_cast< QskControl* >( m_grid->itemAtIndex( index ) ) )
|
|
|
|
{
|
|
|
|
control->setSizePolicy( orientation,
|
|
|
|
static_cast< QskSizePolicy::Policy >( policy ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 18:35:51 +02:00
|
|
|
void GridSkinny::setAlignmentAt( int index, Qt::Alignment alignment )
|
2019-07-22 17:21:33 +02:00
|
|
|
{
|
|
|
|
if ( auto item = m_grid->itemAtIndex( index ) )
|
|
|
|
m_grid->setAlignment( item, alignment );
|
|
|
|
}
|
|
|
|
|
2019-07-23 18:35:51 +02:00
|
|
|
void GridSkinny::setRetainSizeWhenHiddenAt( int index, bool on )
|
2019-07-22 17:21:33 +02:00
|
|
|
{
|
|
|
|
if ( auto item = m_grid->itemAtIndex( index ) )
|
|
|
|
m_grid->setRetainSizeWhenHidden( item, on );
|
2019-07-25 18:39:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GridSkinny::setVisibleAt( int index, bool on )
|
|
|
|
{
|
|
|
|
if ( auto item = m_grid->itemAtIndex( index ) )
|
|
|
|
item->setVisible( on );
|
|
|
|
}
|
2019-07-22 17:21:33 +02:00
|
|
|
|
2019-07-25 18:39:50 +02:00
|
|
|
QSize GridSkinny::preferredSize() const
|
|
|
|
{
|
|
|
|
return m_grid->preferredSize().toSize();
|
2019-07-22 17:21:33 +02:00
|
|
|
}
|