ctkWorkflowWidget.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #ifndef __ctkWorkflowWidget_h
  15. #define __ctkWorkflowWidget_h
  16. // Qt includes
  17. #include <QWidget>
  18. class QPushButton;
  19. #include <QBoxLayout>
  20. // CTK includes
  21. #include "ctkPimpl.h"
  22. #include "CTKWidgetsExport.h"
  23. class ctkWorkflow;
  24. class ctkWorkflowStep;
  25. class ctkWorkflowWidgetStep;
  26. class ctkWorkflowButtonBoxWidget;
  27. class ctkWorkflowWidgetPrivate;
  28. /// \brief ctkWorkflowWidget is the basis for a workflow with a user interface.
  29. ///
  30. /// It is a ctkWorkflow (i.e. a state machine) that has a QWidget* mainWidget.
  31. /// The mainWidget allows for a widget title, sub-title, pre-text, post-text and
  32. /// error text to be displayed, as well as a QWidget* client area, onto which
  33. /// step-specific widgets can be placed. Multiple workflow steps can correspond to
  34. /// the same client area.
  35. /// The main widget can be inserted directly inside another user interface.
  36. class CTK_WIDGETS_EXPORT ctkWorkflowWidget : public QWidget
  37. {
  38. Q_OBJECT
  39. public:
  40. typedef QWidget Superclass;
  41. explicit ctkWorkflowWidget(QWidget* parent = 0);
  42. virtual ~ctkWorkflowWidget();
  43. ///
  44. ///
  45. virtual ctkWorkflow* workflow()const;
  46. virtual void setWorkflow(ctkWorkflow* workflow);
  47. /// \brief Add a widget to the client area, which is the area where
  48. /// custom-step content should be placed.
  49. ///
  50. /// If you are adding ctkWorkflowWidgetSteps to this workflow, you will probably want
  51. /// to use ctkWorkflowWidget::addNextStep() or ctkWorkflowWidget::addStep() instead.
  52. /// A workflow containing a user interface is made up of steps
  53. /// (ctkWorkflowWidgetStep).
  54. ///
  55. /// Each step should either:
  56. /// 1) reimplement ctkWorkflowWidgetStep::populateStepWidgetsList or
  57. /// set its populateStepWidgetsListCommand to point to a method that
  58. /// will add the custom-step's widgets to the list; or
  59. /// 2) reimplement ctkWorkflowWidgetStep::showUserInterface or set
  60. /// its showUserInterfaceCommand to point to a method that will
  61. /// display the step's user interface. Within that method, each of
  62. /// the custom step's widgets should be added to the workflow
  63. /// widget's clientArea using the addWidget() function.
  64. virtual void addWidget(QWidget* widget);
  65. ///
  66. /// If hideWidgetsOfNonCurrentSteps is turned on, then a step's
  67. /// widgets will be hidden when that step is not the current step.
  68. /// If it is turned off, then they will be shown but disabled.
  69. /// (Default OFF).
  70. virtual int hideWidgetsOfNonCurrentSteps()const;
  71. virtual void setHideWidgetsOfNonCurrentSteps(int flag);
  72. ///
  73. /// Set/get the title text (usually a few words), located in the top
  74. /// area.
  75. /// Note that this method is called automatically to display the
  76. /// \brief Set/get the title text (usually a few words), located in the top area.
  77. /// \note This method is called automatically to display the
  78. /// name of the ctkWorkflow's currentStep() step (see the
  79. /// ctkWorkflowStep::name() method).
  80. virtual QString title()const;
  81. virtual void setTitle(const QString& title);
  82. /// \brief Set/get the subtitle text (usually a short sentence or two),
  83. /// located in the top area below the title.
  84. /// \note This method is called automatically to display the
  85. /// description of the ctkWorkflow's currentStep() step.
  86. /// \sa ctkWorkflowStep::description()
  87. virtual QString subTitle()const;
  88. virtual void setSubTitle(const QString& subTitle);
  89. /// \brief Set/get the pre-text, i.e. the contents of a convenience text
  90. /// section placed just above the client area.
  91. virtual QString preText()const;
  92. virtual void setPreText(const QString& preText);
  93. /// \brief Set/get the post-text, i.e. the contents of a convenience text
  94. /// section placed just below the client area.
  95. virtual QString postText()const;
  96. virtual void setPostText(const QString& postText);
  97. /// \brief Set/get the error text, i.e. the contents of the convenience
  98. /// section placed below the client area.
  99. ///
  100. /// This is typically used by a step's ctkWorkflowStep::validate(const QString&) function to report an
  101. /// error when validation fails
  102. virtual QString errorText()const;
  103. virtual void setErrorText(const QString& errorText);
  104. /// Sets the direction of the QBoxLayout that manages this widget's
  105. /// client area, i.e. the layout manager for the area onto which the
  106. /// step's widgets should be placed (default QBoxLayout::TopToBottom)
  107. QBoxLayout::Direction clientAreaDirection()const;
  108. void setClientAreaDirection(const QBoxLayout::Direction& direction);
  109. /// Sets the direction for the QBoxLayout that manages this widget.
  110. /// This is the layout of the entire widget, i.e. the layout manager
  111. /// that places the title, subtitle, preText, client, postText and
  112. /// errorText sections. (default QBoxLayout::TopToBottom)
  113. QBoxLayout::Direction direction()const;
  114. void setDirection(const QBoxLayout::Direction& direction);
  115. ///
  116. /// Provided for advanced customization: get the client area.
  117. /// A workflow containing a user interface is made up of steps
  118. /// (ctkWorkflowWidgetStep). Each step should either:
  119. /// 1) reimplement ctkWorkflowWidgetStep::populateStepWidgetsList or
  120. /// set its populateStepWidgetsListCommand to point to a method that
  121. /// will add the custom-step's widgets to the list; or
  122. /// 2) reimplement ctkWorkflowWidgetStep::showUserInterface or set
  123. /// its showUserInterfaceCommand to point to a method that will
  124. /// display the step's user interface. Within that method, each of
  125. /// the custom step's widgets should be added to the workflow
  126. /// widget's clientArea using the addWidget() function.
  127. /// If you do not associate a layout manager with the clientArea,
  128. /// the default layout manager is a QBoxLayout with direction
  129. /// QBoxLayout::TopToBottom. Use the function
  130. /// setClientAreaDirection() to change the direction, or for
  131. /// additional customization use
  132. /// ctkWorkflowWidget::clientArea()->setLayout()
  133. virtual QWidget* clientArea();
  134. /// Set/get whether or not to associate a buttonBoxWidget with this step (default true)
  135. bool hasButtonBoxWidget()const;
  136. void setHasButtonBoxWidget(bool newHasButtonBoxWidget);
  137. /// The widget with the 'next', 'back' and 'goTo' buttons
  138. virtual ctkWorkflowButtonBoxWidget* buttonBoxWidget()const;
  139. public slots:
  140. ///
  141. ///
  142. virtual void updateClientArea(ctkWorkflowStep* currentStep);
  143. protected:
  144. /// Sets the widget's layout's direction, if widget's layout is a
  145. /// QBoxLayout.
  146. /// Used internally by setWorkflowWidgetDirection() and setClientAreaDirection()
  147. virtual void changeWidgetDirection(QWidget* widget, const QBoxLayout::Direction& direction);
  148. /// These functions are provided to access ctkWorkflowWidgetPrivate's
  149. /// attributes from ctkWorkflowWidget's descendents.
  150. QWidget* clientSection()const;
  151. void setPrivateClientAreaDirection(const QBoxLayout::Direction& direction);
  152. /// Provided for advanced customization: shows a given widget within
  153. /// the client area.
  154. /// A workflow containing a user interface is made up of steps
  155. /// (ctkWorkflowWidgetStep). Each step should either:
  156. /// 1) reimplement ctkWorkflowWidgetStep::populateStepWidgetsList or
  157. /// set its populateStepWidgetsListCommand to point to a method that
  158. /// will add the custom-step's widgets to the list; or
  159. /// 2) reimplement ctkWorkflowWidgetStep::showUserInterface or set
  160. /// its showUserInterfaceCommand to point to a method that will
  161. /// display the step's user interface. Within that method, each of
  162. /// the custom step's widgets should be added to the workflow
  163. /// widget's clientArea using the addWidget() function.
  164. /// Using showWidget() rather than widget()->show() ensures correct
  165. /// display of the widget within the client area. The widget
  166. /// parameter should correspond to a widget that was previously used
  167. /// with the addWidget() function.
  168. virtual void showWidget(QWidget* widget);
  169. private:
  170. CTK_DECLARE_PRIVATE(ctkWorkflowWidget);
  171. };
  172. #endif