ctkWorkflowGroupBox.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.apache.org/licenses/LICENSE-2.0.txt
  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. bool ErrorTextEnabled;
  36. ctkWorkflowStep* StepShownPreviously;
  37. ctkWorkflowStep* StepShownCurrently;
  38. void setupUi(ctkWorkflowGroupBox* widget);
  39. };
  40. // --------------------------------------------------------------------------
  41. // ctkWorkflowGroupBoxPrivate methods
  42. //---------------------------------------------------------------------------
  43. ctkWorkflowGroupBoxPrivate::ctkWorkflowGroupBoxPrivate()
  44. {
  45. this->HideWidgetsOfNonCurrentSteps = false;
  46. this->ErrorTextEnabled = true;
  47. this->StepShownPreviously = 0;
  48. this->StepShownCurrently = 0;
  49. }
  50. //---------------------------------------------------------------------------
  51. ctkWorkflowGroupBoxPrivate::~ctkWorkflowGroupBoxPrivate()
  52. {
  53. }
  54. //---------------------------------------------------------------------------
  55. void ctkWorkflowGroupBoxPrivate::setupUi(ctkWorkflowGroupBox* widget)
  56. {
  57. this->Ui_ctkWorkflowGroupBox::setupUi(widget);
  58. }
  59. // --------------------------------------------------------------------------
  60. // ctkWorkflowGroupBoxMethods
  61. // --------------------------------------------------------------------------
  62. ctkWorkflowGroupBox::ctkWorkflowGroupBox(QWidget* _parent) : Superclass(_parent)
  63. , d_ptr(new ctkWorkflowGroupBoxPrivate)
  64. {
  65. Q_D(ctkWorkflowGroupBox);
  66. d->setupUi(this);
  67. }
  68. // --------------------------------------------------------------------------
  69. ctkWorkflowGroupBox::~ctkWorkflowGroupBox()
  70. {
  71. }
  72. // --------------------------------------------------------------------------
  73. CTK_GET_CPP(ctkWorkflowGroupBox, bool, hideWidgetsOfNonCurrentSteps, HideWidgetsOfNonCurrentSteps);
  74. CTK_SET_CPP(ctkWorkflowGroupBox, bool, setHideWidgetsOfNonCurrentSteps, HideWidgetsOfNonCurrentSteps);
  75. CTK_GET_CPP(ctkWorkflowGroupBox, bool, errorTextEnabled, ErrorTextEnabled);
  76. CTK_SET_CPP(ctkWorkflowGroupBox, bool, setErrorTextEnabled, ErrorTextEnabled);
  77. CTK_GET_CPP(ctkWorkflowGroupBox, QLayout*, clientAreaLayout, ClientAreaLayout);
  78. // --------------------------------------------------------------------------
  79. void ctkWorkflowGroupBox::updateGroupBox(ctkWorkflowStep* currentStep)
  80. {
  81. Q_D(ctkWorkflowGroupBox);
  82. d->StepShownPreviously = d->StepShownCurrently;
  83. d->StepShownCurrently = currentStep;
  84. if (currentStep)
  85. {
  86. this->setTitle(currentStep->name());
  87. this->setSubTitle(currentStep->description());
  88. this->setErrorText(currentStep->statusText());
  89. // don't show textual elements if they are empty
  90. d->SubTitleTextBrowser->setVisible(!this->subTitle().isEmpty());
  91. d->PreTextBrowser->setVisible(!this->preText().isEmpty());
  92. d->PostTextBrowser->setVisible(!this->postText().isEmpty());
  93. d->ErrorTextBrowser->setVisible(!this->errorText().isEmpty() && d->ErrorTextEnabled);
  94. }
  95. // disable/hide the previously shown step
  96. if (ctkWorkflowWidgetStep* prevStep = dynamic_cast<ctkWorkflowWidgetStep*>(d->StepShownPreviously))
  97. {
  98. logger.debug(QString("updateClientArea - hiding %1").arg(prevStep->name()));
  99. if (QWidget* stepArea = prevStep->stepArea())
  100. {
  101. stepArea->setEnabled(false);
  102. if (d->HideWidgetsOfNonCurrentSteps)
  103. {
  104. stepArea->hide();
  105. }
  106. }
  107. }
  108. ctkWorkflowWidgetStep* currentWidgetStep = dynamic_cast<ctkWorkflowWidgetStep*>(currentStep);
  109. // show/enable the current step
  110. if (currentWidgetStep)
  111. {
  112. currentWidgetStep->showUserInterface();
  113. if (QWidget* stepArea = currentWidgetStep->stepArea())
  114. {
  115. // add the step's client area to the widget if we haven't before
  116. if (!this->isAncestorOf(stepArea))
  117. {
  118. d->ClientAreaLayout->addWidget(stepArea);
  119. }
  120. stepArea->setEnabled(true);
  121. stepArea->show();
  122. }
  123. }
  124. }
  125. // --------------------------------------------------------------------------
  126. QString ctkWorkflowGroupBox::title()const
  127. {
  128. Q_D(const ctkWorkflowGroupBox);
  129. return d->CollapsibleButton->text();
  130. }
  131. // --------------------------------------------------------------------------
  132. void ctkWorkflowGroupBox::setTitle(const QString& newTitleText)
  133. {
  134. Q_D(ctkWorkflowGroupBox);
  135. d->CollapsibleButton->setText(newTitleText);
  136. }
  137. // --------------------------------------------------------------------------
  138. QString ctkWorkflowGroupBox::subTitle()const
  139. {
  140. Q_D(const ctkWorkflowGroupBox);
  141. return d->SubTitleTextBrowser->toPlainText();
  142. }
  143. // --------------------------------------------------------------------------
  144. void ctkWorkflowGroupBox::setSubTitle(const QString& newSubTitleText)
  145. {
  146. Q_D(ctkWorkflowGroupBox);
  147. d->SubTitleTextBrowser->setPlainText(newSubTitleText);
  148. }
  149. // --------------------------------------------------------------------------
  150. QString ctkWorkflowGroupBox::preText()const
  151. {
  152. Q_D(const ctkWorkflowGroupBox);
  153. return d->PreTextBrowser->toPlainText();
  154. }
  155. // --------------------------------------------------------------------------
  156. void ctkWorkflowGroupBox::setPreText(const QString& newPreText)
  157. {
  158. Q_D(ctkWorkflowGroupBox);
  159. d->PreTextBrowser->setPlainText(newPreText);
  160. }
  161. // --------------------------------------------------------------------------
  162. QString ctkWorkflowGroupBox::postText()const
  163. {
  164. Q_D(const ctkWorkflowGroupBox);
  165. return d->PostTextBrowser->toPlainText();
  166. }
  167. // --------------------------------------------------------------------------
  168. void ctkWorkflowGroupBox::setPostText(const QString& newPostText)
  169. {
  170. Q_D(ctkWorkflowGroupBox);
  171. d->PostTextBrowser->setPlainText(newPostText);
  172. }
  173. // --------------------------------------------------------------------------
  174. QString ctkWorkflowGroupBox::errorText()const
  175. {
  176. Q_D(const ctkWorkflowGroupBox);
  177. return d->ErrorTextBrowser->toPlainText();
  178. }
  179. // --------------------------------------------------------------------------
  180. void ctkWorkflowGroupBox::setErrorText(const QString& newErrorText)
  181. {
  182. Q_D(ctkWorkflowGroupBox);
  183. d->ErrorTextBrowser->setPlainText(newErrorText);
  184. }