From 9fee8c50b5a4c777d271c2c47a78438f2dacb595 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 19 Jul 2019 12:14:58 +0200 Subject: [PATCH] alternative C++ version added --- examples/layouts/GridLayoutPage.cpp | 61 +++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/examples/layouts/GridLayoutPage.cpp b/examples/layouts/GridLayoutPage.cpp index 32acc2235..97b0861b5 100644 --- a/examples/layouts/GridLayoutPage.cpp +++ b/examples/layouts/GridLayoutPage.cpp @@ -4,20 +4,65 @@ *****************************************************************************/ #include "GridLayoutPage.h" - #include + +#define USE_QML 1 + +#if USE_QML + #include -static QQuickItem* qskCreateItemQml( const QUrl& url ) +static void insertItemQml( QQuickItem* parentItem, const QUrl& url ) { QQmlEngine engine( nullptr ); QQmlComponent component( &engine ); component.loadUrl( url, QQmlComponent::PreferSynchronous ); - return qobject_cast< QQuickItem* >( component.create() ); + if( auto item = qobject_cast< QQuickItem* >( component.create() ) ) + { + item->setParentItem( parentItem ); + item->setParent( parentItem ); + } } +#else + +#include +#include "TestRectangle.h" + +namespace +{ + class Box : public QskGridBox + { + public: + Box( QQuickItem* parent = nullptr ) + : QskGridBox( parent ) + { + setObjectName( "GridBox" ); + + setBackgroundColor( Qt::white ); + setMargins( 10 ); + + addItem( new TestRectangle( "PaleVioletRed" ), 0, 0, 1, 2 ); + addItem( new TestRectangle( "DarkSeaGreen" ), 1, 0, 2, 1 ); + addItem( new TestRectangle( "SkyBlue" ), 2, 1, 1, 1 ); + addItem( new TestRectangle( "NavajoWhite" ), 0, 2, -1, 1 ); + + setRowStretchFactor( 0, 1 ); + setRowStretchFactor( 1, 2 ); + setRowStretchFactor( 2, 1 ); + } + + void mirror() + { + setLayoutMirroring( !layoutMirroring() ); + } + }; +} + +#endif + GridLayoutPage::GridLayoutPage( QQuickItem* parent ) : QskControl( parent ) { @@ -26,9 +71,9 @@ GridLayoutPage::GridLayoutPage( QQuickItem* parent ) setAutoLayoutChildren( true ); - if ( auto item = qskCreateItemQml( QUrl( "qrc:/qml/layouts.qml" ) ) ) - { - item->setParentItem( this ); - item->setParent( this ); - } +#if USE_QML + insertItemQml( this, QUrl( "qrc:/qml/layouts.qml" ) ); +#else + new Box( this ); +#endif }