main.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #include "mainwindow.h"
  5. #include <QtGui/QApplication>
  6. #include <QtDeclarative/QDeclarativeContext>
  7. #include <QtDeclarative/QDeclarativeEngine>
  8. #include "levelcontroller.h"
  9. #include "levelmodel.h"
  10. int main(int argc, char *argv[])
  11. {
  12. QApplication app(argc, argv);
  13. /***********************************************************************************************
  14. *Create a level object. *
  15. *Load a level, terminate the program if loading fails. *
  16. ***********************************************************************************************/
  17. Level level;
  18. if (!level.load())
  19. return 0;
  20. /***********************************************************************************************
  21. *Register the custom QML types as a part of the Shapes 1.0 library *
  22. ***********************************************************************************************/
  23. qmlRegisterType<EllipseItem>("Shapes", 1, 0, "Ellipse");
  24. qmlRegisterType<MultiTouchItem>("Shapes", 1, 0, "MultiTouchItem");
  25. /***********************************************************************************************
  26. *Create the custom QDeclarativeView subclass object. *
  27. ***********************************************************************************************/
  28. View canvas;
  29. /***********************************************************************************************
  30. *Create a LevelController object passing it the games level object. *
  31. *This object is responsible for handling IAP. *
  32. *The controller emits the hack signal every time the IAP buy/restore sequence finalization, *
  33. *needed in order to hide the software keys that have been shown in the process. *
  34. ***********************************************************************************************/
  35. LevelController controller(&level);
  36. QObject::connect(&controller,SIGNAL(hack()),&canvas,SLOT(showFullScreen()));
  37. /***********************************************************************************************
  38. *Make level, canvas, controller and level model visible to the qml context. *
  39. ***********************************************************************************************/
  40. canvas.engine()->rootContext()->setContextProperty("Level",&level);
  41. canvas.engine()->rootContext()->setContextProperty("View",&canvas);
  42. canvas.engine()->rootContext()->setContextProperty("LevelController",&controller);
  43. canvas.engine()->rootContext()->setContextProperty("LevelModel",controller.getLevelModel());
  44. /***********************************************************************************************
  45. *Load the games main qml file. *
  46. ***********************************************************************************************/
  47. canvas.setSource(QString("qrc:/qml/gameboard.qml"));
  48. /***********************************************************************************************
  49. *Lock the ui in landscape mode and show. *
  50. ***********************************************************************************************/
  51. canvas.setOrientation(View::ScreenOrientationLockLandscape);
  52. canvas.showExpanded();
  53. /***********************************************************************************************
  54. *The engines quit signal triggers the sounds to stop. *
  55. *The levels readyToQuit signal triggers the apps quit slot *
  56. ***********************************************************************************************/
  57. QObject::connect(canvas.engine(), SIGNAL(quit()), &level, SIGNAL(stopSounds()));
  58. QObject::connect(&level, SIGNAL(readyToQuit()), qApp, SLOT(quit()));
  59. return app.exec();
  60. }