QtFramework.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef __clang__
  32. #ifndef __llvm__
  33. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  34. #endif
  35. #endif
  36. #endif
  37. }
  38. QtFramework::QtFramework(int& argc, char** argv)
  39. : application(new QApplication(argc, argv)), mainWindow(NULL) {
  40. fake_argv = NULL;
  41. #ifdef NICE_USELIB_GLUT
  42. glutInit(&argc, argv);
  43. #endif
  44. #ifndef WIN32
  45. #ifndef __clang__
  46. #ifndef __llvm__
  47. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  48. #endif
  49. #endif
  50. #endif
  51. }
  52. QtFramework::~QtFramework() {
  53. // NOTE Qt widgets don't seem to enjoy being deleted
  54. // if (mainWindow != NULL) {
  55. // delete mainWindow;
  56. // mainWindow = NULL;
  57. // }
  58. // NOTE Qt's QApplication object doesn't seem to enjoy being deleted
  59. // if (application != NULL) {
  60. // delete application;
  61. // application = NULL;
  62. // }
  63. if ( fake_argv != NULL )
  64. {
  65. if ( fake_argv[0] != NULL )
  66. delete [] fake_argv[0];
  67. delete [] fake_argv;
  68. }
  69. }
  70. int QtFramework::nonstaticExec(bool showDefaultWindow) {
  71. //mainWindow.reset(new DefaultMainWindow("LImUn Qt Framework Application"));
  72. mainWindow = new DefaultMainWindow("LImUn Qt Framework Application");
  73. return doExec(showDefaultWindow);
  74. }
  75. int QtFramework::nonstaticExec(std::auto_ptr<QWidget> _mainWindow,
  76. bool showMainWindow) {
  77. //mainWindow = _mainWindow;
  78. mainWindow = _mainWindow.release();
  79. return doExec(showMainWindow);
  80. }
  81. int QtFramework::nonstaticExec(QWidget* _mainWindow, bool showMainWindow) {
  82. //mainWindow.reset(_mainWindow);
  83. mainWindow = _mainWindow;
  84. return doExec(showMainWindow);
  85. }
  86. int QtFramework::doExec(bool showMainWindow) {
  87. mainWindow->setAttribute(Qt::WA_QuitOnClose, true);
  88. if (showMainWindow) {
  89. mainWindow->show();
  90. }
  91. // application->connect(application.get(), SIGNAL(lastWindowClosed()),
  92. // application.get(), SLOT(quit()));
  93. return application->exec();
  94. }
  95. } // namespace