ctkWorkflowGroupBox.cpp 7.1 KB

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