QtFramework.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimagedisplay - An imagedisplay/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. #include "core/imagedisplay/QtFramework.h"
  7. #include "core/imagedisplay/DefaultMainWindow.h"
  8. #ifdef NICE_USELIB_GLUT
  9. #ifdef __APPLE__
  10. #include <OpenGL/gl.h>
  11. #include <OpenGL/glu.h>
  12. #else
  13. #include <GL/glut.h>
  14. #endif
  15. #endif
  16. namespace NICE {
  17. std::auto_ptr<QtFramework> QtFramework::theInstance;
  18. QtFramework::QtFramework()
  19. : application(NULL), mainWindow(NULL) {
  20. fake_argc = 0;
  21. fake_argv = new char * [1];
  22. fake_argv[0] = new char [2];
  23. fake_argv[0][0] = '.';
  24. fake_argv[0][1] = '\0';
  25. //application.reset(new QApplication(argc, argv));
  26. application = new QApplication(fake_argc, fake_argv);
  27. #ifdef NICE_USELIB_GLUT
  28. glutInit(&fake_argc, fake_argv);
  29. #endif
  30. #ifndef WIN32
  31. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  32. #endif
  33. }
  34. QtFramework::QtFramework(int& argc, char** argv)
  35. : application(new QApplication(argc, argv)), mainWindow(NULL) {
  36. fake_argv = NULL;
  37. #ifdef NICE_USELIB_GLUT
  38. glutInit(&argc, argv);
  39. #endif
  40. #ifndef WIN32
  41. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  42. #endif
  43. }
  44. QtFramework::~QtFramework() {
  45. // NOTE Qt widgets don't seem to enjoy being deleted
  46. // if (mainWindow != NULL) {
  47. // delete mainWindow;
  48. // mainWindow = NULL;
  49. // }
  50. // NOTE Qt's QApplication object doesn't seem to enjoy being deleted
  51. // if (application != NULL) {
  52. // delete application;
  53. // application = NULL;
  54. // }
  55. if ( fake_argv != NULL )
  56. {
  57. if ( fake_argv[0] != NULL )
  58. delete [] fake_argv[0];
  59. delete [] fake_argv;
  60. }
  61. }
  62. int QtFramework::nonstaticExec(bool showDefaultWindow) {
  63. //mainWindow.reset(new DefaultMainWindow("LImUn Qt Framework Application"));
  64. mainWindow = new DefaultMainWindow("LImUn Qt Framework Application");
  65. return doExec(showDefaultWindow);
  66. }
  67. int QtFramework::nonstaticExec(std::auto_ptr<QWidget> _mainWindow,
  68. bool showMainWindow) {
  69. //mainWindow = _mainWindow;
  70. mainWindow = _mainWindow.release();
  71. return doExec(showMainWindow);
  72. }
  73. int QtFramework::nonstaticExec(QWidget* _mainWindow, bool showMainWindow) {
  74. //mainWindow.reset(_mainWindow);
  75. mainWindow = _mainWindow;
  76. return doExec(showMainWindow);
  77. }
  78. int QtFramework::doExec(bool showMainWindow) {
  79. //application->setMainWidget(mainWindow.get());
  80. application->setMainWidget(mainWindow);
  81. if (showMainWindow) {
  82. mainWindow->show();
  83. }
  84. // application->connect(application.get(), SIGNAL(lastWindowClosed()),
  85. // application.get(), SLOT(quit()));
  86. return application->exec();
  87. }
  88. } // namespace