GridQuick added
This commit is contained in:
parent
5432d5f5b0
commit
26d5e56e2e
|
|
@ -11,6 +11,16 @@ void GridAccessor::setSpacing( int spacing )
|
||||||
setSpacing( Qt::Vertical | Qt::Horizontal, spacing );
|
setSpacing( Qt::Vertical | Qt::Horizontal, spacing );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GridAccessor::setRowSizeHint( int row, Qt::SizeHint which, int height )
|
||||||
|
{
|
||||||
|
setSizeHint( row, Qt::Vertical, which, height );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridAccessor::setColumnSizeHint( int column, Qt::SizeHint which, int width )
|
||||||
|
{
|
||||||
|
setSizeHint( column, Qt::Horizontal, which, width );
|
||||||
|
}
|
||||||
|
|
||||||
void GridAccessor::setRowFixedHeight( int row, qreal height )
|
void GridAccessor::setRowFixedHeight( int row, qreal height )
|
||||||
{
|
{
|
||||||
setRowSizeHint( row, Qt::MinimumSize, height );
|
setRowSizeHint( row, Qt::MinimumSize, height );
|
||||||
|
|
@ -23,57 +33,67 @@ void GridAccessor::setColumnFixedWidth( int column, qreal width )
|
||||||
setColumnSizeHint( column, Qt::MaximumSize, width );
|
setColumnSizeHint( column, Qt::MaximumSize, width );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setMinimumWidth( int index, int hint )
|
void GridAccessor::setRowStretchFactor( int row, int stretch )
|
||||||
{
|
{
|
||||||
setSizeHint( index, Qt::Horizontal, Qt::MinimumSize, hint );
|
setStretchFactor( row, Qt::Vertical, stretch );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setMinimumHeight( int index, int hint )
|
void GridAccessor::setColumnStretchFactor( int column, int stretch )
|
||||||
{
|
{
|
||||||
setSizeHint( index, Qt::Vertical, Qt::MinimumSize, hint );
|
setStretchFactor( column, Qt::Vertical, stretch );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setMinimumSize( int index, const QSize& size )
|
void GridAccessor::setMinimumWidthAt( int index, int hint )
|
||||||
{
|
{
|
||||||
setMinimumWidth( index, size.width() );
|
setSizeHintAt( index, Qt::Horizontal, Qt::MinimumSize, hint );
|
||||||
setMinimumHeight( index, size.height() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setPreferredWidth( int index, int hint )
|
void GridAccessor::setMinimumHeightAt( int index, int hint )
|
||||||
{
|
{
|
||||||
setSizeHint( index, Qt::Horizontal, Qt::PreferredSize, hint );
|
setSizeHintAt( index, Qt::Vertical, Qt::MinimumSize, hint );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setPreferredHeight( int index, int hint )
|
void GridAccessor::setMinimumSizeAt( int index, const QSize& size )
|
||||||
{
|
{
|
||||||
setSizeHint( index, Qt::Vertical, Qt::PreferredSize, hint );
|
setMinimumWidthAt( index, size.width() );
|
||||||
|
setMinimumHeightAt( index, size.height() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setPreferredSize( int index, const QSize& size )
|
void GridAccessor::setPreferredWidthAt( int index, int hint )
|
||||||
{
|
{
|
||||||
setPreferredWidth( index, size.width() );
|
setSizeHintAt( index, Qt::Horizontal, Qt::PreferredSize, hint );
|
||||||
setPreferredHeight( index, size.height() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setMaximumWidth( int index, int hint )
|
void GridAccessor::setPreferredHeightAt( int index, int hint )
|
||||||
{
|
{
|
||||||
setSizeHint( index, Qt::Horizontal, Qt::MaximumSize, hint );
|
setSizeHintAt( index, Qt::Vertical, Qt::PreferredSize, hint );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setMaximumHeight( int index, int hint )
|
void GridAccessor::setPreferredSizeAt( int index, const QSize& size )
|
||||||
{
|
{
|
||||||
setSizeHint( index, Qt::Vertical, Qt::MaximumSize, hint );
|
setPreferredWidthAt( index, size.width() );
|
||||||
|
setPreferredHeightAt( index, size.height() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setMaximumSize( int index, const QSize& size )
|
void GridAccessor::setMaximumWidthAt( int index, int hint )
|
||||||
{
|
{
|
||||||
setMaximumWidth( index, size.width() );
|
setSizeHintAt( index, Qt::Horizontal, Qt::MaximumSize, hint );
|
||||||
setMaximumHeight( index, size.height() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccessor::setSizePolicy(
|
void GridAccessor::setMaximumHeightAt( int index, int hint )
|
||||||
|
{
|
||||||
|
setSizeHintAt( index, Qt::Vertical, Qt::MaximumSize, hint );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridAccessor::setMaximumSizeAt( int index, const QSize& size )
|
||||||
|
{
|
||||||
|
setMaximumWidthAt( index, size.width() );
|
||||||
|
setMaximumHeightAt( index, size.height() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridAccessor::setSizePolicyAt(
|
||||||
int index, int horizontalPolicy, int verticalPolicy )
|
int index, int horizontalPolicy, int verticalPolicy )
|
||||||
{
|
{
|
||||||
setSizePolicy( index, Qt::Horizontal, horizontalPolicy );
|
setSizePolicyAt( index, Qt::Horizontal, horizontalPolicy );
|
||||||
setSizePolicy( index, Qt::Vertical, verticalPolicy );
|
setSizePolicyAt( index, Qt::Vertical, verticalPolicy );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,31 +23,36 @@ class GridAccessor
|
||||||
void setSpacing( int spacing );
|
void setSpacing( int spacing );
|
||||||
virtual void setSpacing( Qt::Orientations, int spacing ) = 0;
|
virtual void setSpacing( Qt::Orientations, int spacing ) = 0;
|
||||||
|
|
||||||
virtual void setRowSizeHint( int row, Qt::SizeHint, int height ) = 0;
|
virtual void setSizeHint( int pos, Qt::Orientation, Qt::SizeHint, int height ) = 0;
|
||||||
virtual void setColumnSizeHint( int column, Qt::SizeHint, int width ) = 0;
|
void setRowSizeHint( int row, Qt::SizeHint, int height );
|
||||||
|
void setColumnSizeHint( int column, Qt::SizeHint, int width );
|
||||||
|
|
||||||
void setRowFixedHeight( int row, qreal height );
|
void setRowFixedHeight( int row, qreal height );
|
||||||
void setColumnFixedWidth( int column, qreal width );
|
void setColumnFixedWidth( int column, qreal width );
|
||||||
|
|
||||||
virtual void setSizeHint( int index, Qt::Orientation, Qt::SizeHint, int hint ) = 0;
|
virtual void setStretchFactor( int pos, Qt::Orientation, int stretch ) = 0;
|
||||||
virtual void setSizePolicy(int index, Qt::Orientation, int policy ) = 0;
|
void setRowStretchFactor( int row, int stretch );
|
||||||
|
void setColumnStretchFactor( int row, int stretch );
|
||||||
|
|
||||||
void setSizePolicy( int index, int horizontalPolicy, int verticalPolicy );
|
virtual void setSizeHintAt( int index, Qt::Orientation, Qt::SizeHint, int hint ) = 0;
|
||||||
|
virtual void setSizePolicyAt( int index, Qt::Orientation, int policy ) = 0;
|
||||||
|
|
||||||
void setMinimumWidth( int index, int hint );
|
void setSizePolicyAt( int index, int horizontalPolicy, int verticalPolicy );
|
||||||
void setMinimumHeight( int index, int hint );
|
|
||||||
void setMinimumSize( int index, const QSize& );
|
|
||||||
|
|
||||||
void setPreferredWidth( int index, int hint );
|
void setMinimumWidthAt( int index, int hint );
|
||||||
void setPreferredHeight( int index, int hint );
|
void setMinimumHeightAt( int index, int hint );
|
||||||
void setPreferredSize( int index, const QSize& );
|
void setMinimumSizeAt( int index, const QSize& );
|
||||||
|
|
||||||
void setMaximumWidth( int index, int hint );
|
void setPreferredWidthAt( int index, int hint );
|
||||||
void setMaximumHeight( int index, int hint );
|
void setPreferredHeightAt( int index, int hint );
|
||||||
void setMaximumSize( int index, const QSize& );
|
void setPreferredSizeAt( int index, const QSize& );
|
||||||
|
|
||||||
virtual void setAlignment( int index, Qt::Alignment ) = 0;
|
void setMaximumWidthAt( int index, int hint );
|
||||||
virtual void setRetainSizeWhenHidden( int, bool on ) = 0;
|
void setMaximumHeightAt( int index, int hint );
|
||||||
|
void setMaximumSizeAt( int index, const QSize& );
|
||||||
|
|
||||||
|
virtual void setAlignmentAt( int index, Qt::Alignment ) = 0;
|
||||||
|
virtual void setRetainSizeWhenHiddenAt( int index, bool on ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -27,24 +27,48 @@ namespace
|
||||||
setAutoFillBackground( true );
|
setAutoFillBackground( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
void resizeEvent( QGraphicsSceneResizeEvent* event ) override
|
void resizeEvent( QGraphicsSceneResizeEvent* event ) override
|
||||||
{
|
{
|
||||||
QGraphicsWidget::resizeEvent( event );
|
QGraphicsWidget::resizeEvent( event );
|
||||||
//qDebug() << m_color << size();
|
#if 0
|
||||||
|
qDebug() << m_colorName << size();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QByteArray m_colorName;
|
const QByteArray m_colorName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Grid : public QGraphicsWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Grid()
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
setPalette( QColor( "LightCyan" ) );
|
||||||
|
setAutoFillBackground( true );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QSizeF sizeHint( Qt::SizeHint, const QSizeF& ) const override
|
||||||
|
{
|
||||||
|
// we don't want to derive our size hints from the items
|
||||||
|
return QSizeF( -1, -1 );
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
GridGraphics::GridGraphics( QWidget* parent )
|
GridGraphics::GridGraphics( QWidget* parent )
|
||||||
: QGraphicsView( parent )
|
: QGraphicsView( parent )
|
||||||
{
|
{
|
||||||
setFrameStyle( QFrame::NoFrame );
|
setFrameStyle( QFrame::NoFrame );
|
||||||
setContentsMargins( QMargins() );
|
|
||||||
|
|
||||||
auto grid = new QGraphicsWidget();
|
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||||
|
setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||||
|
|
||||||
|
auto grid = new Grid();
|
||||||
m_layout = new QGraphicsGridLayout( grid );
|
m_layout = new QGraphicsGridLayout( grid );
|
||||||
|
|
||||||
auto scene = new QGraphicsScene();
|
auto scene = new QGraphicsScene();
|
||||||
|
|
@ -73,52 +97,51 @@ void GridGraphics::setSpacing( Qt::Orientations orientations, int spacing )
|
||||||
m_layout->setVerticalSpacing( spacing );
|
m_layout->setVerticalSpacing( spacing );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridGraphics::setRowSizeHint( int row, Qt::SizeHint which, int height )
|
|
||||||
{
|
|
||||||
switch( static_cast< int >( which ) )
|
|
||||||
{
|
|
||||||
case Qt::MinimumSize:
|
|
||||||
{
|
|
||||||
m_layout->setRowMinimumHeight( row, height );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Qt::PreferredSize:
|
|
||||||
{
|
|
||||||
m_layout->setRowPreferredHeight( row, height );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Qt::MaximumSize:
|
|
||||||
{
|
|
||||||
m_layout->setRowMaximumHeight( row, height );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GridGraphics::setColumnSizeHint( int column, Qt::SizeHint which, int width )
|
|
||||||
{
|
|
||||||
switch( static_cast< int >( which ) )
|
|
||||||
{
|
|
||||||
case Qt::MinimumSize:
|
|
||||||
{
|
|
||||||
m_layout->setColumnMinimumWidth( column, width );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Qt::PreferredSize:
|
|
||||||
{
|
|
||||||
m_layout->setColumnPreferredWidth( column, width );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Qt::MaximumSize:
|
|
||||||
{
|
|
||||||
m_layout->setColumnMaximumWidth( column, width );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GridGraphics::setSizeHint(
|
void GridGraphics::setSizeHint(
|
||||||
|
int pos, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
||||||
|
{
|
||||||
|
switch( static_cast< int >( which ) )
|
||||||
|
{
|
||||||
|
case Qt::MinimumSize:
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_layout->setRowMinimumHeight( pos, hint );
|
||||||
|
else
|
||||||
|
m_layout->setColumnMinimumWidth( pos, hint );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Qt::PreferredSize:
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_layout->setRowPreferredHeight( pos, hint );
|
||||||
|
else
|
||||||
|
m_layout->setColumnPreferredWidth( pos, hint );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Qt::MaximumSize:
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_layout->setRowMaximumHeight( pos, hint );
|
||||||
|
else
|
||||||
|
m_layout->setColumnMaximumWidth( pos, hint );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridGraphics::setStretchFactor(
|
||||||
|
int pos, Qt::Orientation orientation, int stretch )
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_layout->setRowStretchFactor( pos, stretch );
|
||||||
|
else
|
||||||
|
m_layout->setColumnStretchFactor( pos, stretch );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridGraphics::setSizeHintAt(
|
||||||
int index, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
int index, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
||||||
{
|
{
|
||||||
if ( auto layoutItem = m_layout->itemAt( index ) )
|
if ( auto layoutItem = m_layout->itemAt( index ) )
|
||||||
|
|
@ -156,7 +179,7 @@ void GridGraphics::setSizeHint(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridGraphics::setSizePolicy( int index, Qt::Orientation orientation, int policy )
|
void GridGraphics::setSizePolicyAt( int index, Qt::Orientation orientation, int policy )
|
||||||
{
|
{
|
||||||
if ( auto layoutItem = m_layout->itemAt( index ) )
|
if ( auto layoutItem = m_layout->itemAt( index ) )
|
||||||
{
|
{
|
||||||
|
|
@ -181,13 +204,13 @@ void GridGraphics::setSizePolicy( int index, Qt::Orientation orientation, int po
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridGraphics::setAlignment( int index, Qt::Alignment alignment )
|
void GridGraphics::setAlignmentAt( int index, Qt::Alignment alignment )
|
||||||
{
|
{
|
||||||
if ( auto layoutItem = m_layout->itemAt( index ) )
|
if ( auto layoutItem = m_layout->itemAt( index ) )
|
||||||
m_layout->setAlignment( layoutItem, alignment );
|
m_layout->setAlignment( layoutItem, alignment );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridGraphics::setRetainSizeWhenHidden( int index, bool on )
|
void GridGraphics::setRetainSizeWhenHiddenAt( int index, bool on )
|
||||||
{
|
{
|
||||||
if ( auto layoutItem = m_layout->itemAt( index ) )
|
if ( auto layoutItem = m_layout->itemAt( index ) )
|
||||||
{
|
{
|
||||||
|
|
@ -199,6 +222,12 @@ void GridGraphics::setRetainSizeWhenHidden( int index, bool on )
|
||||||
|
|
||||||
void GridGraphics::resizeEvent( QResizeEvent* )
|
void GridGraphics::resizeEvent( QResizeEvent* )
|
||||||
{
|
{
|
||||||
|
auto sceneRect = contentsRect();
|
||||||
|
#if 0
|
||||||
|
sceneRect = sceneRect.adjusted( 10, 10, -10, -10 );
|
||||||
|
#endif
|
||||||
|
scene()->setSceneRect( QRectF( QPointF(), sceneRect.size() ) );
|
||||||
|
|
||||||
auto grid = static_cast< QGraphicsWidget* >( scene()->items().last() );
|
auto grid = static_cast< QGraphicsWidget* >( scene()->items().last() );
|
||||||
grid->resize( contentsRect().size() );
|
grid->resize( sceneRect.size() );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ class GridGraphics : public QGraphicsView, public GridAccessor
|
||||||
|
|
||||||
void setSpacing( Qt::Orientations, int spacing ) override;
|
void setSpacing( Qt::Orientations, int spacing ) override;
|
||||||
|
|
||||||
void setRowSizeHint( int row, Qt::SizeHint, int height ) override;
|
void setStretchFactor( int pos, Qt::Orientation, int stretch ) override;
|
||||||
void setColumnSizeHint( int column, Qt::SizeHint, int width ) override;
|
void setSizeHint( int pos, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
|
|
||||||
void setSizeHint( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
void setSizeHintAt( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
void setSizePolicy( int index, Qt::Orientation, int policy ) override;
|
void setSizePolicyAt( int index, Qt::Orientation, int policy ) override;
|
||||||
void setAlignment( int index, Qt::Alignment ) override;
|
void setAlignmentAt( int index, Qt::Alignment ) override;
|
||||||
void setRetainSizeWhenHidden( int index, bool on ) override;
|
void setRetainSizeWhenHiddenAt( int index, bool on ) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent( QResizeEvent* ) override;
|
void resizeEvent( QResizeEvent* ) override;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,181 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
||||||
|
* This file may be used under the terms of the 3-clause BSD License
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "GridQuick.h"
|
||||||
|
#include <QQuickItem>
|
||||||
|
#include <QtQml>
|
||||||
|
|
||||||
|
static QQuickItem* createQml( const char* qmlCode )
|
||||||
|
{
|
||||||
|
QQmlEngine engine( nullptr );
|
||||||
|
|
||||||
|
QQmlComponent component( &engine );
|
||||||
|
component.setData( qmlCode, QUrl() );
|
||||||
|
|
||||||
|
return qobject_cast< QQuickItem* >( component.create() );
|
||||||
|
}
|
||||||
|
|
||||||
|
static QObject* attachedProperties( const QQuickItem* item )
|
||||||
|
{
|
||||||
|
for ( auto child : item->children() )
|
||||||
|
{
|
||||||
|
if ( child->inherits( "QQuickLayoutAttached" ) )
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QObject* attachedPropertiesAt( const QQuickItem* grid, int index )
|
||||||
|
{
|
||||||
|
const auto children = grid->childItems();
|
||||||
|
|
||||||
|
if ( ( index >= 0 ) && ( index < children.count() ) )
|
||||||
|
return attachedProperties( children.at( index ) );
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GridQuick::GridQuick( QWidget* parent )
|
||||||
|
: QQuickWidget( parent )
|
||||||
|
{
|
||||||
|
setContentsMargins( QMargins() );
|
||||||
|
setResizeMode( QQuickWidget::SizeRootObjectToView );
|
||||||
|
|
||||||
|
auto contentItem =
|
||||||
|
createQml( "import QtQuick 2.0\nimport QtQuick.Layouts 1.1\nItem { GridLayout {} }" );
|
||||||
|
setContent( QUrl(), nullptr, contentItem );
|
||||||
|
|
||||||
|
m_grid = contentItem->childItems().first();
|
||||||
|
}
|
||||||
|
|
||||||
|
GridQuick::~GridQuick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::insert( const QByteArray& colorName,
|
||||||
|
int row, int column, int rowSpan, int columnSpan )
|
||||||
|
{
|
||||||
|
auto rectangle = createQml( "import QtQuick 2.0\nRectangle {}" );
|
||||||
|
rectangle->setProperty( "color", QColor( colorName.constData() ) );
|
||||||
|
rectangle->setParent( m_grid );
|
||||||
|
rectangle->setParentItem( m_grid );
|
||||||
|
|
||||||
|
rectangle->setImplicitWidth( 50 );
|
||||||
|
rectangle->setImplicitHeight( 50 );
|
||||||
|
|
||||||
|
auto props = attachedProperties( rectangle );
|
||||||
|
props->setProperty( "row", row );
|
||||||
|
props->setProperty( "column", column );
|
||||||
|
props->setProperty( "rowSpan", rowSpan );
|
||||||
|
props->setProperty( "columnSpan", columnSpan );
|
||||||
|
props->setProperty( "fillWidth", true );
|
||||||
|
props->setProperty( "fillHeight", true );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::setSpacing( Qt::Orientations orientations, int spacing )
|
||||||
|
{
|
||||||
|
if ( orientations & Qt::Vertical )
|
||||||
|
m_grid->setProperty( "rowSpacing", spacing );
|
||||||
|
|
||||||
|
if ( orientations & Qt::Horizontal )
|
||||||
|
m_grid->setProperty( "columnSpacing", spacing );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::setSizeHint( int, Qt::Orientation, Qt::SizeHint, int )
|
||||||
|
{
|
||||||
|
qWarning() << "setSizeHint is not supported by Quick Layouts.";
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::setStretchFactor( int, Qt::Orientation, int )
|
||||||
|
{
|
||||||
|
qWarning() << "setStretchFactor is not supported by Quick Layouts.";
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::setSizeHintAt( int index, Qt::Orientation orientation,
|
||||||
|
Qt::SizeHint which, int hint )
|
||||||
|
{
|
||||||
|
if ( auto props = attachedPropertiesAt( m_grid, index ) )
|
||||||
|
{
|
||||||
|
const qreal size = hint;
|
||||||
|
|
||||||
|
switch( static_cast< int >( which ) )
|
||||||
|
{
|
||||||
|
case Qt::MinimumSize:
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Horizontal )
|
||||||
|
props->setProperty( "minimumWidth", size );
|
||||||
|
else
|
||||||
|
props->setProperty( "minimumHeight", size );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Qt::PreferredSize:
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Horizontal )
|
||||||
|
props->setProperty( "preferredWidth", size );
|
||||||
|
else
|
||||||
|
props->setProperty( "preferredHeight", size );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Qt::MaximumSize:
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Horizontal )
|
||||||
|
props->setProperty( "maximumWidth", size );
|
||||||
|
else
|
||||||
|
props->setProperty( "maximumWidth", size );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::setSizePolicyAt(
|
||||||
|
int index, Qt::Orientation orientation, int policy )
|
||||||
|
{
|
||||||
|
const auto qPolicy = static_cast< QSizePolicy::Policy >( policy & 0xF );
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
const bool isConstrained = policy & ( 1 << 4 );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const bool doFill = ( qPolicy & QSizePolicy::GrowFlag )
|
||||||
|
|| ( qPolicy & QSizePolicy::ExpandFlag );
|
||||||
|
|
||||||
|
if ( auto props = attachedPropertiesAt( m_grid, index ) )
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Horizontal )
|
||||||
|
props->setProperty( "fillWidth", doFill );
|
||||||
|
else
|
||||||
|
props->setProperty( "fillHeight", doFill );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::setAlignmentAt( int index, Qt::Alignment alignment )
|
||||||
|
{
|
||||||
|
if ( auto props = attachedPropertiesAt( m_grid, index ) )
|
||||||
|
props->setProperty( "alignment", QVariant::fromValue( alignment ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::setRetainSizeWhenHiddenAt( int, bool )
|
||||||
|
{
|
||||||
|
qWarning() << "setRetainSizeWhenHidden is not supported by Quick Layouts.";
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridQuick::resizeEvent( QResizeEvent* event )
|
||||||
|
{
|
||||||
|
QQuickWidget::resizeEvent( event );
|
||||||
|
|
||||||
|
const qreal margin = 10.0;
|
||||||
|
|
||||||
|
m_grid->setX( margin );
|
||||||
|
m_grid->setY( margin );
|
||||||
|
m_grid->setWidth( width() - 2 * margin );
|
||||||
|
m_grid->setHeight( height() - 2 * margin );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
||||||
|
* This file may be used under the terms of the 3-clause BSD License
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef GRID_QUICK_H
|
||||||
|
#define GRID_QUICK_H
|
||||||
|
|
||||||
|
#include "GridAccessor.h"
|
||||||
|
#include <QQuickWidget>
|
||||||
|
|
||||||
|
class QGraphicsGridLayout;
|
||||||
|
|
||||||
|
class GridQuick : public QQuickWidget, public GridAccessor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GridQuick( QWidget* parent = nullptr );
|
||||||
|
~GridQuick() override;
|
||||||
|
|
||||||
|
void insert( const QByteArray& colorName,
|
||||||
|
int row, int column, int rowSpan, int columnSpan ) override;
|
||||||
|
|
||||||
|
void setSpacing( Qt::Orientations, int spacing ) override;
|
||||||
|
|
||||||
|
void setStretchFactor( int pos, Qt::Orientation, int stretch ) override;
|
||||||
|
void setSizeHint( int pos, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
|
|
||||||
|
void setSizeHintAt( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
|
void setSizePolicyAt( int index, Qt::Orientation, int policy ) override;
|
||||||
|
void setAlignmentAt( int index, Qt::Alignment ) override;
|
||||||
|
void setRetainSizeWhenHiddenAt( int index, bool on ) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent( QResizeEvent* ) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQuickItem* m_grid;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -76,17 +76,25 @@ void GridSkinny::setSpacing( Qt::Orientations orientations, int spacing )
|
||||||
m_grid->setSpacing( orientations, spacing );
|
m_grid->setSpacing( orientations, spacing );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSkinny::setRowSizeHint( int row, Qt::SizeHint which, int height )
|
void GridSkinny::setSizeHint(
|
||||||
|
int pos, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
||||||
{
|
{
|
||||||
m_grid->setRowSizeHint( row, which, height );
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_grid->setRowSizeHint( pos, which, hint );
|
||||||
|
else
|
||||||
|
m_grid->setColumnSizeHint( pos, which, hint );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSkinny::setColumnSizeHint( int column, Qt::SizeHint which, int width )
|
void GridSkinny::setStretchFactor(
|
||||||
|
int pos, Qt::Orientation orientation, int stretch )
|
||||||
{
|
{
|
||||||
m_grid->setColumnSizeHint( column, which, width );
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_grid->setRowStretchFactor( pos, stretch );
|
||||||
|
else
|
||||||
|
m_grid->setColumnStretchFactor( pos, stretch );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSkinny::setSizeHint( int index, Qt::Orientation orientation,
|
void GridSkinny::setSizeHintAt( int index, Qt::Orientation orientation,
|
||||||
Qt::SizeHint which, int hint )
|
Qt::SizeHint which, int hint )
|
||||||
{
|
{
|
||||||
if ( auto control = qobject_cast< QskControl* >( m_grid->itemAtIndex( index ) ) )
|
if ( auto control = qobject_cast< QskControl* >( m_grid->itemAtIndex( index ) ) )
|
||||||
|
|
@ -102,7 +110,7 @@ void GridSkinny::setSizeHint( int index, Qt::Orientation orientation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSkinny::setSizePolicy(
|
void GridSkinny::setSizePolicyAt(
|
||||||
int index, Qt::Orientation orientation, int policy )
|
int index, Qt::Orientation orientation, int policy )
|
||||||
{
|
{
|
||||||
if ( auto control = qobject_cast< QskControl* >( m_grid->itemAtIndex( index ) ) )
|
if ( auto control = qobject_cast< QskControl* >( m_grid->itemAtIndex( index ) ) )
|
||||||
|
|
@ -112,13 +120,13 @@ void GridSkinny::setSizePolicy(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSkinny::setAlignment( int index, Qt::Alignment alignment )
|
void GridSkinny::setAlignmentAt( int index, Qt::Alignment alignment )
|
||||||
{
|
{
|
||||||
if ( auto item = m_grid->itemAtIndex( index ) )
|
if ( auto item = m_grid->itemAtIndex( index ) )
|
||||||
m_grid->setAlignment( item, alignment );
|
m_grid->setAlignment( item, alignment );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSkinny::setRetainSizeWhenHidden( int index, bool on )
|
void GridSkinny::setRetainSizeWhenHiddenAt( int index, bool on )
|
||||||
{
|
{
|
||||||
if ( auto item = m_grid->itemAtIndex( index ) )
|
if ( auto item = m_grid->itemAtIndex( index ) )
|
||||||
m_grid->setRetainSizeWhenHidden( item, on );
|
m_grid->setRetainSizeWhenHidden( item, on );
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,14 @@ class GridSkinny : public QQuickWidget, public GridAccessor
|
||||||
|
|
||||||
void setSpacing( Qt::Orientations, int spacing ) override;
|
void setSpacing( Qt::Orientations, int spacing ) override;
|
||||||
|
|
||||||
void setRowSizeHint( int row, Qt::SizeHint, int height ) override;
|
void setStretchFactor( int pos, Qt::Orientation, int stretch ) override;
|
||||||
void setColumnSizeHint( int column, Qt::SizeHint, int width ) override;
|
void setSizeHint( int pos, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
|
|
||||||
void setSizeHint( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
void setSizeHintAt( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
void setSizePolicy( int index, Qt::Orientation, int policy ) override;
|
void setSizePolicyAt( int index, Qt::Orientation, int policy ) override;
|
||||||
|
|
||||||
void setAlignment( int index, Qt::Alignment ) override;
|
void setAlignmentAt( int index, Qt::Alignment ) override;
|
||||||
void setRetainSizeWhenHidden( int, bool on ) override;
|
void setRetainSizeWhenHiddenAt( int index, bool on ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QskGridBox* m_grid;
|
QskGridBox* m_grid;
|
||||||
|
|
|
||||||
|
|
@ -83,29 +83,31 @@ void GridWidgets::setSpacing( Qt::Orientations orientations, int spacing )
|
||||||
m_layout->setVerticalSpacing( spacing );
|
m_layout->setVerticalSpacing( spacing );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridWidgets::setRowSizeHint( int row, Qt::SizeHint which, int height )
|
|
||||||
{
|
|
||||||
if ( which != Qt::MinimumSize )
|
|
||||||
{
|
|
||||||
qWarning() << "setRowSizeHint" << which << "is not supported by QGridLayout.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_layout->setRowMinimumHeight( row, height );
|
|
||||||
}
|
|
||||||
|
|
||||||
void GridWidgets::setColumnSizeHint( int column, Qt::SizeHint which, int width )
|
|
||||||
{
|
|
||||||
if ( which != Qt::MinimumSize )
|
|
||||||
{
|
|
||||||
qWarning() << "setColumnSizeHint" << which << "is not supported by QGridLayout.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_layout->setColumnMinimumWidth( column, width );
|
|
||||||
}
|
|
||||||
|
|
||||||
void GridWidgets::setSizeHint(
|
void GridWidgets::setSizeHint(
|
||||||
|
int pos, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
||||||
|
{
|
||||||
|
if ( which != Qt::MinimumSize )
|
||||||
|
{
|
||||||
|
qWarning() << "setSizeHint" << which << "is not supported by QGridLayout.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_layout->setRowMinimumHeight( pos, hint );
|
||||||
|
else
|
||||||
|
m_layout->setColumnMinimumWidth( pos, hint );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridWidgets::setStretchFactor(
|
||||||
|
int pos, Qt::Orientation orientation, int stretch )
|
||||||
|
{
|
||||||
|
if ( orientation == Qt::Vertical )
|
||||||
|
m_layout->setRowStretch( pos, stretch );
|
||||||
|
else
|
||||||
|
m_layout->setColumnStretch( pos, stretch );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridWidgets::setSizeHintAt(
|
||||||
int index, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
int index, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
||||||
{
|
{
|
||||||
Rectangle* rectangle = nullptr;
|
Rectangle* rectangle = nullptr;
|
||||||
|
|
@ -148,7 +150,7 @@ void GridWidgets::setSizeHint(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridWidgets::setSizePolicy( int index, Qt::Orientation orientation, int policy )
|
void GridWidgets::setSizePolicyAt( int index, Qt::Orientation orientation, int policy )
|
||||||
{
|
{
|
||||||
QWidget* widget = nullptr;
|
QWidget* widget = nullptr;
|
||||||
|
|
||||||
|
|
@ -177,13 +179,13 @@ void GridWidgets::setSizePolicy( int index, Qt::Orientation orientation, int pol
|
||||||
widget->setSizePolicy( sizePolicy );
|
widget->setSizePolicy( sizePolicy );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridWidgets::setAlignment( int index, Qt::Alignment alignment )
|
void GridWidgets::setAlignmentAt( int index, Qt::Alignment alignment )
|
||||||
{
|
{
|
||||||
if ( auto layoutItem = m_layout->itemAt( index ) )
|
if ( auto layoutItem = m_layout->itemAt( index ) )
|
||||||
layoutItem->setAlignment( alignment );
|
layoutItem->setAlignment( alignment );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridWidgets::setRetainSizeWhenHidden( int index, bool on )
|
void GridWidgets::setRetainSizeWhenHiddenAt( int index, bool on )
|
||||||
{
|
{
|
||||||
if ( auto layoutItem = m_layout->itemAt( index ) )
|
if ( auto layoutItem = m_layout->itemAt( index ) )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,14 @@ class GridWidgets : public QWidget, public GridAccessor
|
||||||
|
|
||||||
void setSpacing( Qt::Orientations, int spacing ) override;
|
void setSpacing( Qt::Orientations, int spacing ) override;
|
||||||
|
|
||||||
void setRowSizeHint( int row, Qt::SizeHint, int height ) override;
|
void setStretchFactor( int pos, Qt::Orientation, int stretch ) override;
|
||||||
void setColumnSizeHint( int column, Qt::SizeHint, int width ) override;
|
void setSizeHint( int pos, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
|
|
||||||
void setSizeHint( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
void setSizeHintAt( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
void setSizePolicy( int index, Qt::Orientation, int policy ) override;
|
void setSizePolicyAt( int index, Qt::Orientation, int policy ) override;
|
||||||
|
|
||||||
void setAlignment( int index, Qt::Alignment ) override;
|
void setAlignmentAt( int index, Qt::Alignment ) override;
|
||||||
void setRetainSizeWhenHidden( int, bool on ) override;
|
void setRetainSizeWhenHiddenAt( int index, bool on ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGridLayout* m_layout;
|
QGridLayout* m_layout;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "GridGraphics.h"
|
#include "GridGraphics.h"
|
||||||
#include "GridSkinny.h"
|
#include "GridSkinny.h"
|
||||||
#include "GridWidgets.h"
|
#include "GridWidgets.h"
|
||||||
|
#include "GridQuick.h"
|
||||||
|
|
||||||
TestBox::TestBox( QWidget* parent )
|
TestBox::TestBox( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
|
|
@ -19,12 +20,21 @@ TestBox::TestBox( QWidget* parent )
|
||||||
grids[Skinny] = new GridSkinny( this );
|
grids[Skinny] = new GridSkinny( this );
|
||||||
grids[Widgets] = new GridWidgets( this );
|
grids[Widgets] = new GridWidgets( this );
|
||||||
grids[Graphics] = new GridGraphics( this );
|
grids[Graphics] = new GridGraphics( this );
|
||||||
|
grids[Quick] = new GridQuick( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
TestBox::~TestBox()
|
TestBox::~TestBox()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestBox::setColumns( int columnCount )
|
||||||
|
{
|
||||||
|
m_columnCount = qBound( 1, columnCount, static_cast< int >( GridCount ) );
|
||||||
|
|
||||||
|
if ( testAttribute( Qt::WA_WState_Polished ) )
|
||||||
|
layoutGrids();
|
||||||
|
}
|
||||||
|
|
||||||
void TestBox::insert( const QByteArray& colorName,
|
void TestBox::insert( const QByteArray& colorName,
|
||||||
int row, int column, int rowSpan, int columnSpan )
|
int row, int column, int rowSpan, int columnSpan )
|
||||||
{
|
{
|
||||||
|
|
@ -45,63 +55,70 @@ void TestBox::setSpacing( Qt::Orientations orientations, int spacing )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestBox::setRowSizeHint( int row, Qt::SizeHint which, int height )
|
|
||||||
{
|
|
||||||
for ( auto grid : grids )
|
|
||||||
{
|
|
||||||
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
|
||||||
accessor->setRowSizeHint( row, which, height );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestBox::setColumnSizeHint( int column, Qt::SizeHint which, int width )
|
|
||||||
{
|
|
||||||
for ( auto grid : grids )
|
|
||||||
{
|
|
||||||
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
|
||||||
accessor->setColumnSizeHint( column, which, width );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestBox::setSizeHint(
|
void TestBox::setSizeHint(
|
||||||
|
int pos, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
||||||
|
{
|
||||||
|
for ( auto grid : grids )
|
||||||
|
{
|
||||||
|
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
||||||
|
accessor->setSizeHint( pos, orientation, which, hint );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestBox::setStretchFactor(
|
||||||
|
int pos, Qt::Orientation orientation, int stretch )
|
||||||
|
{
|
||||||
|
for ( auto grid : grids )
|
||||||
|
{
|
||||||
|
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
||||||
|
accessor->setStretchFactor( pos, orientation, stretch );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestBox::setSizeHintAt(
|
||||||
int index, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
int index, Qt::Orientation orientation, Qt::SizeHint which, int hint )
|
||||||
{
|
{
|
||||||
for ( auto grid : grids )
|
for ( auto grid : grids )
|
||||||
{
|
{
|
||||||
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
||||||
accessor->setSizeHint( index, orientation, which, hint );
|
accessor->setSizeHintAt( index, orientation, which, hint );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestBox::setSizePolicy(
|
void TestBox::setSizePolicyAt(
|
||||||
int index, Qt::Orientation orientation, int policy )
|
int index, Qt::Orientation orientation, int policy )
|
||||||
{
|
{
|
||||||
for ( auto grid : grids )
|
for ( auto grid : grids )
|
||||||
{
|
{
|
||||||
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
||||||
accessor->setSizePolicy( index, orientation, policy );
|
accessor->setSizePolicyAt( index, orientation, policy );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestBox::setAlignment( int index, Qt::Alignment alignment )
|
void TestBox::setAlignmentAt( int index, Qt::Alignment alignment )
|
||||||
{
|
{
|
||||||
for ( auto grid : grids )
|
for ( auto grid : grids )
|
||||||
{
|
{
|
||||||
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
||||||
accessor->setAlignment( index, alignment );
|
accessor->setAlignmentAt( index, alignment );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestBox::setRetainSizeWhenHidden( int index, bool on )
|
void TestBox::setRetainSizeWhenHiddenAt( int index, bool on )
|
||||||
{
|
{
|
||||||
for ( auto grid : grids )
|
for ( auto grid : grids )
|
||||||
{
|
{
|
||||||
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
auto accessor = dynamic_cast< GridAccessor* >( grid );
|
||||||
accessor->setRetainSizeWhenHidden( index, on );
|
accessor->setRetainSizeWhenHiddenAt( index, on );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestBox::resizeEvent( QResizeEvent* )
|
void TestBox::resizeEvent( QResizeEvent* )
|
||||||
|
{
|
||||||
|
layoutGrids();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestBox::layoutGrids()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Not using layouts here to avoid confusion
|
Not using layouts here to avoid confusion
|
||||||
|
|
@ -109,12 +126,30 @@ void TestBox::resizeEvent( QResizeEvent* )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const auto r = contentsRect();
|
const auto r = contentsRect();
|
||||||
const auto sz = 0.5 * r.size() - QSize( 5, 5 );
|
|
||||||
|
|
||||||
grids[ 0 ]->move( r.left(), r.top() );
|
int rowCount = GridCount / m_columnCount;
|
||||||
grids[ 1 ]->move( r.right() - sz.width(), r.top() );
|
if ( rowCount * m_columnCount < GridCount )
|
||||||
grids[ 2 ]->move( r.left(), r.bottom() - sz.height() );
|
rowCount++;
|
||||||
|
|
||||||
for ( auto grid : grids )
|
const int spacing = 5;
|
||||||
grid->resize( sz );
|
|
||||||
|
const int width = ( r.width() - ( m_columnCount - 1 ) * spacing ) / m_columnCount;
|
||||||
|
const int height = ( r.height() - ( rowCount - 1 ) * spacing ) / rowCount;
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
int col = 0;
|
||||||
|
|
||||||
|
for ( int i = 0; i < GridCount; i++ )
|
||||||
|
{
|
||||||
|
const int x = r.left() + col * ( spacing + width );
|
||||||
|
const int y = r.top() + row * ( spacing + height );
|
||||||
|
|
||||||
|
grids[i]->setGeometry( x, y, width, height );
|
||||||
|
|
||||||
|
if ( ++col >= m_columnCount )
|
||||||
|
{
|
||||||
|
col = 0;
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,34 +15,40 @@ class TestBox : public QWidget, public GridAccessor
|
||||||
TestBox( QWidget* parent = nullptr );
|
TestBox( QWidget* parent = nullptr );
|
||||||
~TestBox() override;
|
~TestBox() override;
|
||||||
|
|
||||||
|
void setColumns( int );
|
||||||
|
|
||||||
void insert( const QByteArray& colorName,
|
void insert( const QByteArray& colorName,
|
||||||
int row, int column, int rowSpan, int columnSpan ) override;
|
int row, int column, int rowSpan, int columnSpan ) override;
|
||||||
|
|
||||||
void setSpacing( Qt::Orientations, int spacing ) override;
|
void setSpacing( Qt::Orientations, int spacing ) override;
|
||||||
|
|
||||||
void setRowSizeHint( int row, Qt::SizeHint, int height ) override;
|
void setStretchFactor( int pos, Qt::Orientation, int stretch ) override;
|
||||||
void setColumnSizeHint( int column, Qt::SizeHint, int width ) override;
|
void setSizeHint( int pos, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
|
|
||||||
void setSizeHint( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
void setSizeHintAt( int index, Qt::Orientation, Qt::SizeHint, int hint ) override;
|
||||||
void setSizePolicy( int index, Qt::Orientation, int policy ) override;
|
void setSizePolicyAt( int index, Qt::Orientation, int policy ) override;
|
||||||
|
|
||||||
void setAlignment( int index, Qt::Alignment ) override;
|
void setAlignmentAt( int index, Qt::Alignment ) override;
|
||||||
void setRetainSizeWhenHidden( int, bool on ) override;
|
void setRetainSizeWhenHiddenAt( int index, bool on ) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent( QResizeEvent* ) override;
|
void resizeEvent( QResizeEvent* ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void layoutGrids();
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
Skinny,
|
Skinny,
|
||||||
Widgets,
|
Widgets,
|
||||||
Graphics,
|
Graphics,
|
||||||
|
Quick,
|
||||||
|
|
||||||
GridCount
|
GridCount
|
||||||
};
|
};
|
||||||
|
|
||||||
QWidget* grids[ GridCount ];
|
QWidget* grids[ GridCount ];
|
||||||
|
int m_columnCount = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ HEADERS += \
|
||||||
GridSkinny.h \
|
GridSkinny.h \
|
||||||
GridWidgets.h \
|
GridWidgets.h \
|
||||||
GridGraphics.h \
|
GridGraphics.h \
|
||||||
|
GridQuick.h \
|
||||||
TestBox.h
|
TestBox.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
|
@ -13,6 +14,7 @@ SOURCES += \
|
||||||
GridSkinny.cpp \
|
GridSkinny.cpp \
|
||||||
GridWidgets.cpp \
|
GridWidgets.cpp \
|
||||||
GridGraphics.cpp \
|
GridGraphics.cpp \
|
||||||
|
GridQuick.cpp \
|
||||||
TestBox.cpp \
|
TestBox.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,34 +10,138 @@
|
||||||
class MainBox : public TestBox
|
class MainBox : public TestBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MainBox()
|
MainBox( int id )
|
||||||
{
|
{
|
||||||
|
switch( id )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
setup0();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
setup1();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
setup2();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
setup3();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void setup0();
|
||||||
|
void setup1();
|
||||||
|
void setup2();
|
||||||
|
void setup3();
|
||||||
|
|
||||||
|
void setSizePolicyAt( int index,
|
||||||
|
QskSizePolicy::Policy horizontalPolicy,
|
||||||
|
QskSizePolicy::Policy verticalPolicy )
|
||||||
|
{
|
||||||
|
TestBox::setSizePolicyAt( index, Qt::Horizontal, horizontalPolicy );
|
||||||
|
TestBox::setSizePolicyAt( index, Qt::Vertical, verticalPolicy );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void MainBox::setup0()
|
||||||
|
{
|
||||||
|
// something, that works with all layouts
|
||||||
|
|
||||||
|
insert( "PaleVioletRed", 0, 0, 1, 1 );
|
||||||
|
insert( "DarkSeaGreen", 1, 1, 1, 1 );
|
||||||
|
insert( "SkyBlue", 2, 1, 1, 1 );
|
||||||
|
insert( "Coral", 2, 2, 1, 1 );
|
||||||
|
insert( "NavajoWhite", 3, 0, 1, 3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainBox::setup1()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
The Graphics layout adds the extra space to the stretchable
|
||||||
|
while the other layouts use the extra space for reaching
|
||||||
|
a ratio according to the stretch factor first,
|
||||||
|
That leads to column 0 being too large.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
setColumns( 1 );
|
||||||
|
|
||||||
insert( "PaleVioletRed", 0, 0, 1, 1 );
|
insert( "PaleVioletRed", 0, 0, 1, 1 );
|
||||||
insert( "DarkSeaGreen", 1, 1, 1, 1 );
|
insert( "DarkSeaGreen", 1, 1, 1, 1 );
|
||||||
insert( "SkyBlue", 2, 1, 1, 1 );
|
insert( "SkyBlue", 2, 1, 1, 1 );
|
||||||
insert( "Coral", 2, 2, 1, 1 );
|
insert( "Coral", 2, 2, 1, 1 );
|
||||||
insert( "NavajoWhite", 3, 0, 1, 3 );
|
insert( "NavajoWhite", 3, 0, 1, 3 );
|
||||||
|
|
||||||
setSizePolicy( 1, QskSizePolicy::Fixed, QskSizePolicy::Preferred );
|
setSizePolicyAt( 0, QskSizePolicy::Expanding, QskSizePolicy::Preferred );
|
||||||
setSizePolicy( 2, QskSizePolicy::Fixed, QskSizePolicy::Preferred );
|
setSizePolicyAt( 1, QskSizePolicy::Fixed, QskSizePolicy::Preferred );
|
||||||
|
setSizePolicyAt( 2, QskSizePolicy::Expanding, QskSizePolicy::Preferred );
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// Quick layouts do not support row/column hints
|
||||||
setColumnSizeHint( 1, Qt::MinimumSize, 100 );
|
setColumnSizeHint( 1, Qt::MinimumSize, 100 );
|
||||||
|
#else
|
||||||
|
for ( int i = 0; i < 4; i++ )
|
||||||
|
setMinimumWidthAt( i, 100 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
void MainBox::setup2()
|
||||||
void setSizePolicy( int index,
|
|
||||||
QskSizePolicy::Policy horizontalPolicy,
|
|
||||||
QskSizePolicy::Policy verticalPolicy )
|
|
||||||
{
|
{
|
||||||
TestBox::setSizePolicy( index, Qt::Horizontal, horizontalPolicy );
|
/*
|
||||||
TestBox::setSizePolicy( index, Qt::Vertical, verticalPolicy );
|
The Graphics layout uses a "magic" formula for how to apply
|
||||||
|
the stretch factors, while the other layouts result in
|
||||||
|
predictable sizes being calculated according to the factors.
|
||||||
|
In the specific situation column 1 in the Graphics layout is
|
||||||
|
larger than twice of columns 0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
setColumns( 4 );
|
||||||
|
|
||||||
|
insert( "PaleVioletRed", 0, 0, 1, 1 );
|
||||||
|
insert( "DarkSeaGreen", 1, 0, 1, 1 );
|
||||||
|
|
||||||
|
setRowStretchFactor( 0, 1 );
|
||||||
|
setRowStretchFactor( 1, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainBox::setup3()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
When setting a maximum size together with an alignment the expected result
|
||||||
|
would be a cell that can grow beyond the maximum, while the content stays
|
||||||
|
at its maximum, being aligned inside the cell.
|
||||||
|
|
||||||
|
But with widgets, the cell size gets always bounded to the preferred size
|
||||||
|
as soon as an alignment has been set. In ths
|
||||||
|
|
||||||
|
With graphics we have the effect, that the cells get bounded to the
|
||||||
|
maximum size and we always end up with being aligned Top | Left.
|
||||||
|
|
||||||
|
*/
|
||||||
|
setColumns( 1 );
|
||||||
|
|
||||||
|
insert( "PaleVioletRed", 0, 0, 1, 1 );
|
||||||
|
|
||||||
|
setPreferredWidthAt( 0, 10 );
|
||||||
|
setPreferredHeightAt( 0, 10 );
|
||||||
|
|
||||||
|
setMaximumWidthAt( 0, 200 );
|
||||||
|
setMaximumHeightAt( 0, 200 );
|
||||||
|
|
||||||
|
setAlignmentAt( 0, Qt::AlignCenter );
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
int main( int argc, char** argv )
|
int main( int argc, char** argv )
|
||||||
{
|
{
|
||||||
QApplication a( argc, argv );
|
QApplication a( argc, argv );
|
||||||
|
|
||||||
MainBox box;
|
MainBox box( 0 );
|
||||||
|
|
||||||
box.resize( 600, 600 );
|
box.resize( 600, 600 );
|
||||||
box.show();
|
box.show();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue