impl navbar plugin
This commit is contained in:
parent
ea8c39e0d7
commit
7f54dd42b4
@ -14,14 +14,28 @@ ApplicationWindow {
|
||||
|
||||
Rectangle {
|
||||
id: navbar
|
||||
objectName: "navbar"
|
||||
visible: false
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 44
|
||||
|
||||
Text {
|
||||
text: "Title"
|
||||
font.pixelSize: 16
|
||||
anchors.centerIn: parent
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "transparent"
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
objectName: "title"
|
||||
font.pixelSize: 16
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.centerIn: parent
|
||||
objectName: "center"
|
||||
color: "red"
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
@ -30,16 +44,15 @@ ApplicationWindow {
|
||||
Layout.preferredWidth: 10
|
||||
}
|
||||
|
||||
Image {
|
||||
Layout.preferredWidth: 24
|
||||
Layout.preferredHeight: 24
|
||||
id: name
|
||||
source: "qrc:/doric/qml/doric_icon_back.png"
|
||||
}
|
||||
RowLayout {
|
||||
objectName: "left"
|
||||
|
||||
Text {
|
||||
text: "Left"
|
||||
font.pixelSize: 16
|
||||
Image {
|
||||
Layout.preferredWidth: 24
|
||||
Layout.preferredHeight: 24
|
||||
id: name
|
||||
source: "qrc:/doric/qml/doric_icon_back.png"
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
@ -55,9 +68,8 @@ ApplicationWindow {
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Text {
|
||||
text: "Right"
|
||||
font.pixelSize: 16
|
||||
RowLayout {
|
||||
objectName: "right"
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
@ -88,7 +100,7 @@ ApplicationWindow {
|
||||
ListView {
|
||||
id: list
|
||||
width: content.width
|
||||
model: 23
|
||||
model: 24
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
|
||||
function getSource(index) : string {
|
||||
@ -118,26 +130,28 @@ ApplicationWindow {
|
||||
case 11:
|
||||
return "ModularDemo.js"
|
||||
case 12:
|
||||
return "NavigatorDemo.js"
|
||||
return "NavBarDemo.js"
|
||||
case 13:
|
||||
return "NetworkDemo.js"
|
||||
return "NavigatorDemo.js"
|
||||
case 14:
|
||||
return "NotificationDemo.js"
|
||||
return "NetworkDemo.js"
|
||||
case 15:
|
||||
return "PopoverDemo.js"
|
||||
return "NotificationDemo.js"
|
||||
case 16:
|
||||
return "ScrollerDemo.js"
|
||||
return "PopoverDemo.js"
|
||||
case 17:
|
||||
return "SimpleDemo.js"
|
||||
return "ScrollerDemo.js"
|
||||
case 18:
|
||||
return "SliderDemo.js"
|
||||
return "SimpleDemo.js"
|
||||
case 19:
|
||||
return "Snake.js"
|
||||
return "SliderDemo.js"
|
||||
case 20:
|
||||
return "StorageDemo.js"
|
||||
return "Snake.js"
|
||||
case 21:
|
||||
return "SwitchDemo.js"
|
||||
return "StorageDemo.js"
|
||||
case 22:
|
||||
return "SwitchDemo.js"
|
||||
case 23:
|
||||
return "TextDemo.js"
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
<file alias="LayoutTestDemo.js">../../../doric-demo/bundle/src/LayoutTestDemo.js</file>
|
||||
<file alias="ModalDemo.js">../../../doric-demo/bundle/src/ModalDemo.js</file>
|
||||
<file alias="ModularDemo.js">../../../doric-demo/bundle/src/ModularDemo.js</file>
|
||||
<file alias="NavBarDemo.js">../../../doric-demo/bundle/src/NavBarDemo.js</file>
|
||||
<file alias="NavigatorDemo.js">../../../doric-demo/bundle/src/NavigatorDemo.js</file>
|
||||
<file alias="NetworkDemo.js">../../../doric-demo/bundle/src/NetworkDemo.js</file>
|
||||
<file alias="NotificationDemo.js">../../../doric-demo/bundle/src/NotificationDemo.js</file>
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "DoricLibrary.h"
|
||||
|
||||
#include "plugin/DoricModalPlugin.h"
|
||||
#include "plugin/DoricNavBarPlugin.h"
|
||||
#include "plugin/DoricNavigatorPlugin.h"
|
||||
#include "plugin/DoricNetworkPlugin.h"
|
||||
#include "plugin/DoricNotificationPlugin.h"
|
||||
@ -33,6 +34,7 @@ DoricRegistry::DoricRegistry() {
|
||||
registerNativePlugin<DoricStoragePlugin>("storage");
|
||||
registerNativePlugin<DoricNotificationPlugin>("notification");
|
||||
registerNativePlugin<DoricNavigatorPlugin>("navigator");
|
||||
registerNativePlugin<DoricNavBarPlugin>("navbar");
|
||||
|
||||
registerViewNode<DoricRootNode>("Root");
|
||||
registerViewNode<DoricStackNode>("Stack");
|
||||
|
@ -39,6 +39,7 @@ SOURCES += \
|
||||
loader/DoricAssetJSLoader.cpp \
|
||||
loader/DoricJSLoaderManager.cpp \
|
||||
plugin/DoricModalPlugin.cpp \
|
||||
plugin/DoricNavBarPlugin.cpp \
|
||||
plugin/DoricNavigatorPlugin.cpp \
|
||||
plugin/DoricNetworkPlugin.cpp \
|
||||
plugin/DoricNotificationPlugin.cpp \
|
||||
@ -131,6 +132,7 @@ HEADERS += \
|
||||
loader/DoricJSLoaderManager.h \
|
||||
plugin/DoricModalPlugin.h \
|
||||
plugin/DoricNativePlugin.h \
|
||||
plugin/DoricNavBarPlugin.h \
|
||||
plugin/DoricNavigatorPlugin.h \
|
||||
plugin/DoricNetworkPlugin.h \
|
||||
plugin/DoricNotificationPlugin.h \
|
||||
|
259
doric-Qt/example/doric/plugin/DoricNavBarPlugin.cpp
Normal file
259
doric-Qt/example/doric/plugin/DoricNavBarPlugin.cpp
Normal file
@ -0,0 +1,259 @@
|
||||
#include "DoricNavBarPlugin.h"
|
||||
|
||||
#include "engine/DoricPromise.h"
|
||||
#include "shader/DoricViewNode.h"
|
||||
#include "utils/DoricUtils.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QQmlComponent>
|
||||
|
||||
void DoricNavBarPlugin::isHidden(QString jsValueString, QString callbackId) {
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
|
||||
if (navbar != nullptr) {
|
||||
bool hidden = !(navbar->isVisible());
|
||||
|
||||
QVariantList args;
|
||||
args.append(hidden);
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setHidden(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
bool hidden = jsValue["hidden"].toBool();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, hidden] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
navbar->setVisible(!hidden);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setTitle(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
QString titleString = jsValue["title"].toString();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, titleString] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QQuickItem *title = navbar->findChild<QQuickItem *>("title");
|
||||
title->setProperty("text", titleString);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setBgColor(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
QString bgColor = DoricUtils::doricColor(jsValue["color"].toInt()).name();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, bgColor] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
navbar->setProperty("color", bgColor);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setLeft(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, jsValue] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QString viewId = jsValue["id"].toString();
|
||||
QString type = jsValue["type"].toString();
|
||||
|
||||
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
||||
if (viewNode == nullptr) {
|
||||
viewNode = DoricViewNode::create(getContext(), type);
|
||||
viewNode->setId(viewId);
|
||||
viewNode->init(nullptr);
|
||||
}
|
||||
|
||||
viewNode->blend(jsValue["props"]);
|
||||
|
||||
QQuickItem *left = navbar->findChild<QQuickItem *>("left");
|
||||
foreach (QQuickItem *child, left->childItems()) {
|
||||
child->setParentItem(nullptr);
|
||||
child->deleteLater();
|
||||
}
|
||||
viewNode->getNodeView()->setParentItem(left);
|
||||
|
||||
getContext()->addHeadNode(TYPE_LEFT, viewNode);
|
||||
|
||||
DoricLayouts *layout = (DoricLayouts *)(viewNode->getNodeView()
|
||||
->property("doricLayout")
|
||||
.toULongLong());
|
||||
layout->apply(QSizeF(navbar->width(), navbar->height()));
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setRight(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, jsValue] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QString viewId = jsValue["id"].toString();
|
||||
QString type = jsValue["type"].toString();
|
||||
|
||||
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
||||
if (viewNode == nullptr) {
|
||||
viewNode = DoricViewNode::create(getContext(), type);
|
||||
viewNode->setId(viewId);
|
||||
viewNode->init(nullptr);
|
||||
}
|
||||
|
||||
viewNode->blend(jsValue["props"]);
|
||||
|
||||
QQuickItem *right = navbar->findChild<QQuickItem *>("right");
|
||||
foreach (QQuickItem *child, right->childItems()) {
|
||||
child->setParentItem(nullptr);
|
||||
child->deleteLater();
|
||||
}
|
||||
viewNode->getNodeView()->setParentItem(right);
|
||||
|
||||
getContext()->addHeadNode(TYPE_RIGHT, viewNode);
|
||||
|
||||
DoricLayouts *layout = (DoricLayouts *)(viewNode->getNodeView()
|
||||
->property("doricLayout")
|
||||
.toULongLong());
|
||||
layout->apply(QSizeF(navbar->width(), navbar->height()));
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setCenter(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, jsValue] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QString viewId = jsValue["id"].toString();
|
||||
QString type = jsValue["type"].toString();
|
||||
|
||||
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
||||
if (viewNode == nullptr) {
|
||||
viewNode = DoricViewNode::create(getContext(), type);
|
||||
viewNode->setId(viewId);
|
||||
viewNode->init(nullptr);
|
||||
}
|
||||
|
||||
viewNode->blend(jsValue["props"]);
|
||||
|
||||
QQuickItem *center = navbar->findChild<QQuickItem *>("center");
|
||||
foreach (QQuickItem *child, center->childItems()) {
|
||||
child->setParentItem(nullptr);
|
||||
child->deleteLater();
|
||||
}
|
||||
viewNode->getNodeView()->setParentItem(center);
|
||||
|
||||
getContext()->addHeadNode(TYPE_CENTER, viewNode);
|
||||
|
||||
DoricLayouts *layout = (DoricLayouts *)(viewNode->getNodeView()
|
||||
->property("doricLayout")
|
||||
.toULongLong());
|
||||
layout->apply(QSizeF(navbar->width(), navbar->height()));
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
34
doric-Qt/example/doric/plugin/DoricNavBarPlugin.h
Normal file
34
doric-Qt/example/doric/plugin/DoricNavBarPlugin.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef DORICNAVBARPLUGIN_H
|
||||
#define DORICNAVBARPLUGIN_H
|
||||
|
||||
#include <QQuickItem>
|
||||
|
||||
#include "DoricExport.h"
|
||||
|
||||
#include "DoricNativePlugin.h"
|
||||
|
||||
static QString TYPE_LEFT = "navbar_left";
|
||||
static QString TYPE_RIGHT = "navbar_right";
|
||||
static QString TYPE_CENTER = "navbar_center";
|
||||
|
||||
class DORIC_EXPORT DoricNavBarPlugin : public DoricNativePlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using DoricNativePlugin::DoricNativePlugin;
|
||||
|
||||
Q_INVOKABLE void isHidden(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setHidden(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setTitle(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setBgColor(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setLeft(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setRight(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setCenter(QString jsValueString, QString callbackId);
|
||||
};
|
||||
|
||||
#endif // DORICNAVBARPLUGIN_H
|
Reference in New Issue
Block a user