ctkWorkflowWidgetStep.h 7.3 KB

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