widgetwindowsmanager.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. (void) instanciated;
  34. qDebug() << "WindowsWidgetManager : initializing";
  35. _mainWindow = mainWindow;
  36. _mdiArea = mdiArea;
  37. instanciated = true;
  38. }
  39. WidgetWindowsManager::~WidgetWindowsManager()
  40. {
  41. qDebug() << "WindowsWidgetManager : terminating";
  42. }
  43. void WidgetWindowsManager::displayWidgetWindow(
  44. AbstractWidgetWindow *widgetWindow) const
  45. {
  46. qDebug() << "WidgetWindowsManager : displaying widget window";
  47. if (widgetWindow->isInside() == true)
  48. { // MDI mode
  49. _mdiArea->addSubWindow(widgetWindow);
  50. }
  51. widgetWindow->setVisible(true);
  52. }
  53. void WidgetWindowsManager::mdiToFlyingWindows() const
  54. {
  55. qDebug() << "WidgetWindowsManager : putting all widget windows outside";
  56. _mdiArea->setVisible(false);
  57. // Data widgets
  58. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  59. {
  60. AbstractWidgetWindow *widgetWindow = _mainWindow->dataWidgets()->at(i);
  61. if (widgetWindow != 0)
  62. {
  63. if (widgetWindow->isInside())
  64. {
  65. _mdiArea->removeSubWindow(widgetWindow);
  66. widgetWindow->setInside(false);
  67. displayWidgetWindow(widgetWindow);
  68. }
  69. }
  70. }
  71. // Data aggregator widgets
  72. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  73. {
  74. AbstractWidgetWindow
  75. *widgetWindow =
  76. (AbstractWidgetWindow*) _mainWindow
  77. ->dataAggregatorWidgets()->at(i).data();
  78. if (widgetWindow != 0)
  79. {
  80. if (widgetWindow->isInside())
  81. {
  82. _mdiArea->removeSubWindow(widgetWindow);
  83. widgetWindow->setInside(false);
  84. displayWidgetWindow(widgetWindow);
  85. }
  86. }
  87. }
  88. _mdiArea->closeAllSubWindows();
  89. }
  90. void WidgetWindowsManager::flyingWindowsToMdi() const
  91. {
  92. qDebug() << "WidgetWindowsManager : putting all widget windows inside";
  93. _mdiArea->setVisible(true);
  94. // Data widgets
  95. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  96. {
  97. AbstractWidgetWindow *widgetWindow = _mainWindow->dataWidgets()->at(i);
  98. if (widgetWindow != 0)
  99. {
  100. if (widgetWindow->isInside() == false)
  101. {
  102. widgetWindow->setInside(true);
  103. displayWidgetWindow(widgetWindow);
  104. }
  105. }
  106. }
  107. // Data aggregator widgets
  108. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  109. {
  110. AbstractWidgetWindow
  111. *widgetWindow =
  112. (AbstractWidgetWindow*) _mainWindow
  113. ->dataAggregatorWidgets()->at(i).data();
  114. if (widgetWindow != 0)
  115. {
  116. if (widgetWindow->isInside() == false)
  117. {
  118. widgetWindow->setInside(true);
  119. displayWidgetWindow(widgetWindow);
  120. }
  121. }
  122. }
  123. }
  124. void WidgetWindowsManager::mdiToFlyingWindow(
  125. AbstractWidgetWindow *widgetWindow) const
  126. {
  127. QWidget* parentWindow = widgetWindow->parentWidget();
  128. _mdiArea->removeSubWindow(widgetWindow);
  129. _mdiArea->removeSubWindow(parentWindow);
  130. displayWidgetWindow(widgetWindow);
  131. }
  132. void WidgetWindowsManager::flyingWindowToMdi(
  133. AbstractWidgetWindow *widgetWindow) const
  134. {
  135. if (_mdiArea->isVisible() == false)
  136. _mdiArea->setVisible(true);
  137. displayWidgetWindow(widgetWindow);
  138. }
  139. void WidgetWindowsManager::closeWidgetWindow(
  140. AbstractWidgetWindow *widgetWindow) const
  141. {
  142. if (widgetWindow->isInside())
  143. {
  144. QWidget* parentWindow = widgetWindow->parentWidget();
  145. _mdiArea->removeSubWindow(widgetWindow);
  146. _mdiArea->removeSubWindow(parentWindow);
  147. }
  148. widgetWindow->close();
  149. }
  150. void WidgetWindowsManager::closeWidgetWindows() const
  151. {
  152. qDebug() << "WidgetWindowsManager : closing all widget windows";
  153. // Data widgets
  154. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  155. {
  156. AbstractWidgetWindow* widgetWindow =
  157. _mainWindow->dataWidgets()->at(i).data();
  158. if (widgetWindow != 0)
  159. {
  160. closeWidgetWindow(widgetWindow);
  161. }
  162. }
  163. // Data aggregator widgets
  164. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  165. {
  166. AbstractWidgetWindow
  167. * widgetWindow =
  168. (AbstractWidgetWindow*) _mainWindow
  169. ->dataAggregatorWidgets()->at(i).data();
  170. if (widgetWindow != 0)
  171. {
  172. closeWidgetWindow(widgetWindow);
  173. }
  174. }
  175. }
  176. const QList<AbstractWidgetWindow*> WidgetWindowsManager::widgetWindows() const
  177. {
  178. QList<AbstractWidgetWindow*> widgetWindows;
  179. // Get data widget windows
  180. for (int i = 0; i < _mainWindow->dataWidgets()->count(); i++)
  181. {
  182. widgetWindows.append(_mainWindow->dataWidgets()->at(i));
  183. }
  184. // Get data aggregator widget windows
  185. for (int i = 0; i < _mainWindow->dataAggregatorWidgets()->count(); i++)
  186. {
  187. widgetWindows.append(_mainWindow->dataAggregatorWidgets()->at(i));
  188. }
  189. return widgetWindows;
  190. }