widgetwindowsmanager.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. = StarPU-Top for StarPU =
  3. Copyright (C) 2011
  4. William Braik
  5. Yann Courtois
  6. Jean-Marie Couteyen
  7. Anthony Roy
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "widgetwindowsmanager.h"
  21. #include "mainwindow.h"
  22. #include "abstractwidgetwindow.h"
  23. #include "datawidget.h"
  24. #include "dataaggregatorwidget.h"
  25. #include <QDebug>
  26. WidgetWindowsManager::WidgetWindowsManager(MainWindow *mainWindow,
  27. QMdiArea *mdiArea)
  28. {
  29. static bool instanciated = false;
  30. Q_ASSERT_X(instanciated == false, "WidgetWindowsManager's' constructor",
  31. "Singleton pattern violated - "
  32. "WidgetWindowsManager instanciated more than once");
  33. qDebug() << "WindowsWidgetManager : initializing";
  34. _mainWindow = mainWindow;
  35. _mdiArea = mdiArea;
  36. instanciated = true;
  37. }
  38. WidgetWindowsManager::~WidgetWindowsManager()
  39. {
  40. qDebug() << "WindowsWidgetManager : terminating";
  41. }
  42. void WidgetWindowsManager::displayWidgetWindow(
  43. AbstractWidgetWindow *widgetWindow) const
  44. {
  45. qDebug() << "WidgetWindowsManager : displaying widget window";
  46. if (widgetWindow->isInside() == true)
  47. { // MDI mode
  48. _mdiArea->addSubWindow(widgetWindow);
  49. }
  50. widgetWindow->setVisible(true);
  51. }
  52. void WidgetWindowsManager::mdiToFlyingWindows() const
  53. {
  54. qDebug() << "WidgetWindowsManager : putting all widget windows outside";
  55. _mdiArea->setVisible(false);
  56. // Data widgets
  57. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  58. {
  59. AbstractWidgetWindow *widgetWindow = _mainWindow->dataWidgets()->at(i);
  60. if (widgetWindow != 0)
  61. {
  62. if (widgetWindow->isInside())
  63. {
  64. _mdiArea->removeSubWindow(widgetWindow);
  65. widgetWindow->setInside(false);
  66. displayWidgetWindow(widgetWindow);
  67. }
  68. }
  69. }
  70. // Data aggregator widgets
  71. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  72. {
  73. AbstractWidgetWindow
  74. *widgetWindow =
  75. (AbstractWidgetWindow*) _mainWindow
  76. ->dataAggregatorWidgets()->at(i).data();
  77. if (widgetWindow != 0)
  78. {
  79. if (widgetWindow->isInside())
  80. {
  81. _mdiArea->removeSubWindow(widgetWindow);
  82. widgetWindow->setInside(false);
  83. displayWidgetWindow(widgetWindow);
  84. }
  85. }
  86. }
  87. _mdiArea->closeAllSubWindows();
  88. }
  89. void WidgetWindowsManager::flyingWindowsToMdi() const
  90. {
  91. qDebug() << "WidgetWindowsManager : putting all widget windows inside";
  92. _mdiArea->setVisible(true);
  93. // Data widgets
  94. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  95. {
  96. AbstractWidgetWindow *widgetWindow = _mainWindow->dataWidgets()->at(i);
  97. if (widgetWindow != 0)
  98. {
  99. if (widgetWindow->isInside() == false)
  100. {
  101. widgetWindow->setInside(true);
  102. displayWidgetWindow(widgetWindow);
  103. }
  104. }
  105. }
  106. // Data aggregator widgets
  107. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  108. {
  109. AbstractWidgetWindow
  110. *widgetWindow =
  111. (AbstractWidgetWindow*) _mainWindow
  112. ->dataAggregatorWidgets()->at(i).data();
  113. if (widgetWindow != 0)
  114. {
  115. if (widgetWindow->isInside() == false)
  116. {
  117. widgetWindow->setInside(true);
  118. displayWidgetWindow(widgetWindow);
  119. }
  120. }
  121. }
  122. }
  123. void WidgetWindowsManager::mdiToFlyingWindow(
  124. AbstractWidgetWindow *widgetWindow) const
  125. {
  126. QWidget* parentWindow = widgetWindow->parentWidget();
  127. _mdiArea->removeSubWindow(widgetWindow);
  128. _mdiArea->removeSubWindow(parentWindow);
  129. displayWidgetWindow(widgetWindow);
  130. }
  131. void WidgetWindowsManager::flyingWindowToMdi(
  132. AbstractWidgetWindow *widgetWindow) const
  133. {
  134. if (_mdiArea->isVisible() == false)
  135. _mdiArea->setVisible(true);
  136. displayWidgetWindow(widgetWindow);
  137. }
  138. void WidgetWindowsManager::closeWidgetWindow(
  139. AbstractWidgetWindow *widgetWindow) const
  140. {
  141. if (widgetWindow->isInside())
  142. {
  143. QWidget* parentWindow = widgetWindow->parentWidget();
  144. _mdiArea->removeSubWindow(widgetWindow);
  145. _mdiArea->removeSubWindow(parentWindow);
  146. }
  147. widgetWindow->close();
  148. }
  149. void WidgetWindowsManager::closeWidgetWindows() const
  150. {
  151. qDebug() << "WidgetWindowsManager : closing all widget windows";
  152. // Data widgets
  153. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  154. {
  155. AbstractWidgetWindow* widgetWindow =
  156. _mainWindow->dataWidgets()->at(i).data();
  157. if (widgetWindow != 0)
  158. {
  159. closeWidgetWindow(widgetWindow);
  160. }
  161. }
  162. // Data aggregator widgets
  163. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  164. {
  165. AbstractWidgetWindow
  166. * widgetWindow =
  167. (AbstractWidgetWindow*) _mainWindow
  168. ->dataAggregatorWidgets()->at(i).data();
  169. if (widgetWindow != 0)
  170. {
  171. closeWidgetWindow(widgetWindow);
  172. }
  173. }
  174. }
  175. const QList<AbstractWidgetWindow*> WidgetWindowsManager::widgetWindows() const
  176. {
  177. QList<AbstractWidgetWindow*> widgetWindows;
  178. // Get data widget windows
  179. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  180. {
  181. widgetWindows.append(_mainWindow->dataWidgets()->at(i));
  182. }
  183. // Get data aggregator widget windows
  184. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  185. {
  186. widgetWindows.append(_mainWindow->dataAggregatorWidgets()->at(i));
  187. }
  188. return widgetWindows;
  189. }