abstractwidgetwindow.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 "abstractwidgetwindow.h"
  21. #include "widgetwindowsmanager.h"
  22. #include "mainwindow.h"
  23. #include <QVBoxLayout>
  24. AbstractWidgetWindow::AbstractWidgetWindow(
  25. WidgetWindowsManager *widgetWindowsManager,
  26. MainWindow *mainWindow,
  27. bool inside)
  28. : QWidget(mainWindow)
  29. {
  30. _widgetWindowsManager = widgetWindowsManager;
  31. _mainWindow = mainWindow;
  32. _inside = inside;
  33. // Init id
  34. _windowId = generateWindowId();
  35. // Init GUI
  36. _sizeGrip = new QSizeGrip(this);
  37. _sizeGrip->move(width()-32,height()-32);
  38. _sizeGrip->resize(32,32);
  39. _inOutButton = new QToolButton();
  40. QObject::connect(_inOutButton, SIGNAL(clicked()),
  41. this, SLOT(on_inOutButton_clicked()));
  42. _inside ? _inOutButton->setToolTip(tr("To flying window"))
  43. : _inOutButton->setToolTip(tr("To MDI"));
  44. _inside ? _inOutButton->setIcon(QIcon(":/images/outside.png"))
  45. : _inOutButton->setIcon(QIcon(":/images/inside.png"));
  46. // Set attributes
  47. setAttribute(Qt::WA_DeleteOnClose);
  48. }
  49. AbstractWidgetWindow::~AbstractWidgetWindow()
  50. {
  51. delete _sizeGrip;
  52. delete _inOutButton;
  53. }
  54. /* -------------------------------------------------------------------------- */
  55. /* Events */
  56. /* -------------------------------------------------------------------------- */
  57. void AbstractWidgetWindow::mousePressEvent(QMouseEvent *event)
  58. {
  59. if ((isInside() == false) && (event->button() == Qt::LeftButton))
  60. {
  61. dragPosition = event->globalPos() - frameGeometry().topLeft();
  62. event->accept();
  63. }
  64. }
  65. void AbstractWidgetWindow::mouseMoveEvent(QMouseEvent *event)
  66. {
  67. if ((isInside() == false) && (event->buttons() & Qt::LeftButton))
  68. {
  69. move(event->globalPos() - dragPosition);
  70. event->accept();
  71. }
  72. }
  73. void AbstractWidgetWindow::resizeEvent(QResizeEvent *event)
  74. {
  75. _sizeGrip->move(width()-32,height()-32);
  76. _sizeGrip->resize(32,32);
  77. }
  78. /* -------------------------------------------------------------------------- */
  79. /* Getters */
  80. /* -------------------------------------------------------------------------- */
  81. int AbstractWidgetWindow::windowId() const
  82. {
  83. return _windowId;
  84. }
  85. bool AbstractWidgetWindow::isInside() const
  86. {
  87. return _inside;
  88. }
  89. /* -------------------------------------------------------------------------- */
  90. /* Setters */
  91. /* -------------------------------------------------------------------------- */
  92. void AbstractWidgetWindow::setInside(bool inside)
  93. {
  94. _inside = inside;
  95. if(isInside() == false)
  96. {
  97. _inOutButton->setToolTip(tr("To MDI"));
  98. _inOutButton->setIcon(QIcon(":/images/inside.png"));
  99. }
  100. else
  101. {
  102. _inOutButton->setToolTip(tr("To flying window"));
  103. _inOutButton->setIcon(QIcon(":/images/outside.png"));
  104. }
  105. }
  106. /* -------------------------------------------------------------------------- */
  107. /* GUI interactions */
  108. /* -------------------------------------------------------------------------- */
  109. void AbstractWidgetWindow::on_inOutButton_clicked()
  110. {
  111. setInside(!isInside());
  112. if(_inside)
  113. {
  114. _widgetWindowsManager->flyingWindowToMdi(this);
  115. }
  116. else
  117. {
  118. _widgetWindowsManager->mdiToFlyingWindow(this);
  119. }
  120. }
  121. /* -------------------------------------------------------------------------- */
  122. /* Window ID generation */
  123. /* -------------------------------------------------------------------------- */
  124. int AbstractWidgetWindow::generateWindowId()
  125. {
  126. static int windowId = 0;
  127. return windowId++;
  128. }