split project with app & doric module
This commit is contained in:
38
doric-Qt/example/doric/utils/DoricConstant.cpp
Normal file
38
doric-Qt/example/doric/utils/DoricConstant.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "DoricConstant.h"
|
||||
|
||||
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
|
||||
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.js";
|
||||
const QString DoricConstant::DORIC_MODULE_LIB = "doric";
|
||||
|
||||
const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";
|
||||
const QString DoricConstant::INJECT_LOG = "nativeLog";
|
||||
const QString DoricConstant::INJECT_EMPTY = "nativeEmpty";
|
||||
const QString DoricConstant::INJECT_REQUIRE = "nativeRequire";
|
||||
const QString DoricConstant::INJECT_TIMER_SET = "nativeSetTimer";
|
||||
const QString DoricConstant::INJECT_TIMER_CLEAR = "nativeClearTimer";
|
||||
const QString DoricConstant::INJECT_BRIDGE = "nativeBridge";
|
||||
|
||||
const QString DoricConstant::TEMPLATE_CONTEXT_CREATE =
|
||||
QString("Reflect.apply(") +
|
||||
"function(doric,context,Entry,require,exports){" + "\n" + "%s1" + "\n" +
|
||||
"},undefined,[" + "undefined," + "doric.jsObtainContext(\"%s2\")," +
|
||||
"doric.jsObtainEntry(\"%s3\")," + "doric.__require__" + ",{}" + "])";
|
||||
const QString DoricConstant::TEMPLATE_MODULE =
|
||||
QString("Reflect.apply(doric.jsRegisterModule,this,[") + "\"%s1\"," +
|
||||
"Reflect.apply(function(__module){" + "(function(module,exports,require){" +
|
||||
"\n" + "%s2" + "\n" + "})(__module,__module.exports,doric.__require__);" +
|
||||
"\nreturn __module.exports;" + "},this,[{exports:{}}])" + "])";
|
||||
const QString DoricConstant::TEMPLATE_CONTEXT_DESTROY =
|
||||
QString("doric.jsReleaseContext(\"%s\")");
|
||||
|
||||
const QString DoricConstant::GLOBAL_DORIC = "doric";
|
||||
const QString DoricConstant::DORIC_CONTEXT_INVOKE = "jsCallEntityMethod";
|
||||
const QString DoricConstant::DORIC_TIMER_CALLBACK = "jsCallbackTimer";
|
||||
const QString DoricConstant::DORIC_BRIDGE_RESOLVE = "jsCallResolve";
|
||||
const QString DoricConstant::DORIC_BRIDGE_REJECT = "jsCallReject";
|
||||
|
||||
const QString DoricConstant::DORIC_ENTITY_RESPONSE = "__response__";
|
||||
const QString DoricConstant::DORIC_ENTITY_INIT = "__init__";
|
||||
const QString DoricConstant::DORIC_ENTITY_CREATE = "__onCreate__";
|
||||
const QString DoricConstant::DORIC_ENTITY_BUILD = "__build__";
|
||||
const QString DoricConstant::DORIC_ENTITY_DESTROY = "__onDestroy__";
|
38
doric-Qt/example/doric/utils/DoricConstant.h
Normal file
38
doric-Qt/example/doric/utils/DoricConstant.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef CONSTANT_H
|
||||
#define CONSTANT_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class DoricConstant {
|
||||
|
||||
public:
|
||||
static const QString DORIC_BUNDLE_SANDBOX;
|
||||
static const QString DORIC_BUNDLE_LIB;
|
||||
static const QString DORIC_MODULE_LIB;
|
||||
|
||||
static const QString INJECT_ENVIRONMENT;
|
||||
static const QString INJECT_LOG;
|
||||
static const QString INJECT_EMPTY;
|
||||
static const QString INJECT_REQUIRE;
|
||||
static const QString INJECT_TIMER_SET;
|
||||
static const QString INJECT_TIMER_CLEAR;
|
||||
static const QString INJECT_BRIDGE;
|
||||
|
||||
static const QString TEMPLATE_CONTEXT_CREATE;
|
||||
static const QString TEMPLATE_MODULE;
|
||||
static const QString TEMPLATE_CONTEXT_DESTROY;
|
||||
|
||||
static const QString GLOBAL_DORIC;
|
||||
static const QString DORIC_CONTEXT_INVOKE;
|
||||
static const QString DORIC_TIMER_CALLBACK;
|
||||
static const QString DORIC_BRIDGE_RESOLVE;
|
||||
static const QString DORIC_BRIDGE_REJECT;
|
||||
|
||||
static const QString DORIC_ENTITY_RESPONSE;
|
||||
static const QString DORIC_ENTITY_CREATE;
|
||||
static const QString DORIC_ENTITY_INIT;
|
||||
static const QString DORIC_ENTITY_BUILD;
|
||||
static const QString DORIC_ENTITY_DESTROY;
|
||||
};
|
||||
|
||||
#endif // CONSTANT_H
|
9
doric-Qt/example/doric/utils/DoricContextHolder.cpp
Normal file
9
doric-Qt/example/doric/utils/DoricContextHolder.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "DoricContextHolder.h"
|
||||
|
||||
DoricContextHolder::DoricContextHolder(QObject *parent) { mContext = NULL; }
|
||||
|
||||
void DoricContextHolder::setContext(DoricContext *context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
DoricContext *DoricContextHolder::getContext() { return mContext; }
|
18
doric-Qt/example/doric/utils/DoricContextHolder.h
Normal file
18
doric-Qt/example/doric/utils/DoricContextHolder.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef DORICCONTEXTHOLDER_H
|
||||
#define DORICCONTEXTHOLDER_H
|
||||
|
||||
#include "../DoricContext.h"
|
||||
|
||||
class DoricContextHolder : public QObject {
|
||||
protected:
|
||||
DoricContext *mContext = NULL;
|
||||
|
||||
public:
|
||||
explicit DoricContextHolder(QObject *parent = nullptr);
|
||||
|
||||
void setContext(DoricContext *context);
|
||||
|
||||
DoricContext *getContext();
|
||||
};
|
||||
|
||||
#endif // DORICCONTEXTHOLDER_H
|
32
doric-Qt/example/doric/utils/DoricCountDownLatch.h
Normal file
32
doric-Qt/example/doric/utils/DoricCountDownLatch.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef COUNTDOWNLATCH_H
|
||||
#define COUNTDOWNLATCH_H
|
||||
|
||||
#include <QSemaphore>
|
||||
#include <climits>
|
||||
|
||||
class DoricCountDownLatch {
|
||||
Q_DISABLE_COPY(DoricCountDownLatch)
|
||||
QSemaphore m_sem{INT_MAX};
|
||||
|
||||
public:
|
||||
DoricCountDownLatch() {}
|
||||
~DoricCountDownLatch() {
|
||||
m_sem.acquire(INT_MAX);
|
||||
m_sem.release(INT_MAX);
|
||||
}
|
||||
class Locker {
|
||||
DoricCountDownLatch *sem;
|
||||
|
||||
public:
|
||||
Locker(const Locker &other) : sem{other.sem} { sem->m_sem.acquire(); }
|
||||
Locker(Locker &&other) : sem{other.sem} { other.sem = nullptr; }
|
||||
Locker(DoricCountDownLatch *sem) : sem{sem} { sem->m_sem.acquire(); }
|
||||
~Locker() {
|
||||
if (sem)
|
||||
sem->m_sem.release();
|
||||
}
|
||||
};
|
||||
Locker lock() { return Locker{this}; }
|
||||
};
|
||||
|
||||
#endif // COUNTDOWNLATCH_H
|
68
doric-Qt/example/doric/utils/DoricDialogBridge.cpp
Normal file
68
doric-Qt/example/doric/utils/DoricDialogBridge.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "DoricDialogBridge.h"
|
||||
#include "plugin/DoricModalPlugin.h"
|
||||
|
||||
#include <QQuickWindow>
|
||||
|
||||
DoricDialogBridge::DoricDialogBridge(QObject *parent) : QObject(parent) {}
|
||||
|
||||
void DoricDialogBridge::onAccepted(QString windowPointer, QString pluginPointer,
|
||||
QString callbackId) {
|
||||
{
|
||||
QObject *object = (QObject *)(windowPointer.toULongLong());
|
||||
QQuickWindow *window = dynamic_cast<QQuickWindow *>(object);
|
||||
window->deleteLater();
|
||||
}
|
||||
|
||||
{
|
||||
QObject *object = (QObject *)(pluginPointer.toULongLong());
|
||||
DoricModalPlugin *modalPlugin = dynamic_cast<DoricModalPlugin *>(object);
|
||||
modalPlugin->onAccepted(callbackId);
|
||||
}
|
||||
}
|
||||
|
||||
void DoricDialogBridge::onRejected(QString windowPointer, QString pluginPointer,
|
||||
QString callbackId) {
|
||||
{
|
||||
QObject *object = (QObject *)(windowPointer.toULongLong());
|
||||
QQuickWindow *window = dynamic_cast<QQuickWindow *>(object);
|
||||
window->deleteLater();
|
||||
}
|
||||
|
||||
{
|
||||
QObject *object = (QObject *)(pluginPointer.toULongLong());
|
||||
DoricModalPlugin *modalPlugin = dynamic_cast<DoricModalPlugin *>(object);
|
||||
modalPlugin->onRejected(callbackId);
|
||||
}
|
||||
}
|
||||
|
||||
void DoricDialogBridge::onAcceptedWithInput(QString windowPointer,
|
||||
QString pluginPointer,
|
||||
QString callbackId, QString input) {
|
||||
{
|
||||
QObject *object = (QObject *)(windowPointer.toULongLong());
|
||||
QQuickWindow *window = dynamic_cast<QQuickWindow *>(object);
|
||||
window->deleteLater();
|
||||
}
|
||||
|
||||
{
|
||||
QObject *object = (QObject *)(pluginPointer.toULongLong());
|
||||
DoricModalPlugin *modalPlugin = dynamic_cast<DoricModalPlugin *>(object);
|
||||
modalPlugin->onAcceptedWithInput(callbackId, input);
|
||||
}
|
||||
}
|
||||
|
||||
void DoricDialogBridge::onRejectedWithInput(QString windowPointer,
|
||||
QString pluginPointer,
|
||||
QString callbackId, QString input) {
|
||||
{
|
||||
QObject *object = (QObject *)(windowPointer.toULongLong());
|
||||
QQuickWindow *window = dynamic_cast<QQuickWindow *>(object);
|
||||
window->deleteLater();
|
||||
}
|
||||
|
||||
{
|
||||
QObject *object = (QObject *)(pluginPointer.toULongLong());
|
||||
DoricModalPlugin *modalPlugin = dynamic_cast<DoricModalPlugin *>(object);
|
||||
modalPlugin->onRejectedWithInput(callbackId, input);
|
||||
}
|
||||
}
|
28
doric-Qt/example/doric/utils/DoricDialogBridge.h
Normal file
28
doric-Qt/example/doric/utils/DoricDialogBridge.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef DORICDIALOGBRIDGE_H
|
||||
#define DORICDIALOGBRIDGE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class DoricDialogBridge : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DoricDialogBridge(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onAccepted(QString windowPointer, QString pluginPointer,
|
||||
QString callbackId);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onAcceptedWithInput(QString windowPointer, QString pluginPointer,
|
||||
QString callbackId, QString input);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onRejected(QString windowPointer, QString pluginPointer,
|
||||
QString callbackId);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onRejectedWithInput(QString windowPointer, QString pluginPointer,
|
||||
QString callbackId, QString input);
|
||||
};
|
||||
|
||||
#endif // DORICDIALOGBRIDGE_H
|
20
doric-Qt/example/doric/utils/DoricImageBridge.cpp
Normal file
20
doric-Qt/example/doric/utils/DoricImageBridge.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "DoricImageBridge.h"
|
||||
#include "shader/DoricImageNode.h"
|
||||
|
||||
DoricImageBridge::DoricImageBridge(QObject *parent) : QObject(parent) {}
|
||||
|
||||
void DoricImageBridge::onNull(QString pointer) {}
|
||||
|
||||
void DoricImageBridge::onReady(QString pointer) {
|
||||
QObject *object = (QObject *)(pointer.toULongLong());
|
||||
DoricImageNode *imageNode = dynamic_cast<DoricImageNode *>(object);
|
||||
imageNode->onReady();
|
||||
}
|
||||
|
||||
void DoricImageBridge::onLoading(QString pointer) {}
|
||||
|
||||
void DoricImageBridge::onError(QString pointer) {
|
||||
QObject *object = (QObject *)(pointer.toULongLong());
|
||||
DoricImageNode *imageNode = dynamic_cast<DoricImageNode *>(object);
|
||||
imageNode->onError();
|
||||
}
|
24
doric-Qt/example/doric/utils/DoricImageBridge.h
Normal file
24
doric-Qt/example/doric/utils/DoricImageBridge.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef DORICIMAGEBRIDGE_H
|
||||
#define DORICIMAGEBRIDGE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class DoricImageBridge : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DoricImageBridge(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onNull(QString pointer);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onReady(QString pointer);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onLoading(QString pointer);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onError(QString pointer);
|
||||
};
|
||||
|
||||
#endif // DORICIMAGEBRIDGE_H
|
752
doric-Qt/example/doric/utils/DoricLayouts.cpp
Normal file
752
doric-Qt/example/doric/utils/DoricLayouts.cpp
Normal file
@@ -0,0 +1,752 @@
|
||||
#include "DoricLayouts.h"
|
||||
#include "shader/DoricScrollerNode.h"
|
||||
|
||||
DoricLayouts::DoricLayouts(QObject *parent) : QObject(parent) {
|
||||
this->widthSpec = DoricLayoutSpec::DoricLayoutJust;
|
||||
this->heightSpec = DoricLayoutSpec::DoricLayoutJust;
|
||||
|
||||
this->alignment = 0;
|
||||
this->gravity = 0;
|
||||
|
||||
this->width = 0;
|
||||
this->height = 0;
|
||||
|
||||
this->spacing = 0;
|
||||
|
||||
this->marginBottom = 0;
|
||||
this->marginTop = 0;
|
||||
this->marginLeft = 0;
|
||||
this->marginRight = 0;
|
||||
|
||||
this->paddingLeft = 0;
|
||||
this->paddingRight = 0;
|
||||
this->paddingBottom = 0;
|
||||
this->paddingTop = 0;
|
||||
|
||||
this->weight = 0;
|
||||
|
||||
this->layoutType = DoricLayoutType::DoricUndefined;
|
||||
|
||||
this->disabled = false;
|
||||
|
||||
this->maxWidth = INT_MAX;
|
||||
this->maxHeight = INT_MAX;
|
||||
this->minWidth = 0;
|
||||
this->minHeight = 0;
|
||||
|
||||
this->measuredWidth = 0;
|
||||
this->measuredHeight = 0;
|
||||
|
||||
this->measuredX = 0;
|
||||
this->measuredY = 0;
|
||||
|
||||
this->undefined = false;
|
||||
|
||||
this->contentWidth = 0;
|
||||
this->contentHeight = 0;
|
||||
}
|
||||
|
||||
void DoricLayouts::setWidthSpec(int widthSpec) { this->widthSpec = widthSpec; }
|
||||
void DoricLayouts::setHeightSpec(int heightSpec) {
|
||||
this->heightSpec = heightSpec;
|
||||
}
|
||||
|
||||
void DoricLayouts::setAlignment(int alignment) { this->alignment = alignment; }
|
||||
|
||||
void DoricLayouts::setGravity(int gravity) { this->gravity = gravity; }
|
||||
|
||||
void DoricLayouts::setWidth(qreal width) { this->width = width; }
|
||||
void DoricLayouts::setHeight(qreal height) { this->height = height; }
|
||||
|
||||
void DoricLayouts::setSpacing(qreal spacing) { this->spacing = spacing; }
|
||||
|
||||
void DoricLayouts::setMarginLeft(qreal marginLeft) {
|
||||
this->marginLeft = marginLeft;
|
||||
}
|
||||
void DoricLayouts::setMarginTop(qreal marginTop) {
|
||||
this->marginTop = marginTop;
|
||||
}
|
||||
void DoricLayouts::setMarginRight(qreal marginRight) {
|
||||
this->marginRight = marginRight;
|
||||
}
|
||||
void DoricLayouts::setMarginBottom(qreal marginBottom) {
|
||||
this->marginBottom = marginBottom;
|
||||
}
|
||||
|
||||
void DoricLayouts::setPaddingLeft(qreal paddingLeft) {
|
||||
this->paddingLeft = paddingLeft;
|
||||
}
|
||||
void DoricLayouts::setPaddingTop(qreal paddingTop) {
|
||||
this->paddingTop = paddingTop;
|
||||
}
|
||||
void DoricLayouts::setPaddingRight(qreal paddingRight) {
|
||||
this->paddingRight = paddingRight;
|
||||
}
|
||||
void DoricLayouts::setPaddingBottom(qreal paddingBottom) {
|
||||
this->paddingBottom = paddingBottom;
|
||||
}
|
||||
|
||||
void DoricLayouts::setWeight(int weight) { this->weight = weight; }
|
||||
|
||||
void DoricLayouts::setView(QQuickItem *view) {
|
||||
this->view = view;
|
||||
this->setParent(view);
|
||||
this->tag = view->property("tag").toString();
|
||||
}
|
||||
|
||||
void DoricLayouts::setLayoutType(int layoutType) {
|
||||
this->layoutType = layoutType;
|
||||
}
|
||||
|
||||
void DoricLayouts::setDisabled(bool disabled) { this->disabled = disabled; }
|
||||
|
||||
void DoricLayouts::setMaxWidth(qreal maxWidth) { this->maxWidth = maxWidth; }
|
||||
void DoricLayouts::setMaxHeight(qreal maxHeight) {
|
||||
this->maxHeight = maxHeight;
|
||||
}
|
||||
void DoricLayouts::setMinWidth(qreal minWidth) { this->minWidth = minWidth; }
|
||||
void DoricLayouts::setMinHeight(qreal minHeight) {
|
||||
this->minHeight = minHeight;
|
||||
}
|
||||
|
||||
void DoricLayouts::apply(QSizeF frameSize) {
|
||||
this->resolved = false;
|
||||
|
||||
this->measure(frameSize);
|
||||
this->setFrame();
|
||||
|
||||
this->resolved = true;
|
||||
}
|
||||
|
||||
void DoricLayouts::apply() {
|
||||
this->apply(QSizeF(this->view->width(), this->view->height()));
|
||||
}
|
||||
|
||||
void DoricLayouts::measure(QSizeF targetSize) {
|
||||
this->measureSelf(targetSize);
|
||||
this->layout();
|
||||
}
|
||||
|
||||
void DoricLayouts::measureSelf(QSizeF targetSize) {
|
||||
// measure width
|
||||
qreal width;
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
QQuickItem *parent = this->view->parentItem();
|
||||
if (parent == nullptr) {
|
||||
// incase parent is scroller
|
||||
width = targetSize.width();
|
||||
setMeasuredWidth(targetSize.width());
|
||||
} else {
|
||||
DoricLayouts *parentDoricLayout =
|
||||
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
||||
if (parentDoricLayout != nullptr &&
|
||||
parentDoricLayout->layoutType == DoricLayoutType::DoricHLayout &&
|
||||
this->weight > 0) {
|
||||
width = 0;
|
||||
setMeasuredWidth(0);
|
||||
} else {
|
||||
width = targetSize.width();
|
||||
setMeasuredWidth(targetSize.width());
|
||||
}
|
||||
}
|
||||
} else if (this->widthSpec == DoricLayoutSpec::DoricLayoutJust) {
|
||||
width = this->width;
|
||||
setMeasuredWidth(this->width);
|
||||
} else {
|
||||
width = targetSize.width();
|
||||
}
|
||||
|
||||
// measure height
|
||||
qreal height;
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
QQuickItem *parent = this->view->parentItem();
|
||||
if (parent == nullptr) {
|
||||
// incase parent is scroller
|
||||
height = targetSize.height();
|
||||
setMeasuredHeight(targetSize.height());
|
||||
} else {
|
||||
DoricLayouts *parentDoricLayout =
|
||||
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
||||
if (parentDoricLayout != nullptr &&
|
||||
parentDoricLayout->layoutType == DoricLayoutType::DoricVLayout &&
|
||||
this->weight > 0) {
|
||||
height = 0;
|
||||
setMeasuredHeight(0);
|
||||
} else {
|
||||
height = targetSize.height();
|
||||
setMeasuredHeight(targetSize.height());
|
||||
}
|
||||
}
|
||||
|
||||
} else if (this->heightSpec == DoricLayoutSpec::DoricLayoutJust) {
|
||||
height = this->height;
|
||||
setMeasuredHeight(this->height);
|
||||
} else {
|
||||
height = targetSize.height();
|
||||
}
|
||||
|
||||
// measure content
|
||||
this->measureContent(QSizeF(width - this->paddingLeft - this->paddingRight,
|
||||
height - this->paddingTop - this->paddingBottom));
|
||||
|
||||
if (this->restrainSize()) {
|
||||
this->measureContent(
|
||||
QSizeF(this->measuredWidth - this->paddingLeft - this->paddingRight,
|
||||
this->measuredHeight - this->paddingTop - this->paddingBottom));
|
||||
}
|
||||
this->restrainSize();
|
||||
}
|
||||
|
||||
void DoricLayouts::measureContent(QSizeF targetSize) {
|
||||
qCritical() << "measureContent: " << tag << this->view->property("uuid");
|
||||
switch (this->layoutType) {
|
||||
case DoricLayoutType::DoricStack: {
|
||||
this->measureStackContent(targetSize);
|
||||
break;
|
||||
}
|
||||
case DoricLayoutType::DoricVLayout: {
|
||||
this->measureVLayoutContent(targetSize);
|
||||
break;
|
||||
}
|
||||
case DoricLayoutType::DoricHLayout: {
|
||||
this->measureHLayoutContent(targetSize);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
this->measureUndefinedContent(targetSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QQuickItem *parent = this->view->parentItem();
|
||||
if (parent != nullptr) {
|
||||
DoricLayouts *parentDoricLayout =
|
||||
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
||||
if (parentDoricLayout != nullptr) {
|
||||
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
||||
parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
setMeasuredWidth(targetSize.width());
|
||||
}
|
||||
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
||||
parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
setMeasuredHeight(targetSize.height());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoricLayouts::measureUndefinedContent(QSizeF targetSize) {
|
||||
// begin size that fits
|
||||
QSizeF measuredSize;
|
||||
|
||||
if (tag == "Scroller") {
|
||||
QObject *object =
|
||||
(QObject *)(this->view->property("wrapper").toULongLong());
|
||||
DoricScrollerNode *viewNode = dynamic_cast<DoricScrollerNode *>(object);
|
||||
measuredSize = viewNode->sizeThatFits(targetSize);
|
||||
} else {
|
||||
qreal actualWidth = this->view->width();
|
||||
qreal actualHeight = this->view->height();
|
||||
|
||||
measuredSize = QSizeF(actualWidth, actualHeight);
|
||||
}
|
||||
// end size that fits
|
||||
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredWidth(measuredSize.width() + this->paddingLeft +
|
||||
this->paddingRight);
|
||||
}
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredHeight(measuredSize.height() + this->paddingTop +
|
||||
this->paddingBottom);
|
||||
}
|
||||
}
|
||||
void DoricLayouts::measureStackContent(QSizeF targetSize) {
|
||||
qreal contentWidth = 0, contentHeight = 0;
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
layout->measure(layout->removeMargin(targetSize));
|
||||
contentWidth = qMax(contentWidth, layout->takenWidth());
|
||||
contentHeight = qMax(contentHeight, layout->takenHeight());
|
||||
}
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
||||
}
|
||||
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
||||
}
|
||||
|
||||
this->contentWidth = contentWidth;
|
||||
this->contentHeight = contentHeight;
|
||||
}
|
||||
void DoricLayouts::measureVLayoutContent(QSizeF targetSize) {
|
||||
qreal contentWidth = 0, contentHeight = 0, contentWeight = 0;
|
||||
bool had = false;
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
had = true;
|
||||
|
||||
layout->measure(layout->removeMargin(
|
||||
QSizeF(targetSize.width(), targetSize.height() - contentHeight)));
|
||||
contentWidth = qMax(contentWidth, layout->takenWidth());
|
||||
contentHeight += layout->takenHeight() + this->spacing;
|
||||
contentWeight += layout->weight;
|
||||
}
|
||||
|
||||
if (had) {
|
||||
contentHeight -= this->spacing;
|
||||
}
|
||||
|
||||
if (contentWeight > 0) {
|
||||
qreal remaining = targetSize.height() - contentHeight;
|
||||
contentWidth = 0;
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
qreal measuredHeight =
|
||||
layout->measuredHeight + remaining / contentWeight * layout->weight;
|
||||
layout->measuredHeight = measuredHeight;
|
||||
// Need Remeasure
|
||||
layout->measureContent(QSizeF(
|
||||
layout->measuredWidth - layout->paddingLeft - layout->paddingRight,
|
||||
measuredHeight - layout->paddingTop - layout->paddingBottom));
|
||||
layout->measuredHeight = measuredHeight;
|
||||
contentWidth = qMax(contentWidth, layout->takenWidth());
|
||||
}
|
||||
contentHeight = targetSize.height();
|
||||
}
|
||||
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
||||
}
|
||||
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
||||
}
|
||||
|
||||
this->contentWidth = contentWidth;
|
||||
this->contentHeight = contentHeight;
|
||||
}
|
||||
void DoricLayouts::measureHLayoutContent(QSizeF targetSize) {
|
||||
qreal contentWidth = 0, contentHeight = 0, contentWeight = 0;
|
||||
bool had = false;
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
had = true;
|
||||
|
||||
layout->measure(layout->removeMargin(
|
||||
QSizeF(targetSize.width() - contentWidth, targetSize.height())));
|
||||
contentWidth += layout->takenWidth() + this->spacing;
|
||||
contentHeight = qMax(contentHeight, layout->takenHeight());
|
||||
contentWeight += layout->weight;
|
||||
}
|
||||
|
||||
if (had) {
|
||||
contentWidth -= this->spacing;
|
||||
}
|
||||
|
||||
if (contentWeight > 0) {
|
||||
qreal remaining = targetSize.width() - contentWidth;
|
||||
contentHeight = 0;
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
qreal measuredWidth =
|
||||
layout->measuredWidth + remaining / contentWeight * layout->weight;
|
||||
layout->measuredWidth = measuredWidth;
|
||||
// Need Remeasure
|
||||
layout->measureContent(QSizeF(
|
||||
measuredWidth - layout->paddingLeft - layout->paddingRight,
|
||||
layout->measuredHeight - layout->paddingTop - layout->paddingBottom));
|
||||
layout->measuredWidth = measuredWidth;
|
||||
contentHeight = qMax(contentHeight, layout->takenHeight());
|
||||
}
|
||||
contentWidth = targetSize.width();
|
||||
}
|
||||
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
||||
}
|
||||
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
||||
}
|
||||
|
||||
this->contentWidth = contentWidth;
|
||||
this->contentHeight = contentHeight;
|
||||
}
|
||||
|
||||
qreal DoricLayouts::takenWidth() {
|
||||
return this->measuredWidth + this->marginLeft + this->marginRight;
|
||||
}
|
||||
qreal DoricLayouts::takenHeight() {
|
||||
return this->measuredHeight + this->marginTop + this->marginBottom;
|
||||
}
|
||||
QSizeF DoricLayouts::removeMargin(QSizeF targetSize) {
|
||||
return QSizeF(targetSize.width() - this->marginLeft - this->marginRight,
|
||||
targetSize.height() - this->marginTop - this->marginBottom);
|
||||
}
|
||||
|
||||
bool DoricLayouts::restrainSize() {
|
||||
bool needRemeasure = false;
|
||||
if (this->measuredWidth > this->maxWidth) {
|
||||
setMeasuredWidth(this->maxWidth);
|
||||
needRemeasure = true;
|
||||
}
|
||||
if (this->measuredHeight > this->maxHeight) {
|
||||
setMeasuredHeight(this->maxHeight);
|
||||
needRemeasure = true;
|
||||
}
|
||||
if (this->measuredWidth < this->minWidth) {
|
||||
setMeasuredWidth(this->minWidth);
|
||||
needRemeasure = true;
|
||||
}
|
||||
if (this->measuredHeight < this->minHeight) {
|
||||
setMeasuredHeight(this->minHeight);
|
||||
needRemeasure = true;
|
||||
}
|
||||
return needRemeasure;
|
||||
}
|
||||
|
||||
void DoricLayouts::layout() {
|
||||
switch (this->layoutType) {
|
||||
case DoricLayoutType::DoricStack: {
|
||||
this->layoutStack();
|
||||
break;
|
||||
}
|
||||
case DoricLayoutType::DoricVLayout: {
|
||||
this->layoutVLayout();
|
||||
break;
|
||||
}
|
||||
case DoricLayoutType::DoricHLayout: {
|
||||
this->layoutHLayout();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoricLayouts::setFrame() {
|
||||
if (this->layoutType != DoricLayoutType::DoricUndefined) {
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
layout->setFrame();
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "DoricLayouts setProperty: " << tag
|
||||
<< this->view->property("uuid")
|
||||
<< " measuredWidth: " << this->measuredWidth
|
||||
<< " measuredHeight: " << this->measuredHeight
|
||||
<< " width: " << this->view->width()
|
||||
<< " height: " << this->view->height()
|
||||
<< " measuredX: " << this->measuredX
|
||||
<< " measuredY: " << this->measuredY;
|
||||
|
||||
if (qAbs(this->measuredWidth - this->view->width()) >= 0.00001f)
|
||||
this->view->setProperty("width", this->measuredWidth);
|
||||
if (qAbs(this->measuredHeight - this->view->height()) >= 0.00001f)
|
||||
this->view->setProperty("height", this->measuredHeight);
|
||||
|
||||
this->view->setProperty("x", this->measuredX);
|
||||
this->view->setProperty("y", this->measuredY);
|
||||
}
|
||||
|
||||
void DoricLayouts::layoutStack() {
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
layout->measuredWidth =
|
||||
this->measuredWidth - layout->marginLeft - layout->marginRight;
|
||||
}
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
layout->measuredHeight =
|
||||
this->measuredHeight - layout->marginTop - layout->marginBottom;
|
||||
}
|
||||
layout->layout();
|
||||
|
||||
int gravity = layout->alignment;
|
||||
if ((gravity & DoricGravity::DoricGravityLeft) ==
|
||||
DoricGravity::DoricGravityLeft) {
|
||||
layout->setMeasuredX(this->paddingLeft);
|
||||
} else if ((gravity & DoricGravity::DoricGravityRight) ==
|
||||
DoricGravity::DoricGravityRight) {
|
||||
layout->setMeasuredX(this->measuredWidth - this->paddingRight -
|
||||
layout->measuredWidth);
|
||||
} else if ((gravity & DoricGravity::DoricGravityCenterX) ==
|
||||
DoricGravity::DoricGravityCenterX) {
|
||||
layout->setMeasuredX(this->measuredWidth / 2 - layout->measuredWidth / 2);
|
||||
} else {
|
||||
if (layout->marginLeft || layout->marginRight) {
|
||||
layout->setMeasuredX(this->paddingLeft);
|
||||
} else {
|
||||
layout->setMeasuredX(0);
|
||||
}
|
||||
}
|
||||
|
||||
if ((gravity & DoricGravity::DoricGravityTop) ==
|
||||
DoricGravity::DoricGravityTop) {
|
||||
layout->setMeasuredY(this->paddingTop);
|
||||
} else if ((gravity & DoricGravity::DoricGravityBottom) ==
|
||||
DoricGravity::DoricGravityBottom) {
|
||||
layout->setMeasuredY(this->measuredHeight - this->paddingBottom -
|
||||
layout->measuredHeight);
|
||||
} else if ((gravity & DoricGravity::DoricGravityCenterY) ==
|
||||
DoricGravity::DoricGravityCenterY) {
|
||||
layout->setMeasuredY(this->measuredHeight / 2 -
|
||||
layout->measuredHeight / 2);
|
||||
} else {
|
||||
if (layout->marginTop || layout->marginBottom) {
|
||||
layout->setMeasuredY(this->paddingTop);
|
||||
} else {
|
||||
layout->setMeasuredY(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!gravity) {
|
||||
gravity = DoricGravity::DoricGravityLeft | DoricGravity::DoricGravityTop;
|
||||
}
|
||||
if (layout->marginLeft && !((gravity & DoricGravity::DoricGravityRight) ==
|
||||
DoricGravity::DoricGravityRight)) {
|
||||
layout->measuredX += layout->marginLeft;
|
||||
}
|
||||
if (layout->marginRight && !((gravity & DoricGravity::DoricGravityLeft) ==
|
||||
DoricGravity::DoricGravityLeft)) {
|
||||
layout->measuredX -= layout->marginRight;
|
||||
}
|
||||
if (layout->marginTop && !((gravity & DoricGravity::DoricGravityBottom) ==
|
||||
DoricGravity::DoricGravityBottom)) {
|
||||
layout->measuredY += layout->marginTop;
|
||||
}
|
||||
if (layout->marginBottom && !((gravity & DoricGravity::DoricGravityTop) ==
|
||||
DoricGravity::DoricGravityTop)) {
|
||||
layout->measuredY -= layout->marginBottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoricLayouts::layoutVLayout() {
|
||||
qreal yStart = this->paddingTop;
|
||||
if ((this->gravity & DoricGravity::DoricGravityTop) ==
|
||||
DoricGravity::DoricGravityTop) {
|
||||
yStart = this->paddingTop;
|
||||
} else if ((this->gravity & DoricGravity::DoricGravityBottom) ==
|
||||
DoricGravity::DoricGravityBottom) {
|
||||
yStart = this->measuredHeight - this->contentHeight - this->paddingBottom;
|
||||
} else if ((this->gravity & DoricGravity::DoricGravityCenterY) ==
|
||||
DoricGravity::DoricGravityCenterY) {
|
||||
yStart = (this->measuredHeight - this->contentHeight - this->paddingTop -
|
||||
this->paddingBottom) /
|
||||
2 +
|
||||
this->paddingTop;
|
||||
}
|
||||
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
layout->measuredWidth =
|
||||
this->measuredWidth - layout->marginLeft - layout->marginRight;
|
||||
}
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
layout->measuredHeight = this->measuredHeight - yStart -
|
||||
layout->marginTop - layout->marginBottom;
|
||||
}
|
||||
layout->layout();
|
||||
int gravity = layout->alignment | this->gravity;
|
||||
if ((gravity & DoricGravity::DoricGravityLeft) ==
|
||||
DoricGravity::DoricGravityLeft) {
|
||||
layout->setMeasuredX(this->paddingLeft);
|
||||
} else if ((gravity & DoricGravity::DoricGravityRight) ==
|
||||
DoricGravity::DoricGravityRight) {
|
||||
layout->setMeasuredX(this->measuredWidth - this->paddingRight -
|
||||
layout->measuredWidth);
|
||||
} else if ((gravity & DoricGravity::DoricGravityCenterX) ==
|
||||
DoricGravity::DoricGravityCenterX) {
|
||||
layout->setMeasuredX(this->measuredWidth / 2 - layout->measuredWidth / 2);
|
||||
} else {
|
||||
layout->setMeasuredX(this->paddingLeft);
|
||||
}
|
||||
if (!gravity) {
|
||||
gravity = DoricGravity::DoricGravityLeft;
|
||||
}
|
||||
if (layout->marginLeft && !((gravity & DoricGravity::DoricGravityRight) ==
|
||||
DoricGravity::DoricGravityRight)) {
|
||||
layout->measuredX += layout->marginLeft;
|
||||
}
|
||||
if (layout->marginRight && !((gravity & DoricGravity::DoricGravityLeft) ==
|
||||
DoricGravity::DoricGravityLeft)) {
|
||||
layout->measuredX -= layout->marginRight;
|
||||
}
|
||||
layout->setMeasuredY(yStart + layout->marginTop);
|
||||
yStart += this->spacing + layout->takenHeight();
|
||||
}
|
||||
}
|
||||
|
||||
void DoricLayouts::layoutHLayout() {
|
||||
qreal xStart = this->paddingLeft;
|
||||
if ((this->gravity & DoricGravity::DoricGravityLeft) ==
|
||||
DoricGravity::DoricGravityLeft) {
|
||||
xStart = this->paddingLeft;
|
||||
} else if ((this->gravity & DoricGravity::DoricGravityRight) ==
|
||||
DoricGravity::DoricGravityRight) {
|
||||
xStart = this->measuredWidth - this->contentWidth - this->paddingRight;
|
||||
} else if ((this->gravity & DoricGravity::DoricGravityCenterX) ==
|
||||
DoricGravity::DoricGravityCenterX) {
|
||||
xStart = (this->measuredWidth - this->contentWidth - this->paddingLeft -
|
||||
this->paddingRight) /
|
||||
2 +
|
||||
this->paddingLeft;
|
||||
}
|
||||
foreach (QQuickItem *subview, this->view->childItems()) {
|
||||
DoricLayouts *layout =
|
||||
(DoricLayouts *)(subview->property("doricLayout").toULongLong());
|
||||
if (layout == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout->disabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
layout->measuredWidth = this->measuredWidth - xStart -
|
||||
layout->marginLeft - layout->marginRight;
|
||||
}
|
||||
|
||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||
layout->measuredHeight =
|
||||
this->measuredHeight - layout->marginTop - layout->marginBottom;
|
||||
}
|
||||
|
||||
layout->layout();
|
||||
|
||||
int gravity = layout->alignment | this->gravity;
|
||||
if ((gravity & DoricGravity::DoricGravityTop) ==
|
||||
DoricGravity::DoricGravityTop) {
|
||||
layout->setMeasuredY(this->paddingTop);
|
||||
} else if ((gravity & DoricGravity::DoricGravityBottom) ==
|
||||
DoricGravity::DoricGravityBottom) {
|
||||
layout->setMeasuredY(this->measuredHeight - this->paddingBottom -
|
||||
layout->measuredHeight);
|
||||
} else if ((gravity & DoricGravity::DoricGravityCenterY) ==
|
||||
DoricGravity::DoricGravityCenterY) {
|
||||
layout->setMeasuredY(this->measuredHeight / 2 -
|
||||
layout->measuredHeight / 2);
|
||||
} else {
|
||||
layout->setMeasuredY(this->paddingTop);
|
||||
}
|
||||
if (!gravity) {
|
||||
gravity = DoricGravity::DoricGravityTop;
|
||||
}
|
||||
if (layout->marginTop && !((gravity & DoricGravity::DoricGravityBottom) ==
|
||||
DoricGravity::DoricGravityBottom)) {
|
||||
layout->measuredY += layout->marginTop;
|
||||
}
|
||||
if (layout->marginBottom && !((gravity & DoricGravity::DoricGravityTop) ==
|
||||
DoricGravity::DoricGravityTop)) {
|
||||
layout->measuredY -= layout->marginBottom;
|
||||
}
|
||||
layout->setMeasuredX(xStart + layout->marginLeft);
|
||||
xStart += this->spacing + layout->takenWidth();
|
||||
}
|
||||
}
|
||||
|
||||
// Private Section
|
||||
void DoricLayouts::setMeasuredWidth(qreal measuredWidth) {
|
||||
this->measuredWidth = measuredWidth;
|
||||
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
||||
<< " measuredWidth: " << this->measuredWidth;
|
||||
}
|
||||
|
||||
qreal DoricLayouts::getMeasuredWidth() { return this->measuredWidth; }
|
||||
|
||||
void DoricLayouts::setMeasuredHeight(qreal measuredHeight) {
|
||||
this->measuredHeight = measuredHeight;
|
||||
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
||||
<< " measuredHeight: " << this->measuredHeight;
|
||||
}
|
||||
|
||||
qreal DoricLayouts::getMeasuredHeight() { return this->measuredHeight; }
|
||||
|
||||
void DoricLayouts::setMeasuredX(qreal measuredX) {
|
||||
this->measuredX = measuredX;
|
||||
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
||||
<< " measuredX: " << this->measuredX;
|
||||
}
|
||||
|
||||
void DoricLayouts::setMeasuredY(qreal measuredY) {
|
||||
this->measuredY = measuredY;
|
||||
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
||||
<< " measuredY: " << this->measuredY;
|
||||
}
|
171
doric-Qt/example/doric/utils/DoricLayouts.h
Normal file
171
doric-Qt/example/doric/utils/DoricLayouts.h
Normal file
@@ -0,0 +1,171 @@
|
||||
#ifndef DORICLAYOUTS_H
|
||||
#define DORICLAYOUTS_H
|
||||
|
||||
#include <QQuickItem>
|
||||
|
||||
class DoricLayoutType {
|
||||
public:
|
||||
const static int DoricUndefined = 0;
|
||||
const static int DoricStack = 1;
|
||||
const static int DoricVLayout = 2;
|
||||
const static int DoricHLayout = 3;
|
||||
};
|
||||
|
||||
class DoricLayoutSpec {
|
||||
public:
|
||||
const static int DoricLayoutJust = 0;
|
||||
const static int DoricLayoutFit = 1;
|
||||
const static int DoricLayoutMost = 2;
|
||||
};
|
||||
|
||||
class DoricGravity {
|
||||
public:
|
||||
const static int DoricGravitySpecified = 1;
|
||||
const static int DoricGravityStart = 1 << 1;
|
||||
const static int DoricGravityEnd = 1 << 2;
|
||||
const static int DoricGravityShiftX = 0;
|
||||
const static int DoricGravityShiftY = 4;
|
||||
const static int DoricGravityLeft =
|
||||
(DoricGravityStart | DoricGravitySpecified) << DoricGravityShiftX;
|
||||
const static int DoricGravityRight = (DoricGravityEnd | DoricGravitySpecified)
|
||||
<< DoricGravityShiftX;
|
||||
const static int DoricGravityTop = (DoricGravityStart | DoricGravitySpecified)
|
||||
<< DoricGravityShiftY;
|
||||
const static int DoricGravityBottom =
|
||||
(DoricGravityEnd | DoricGravitySpecified) << DoricGravityShiftY;
|
||||
const static int DoricGravityCenterX = DoricGravitySpecified
|
||||
<< DoricGravityShiftX;
|
||||
const static int DoricGravityCenterY = DoricGravitySpecified
|
||||
<< DoricGravityShiftY;
|
||||
const static int DoricGravityCenter =
|
||||
DoricGravityCenterX | DoricGravityCenterY;
|
||||
};
|
||||
|
||||
class DoricLayouts : public QObject {
|
||||
public:
|
||||
explicit DoricLayouts(QObject *parent = nullptr);
|
||||
|
||||
void setWidthSpec(int widthSpec);
|
||||
void setHeightSpec(int heightSpec);
|
||||
|
||||
void setAlignment(int alignment);
|
||||
|
||||
void setGravity(int gravity);
|
||||
|
||||
void setWidth(qreal width);
|
||||
void setHeight(qreal height);
|
||||
|
||||
void setSpacing(qreal spacing);
|
||||
|
||||
void setMarginLeft(qreal marginLeft);
|
||||
void setMarginTop(qreal marginTop);
|
||||
void setMarginRight(qreal marginRight);
|
||||
void setMarginBottom(qreal marginBottom);
|
||||
|
||||
void setPaddingLeft(qreal paddingLeft);
|
||||
void setPaddingTop(qreal paddingTop);
|
||||
void setPaddingRight(qreal paddingRight);
|
||||
void setPaddingBottom(qreal paddingBottom);
|
||||
|
||||
void setWeight(int weight);
|
||||
|
||||
void setView(QQuickItem *view);
|
||||
|
||||
void setLayoutType(int layoutType);
|
||||
|
||||
void setDisabled(bool disabled);
|
||||
|
||||
void setMaxWidth(qreal maxWidth);
|
||||
void setMaxHeight(qreal maxHeight);
|
||||
void setMinWidth(qreal minWidth);
|
||||
void setMinHeight(qreal minHeight);
|
||||
|
||||
void apply(QSizeF frameSize);
|
||||
|
||||
void apply();
|
||||
|
||||
qreal getMeasuredWidth();
|
||||
qreal getMeasuredHeight();
|
||||
|
||||
private:
|
||||
QString tag;
|
||||
|
||||
int widthSpec;
|
||||
int heightSpec;
|
||||
|
||||
int alignment;
|
||||
|
||||
int gravity;
|
||||
|
||||
qreal width;
|
||||
qreal height;
|
||||
|
||||
qreal spacing;
|
||||
|
||||
qreal marginLeft;
|
||||
qreal marginTop;
|
||||
qreal marginRight;
|
||||
qreal marginBottom;
|
||||
|
||||
qreal paddingLeft;
|
||||
qreal paddingTop;
|
||||
qreal paddingRight;
|
||||
qreal paddingBottom;
|
||||
|
||||
int weight;
|
||||
|
||||
QQuickItem *view;
|
||||
|
||||
int layoutType;
|
||||
|
||||
bool disabled;
|
||||
|
||||
qreal maxWidth;
|
||||
qreal maxHeight;
|
||||
qreal minWidth;
|
||||
qreal minHeight;
|
||||
|
||||
bool resolved;
|
||||
|
||||
qreal measuredWidth;
|
||||
void setMeasuredWidth(qreal measuredWidth);
|
||||
qreal measuredHeight;
|
||||
void setMeasuredHeight(qreal measuredHeight);
|
||||
qreal measuredX;
|
||||
void setMeasuredX(qreal measuredX);
|
||||
qreal measuredY;
|
||||
void setMeasuredY(qreal measuredY);
|
||||
|
||||
bool undefined;
|
||||
|
||||
//
|
||||
qreal contentWidth;
|
||||
qreal contentHeight;
|
||||
|
||||
void measure(QSizeF targetSize);
|
||||
|
||||
void measureSelf(QSizeF targetSize);
|
||||
|
||||
void measureContent(QSizeF targetSize);
|
||||
|
||||
void measureUndefinedContent(QSizeF targetSize);
|
||||
void measureStackContent(QSizeF targetSize);
|
||||
void measureVLayoutContent(QSizeF targetSize);
|
||||
void measureHLayoutContent(QSizeF targetSize);
|
||||
|
||||
qreal takenWidth();
|
||||
qreal takenHeight();
|
||||
QSizeF removeMargin(QSizeF targetSize);
|
||||
|
||||
bool restrainSize();
|
||||
|
||||
void layout();
|
||||
|
||||
void layoutStack();
|
||||
void layoutVLayout();
|
||||
void layoutHLayout();
|
||||
|
||||
void setFrame();
|
||||
};
|
||||
|
||||
#endif // DORICLAYOUTS_H
|
10
doric-Qt/example/doric/utils/DoricMouseAreaBridge.cpp
Normal file
10
doric-Qt/example/doric/utils/DoricMouseAreaBridge.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "DoricMouseAreaBridge.h"
|
||||
#include "shader/DoricViewNode.h"
|
||||
|
||||
DoricMouseAreaBridge::DoricMouseAreaBridge(QObject *parent) : QObject(parent) {}
|
||||
|
||||
void DoricMouseAreaBridge::onClick(QString pointer) {
|
||||
QObject *object = (QObject *)(pointer.toULongLong());
|
||||
DoricViewNode *viewNode = dynamic_cast<DoricViewNode *>(object);
|
||||
viewNode->onClick();
|
||||
}
|
17
doric-Qt/example/doric/utils/DoricMouseAreaBridge.h
Normal file
17
doric-Qt/example/doric/utils/DoricMouseAreaBridge.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef DORICMOUSEAREABRIDGE_H
|
||||
#define DORICMOUSEAREABRIDGE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
class DoricMouseAreaBridge : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DoricMouseAreaBridge(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE
|
||||
void onClick(QString pointer);
|
||||
signals:
|
||||
};
|
||||
|
||||
#endif // DORICMOUSEAREABRIDGE_H
|
97
doric-Qt/example/doric/utils/DoricNetworkService.h
Normal file
97
doric-Qt/example/doric/utils/DoricNetworkService.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef DORICNETWORKSERVICE_H
|
||||
#define DORICNETWORKSERVICE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QThread>
|
||||
|
||||
class InnerTask : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QNetworkRequest httpRequest;
|
||||
QNetworkAccessManager networkAccessManager;
|
||||
|
||||
public:
|
||||
explicit InnerTask() {
|
||||
connect(this, &InnerTask::run, this, &InnerTask::innerRun);
|
||||
}
|
||||
|
||||
void innerRun(QJsonValue jsValue) {
|
||||
QString url = jsValue["url"].toString();
|
||||
QString method = jsValue["method"].toString();
|
||||
|
||||
QJsonValue headerVal = jsValue["headers"];
|
||||
QJsonValue dataVal = jsValue["data"];
|
||||
QJsonValue timeoutVal = jsValue["timeout"];
|
||||
|
||||
if (headerVal.isObject()) {
|
||||
foreach (QString key, headerVal.toObject().keys()) {
|
||||
httpRequest.setRawHeader(key.toUtf8(),
|
||||
headerVal[key].toString().toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
if (timeoutVal.isDouble()) {
|
||||
networkAccessManager.setTransferTimeout(timeoutVal.toInt());
|
||||
}
|
||||
|
||||
if (method == "get") {
|
||||
httpRequest.setUrl(QUrl(url));
|
||||
QNetworkReply *reply = networkAccessManager.get(httpRequest);
|
||||
|
||||
connect(reply, &QNetworkReply::finished, this, [this, reply] {
|
||||
int statusCode =
|
||||
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
emit response(statusCode, reply->rawHeaderList(), reply->readAll());
|
||||
} else {
|
||||
emit response(statusCode, reply->rawHeaderList(), QByteArray());
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
this->deleteLater();
|
||||
});
|
||||
}
|
||||
}
|
||||
signals:
|
||||
void run(QJsonValue jsValue);
|
||||
void response(int code, QList<QByteArray> headers, QByteArray data);
|
||||
};
|
||||
|
||||
class DoricNetworkService : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QThread thread;
|
||||
|
||||
static DoricNetworkService *local_instance;
|
||||
DoricNetworkService() {
|
||||
qDebug() << "constructor";
|
||||
thread.start();
|
||||
}
|
||||
|
||||
~DoricNetworkService() { qDebug() << "destructor"; }
|
||||
|
||||
public:
|
||||
static DoricNetworkService *getInstance() {
|
||||
static DoricNetworkService instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
QThread *getThread() { return &thread; }
|
||||
|
||||
template <typename T>
|
||||
void request(QJsonValue jsValue, QObject *receiver, T lambda) {
|
||||
InnerTask *innerTask = new InnerTask();
|
||||
innerTask->moveToThread(&thread);
|
||||
|
||||
connect(innerTask, &InnerTask::response, receiver, lambda);
|
||||
innerTask->run(jsValue);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // DORICNETWORKSERVICE_H
|
38
doric-Qt/example/doric/utils/DoricObjectFactory.h
Normal file
38
doric-Qt/example/doric/utils/DoricObjectFactory.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef OBJECTFACTORY_H
|
||||
#define OBJECTFACTORY_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QHash>
|
||||
#include <QMetaObject>
|
||||
|
||||
class DoricObjectFactory {
|
||||
public:
|
||||
template <typename T> static void registerClass(QString name) {
|
||||
constructors().insert(name, &constructorHelper<T>);
|
||||
}
|
||||
|
||||
static bool acquireClass(QString name) {
|
||||
return constructors().keys().contains(name);
|
||||
}
|
||||
|
||||
static QObject *createObject(const QString &name, QObject *parent = NULL) {
|
||||
Constructor constructor = constructors().value(name);
|
||||
if (constructor == NULL)
|
||||
return NULL;
|
||||
return (*constructor)(parent);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef QObject *(*Constructor)(QObject *parent);
|
||||
|
||||
template <typename T> static QObject *constructorHelper(QObject *parent) {
|
||||
return new T(parent);
|
||||
}
|
||||
|
||||
static QHash<QString, Constructor> &constructors() {
|
||||
static QHash<QString, Constructor> instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // OBJECTFACTORY_H
|
9
doric-Qt/example/doric/utils/DoricThreadMode.h
Normal file
9
doric-Qt/example/doric/utils/DoricThreadMode.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef DORICTHREADMODE_H
|
||||
#define DORICTHREADMODE_H
|
||||
|
||||
enum DoricThreadMode {
|
||||
UI,
|
||||
JS,
|
||||
};
|
||||
|
||||
#endif // DORICTHREADMODE_H
|
39
doric-Qt/example/doric/utils/DoricUtils.h
Normal file
39
doric-Qt/example/doric/utils/DoricUtils.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QFile>
|
||||
#include <QResource>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
|
||||
class DoricUtils {
|
||||
public:
|
||||
static QString readAssetFile(QString preffix, QString assetName) {
|
||||
QResource resource(":" + preffix + "/" + assetName);
|
||||
QFile *file = new QFile(resource.fileName());
|
||||
file->open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream in(file);
|
||||
in.setAutoDetectUnicode(true);
|
||||
QString content = in.readAll();
|
||||
file->close();
|
||||
delete file;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
template <typename Base, typename T>
|
||||
static inline bool instanceof (const T *) {
|
||||
return std::is_base_of<Base, T>::value;
|
||||
}
|
||||
|
||||
static QColor doricColor(long colorValue) {
|
||||
float a = ((colorValue >> 24) & 0xff);
|
||||
float r = ((colorValue >> 16) & 0xff);
|
||||
float g = ((colorValue >> 8) & 0xff);
|
||||
float b = ((colorValue >> 0) & 0xff);
|
||||
return QColor(r, g, b, a);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // UTILS_H
|
Reference in New Issue
Block a user