QtFramework.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include <GL/glut.h>
  10. #endif
  11. namespace NICE {
  12. std::auto_ptr<QtFramework> QtFramework::theInstance;
  13. QtFramework::QtFramework()
  14. : application(NULL), mainWindow(NULL) {
  15. fake_argc = 0;
  16. fake_argv = new char * [1];
  17. fake_argv[0] = new char [2];
  18. fake_argv[0][0] = '.';
  19. fake_argv[0][1] = '\0';
  20. //application.reset(new QApplication(argc, argv));
  21. application = new QApplication(fake_argc, fake_argv);
  22. #ifdef NICE_USELIB_GLUT
  23. glutInit(&fake_argc, fake_argv);
  24. #endif
  25. #ifndef WIN32
  26. #ifndef __clang__
  27. #ifndef __llvm__
  28. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  29. #endif
  30. #endif
  31. #endif
  32. }
  33. QtFramework::QtFramework(int& argc, char** argv)
  34. : application(new QApplication(argc, argv)), mainWindow(NULL) {
  35. fake_argv = NULL;
  36. #ifdef NICE_USELIB_GLUT
  37. glutInit(&argc, argv);
  38. #endif
  39. #ifndef WIN32
  40. #ifndef __clang__
  41. #ifndef __llvm__
  42. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  43. #endif
  44. #endif
  45. #endif
  46. }
  47. QtFramework::~QtFramework() {
  48. // NOTE Qt widgets don't seem to enjoy being deleted
  49. // if (mainWindow != NULL) {
  50. // delete mainWindow;
  51. // mainWindow = NULL;
  52. // }
  53. // NOTE Qt's QApplication object doesn't seem to enjoy being deleted
  54. // if (application != NULL) {
  55. // delete application;
  56. // application = NULL;
  57. // }
  58. if ( fake_argv != NULL )
  59. {
  60. if ( fake_argv[0] != NULL )
  61. delete [] fake_argv[0];
  62. delete [] fake_argv;
  63. }
  64. }
  65. int QtFramework::nonstaticExec(bool showDefaultWindow) {
  66. //mainWindow.reset(new DefaultMainWindow("LImUn Qt Framework Application"));
  67. mainWindow = new DefaultMainWindow("LImUn Qt Framework Application");
  68. return doExec(showDefaultWindow);
  69. }
  70. int QtFramework::nonstaticExec(std::auto_ptr<QWidget> _mainWindow,
  71. bool showMainWindow) {
  72. //mainWindow = _mainWindow;
  73. mainWindow = _mainWindow.release();
  74. return doExec(showMainWindow);
  75. }
  76. int QtFramework::nonstaticExec(QWidget* _mainWindow, bool showMainWindow) {
  77. //mainWindow.reset(_mainWindow);
  78. mainWindow = _mainWindow;
  79. return doExec(showMainWindow);
  80. }
  81. int QtFramework::doExec(bool showMainWindow) {
  82. mainWindow->setAttribute(Qt::WA_QuitOnClose, true);
  83. if (showMainWindow) {
  84. mainWindow->show();
  85. }
  86. // application->connect(application.get(), SIGNAL(lastWindowClosed()),
  87. // application.get(), SLOT(quit()));
  88. return application->exec();
  89. }
  90. } // namespace