ctkWorkflowGroupBox.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QString>
  16. #include <QVBoxLayout>
  17. #include <QDebug>
  18. #include <QList>
  19. // CTK includes
  20. #include "ctkWorkflowGroupBox.h"
  21. #include "ctkWorkflowWidgetStep.h"
  22. #include "ctkFittedTextBrowser.h"
  23. #include "ui_ctkWorkflowGroupBox.h"
  24. #include "ctkLogger.h"
  25. //--------------------------------------------------------------------------
  26. static ctkLogger logger("org.commontk.libs.widgets.ctkWorkflowGroupBox");
  27. //--------------------------------------------------------------------------
  28. //-----------------------------------------------------------------------------
  29. class ctkWorkflowGroupBoxPrivate: public Ui_ctkWorkflowGroupBox
  30. {
  31. public:
  32. ctkWorkflowGroupBoxPrivate();
  33. ~ctkWorkflowGroupBoxPrivate();
  34. bool HideWidgetsOfNonCurrentSteps;
  35. ctkWorkflowStep* StepShownPreviously;
  36. ctkWorkflowStep* StepShownCurrently;
  37. void setupUi(ctkWorkflowGroupBox* widget);
  38. };
  39. // --------------------------------------------------------------------------
  40. // ctkWorkflowGroupBoxPrivate methods
  41. //---------------------------------------------------------------------------
  42. ctkWorkflowGroupBoxPrivate::ctkWorkflowGroupBoxPrivate()
  43. {
  44. this->HideWidgetsOfNonCurrentSteps = false;
  45. this->StepShownPreviously = 0;
  46. this->StepShownCurrently = 0;
  47. }
  48. //---------------------------------------------------------------------------
  49. ctkWorkflowGroupBoxPrivate::~ctkWorkflowGroupBoxPrivate()
  50. {
  51. }
  52. //---------------------------------------------------------------------------
  53. void ctkWorkflowGroupBoxPrivate::setupUi(ctkWorkflowGroupBox* widget)
  54. {
  55. this->Ui_ctkWorkflowGroupBox::setupUi(widget);
  56. }
  57. // --------------------------------------------------------------------------
  58. // ctkWorkflowGroupBoxMethods
  59. // --------------------------------------------------------------------------
  60. ctkWorkflowGroupBox::ctkWorkflowGroupBox(QWidget* _parent) : Superclass(_parent)
  61. , d_ptr(new ctkWorkflowGroupBoxPrivate)
  62. {
  63. Q_D(ctkWorkflowGroupBox);
  64. d->setupUi(this);
  65. }
  66. // --------------------------------------------------------------------------
  67. ctkWorkflowGroupBox::~ctkWorkflowGroupBox()
  68. {
  69. }
  70. // --------------------------------------------------------------------------
  71. CTK_GET_CPP(ctkWorkflowGroupBox, bool, hideWidgetsOfNonCurrentSteps, HideWidgetsOfNonCurrentSteps);
  72. CTK_SET_CPP(ctkWorkflowGroupBox, bool, setHideWidgetsOfNonCurrentSteps, HideWidgetsOfNonCurrentSteps);
  73. CTK_GET_CPP(ctkWorkflowGroupBox, QLayout*, clientAreaLayout, ClientAreaLayout);
  74. // --------------------------------------------------------------------------
  75. void ctkWorkflowGroupBox::updateGroupBox(ctkWorkflowStep* currentStep)
  76. {
  77. Q_D(ctkWorkflowGroupBox);
  78. d->StepShownPreviously = d->StepShownCurrently;
  79. d->StepShownCurrently = currentStep;
  80. if (currentStep)
  81. {
  82. this->setTitle(currentStep->name());
  83. this->setSubTitle(currentStep->description());
  84. this->setErrorText(currentStep->statusText());
  85. // don't show textual elements if they are empty
  86. d->SubTitleTextBrowser->setVisible(!this->subTitle().isEmpty());
  87. d->PreTextBrowser->setVisible(!this->preText().isEmpty());
  88. d->PostTextBrowser->setVisible(!this->postText().isEmpty());
  89. d->ErrorTextBrowser->setVisible(!this->errorText().isEmpty());
  90. }
  91. // disable/hide the previously shown step
  92. if (ctkWorkflowWidgetStep* prevStep = dynamic_cast<ctkWorkflowWidgetStep*>(d->StepShownPreviously))
  93. {
  94. logger.debug(QString("updateClientArea - hiding %1").arg(prevStep->name()));
  95. if (QWidget* stepArea = prevStep->stepArea())
  96. {
  97. stepArea->setEnabled(false);
  98. if (d->HideWidgetsOfNonCurrentSteps)
  99. {
  100. stepArea->hide();
  101. }
  102. }
  103. }
  104. ctkWorkflowWidgetStep* currentWidgetStep = dynamic_cast<ctkWorkflowWidgetStep*>(currentStep);
  105. // show/enable the current step
  106. if (currentWidgetStep)
  107. {
  108. currentWidgetStep->showUserInterface();
  109. if (QWidget* stepArea = currentWidgetStep->stepArea())
  110. {
  111. // add the step's client area to the widget if we haven't before
  112. if (!this->isAncestorOf(stepArea))
  113. {
  114. d->ClientAreaLayout->addWidget(stepArea);
  115. }
  116. stepArea->setEnabled(true);
  117. stepArea->show();
  118. }
  119. }
  120. }
  121. // --------------------------------------------------------------------------
  122. QString ctkWorkflowGroupBox::title()const
  123. {
  124. Q_D(const ctkWorkflowGroupBox);
  125. return d->CollapsibleButton->text();
  126. }
  127. // --------------------------------------------------------------------------
  128. void ctkWorkflowGroupBox::setTitle(const QString& newTitleText)
  129. {
  130. Q_D(ctkWorkflowGroupBox);
  131. d->CollapsibleButton->setText(newTitleText);
  132. }
  133. // --------------------------------------------------------------------------
  134. QString ctkWorkflowGroupBox::subTitle()const
  135. {
  136. Q_D(const ctkWorkflowGroupBox);
  137. return d->SubTitleTextBrowser->toPlainText();
  138. }
  139. // --------------------------------------------------------------------------
  140. void ctkWorkflowGroupBox::setSubTitle(const QString& newSubTitleText)
  141. {
  142. Q_D(ctkWorkflowGroupBox);
  143. d->SubTitleTextBrowser->setPlainText(newSubTitleText);
  144. }
  145. // --------------------------------------------------------------------------
  146. QString ctkWorkflowGroupBox::preText()const
  147. {
  148. Q_D(const ctkWorkflowGroupBox);
  149. return d->PreTextBrowser->toPlainText();
  150. }
  151. // --------------------------------------------------------------------------
  152. void ctkWorkflowGroupBox::setPreText(const QString& newPreText)
  153. {
  154. Q_D(ctkWorkflowGroupBox);
  155. d->PreTextBrowser->setPlainText(newPreText);
  156. }
  157. // --------------------------------------------------------------------------
  158. QString ctkWorkflowGroupBox::postText()const
  159. {
  160. Q_D(const ctkWorkflowGroupBox);
  161. return d->PostTextBrowser->toPlainText();
  162. }
  163. // --------------------------------------------------------------------------
  164. void ctkWorkflowGroupBox::setPostText(const QString& newPostText)
  165. {
  166. Q_D(ctkWorkflowGroupBox);
  167. d->PostTextBrowser->setPlainText(newPostText);
  168. }
  169. // --------------------------------------------------------------------------
  170. QString ctkWorkflowGroupBox::errorText()const
  171. {
  172. Q_D(const ctkWorkflowGroupBox);
  173. return d->ErrorTextBrowser->toPlainText();
  174. }
  175. // --------------------------------------------------------------------------
  176. void ctkWorkflowGroupBox::setErrorText(const QString& newErrorText)
  177. {
  178. Q_D(ctkWorkflowGroupBox);
  179. d->ErrorTextBrowser->setPlainText(newErrorText);
  180. }