doing the GridLayoutPage in Qml to demonstrate how parts written in Qml
can be embedded into C++
This commit is contained in:
parent
ce6587a044
commit
e0cf43d8e1
@ -4,49 +4,31 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GridLayoutPage.h"
|
||||
#include "TestRectangle.h"
|
||||
|
||||
#include <QskGridBox.h>
|
||||
#include <QskRgbValue.h>
|
||||
#include <QtQml>
|
||||
|
||||
namespace
|
||||
static QQuickItem* qskCreateItemQml( const QUrl& url )
|
||||
{
|
||||
class Box : public QskGridBox
|
||||
{
|
||||
public:
|
||||
Box( QQuickItem* parent = nullptr )
|
||||
: QskGridBox( parent )
|
||||
{
|
||||
setObjectName( "GridBox" );
|
||||
QQmlEngine engine( nullptr );
|
||||
|
||||
setBackgroundColor( Qt::white );
|
||||
setMargins( 10 );
|
||||
QQmlComponent component( &engine );
|
||||
component.loadUrl( url, QQmlComponent::PreferSynchronous );
|
||||
|
||||
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() );
|
||||
}
|
||||
};
|
||||
return qobject_cast< QQuickItem* >( component.create() );
|
||||
}
|
||||
|
||||
GridLayoutPage::GridLayoutPage( QQuickItem* parent )
|
||||
: QskControl( parent )
|
||||
{
|
||||
#if 1
|
||||
setMargins( 10 );
|
||||
setBackgroundColor( QskRgbValue::LightSteelBlue );
|
||||
#endif
|
||||
|
||||
setAutoLayoutChildren( true );
|
||||
new Box( this );
|
||||
|
||||
if ( auto item = qskCreateItemQml( QUrl( "qrc:/qml/layouts.qml" ) ) )
|
||||
{
|
||||
item->setParentItem( this );
|
||||
item->setParent( this );
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef GRID_LAYOUT_PAGE
|
||||
#define GRID_LAYOUT_PAGE 1
|
||||
#define GRID_LAYOUT_PAGE
|
||||
|
||||
#include <QskControl.h>
|
||||
|
||||
|
@ -5,17 +5,33 @@
|
||||
|
||||
#include "TestRectangle.h"
|
||||
|
||||
#include <QskAspect.h>
|
||||
|
||||
TestRectangle::TestRectangle( const char* colorName, QQuickItem* parent )
|
||||
TestRectangle::TestRectangle( QQuickItem* parent )
|
||||
: QskTextLabel( parent )
|
||||
{
|
||||
setObjectName( colorName );
|
||||
|
||||
setAlignment( Qt::AlignCenter );
|
||||
setBackgroundColor( colorName );
|
||||
|
||||
setPreferredSize( 10, 10 );
|
||||
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum );
|
||||
setFocusPolicy( Qt::TabFocus ); // for checking the focus tab chain
|
||||
}
|
||||
|
||||
TestRectangle::TestRectangle( const char* colorName, QQuickItem* parent )
|
||||
: TestRectangle( parent )
|
||||
{
|
||||
setColorName( colorName );
|
||||
}
|
||||
|
||||
void TestRectangle::setColorName( const QString& colorName )
|
||||
{
|
||||
m_colorName = colorName;
|
||||
|
||||
setObjectName( colorName );
|
||||
setBackgroundColor( colorName );
|
||||
}
|
||||
|
||||
QString TestRectangle::colorName() const
|
||||
{
|
||||
return m_colorName;
|
||||
}
|
||||
|
||||
#include "moc_TestRectangle.cpp"
|
||||
|
@ -4,14 +4,25 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef TEST_RECTANGLE
|
||||
#define TEST_RECTANGLE 1
|
||||
#define TEST_RECTANGLE
|
||||
|
||||
#include <QskTextLabel.h>
|
||||
|
||||
class TestRectangle : public QskTextLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QString color READ colorName WRITE setColorName )
|
||||
|
||||
public:
|
||||
TestRectangle( QQuickItem* parent = nullptr );
|
||||
TestRectangle( const char* colorName, QQuickItem* parent = nullptr );
|
||||
|
||||
void setColorName( const QString& );
|
||||
QString colorName() const;
|
||||
|
||||
private:
|
||||
QString m_colorName;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,7 @@
|
||||
CONFIG += qskexample
|
||||
CONFIG += qskexample qskqmlexport
|
||||
|
||||
RESOURCES += \
|
||||
layouts.qrc
|
||||
|
||||
HEADERS += \
|
||||
TestRectangle.h \
|
||||
|
54
examples/layouts/layouts.qml
Normal file
54
examples/layouts/layouts.qml
Normal file
@ -0,0 +1,54 @@
|
||||
import QtQuick 2.0
|
||||
import Skinny 1.0
|
||||
import Test 1.0
|
||||
|
||||
GridBox
|
||||
{
|
||||
margins: 10
|
||||
autoFillBackground : true
|
||||
|
||||
background
|
||||
{
|
||||
stops: [
|
||||
{ position: 0.0, color: "White" },
|
||||
{ position: 1.0, color: "White" },
|
||||
]
|
||||
}
|
||||
|
||||
TestRectangle
|
||||
{
|
||||
id: paleVioletRed
|
||||
color: "PaleVioletRed"
|
||||
}
|
||||
|
||||
TestRectangle
|
||||
{
|
||||
id: darkSeaGreen
|
||||
color: "DarkSeaGreen"
|
||||
}
|
||||
|
||||
TestRectangle
|
||||
{
|
||||
id: skyBlue
|
||||
color: "SkyBlue"
|
||||
}
|
||||
|
||||
TestRectangle
|
||||
{
|
||||
id: navajoWhite
|
||||
color: "NavajoWhite"
|
||||
}
|
||||
|
||||
Component.onCompleted:
|
||||
{
|
||||
addItem( paleVioletRed, 0, 0, 1, 2 );
|
||||
addItem( darkSeaGreen, 1, 0, 2, 1 );
|
||||
addItem( skyBlue, 2, 1, 1, 1 );
|
||||
addItem( navajoWhite, 0, 2, -1, 1 );
|
||||
|
||||
setRowStretchFactor( 0, 1 );
|
||||
setRowStretchFactor( 1, 2 );
|
||||
setRowStretchFactor( 2, 1 );
|
||||
}
|
||||
}
|
||||
|
5
examples/layouts/layouts.qrc
Normal file
5
examples/layouts/layouts.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/qml">
|
||||
<file>layouts.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -8,6 +8,7 @@
|
||||
#include "LinearLayoutPage.h"
|
||||
#include "GridLayoutPage.h"
|
||||
#include "StackLayoutPage.h"
|
||||
#include "TestRectangle.h"
|
||||
|
||||
#include <SkinnyFont.h>
|
||||
#include <SkinnyShortcut.h>
|
||||
@ -21,31 +22,17 @@
|
||||
#include <QskTextLabel.h>
|
||||
#include <QskTextOptions.h>
|
||||
#include <QskWindow.h>
|
||||
#include <QskQml.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
|
||||
class DummyLabel : public QskTextLabel
|
||||
{
|
||||
public:
|
||||
DummyLabel( const QString& text, QQuickItem* parent = nullptr )
|
||||
: QskTextLabel( text, parent )
|
||||
{
|
||||
setBackgroundColor( Qt::black );
|
||||
setTextColor( Qt::white );
|
||||
setFontRole( QskSkin::MediumFont );
|
||||
|
||||
setWrapMode( QskTextOptions::WordWrap );
|
||||
|
||||
setAlignment( Qt::AlignCenter );
|
||||
setSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Ignored );
|
||||
}
|
||||
};
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
#ifdef ITEM_STATISTICS
|
||||
QskObjectCounter counter( true );
|
||||
#endif
|
||||
QskQml::registerTypes();
|
||||
qmlRegisterType< TestRectangle >( "Test", 1, 0, "TestRectangle" );
|
||||
|
||||
QGuiApplication app( argc, argv );
|
||||
|
||||
@ -69,7 +56,7 @@ int main( int argc, char* argv[] )
|
||||
|
||||
tabView->addTab( "Stack Layout", new StackLayoutPage() );
|
||||
|
||||
tabView->setCurrentIndex( 4 );
|
||||
tabView->setCurrentIndex( 0 );
|
||||
|
||||
QSize size( 800, 600 );
|
||||
size = size.expandedTo( tabView->sizeHint().toSize() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user