Make demo.qml depend less on externally supplied values
parent
14f95acd8b
commit
0ea99bff54
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue