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 "GridLayoutPage.h"
|
||||||
#include "TestRectangle.h"
|
|
||||||
|
|
||||||
#include <QskGridBox.h>
|
|
||||||
#include <QskRgbValue.h>
|
#include <QskRgbValue.h>
|
||||||
|
#include <QtQml>
|
||||||
|
|
||||||
namespace
|
static QQuickItem* qskCreateItemQml( const QUrl& url )
|
||||||
{
|
{
|
||||||
class Box : public QskGridBox
|
QQmlEngine engine( nullptr );
|
||||||
{
|
|
||||||
public:
|
|
||||||
Box( QQuickItem* parent = nullptr )
|
|
||||||
: QskGridBox( parent )
|
|
||||||
{
|
|
||||||
setObjectName( "GridBox" );
|
|
||||||
|
|
||||||
setBackgroundColor( Qt::white );
|
QQmlComponent component( &engine );
|
||||||
setMargins( 10 );
|
component.loadUrl( url, QQmlComponent::PreferSynchronous );
|
||||||
|
|
||||||
addItem( new TestRectangle( "PaleVioletRed" ), 0, 0, 1, 2 );
|
return qobject_cast< QQuickItem* >( component.create() );
|
||||||
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() );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayoutPage::GridLayoutPage( QQuickItem* parent )
|
GridLayoutPage::GridLayoutPage( QQuickItem* parent )
|
||||||
: QskControl( parent )
|
: QskControl( parent )
|
||||||
{
|
{
|
||||||
#if 1
|
|
||||||
setMargins( 10 );
|
setMargins( 10 );
|
||||||
setBackgroundColor( QskRgbValue::LightSteelBlue );
|
setBackgroundColor( QskRgbValue::LightSteelBlue );
|
||||||
#endif
|
|
||||||
|
|
||||||
setAutoLayoutChildren( true );
|
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
|
#ifndef GRID_LAYOUT_PAGE
|
||||||
#define GRID_LAYOUT_PAGE 1
|
#define GRID_LAYOUT_PAGE
|
||||||
|
|
||||||
#include <QskControl.h>
|
#include <QskControl.h>
|
||||||
|
|
||||||
|
|
|
@ -5,17 +5,33 @@
|
||||||
|
|
||||||
#include "TestRectangle.h"
|
#include "TestRectangle.h"
|
||||||
|
|
||||||
#include <QskAspect.h>
|
TestRectangle::TestRectangle( QQuickItem* parent )
|
||||||
|
|
||||||
TestRectangle::TestRectangle( const char* colorName, QQuickItem* parent )
|
|
||||||
: QskTextLabel( parent )
|
: QskTextLabel( parent )
|
||||||
{
|
{
|
||||||
setObjectName( colorName );
|
|
||||||
|
|
||||||
setAlignment( Qt::AlignCenter );
|
setAlignment( Qt::AlignCenter );
|
||||||
setBackgroundColor( colorName );
|
|
||||||
|
|
||||||
setPreferredSize( 10, 10 );
|
setPreferredSize( 10, 10 );
|
||||||
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum );
|
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum );
|
||||||
setFocusPolicy( Qt::TabFocus ); // for checking the focus tab chain
|
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
|
#ifndef TEST_RECTANGLE
|
||||||
#define TEST_RECTANGLE 1
|
#define TEST_RECTANGLE
|
||||||
|
|
||||||
#include <QskTextLabel.h>
|
#include <QskTextLabel.h>
|
||||||
|
|
||||||
class TestRectangle : public QskTextLabel
|
class TestRectangle : public QskTextLabel
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( QString color READ colorName WRITE setColorName )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
TestRectangle( QQuickItem* parent = nullptr );
|
||||||
TestRectangle( const char* colorName, QQuickItem* parent = nullptr );
|
TestRectangle( const char* colorName, QQuickItem* parent = nullptr );
|
||||||
|
|
||||||
|
void setColorName( const QString& );
|
||||||
|
QString colorName() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_colorName;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
CONFIG += qskexample
|
CONFIG += qskexample qskqmlexport
|
||||||
|
|
||||||
|
RESOURCES += \
|
||||||
|
layouts.qrc
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
TestRectangle.h \
|
TestRectangle.h \
|
||||||
|
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/qml">
|
||||||
|
<file>layouts.qml</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
|
@ -8,6 +8,7 @@
|
||||||
#include "LinearLayoutPage.h"
|
#include "LinearLayoutPage.h"
|
||||||
#include "GridLayoutPage.h"
|
#include "GridLayoutPage.h"
|
||||||
#include "StackLayoutPage.h"
|
#include "StackLayoutPage.h"
|
||||||
|
#include "TestRectangle.h"
|
||||||
|
|
||||||
#include <SkinnyFont.h>
|
#include <SkinnyFont.h>
|
||||||
#include <SkinnyShortcut.h>
|
#include <SkinnyShortcut.h>
|
||||||
|
@ -21,31 +22,17 @@
|
||||||
#include <QskTextLabel.h>
|
#include <QskTextLabel.h>
|
||||||
#include <QskTextOptions.h>
|
#include <QskTextOptions.h>
|
||||||
#include <QskWindow.h>
|
#include <QskWindow.h>
|
||||||
|
#include <QskQml.h>
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#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[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
#ifdef ITEM_STATISTICS
|
#ifdef ITEM_STATISTICS
|
||||||
QskObjectCounter counter( true );
|
QskObjectCounter counter( true );
|
||||||
#endif
|
#endif
|
||||||
|
QskQml::registerTypes();
|
||||||
|
qmlRegisterType< TestRectangle >( "Test", 1, 0, "TestRectangle" );
|
||||||
|
|
||||||
QGuiApplication app( argc, argv );
|
QGuiApplication app( argc, argv );
|
||||||
|
|
||||||
|
@ -69,7 +56,7 @@ int main( int argc, char* argv[] )
|
||||||
|
|
||||||
tabView->addTab( "Stack Layout", new StackLayoutPage() );
|
tabView->addTab( "Stack Layout", new StackLayoutPage() );
|
||||||
|
|
||||||
tabView->setCurrentIndex( 4 );
|
tabView->setCurrentIndex( 0 );
|
||||||
|
|
||||||
QSize size( 800, 600 );
|
QSize size( 800, 600 );
|
||||||
size = size.expandedTo( tabView->sizeHint().toSize() );
|
size = size.expandedTo( tabView->sizeHint().toSize() );
|
||||||
|
|
Loading…
Reference in New Issue