add modal plugin interface; optimize layouts code

This commit is contained in:
王劲鹏 2021-04-20 11:46:56 +08:00 committed by osborn
parent 8d04d41b19
commit f488f023fa
6 changed files with 38 additions and 14 deletions

View File

@ -1,6 +1,8 @@
#include "DoricRegistry.h" #include "DoricRegistry.h"
#include "plugin/DoricModalPlugin.h"
#include "plugin/DoricShaderPlugin.h" #include "plugin/DoricShaderPlugin.h"
#include "shader/DoricHLayoutNode.h" #include "shader/DoricHLayoutNode.h"
#include "shader/DoricRootNode.h" #include "shader/DoricRootNode.h"
#include "shader/DoricScrollerNode.h" #include "shader/DoricScrollerNode.h"
@ -10,6 +12,7 @@
DoricRegistry::DoricRegistry() { DoricRegistry::DoricRegistry() {
registerNativePlugin<DoricShaderPlugin>("shader"); registerNativePlugin<DoricShaderPlugin>("shader");
registerNativePlugin<DoricModalPlugin>("modal");
registerViewNode<DoricRootNode>("Root"); registerViewNode<DoricRootNode>("Root");
registerViewNode<DoricStackNode>("Stack"); registerViewNode<DoricStackNode>("Stack");

View File

@ -34,6 +34,7 @@ SOURCES += \
engine/v8/JSValueHelper.cpp \ engine/v8/JSValueHelper.cpp \
engine/v8/V8Executor.cpp \ engine/v8/V8Executor.cpp \
main.cpp \ main.cpp \
plugin/DoricModalPlugin.cpp \
plugin/DoricShaderPlugin.cpp \ plugin/DoricShaderPlugin.cpp \
shader/DoricGroupNode.cpp \ shader/DoricGroupNode.cpp \
shader/DoricHLayoutNode.cpp \ shader/DoricHLayoutNode.cpp \
@ -100,6 +101,7 @@ HEADERS += \
engine/native/NativeExecutor.h \ engine/native/NativeExecutor.h \
engine/v8/JSValueHelper.h \ engine/v8/JSValueHelper.h \
engine/v8/V8Executor.h \ engine/v8/V8Executor.h \
plugin/DoricModalPlugin.h \
plugin/DoricNativePlugin.h \ plugin/DoricNativePlugin.h \
plugin/DoricShaderPlugin.h \ plugin/DoricShaderPlugin.h \
shader/DoricGroupNode.h \ shader/DoricGroupNode.h \

View File

@ -0,0 +1,5 @@
#include "DoricModalPlugin.h"
void DoricModalPlugin::toast(QString jsValueString, QString callbackId) {
qDebug() << "toast";
}

View File

@ -0,0 +1,14 @@
#ifndef DORICMODALPLUGIN_H
#define DORICMODALPLUGIN_H
#include "DoricNativePlugin.h"
class DoricModalPlugin : public DoricNativePlugin {
Q_OBJECT
public:
using DoricNativePlugin::DoricNativePlugin;
Q_INVOKABLE void toast(QString jsValueString, QString callbackId);
};
#endif // DORICMODALPLUGIN_H

View File

@ -1,9 +1,6 @@
#ifndef SHADERPLUGIN_H #ifndef SHADERPLUGIN_H
#define SHADERPLUGIN_H #define SHADERPLUGIN_H
#include <QJSValue>
#include <QObject>
#include "DoricNativePlugin.h" #include "DoricNativePlugin.h"
class DoricShaderPlugin : public DoricNativePlugin { class DoricShaderPlugin : public DoricNativePlugin {

View File

@ -224,31 +224,34 @@ void DoricLayouts::measureContent(QSizeF targetSize) {
void DoricLayouts::measureUndefinedContent(QSizeF targetSize) { void DoricLayouts::measureUndefinedContent(QSizeF targetSize) {
// begin size that fits // begin size that fits
qreal width = this->view->width(); QSizeF measuredSize;
qreal height = this->view->height();
if (tag == "Scroller") { if (tag == "Scroller") {
QObject *object = QObject *object =
(QObject *)(this->view->property("wrapper").toULongLong()); (QObject *)(this->view->property("wrapper").toULongLong());
DoricScrollerNode *viewNode = dynamic_cast<DoricScrollerNode *>(object); DoricScrollerNode *viewNode = dynamic_cast<DoricScrollerNode *>(object);
QSizeF measuredSize = viewNode->sizeThatFits(targetSize); measuredSize = viewNode->sizeThatFits(targetSize);
width = measuredSize.width();
height = measuredSize.height();
} else { } else {
if (width > targetSize.width()) { qreal actualWidth = this->view->width();
width = targetSize.width(); qreal actualHeight = this->view->height();
if (actualWidth > targetSize.width()) {
actualWidth = targetSize.width();
} }
if (height > targetSize.height()) { if (actualHeight > targetSize.height()) {
height = targetSize.height(); actualHeight = targetSize.height();
} }
measuredSize = QSizeF(actualWidth, actualHeight);
} }
// end size that fits // end size that fits
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) { if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
setMeasuredWidth(width + this->paddingLeft + this->paddingRight); setMeasuredWidth(measuredSize.width() + this->paddingLeft +
this->paddingRight);
} }
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) { if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
setMeasuredHeight(height + this->paddingTop + this->paddingBottom); setMeasuredHeight(measuredSize.height() + this->paddingTop +
this->paddingBottom);
} }
} }
void DoricLayouts::measureStackContent(QSizeF targetSize) { void DoricLayouts::measureStackContent(QSizeF targetSize) {