1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
qsrand(QDateTime::currentDateTime().toTime_t());
// Create solitaire context as a 'child' of the root context
QScopedPointer<QDeclarativeContext> solitaireContext(new QDeclarativeContext(viewer->engine()->rootContext()));
QScopedPointer<QDeclarativeContext> freecellContext(new QDeclarativeContext(viewer->engine()->rootContext()));
// Initialize ce contexte avec l'interface du solitaire
QScopedPointer<SolitaireToQmlInterface> solitaireInterface(new SolitaireToQmlInterface());
solitaireInterface->initializeContext(solitaireContext.data());
QScopedPointer<FreecellToQmlInterface> freecellInterface(new FreecellToQmlInterface());
freecellInterface->initializeContext(freecellContext.data());
// Build a freecell component
QDeclarativeComponent freecellComponent(viewer->engine(), QUrl::fromLocalFile("qml/Freecell.qml"));
QDeclarativeItem* freecellObject = qobject_cast<QDeclarativeItem *>(freecellComponent.create(freecellContext.data()));
freecellObject->setOpacity(0);
viewer->engine()->rootContext()->setContextProperty("freecell", freecellObject);
// Build a solitaire component
QDeclarativeComponent solitaireComponent(viewer->engine(), QUrl::fromLocalFile("qml/Solitaire.qml"));
QDeclarativeItem* solitaireObject = qobject_cast<QDeclarativeItem *>(solitaireComponent.create(solitaireContext.data()));
solitaireObject->setOpacity(0);
viewer->engine()->rootContext()->setContextProperty("solitaire", solitaireObject);
// Set main qml file to the viewer
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer->setMainQmlFile(QLatin1String("qml/main.qml"));
// Reparent newly created objects to the rootObject
freecellObject->setParentItem(qobject_cast<QDeclarativeItem*>(viewer->rootObject()));
solitaireObject->setParentItem(qobject_cast<QDeclarativeItem*>(viewer->rootObject()));
viewer->showExpanded();
return app->exec();
} |