Skip to content

Commit

Permalink
alternative C++ version added
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Jul 19, 2019
1 parent 401adac commit 9fee8c5
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions examples/layouts/GridLayoutPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,65 @@
*****************************************************************************/

#include "GridLayoutPage.h"

#include <QskRgbValue.h>

#define USE_QML 1

#if USE_QML

#include <QtQml>

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 <QskGridBox.h>
#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 )
{
Expand All @@ -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
}

0 comments on commit 9fee8c5

Please sign in to comment.