QtFramework.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimagedisplay - A library for image and video display
  4. * See file License for license information.
  5. */
  6. #ifndef _IMAGEDISPLAY_QTFRAMEWORK_H
  7. #define _IMAGEDISPLAY_QTFRAMEWORK_H
  8. #include <qapplication.h>
  9. #include <core/basics/NonCopyable.h>
  10. #include <memory>
  11. namespace NICE {
  12. /**
  13. * A simple framework for Qt applications.
  14. *
  15. * @author Ferid Bajramovic
  16. *
  17. * @note
  18. * This class is experimental and might change in the future.
  19. */
  20. class QtFramework : private NonCopyable {
  21. private:
  22. /**
  23. * Constructor: also creates the QApplication object.
  24. * @note This constructor will pass dummy commandline options to Qt!!!
  25. */
  26. QtFramework();
  27. /**
  28. * Constructor: also creates the QApplication object.
  29. */
  30. QtFramework(int& argc, char** argv);
  31. public:
  32. //! Destructor
  33. virtual ~QtFramework();
  34. static inline QtFramework& instance() {
  35. if (theInstance.get() == NULL) {
  36. theInstance.reset(new QtFramework());
  37. }
  38. return *theInstance;
  39. }
  40. static inline bool isInstanceInitialized() {
  41. return theInstance.get() != NULL;
  42. }
  43. static inline void init(int& argc, char** argv) {
  44. if (theInstance.get() != NULL) {
  45. return;
  46. }
  47. theInstance.reset(new QtFramework(argc, argv));
  48. }
  49. static inline int exec(bool showDefaultWindow = true) {
  50. return instance().nonstaticExec(showDefaultWindow);
  51. }
  52. /**
  53. * Start the framework (and thus Qt).
  54. * @param _mainWindow the main window (Ownership is taken!)
  55. * @param showMainWindow automatically show the main window?
  56. */
  57. static inline int exec(std::auto_ptr<QWidget> _mainWindow,
  58. bool showMainWindow = true) {
  59. return instance().nonstaticExec(_mainWindow, showMainWindow);
  60. }
  61. /**
  62. * Start the framework (and thus Qt).
  63. * @param _mainWindow the main window (Ownership is taken!)
  64. * @param showMainWindow automatically show the main window?
  65. */
  66. static inline int exec(QWidget* _mainWindow, bool showMainWindow = true) {
  67. return instance().nonstaticExec(_mainWindow, showMainWindow);
  68. }
  69. /**
  70. * Access the main window.
  71. */
  72. inline QWidget* getMainWindow() const {
  73. return mainWindow;
  74. }
  75. private:
  76. static std::auto_ptr<QtFramework> theInstance;
  77. int doExec(bool showMainWindow);
  78. /**
  79. * Start the framework (and thus Qt) with a default main window.
  80. * @param showDefaultWindow automatically show the main window?
  81. */
  82. int nonstaticExec(bool showDefaultWindow = true);
  83. /**
  84. * Start the framework (and thus Qt).
  85. * @param _mainWindow the main window (Ownership is taken!)
  86. * @param showMainWindow automatically show the main window?
  87. */
  88. int nonstaticExec(std::auto_ptr<QWidget> _mainWindow,
  89. bool showMainWindow = true);
  90. /**
  91. * Start the framework (and thus Qt).
  92. * @param _mainWindow the main window (Ownership is taken!)
  93. * @param showMainWindow automatically show the main window?
  94. */
  95. int nonstaticExec(QWidget* _mainWindow, bool showMainWindow = true);
  96. //std::auto_ptr<QApplication> application;
  97. QApplication* application;
  98. //std::auto_ptr<QWidget> mainWindow;
  99. QWidget* mainWindow;
  100. int fake_argc;
  101. char **fake_argv;
  102. };
  103. } // namespace
  104. #endif /* _IMAGEDISPLAY_QTFRAMEWORK_H */