ctkWorkflowWidgetStep.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 __ctkWorkflowWidgetStep_h
  15. #define __ctkWorkflowWidgetStep_h
  16. // QT includes
  17. class QObject;
  18. class QWidget;
  19. #include <QBoxLayout>
  20. #include <QFlags>
  21. // CTK includes
  22. #include "ctkPimpl.h"
  23. #include "CTKWidgetsExport.h"
  24. #include "ctkWorkflowStep.h"
  25. #include "ctkWorkflowTransitions.h"
  26. class ctkWorkflowWidget;
  27. class ctkWorkflowButtonBoxWidget;
  28. class ctkWorkflowWidgetStepPrivate;
  29. ///
  30. /// \brief ctkWorkflowWidgetStep is a convienience class to quickly
  31. /// construct a ctkWorkflowStep with a user interface, for use in a ctkWorkflowWidget.
  32. ///
  33. /// It embeds a QWidget* stepArea, onto which step-specific widgets can be placed.
  34. /// The showUserInterface() and hideUserInterface() commands of ctkWorkflowStep are
  35. /// written for you, and, if you desire, the step's "Next" and/or "Back" buttons are
  36. /// added with the appropriate signals and slots.
  37. /// To create a custom step, you can derive from this class and
  38. /// implement only two functions:
  39. /// 1) ctkWorkflowWidgetStep::populateStepWidgetsList(), to define the
  40. /// step-specific widgets;
  41. /// 2) ctkWorkflowWidgetStep::validate(const QString&), to validate the processing
  42. /// state associated with this step.
  43. /// For additional customization, you can reimplement
  44. /// showUserInterface() and hideUserInterface() in derived classes.
  45. /// \sa showUserInterface() hideUserInterface()
  46. class CTK_WIDGETS_EXPORT ctkWorkflowWidgetStep : public ctkWorkflowStep
  47. {
  48. Q_OBJECT
  49. Q_FLAGS(ButtonBoxHint)
  50. public:
  51. enum ButtonBoxHint {
  52. NoHints = 0x0,
  53. BackButtonHidden = 0x1,
  54. BackButtonDisabled = 0x2,
  55. NextButtonHidden = 0x4,
  56. NextButtonDisabled = 0x8,
  57. ButtonBoxHidden = 0x10
  58. };
  59. Q_DECLARE_FLAGS(ButtonBoxHints, ButtonBoxHint)
  60. typedef ctkWorkflowStep Superclass;
  61. explicit ctkWorkflowWidgetStep(ctkWorkflow* newWorkflow, const QString& newId);
  62. virtual ~ctkWorkflowWidgetStep(){}
  63. virtual QString backButtonText()const;
  64. virtual void setBackButtonText(const QString& name);
  65. virtual QString nextButtonText()const;
  66. virtual void setNextButtonText(const QString& name);
  67. // /// TODO - same text for all finish buttons
  68. // virtual QList<QString> finishButtonTexts()const;
  69. // virtual void setFinishButtonText(const QString& name);
  70. // virtual void setFinishButtonTexts(const QList<QString>);
  71. ///
  72. /// Set/get whether a populateStepWidgetsListCommand has been
  73. /// provided in a separate QObject (see method 2 described for
  74. /// populateStepWidgetsList())
  75. virtual int hasPopulateStepWidgetsListCommand()const;
  76. virtual void setHasPopulateStepWidgetsListCommand(int flag);
  77. /// Set/get whether a showUserInterfaceCommand has been provided in
  78. /// a separate QObject (see method 2 described for
  79. /// showUserInterface())
  80. virtual int hasShowUserInterfaceCommand()const;
  81. virtual void setHasShowUserInterfaceCommand(int flag);
  82. ///
  83. /// Sets the direction of the QBoxLayout that manages this widget's
  84. /// client area, i.e. the layout manager for the area onto which the
  85. /// step-specific widgets should be placed. (default
  86. /// QBoxLayout::TopToBottom)
  87. QBoxLayout::Direction stepAreaDirection()const;
  88. void setStepAreaDirection(const QBoxLayout::Direction& direction);
  89. /// Provided for advanced customization: get the stepArea, which is
  90. /// the parent widget for all of this step's step-specific widgets
  91. /// and which will be placed onto the workflow widget's client area.
  92. /// If you do not associate a layout manager with the step area, the
  93. /// default layout manager is a QBoxLayout with direction
  94. /// QBoxLayout::TopToBottom. Use the function
  95. /// setStepAreaDirection() to change the direction, or for
  96. /// additional customization use
  97. /// ctkWorkflowWidgetStep::stepArea()->setLayout()
  98. virtual QWidget* stepArea();
  99. /// Set/get whether or not to associate a buttonBoxWidget with this step (default false)
  100. bool hasButtonBoxWidget()const;
  101. void setHasButtonBoxWidget(bool newHasButtonBoxWidget);
  102. /// The widget with the 'next', 'back' and 'goTo' buttons
  103. virtual ctkWorkflowButtonBoxWidget* buttonBoxWidget();
  104. void setButtonBoxHints(ButtonBoxHints buttonBoxHints);
  105. ButtonBoxHints buttonBoxHints()const;
  106. protected:
  107. virtual void addButtons();
  108. protected slots:
  109. ///
  110. /// For each custom step using the given implementations of
  111. /// showUserInterface() and hideUserInterface(), you must do the
  112. /// following within a reimplmentation of this function:
  113. /// 1) Create instances of the step's widget(s)
  114. /// 2) Set any desired attributes of the step's widget(s)
  115. /// 3) Add the widget(s) to the stepWidgetsList given in the
  116. /// parameter
  117. /// These widgets will be added to the stepArea *in the order in
  118. /// which they were added to the list*, according to the step area's
  119. /// layout
  120. /// Developers can either reimplement the populateStepWidgetsList()
  121. /// method in a subclass of ctkWorkflowWidgetStep (*do* call the
  122. /// superclass's populateStepWidgetsList() method first), or create
  123. /// a ctkWorkflowWidgetStep instance and set the
  124. /// populateStepWidgetListCommand to point to a callback of their
  125. /// choice.
  126. /// Reimplemented in derived classes.
  127. virtual void populateStepWidgetsList(QList<QWidget*>& stepWidgetsList);
  128. ///
  129. /// Shows the user interface associated with this step.
  130. /// Do not call showUserInterface() directly, use onEntry() instead.
  131. /// An implementation of showUserInterface is provided; to use it
  132. /// you must provide an implementation of
  133. /// populateStepWidgetsList().
  134. /// For additional customization, developers can either reimplement
  135. /// the showUserInterface() method in a subclass of
  136. /// ctkWorkflowWidgetStep (*do* call the superclass's
  137. /// showUserInterface() method first), or create a
  138. /// ctkWorkflowWidgetStep instance and set the
  139. /// showUserInterfaceCommand to point to a callback of their choice.
  140. /// Reimplement in derived classes.
  141. virtual void showUserInterface();
  142. ///
  143. /// TODO
  144. virtual void evaluatePopulateStepWidgetsListResults();
  145. signals:
  146. void invokePopulateStepWidgetsListCommand(QList<QWidget*>& stepWidgetsList)const;
  147. void populateStepWidgetsListComplete()const;
  148. void invokeShowUserInterfaceCommand()const;
  149. void showUserInterfaceComplete()const;
  150. private:
  151. CTK_DECLARE_PRIVATE(ctkWorkflowWidgetStep);
  152. friend class ctkWorkflowWidget; // For access to ..
  153. ///
  154. /// Sets the widget's layout's direction, if widget's layout is a
  155. /// QBoxLayout. Used internally by setWorkflowWidgetDirection() and
  156. /// setClientAreaDirection()
  157. virtual void changeWidgetDirection(QWidget* widget, const QBoxLayout::Direction& direction);
  158. };
  159. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkWorkflowWidgetStep::ButtonBoxHints)
  160. #endif