Make demo.qml depend less on externally supplied values

master
Jos van den Oever 2017-09-02 00:32:35 +02:00
parent 14f95acd8b
commit 0ea99bff54
2 changed files with 16 additions and 13 deletions

View File

@ -5,10 +5,8 @@ import QtQuick.Layouts 1.3
ApplicationWindow {
id: application
x: windowX
y: windowY
width: windowWidth
height: windowHeight
width: 640
height: 480
visible: true
ItemSelectionModel {
id: selectionModel
@ -23,7 +21,7 @@ ApplicationWindow {
anchors.fill: parent
onCountChanged: {
for (var i = 0; i < tabView.count; ++i) {
if (tabView.getTab(i).title == initialTab) {
if (tabView.getTab(i).title === initialTab) {
tabView.currentIndex = i;
}
}

View File

@ -63,13 +63,12 @@ QWindow* getWindow(QWidget* w) {
#ifdef QT_QUICK_LIB
void copyWindowGeometry(QWidget* w, QQmlContext* c) {
QWindow* window = getWindow(w);
if (window) {
c->setContextProperty("windowX", window->x());
c->setContextProperty("windowY", window->y());
c->setContextProperty("windowWidth", window->width());
c->setContextProperty("windowHeight", window->height());
void copyWindowGeometry(const QRect& rect, QObject* c) {
if (rect.width() && rect.height()) {
c->setProperty("x", rect.x());
c->setProperty("y", rect.y());
c->setProperty("width", rect.width());
c->setProperty("heigth", rect.height());
}
}
@ -86,8 +85,14 @@ void createQtQuick(const QString& name, const QString& qml, Model* model,
c->setContextProperty("qtquickIndex",
QVariant(model->styles.stringList().indexOf(name)));
c->setContextProperty("initialTab", initialTab);
copyWindowGeometry(widgets, engine->rootContext());
QRect geometry;
QWindow* window = getWindow(widgets);
if (window) {
geometry = window->geometry();
}
engine->load(QUrl(qml));
auto root = engine->rootObjects().first();
copyWindowGeometry(geometry, root);
}
#endif