split project with app & doric module
This commit is contained in:
341
doric-Qt/example/doric/widget/flex/FlexLayout.cpp
Normal file
341
doric-Qt/example/doric/widget/flex/FlexLayout.cpp
Normal file
@@ -0,0 +1,341 @@
|
||||
#include "FlexLayout.h"
|
||||
|
||||
FlexLayout::FlexLayout(FlexLayoutConfig *config, QObject *parent)
|
||||
: QObject(parent) {
|
||||
node = YGNodeNewWithConfig(config->getConfig());
|
||||
this->config = config;
|
||||
}
|
||||
|
||||
FlexLayout::~FlexLayout() { YGNodeFree(node); }
|
||||
|
||||
YGNodeRef FlexLayout::getNode() { return node; }
|
||||
|
||||
void FlexLayout::appendChildren(QVariant children) {
|
||||
QJSValue child = qvariant_cast<QJSValue>(children);
|
||||
std::vector<YGNodeRef> tmp;
|
||||
if (child.isUndefined()) {
|
||||
qCritical() << "FlexLayout appendChildren child undefined";
|
||||
} else if (!child.isArray()) {
|
||||
qCritical() << "FlexLayout appendChildren child is not array";
|
||||
} else {
|
||||
const int length = child.property("length").toInt();
|
||||
for (int i = 0; i != length; i++) {
|
||||
FlexLayout *node = nullptr;
|
||||
if (!tryCast(child.property(i), node)) {
|
||||
qCritical() << "FlexLayout appendChildren child is not qobject";
|
||||
return;
|
||||
} else {
|
||||
node->setParent(this);
|
||||
tmp.push_back(node->getNode());
|
||||
}
|
||||
}
|
||||
YGNodeSetChildren(this->node, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
int FlexLayout::getFlexGrow() {
|
||||
return static_cast<int>(YGNodeStyleGetFlexGrow(node));
|
||||
}
|
||||
|
||||
void FlexLayout::setFlexGrow(int v) {
|
||||
YGNodeStyleSetFlexGrow(node, static_cast<float>(v));
|
||||
}
|
||||
|
||||
int FlexLayout::getFlexShrink() {
|
||||
return static_cast<int>(YGNodeStyleGetFlexShrink(node));
|
||||
}
|
||||
|
||||
void FlexLayout::setFlexShrink(int v) {
|
||||
YGNodeStyleSetFlexShrink(node, static_cast<float>(v));
|
||||
}
|
||||
|
||||
int FlexLayout::getHeight() {
|
||||
return static_cast<int>(YGNodeStyleGetHeight(node).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setHeight(int points) {
|
||||
YGNodeStyleSetHeight(node, static_cast<float>(points));
|
||||
}
|
||||
|
||||
int FlexLayout::getMinHeight() {
|
||||
return static_cast<int>(YGNodeStyleGetMinHeight(node).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setMinHeight(int point) {
|
||||
YGNodeStyleSetMinHeight(node, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getWidth() {
|
||||
return static_cast<int>(YGNodeStyleGetWidth(node).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setWidth(int points) {
|
||||
YGNodeStyleSetWidth(node, static_cast<float>(points));
|
||||
}
|
||||
|
||||
int FlexLayout::getMinWidth() {
|
||||
return static_cast<int>(YGNodeStyleGetMinWidth(node).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setMinWidth(int point) {
|
||||
YGNodeStyleSetMinWidth(node, static_cast<float>(point));
|
||||
}
|
||||
|
||||
void FlexLayout::setDisplayNone() {
|
||||
YGNodeStyleSetDisplay(node, YGDisplayNone);
|
||||
}
|
||||
|
||||
void FlexLayout::setDisplayFlex() {
|
||||
YGNodeStyleSetDisplay(node, YGDisplayFlex);
|
||||
}
|
||||
|
||||
void FlexLayout::setFlexDirectionRow() {
|
||||
YGNodeStyleSetFlexDirection(node, YGFlexDirectionRow);
|
||||
}
|
||||
|
||||
void FlexLayout::setFlexDirectionRowReverse() {
|
||||
YGNodeStyleSetFlexDirection(node, YGFlexDirectionRowReverse);
|
||||
}
|
||||
|
||||
void FlexLayout::setFlexDirectionColumn() {
|
||||
YGNodeStyleSetFlexDirection(node, YGFlexDirectionColumn);
|
||||
}
|
||||
|
||||
void FlexLayout::setFlexDirectionColumnReverse() {
|
||||
YGNodeStyleSetFlexDirection(node, YGFlexDirectionColumnReverse);
|
||||
}
|
||||
|
||||
void FlexLayout::setJustifyCenter() {
|
||||
YGNodeStyleSetJustifyContent(node, YGJustifyCenter);
|
||||
}
|
||||
|
||||
void FlexLayout::setJustifyFlexStart() {
|
||||
YGNodeStyleSetJustifyContent(node, YGJustifyFlexStart);
|
||||
}
|
||||
|
||||
void FlexLayout::setJustifyFlexEnd() {
|
||||
YGNodeStyleSetJustifyContent(node, YGJustifyFlexEnd);
|
||||
}
|
||||
|
||||
void FlexLayout::setJustifySpaceAround() {
|
||||
YGNodeStyleSetJustifyContent(node, YGJustifySpaceAround);
|
||||
}
|
||||
|
||||
void FlexLayout::setJustifySpaceEvenly() {
|
||||
YGNodeStyleSetJustifyContent(node, YGJustifySpaceEvenly);
|
||||
}
|
||||
|
||||
void FlexLayout::setJustifySpaceBetween() {
|
||||
YGNodeStyleSetJustifyContent(node, YGJustifySpaceBetween);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentAuto() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignAuto);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentCenter() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignCenter);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentFlexEnd() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignFlexEnd);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentStretch() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignStretch);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentBaseline() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignBaseline);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentFlexStart() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignFlexStart);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentSpaceAround() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignSpaceAround);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignContentSpaceBetween() {
|
||||
YGNodeStyleSetAlignContent(node, YGAlignSpaceBetween);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsAuto() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignAuto);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsCenter() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignCenter);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsFlexEnd() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignFlexEnd);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsStretch() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignStretch);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsBaseline() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignBaseline);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsFlexStart() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignFlexStart);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsSpaceAround() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignSpaceAround);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignItemsSpaceBetween() {
|
||||
YGNodeStyleSetAlignItems(node, YGAlignSpaceBetween);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfAuto() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignAuto);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfCenter() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignCenter);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfFlexEnd() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignFlexEnd);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfStretch() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignStretch);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfBaseline() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignBaseline);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfFlexStart() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignFlexStart);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfSpaceAround() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignSpaceAround);
|
||||
}
|
||||
|
||||
void FlexLayout::setAlignSelfSpaceBetween() {
|
||||
YGNodeStyleSetAlignSelf(node, YGAlignSpaceBetween);
|
||||
}
|
||||
|
||||
void FlexLayout::setWrap() { YGNodeStyleSetFlexWrap(node, YGWrapWrap); }
|
||||
|
||||
void FlexLayout::setNoWrap() { YGNodeStyleSetFlexWrap(node, YGWrapNoWrap); }
|
||||
|
||||
void FlexLayout::setWrapReverse() {
|
||||
YGNodeStyleSetFlexWrap(node, YGWrapWrapReverse);
|
||||
}
|
||||
|
||||
int FlexLayout::getMarginTop() {
|
||||
return static_cast<int>(YGNodeStyleGetMargin(node, YGEdgeTop).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setMarginTop(int point) {
|
||||
YGNodeStyleSetMargin(node, YGEdgeTop, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getMarginLeft() {
|
||||
return static_cast<int>(YGNodeStyleGetMargin(node, YGEdgeLeft).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setMarginLeft(int point) {
|
||||
YGNodeStyleSetMargin(node, YGEdgeLeft, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getMarginRight() {
|
||||
return static_cast<int>(YGNodeStyleGetMargin(node, YGEdgeRight).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setMarginRight(int point) {
|
||||
YGNodeStyleSetMargin(node, YGEdgeRight, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getMarginBottom() {
|
||||
return static_cast<int>(YGNodeStyleGetMargin(node, YGEdgeBottom).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setMarginBottom(int point) {
|
||||
YGNodeStyleSetMargin(node, YGEdgeBottom, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getPaddingTop() {
|
||||
return static_cast<int>(YGNodeStyleGetPadding(node, YGEdgeTop).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setPaddingTop(int point) {
|
||||
YGNodeStyleSetPadding(node, YGEdgeTop, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getPaddingLeft() {
|
||||
return static_cast<int>(YGNodeStyleGetPadding(node, YGEdgeLeft).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setPaddingLeft(int point) {
|
||||
YGNodeStyleSetPadding(node, YGEdgeLeft, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getPaddingRight() {
|
||||
return static_cast<int>(YGNodeStyleGetPadding(node, YGEdgeRight).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setPaddingRight(int point) {
|
||||
YGNodeStyleSetPadding(node, YGEdgeRight, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getPaddingBottom() {
|
||||
return static_cast<int>(YGNodeStyleGetPadding(node, YGEdgeBottom).value);
|
||||
}
|
||||
|
||||
void FlexLayout::setPaddingBottom(int point) {
|
||||
YGNodeStyleSetPadding(node, YGEdgeBottom, static_cast<float>(point));
|
||||
}
|
||||
|
||||
int FlexLayout::getLayoutTop() {
|
||||
return static_cast<int>(YGNodeLayoutGetTop(node));
|
||||
}
|
||||
|
||||
int FlexLayout::getLayoutLeft() {
|
||||
return static_cast<int>(YGNodeLayoutGetLeft(node));
|
||||
}
|
||||
|
||||
int FlexLayout::getLayoutRight() {
|
||||
return static_cast<int>(YGNodeLayoutGetRight(node));
|
||||
}
|
||||
|
||||
int FlexLayout::getLayoutBottom() {
|
||||
return static_cast<int>(YGNodeLayoutGetBottom(node));
|
||||
}
|
||||
|
||||
int FlexLayout::getLayoutWidth() {
|
||||
return static_cast<int>(YGNodeLayoutGetWidth(node));
|
||||
}
|
||||
|
||||
int FlexLayout::getLayoutHeight() {
|
||||
return static_cast<int>(YGNodeLayoutGetHeight(node));
|
||||
}
|
||||
|
||||
void FlexLayout::calculateLayoutRtl(int width, int height) {
|
||||
YGNodeCalculateLayout(node, static_cast<float>(width),
|
||||
static_cast<float>(height), YGDirectionRTL);
|
||||
}
|
||||
|
||||
void FlexLayout::calculateLayoutLtr(int width, int height) {
|
||||
YGNodeCalculateLayout(node, static_cast<float>(width),
|
||||
static_cast<float>(height), YGDirectionLTR);
|
||||
}
|
||||
|
||||
bool FlexLayout::tryCast(QJSValue src, FlexLayout *&dst) {
|
||||
if (!src.isQObject()) {
|
||||
return false;
|
||||
} else {
|
||||
dst = qobject_cast<FlexLayout *>(src.toQObject());
|
||||
return dst != nullptr;
|
||||
}
|
||||
}
|
141
doric-Qt/example/doric/widget/flex/FlexLayout.h
Normal file
141
doric-Qt/example/doric/widget/flex/FlexLayout.h
Normal file
@@ -0,0 +1,141 @@
|
||||
#ifndef FLEXLAYOUT_H
|
||||
#define FLEXLAYOUT_H
|
||||
|
||||
#include <QJSValue>
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "yoga/Yoga.h"
|
||||
#include "FlexLayoutConfig.h"
|
||||
|
||||
class FlexLayout : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int flexShrink READ getFlexShrink WRITE setFlexShrink)
|
||||
Q_PROPERTY(int flexGrow READ getFlexGrow WRITE setFlexGrow)
|
||||
|
||||
Q_PROPERTY(int minHeight READ getHeight WRITE setHeight)
|
||||
Q_PROPERTY(int height READ getHeight WRITE setHeight)
|
||||
Q_PROPERTY(int minWidth READ getWidth WRITE setWidth)
|
||||
Q_PROPERTY(int width READ getWidth WRITE setWidth)
|
||||
|
||||
Q_PROPERTY(int marginTop READ getMarginTop WRITE setMarginTop)
|
||||
Q_PROPERTY(int marginLeft READ getMarginLeft WRITE setMarginLeft)
|
||||
Q_PROPERTY(int marginRight READ getMarginRight WRITE setMarginRight)
|
||||
Q_PROPERTY(int marginBottom READ getMarginBottom WRITE setMarginBottom)
|
||||
|
||||
Q_PROPERTY(int paddingTop READ getPaddingTop WRITE setPaddingTop)
|
||||
Q_PROPERTY(int paddingLeft READ getPaddingLeft WRITE setPaddingLeft)
|
||||
Q_PROPERTY(int paddingRight READ getPaddingRight WRITE setPaddingRight)
|
||||
Q_PROPERTY(int paddingBottom READ getPaddingBottom WRITE setPaddingBottom)
|
||||
|
||||
Q_PROPERTY(int layoutTop READ getLayoutTop)
|
||||
Q_PROPERTY(int layoutLeft READ getLayoutLeft)
|
||||
Q_PROPERTY(int layoutRight READ getLayoutRight)
|
||||
Q_PROPERTY(int layoutBottom READ getLayoutBottom)
|
||||
|
||||
private:
|
||||
YGNodeRef node;
|
||||
FlexLayoutConfig *config;
|
||||
|
||||
public:
|
||||
FlexLayout(FlexLayoutConfig *config, QObject *parent = nullptr);
|
||||
virtual ~FlexLayout();
|
||||
YGNodeRef getNode();
|
||||
public slots:
|
||||
/* child */
|
||||
Q_INVOKABLE void appendChildren(QVariant children);
|
||||
/* flex */
|
||||
int getFlexGrow();
|
||||
void setFlexGrow(int v);
|
||||
int getFlexShrink();
|
||||
void setFlexShrink(int v);
|
||||
/* height */
|
||||
int getHeight();
|
||||
void setHeight(int point);
|
||||
int getMinHeight();
|
||||
void setMinHeight(int point);
|
||||
/* width */
|
||||
int getWidth();
|
||||
void setWidth(int point);
|
||||
int getMinWidth();
|
||||
void setMinWidth(int point);
|
||||
/* display */
|
||||
Q_INVOKABLE void setDisplayNone();
|
||||
Q_INVOKABLE void setDisplayFlex();
|
||||
/* flex-direction */
|
||||
Q_INVOKABLE void setFlexDirectionRow();
|
||||
Q_INVOKABLE void setFlexDirectionRowReverse();
|
||||
Q_INVOKABLE void setFlexDirectionColumn();
|
||||
Q_INVOKABLE void setFlexDirectionColumnReverse();
|
||||
/* justify-content */
|
||||
Q_INVOKABLE void setJustifyCenter();
|
||||
Q_INVOKABLE void setJustifyFlexStart();
|
||||
Q_INVOKABLE void setJustifyFlexEnd();
|
||||
Q_INVOKABLE void setJustifySpaceAround();
|
||||
Q_INVOKABLE void setJustifySpaceEvenly();
|
||||
Q_INVOKABLE void setJustifySpaceBetween();
|
||||
/* align-content */
|
||||
Q_INVOKABLE void setAlignContentAuto();
|
||||
Q_INVOKABLE void setAlignContentCenter();
|
||||
Q_INVOKABLE void setAlignContentFlexEnd();
|
||||
Q_INVOKABLE void setAlignContentStretch();
|
||||
Q_INVOKABLE void setAlignContentBaseline();
|
||||
Q_INVOKABLE void setAlignContentFlexStart();
|
||||
Q_INVOKABLE void setAlignContentSpaceAround();
|
||||
Q_INVOKABLE void setAlignContentSpaceBetween();
|
||||
/* align-items */
|
||||
Q_INVOKABLE void setAlignItemsAuto();
|
||||
Q_INVOKABLE void setAlignItemsCenter();
|
||||
Q_INVOKABLE void setAlignItemsFlexEnd();
|
||||
Q_INVOKABLE void setAlignItemsStretch();
|
||||
Q_INVOKABLE void setAlignItemsBaseline();
|
||||
Q_INVOKABLE void setAlignItemsFlexStart();
|
||||
Q_INVOKABLE void setAlignItemsSpaceAround();
|
||||
Q_INVOKABLE void setAlignItemsSpaceBetween();
|
||||
/* align-self */
|
||||
Q_INVOKABLE void setAlignSelfAuto();
|
||||
Q_INVOKABLE void setAlignSelfCenter();
|
||||
Q_INVOKABLE void setAlignSelfFlexEnd();
|
||||
Q_INVOKABLE void setAlignSelfStretch();
|
||||
Q_INVOKABLE void setAlignSelfBaseline();
|
||||
Q_INVOKABLE void setAlignSelfFlexStart();
|
||||
Q_INVOKABLE void setAlignSelfSpaceAround();
|
||||
Q_INVOKABLE void setAlignSelfSpaceBetween();
|
||||
/* flex-wrap */
|
||||
Q_INVOKABLE void setWrap();
|
||||
Q_INVOKABLE void setNoWrap();
|
||||
Q_INVOKABLE void setWrapReverse();
|
||||
/* margin */
|
||||
int getMarginTop();
|
||||
void setMarginTop(int point);
|
||||
int getMarginLeft();
|
||||
void setMarginLeft(int point);
|
||||
int getMarginRight();
|
||||
void setMarginRight(int point);
|
||||
int getMarginBottom();
|
||||
void setMarginBottom(int point);
|
||||
/* padding */
|
||||
int getPaddingTop();
|
||||
void setPaddingTop(int point);
|
||||
int getPaddingLeft();
|
||||
void setPaddingLeft(int point);
|
||||
int getPaddingRight();
|
||||
void setPaddingRight(int point);
|
||||
int getPaddingBottom();
|
||||
void setPaddingBottom(int point);
|
||||
/* calculate */
|
||||
int getLayoutTop();
|
||||
int getLayoutLeft();
|
||||
int getLayoutRight();
|
||||
int getLayoutBottom();
|
||||
int getLayoutWidth();
|
||||
int getLayoutHeight();
|
||||
Q_INVOKABLE void calculateLayoutRtl(int width, int height);
|
||||
Q_INVOKABLE void calculateLayoutLtr(int width, int height);
|
||||
|
||||
private:
|
||||
static bool tryCast(QJSValue src, FlexLayout *&dst);
|
||||
};
|
||||
#endif // FLEXLAYOUT_H
|
9
doric-Qt/example/doric/widget/flex/FlexLayoutConfig.cpp
Normal file
9
doric-Qt/example/doric/widget/flex/FlexLayoutConfig.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "FlexLayoutConfig.h"
|
||||
|
||||
FlexLayoutConfig::FlexLayoutConfig(QObject *parent) : QObject(parent) {
|
||||
config = YGConfigNew();
|
||||
}
|
||||
|
||||
FlexLayoutConfig::~FlexLayoutConfig() { YGConfigFree(config); }
|
||||
|
||||
YGConfigRef FlexLayoutConfig::getConfig() const { return config; }
|
20
doric-Qt/example/doric/widget/flex/FlexLayoutConfig.h
Normal file
20
doric-Qt/example/doric/widget/flex/FlexLayoutConfig.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef FLEXLAYOUTCONFIG_H
|
||||
#define FLEXLAYOUTCONFIG_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "yoga/Yoga.h"
|
||||
|
||||
class FlexLayoutConfig : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
YGConfigRef config;
|
||||
|
||||
public:
|
||||
explicit FlexLayoutConfig(QObject *parent = nullptr);
|
||||
virtual ~FlexLayoutConfig();
|
||||
YGConfigRef getConfig() const;
|
||||
};
|
||||
|
||||
#endif // FLEXLAYOUTCONFIG_H
|
35
doric-Qt/example/doric/widget/flex/FlexLayoutService.cpp
Normal file
35
doric-Qt/example/doric/widget/flex/FlexLayoutService.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "FlexLayoutService.h"
|
||||
|
||||
FlexLayoutService::FlexLayoutService(QObject *parent) : QObject(parent) {
|
||||
config = new FlexLayoutConfig(this);
|
||||
}
|
||||
|
||||
FlexLayoutService::~FlexLayoutService() {}
|
||||
|
||||
QVariant FlexLayoutService::createNode(QVariant config) {
|
||||
FlexLayoutConfig *object = qvariant_cast<FlexLayoutConfig *>(config);
|
||||
QVariant result;
|
||||
if (object == nullptr) {
|
||||
qCritical() << "FlexLayoutService createNode config not FlexLayoutConfig*";
|
||||
} else {
|
||||
result = QVariant::fromValue(new FlexLayout(object, this));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void FlexLayoutService::collectGarbage(QVariant rootNode) {
|
||||
FlexLayout *node = qvariant_cast<FlexLayout *>(rootNode);
|
||||
if (node == nullptr) {
|
||||
qCritical() << "FlexLayoutService collectGarbage node to FlexLayout*";
|
||||
} else {
|
||||
node->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant FlexLayoutService::createConfig() {
|
||||
return QVariant::fromValue(new FlexLayoutConfig(this));
|
||||
}
|
||||
|
||||
QVariant FlexLayoutService::createNode() {
|
||||
return QVariant::fromValue(new FlexLayout(config, this));
|
||||
}
|
29
doric-Qt/example/doric/widget/flex/FlexLayoutService.h
Normal file
29
doric-Qt/example/doric/widget/flex/FlexLayoutService.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef FLEXLAYOUTSERVICE_H
|
||||
#define FLEXLAYOUTSERVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlContext>
|
||||
#include <QVariant>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "FlexLayoutConfig.h"
|
||||
#include "FlexLayout.h"
|
||||
|
||||
#include "yoga/Yoga.h"
|
||||
|
||||
class FlexLayoutService : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
FlexLayoutConfig *config;
|
||||
|
||||
public:
|
||||
explicit FlexLayoutService(QObject *parent = nullptr);
|
||||
virtual ~FlexLayoutService();
|
||||
public slots:
|
||||
QVariant createConfig();
|
||||
QVariant createNode();
|
||||
QVariant createNode(QVariant config);
|
||||
void collectGarbage(QVariant rootNode);
|
||||
};
|
||||
|
||||
#endif // FLEXLAYOUTSERVICE_H
|
Reference in New Issue
Block a user