QtFramework.cpp 2.6 KB

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