ctkWorkflowAbstractPagedWidget.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 __ctkWorkflowAbstractPagedWidget_h
  15. #define __ctkWorkflowAbstractPagedWidget_h
  16. // Qt includes
  17. // CTK includes
  18. #include "ctkWorkflowWidget.h"
  19. #include "ctkPimpl.h"
  20. #include "CTKWidgetsExport.h"
  21. class ctkWorkflowWidgetStep;
  22. class ctkWorkflowAbstractPagedWidgetPrivate;
  23. /// ctkWorkflowAbstractPagedWidget is the basis for a workflow with a
  24. /// user interface containing multiple pages.
  25. /// It is an abstract child of ctkWorkflowWidget and therefore is a
  26. /// ctkWorkflow (i.e. a state machine). It has a client area
  27. /// consisting of multiple pages (i.e. a QStackedWidget or a
  28. /// QTabWidget), onto which step-specific widgets can be placed.
  29. /// Multiple workflow steps can correspond to the same page. The main
  30. /// widget can be inserted directly inside another user interface.
  31. class CTK_WIDGETS_EXPORT ctkWorkflowAbstractPagedWidget : public ctkWorkflowWidget
  32. {
  33. Q_OBJECT
  34. // TODO DESIGNER: properties here
  35. public:
  36. ///
  37. /// Superclass typedef
  38. typedef ctkWorkflowWidget Superclass;
  39. ///
  40. /// Constructors
  41. explicit ctkWorkflowAbstractPagedWidget(QWidget* parent = 0);
  42. virtual ~ctkWorkflowAbstractPagedWidget();
  43. /// only need to do if you're specifying an index/label, otherwise
  44. /// the workflow's steps will be added automatically
  45. virtual void addStepArea(ctkWorkflowWidgetStep* step, const QString& label);
  46. virtual void addStepArea(ctkWorkflowWidgetStep* step, int index);
  47. virtual void addStepArea(ctkWorkflowWidgetStep* step, int index, const QString& label);
  48. ///
  49. /// Add a widget to the client area, which is the area where
  50. /// custom-step content should be placed. If you are adding
  51. /// ctkWorkflowWidgetSteps to this workflow, you will probably want
  52. /// to use ctkWorkflowWidget::addNextStep() or
  53. /// ctkWorkflowWidget::addStep() instead.
  54. /// A workflow containing a user interface is made up of steps
  55. /// (ctkWorkflowWidgetStep). 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. /// If not given an index: creates a new page on the client area.
  65. /// If given an index: adds a widget to a previously created page on
  66. /// the client area, as denoted by the page's index. If the given
  67. /// index does not correspond to a previously created page, then a
  68. /// new page will be created.
  69. /// The optional label may or may not be considered by the concrete
  70. /// implementation of this class.
  71. using ctkWorkflowWidget::addWidget;
  72. virtual void addWidget(QWidget* widget);
  73. virtual void addWidget(QWidget* widget, const QString& label);
  74. virtual void addWidget(QWidget* widget, int index);
  75. virtual void addWidget(QWidget* widget, int index, const QString& label);
  76. ///
  77. /// Sets the direction of the QBoxLayout that manages this widget's
  78. /// client area, i.e. the layout manager for the area onto which the
  79. /// step's widgets should be placed (default
  80. /// QBoxLayout::TopToBottom)
  81. /// To change the layout for a specific page, provide its index.
  82. /// Calling ctkPagedWorkflowWidget::setClientAreaDirect() without an
  83. /// index changes the layout direction for all previously created
  84. /// and future pages.
  85. virtual void setClientAreaDirection(const QBoxLayout::Direction& direction, int index = -1);
  86. ///
  87. /// Provided for advanced customization: get the client area.
  88. /// A workflow containing a user interface is made up of steps
  89. /// (ctkWorkflowWidgetStep). Each step should either:
  90. /// 1) reimplement ctkWorkflowWidgetStep::populateStepWidgetsList or
  91. /// set its populateStepWidgetsListCommand to point to a method that
  92. /// will add the custom-step's widgets to the list; or
  93. /// 2) reimplement ctkWorkflowWidgetStep::showUserInterface or set
  94. /// its showUserInterfaceCommand to point to a method that will
  95. /// display the step's user interface. Within that method, each of
  96. /// the custom step's widgets should be added to the workflow
  97. /// widget's clientArea using the addWidget() function.
  98. /// If you do not associate a layout manager with the clientArea,
  99. /// the default layout manager is a QBoxLayout with direction
  100. /// QBoxLayout::TopToBottom. Use the function
  101. /// setClientAreaDirection() to change the direction.
  102. /// For additional customization of layouts, note that
  103. /// ctkWorkflowAbstractPagedWidget()->clientArea()->setLayout() will
  104. /// likely not allow you to customize the client area layout.
  105. /// Customize specific pages instead using
  106. /// ctkWorkflowAbstractPagedWidget::getWidgetFromIndex(index)->setLayout()
  107. /// Reimplement this function in derived classes
  108. virtual QWidget* clientArea() = 0;
  109. ///
  110. /// Provided for advanced customization: get the widget
  111. /// corresponding to the page of the given index
  112. /// Reimplement this function in derived classes
  113. virtual QWidget* getWidgetFromIndex(int index) = 0;
  114. ///
  115. /// Provided for advanced customization: shows a given widget within
  116. /// 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. /// Using showWidget() rather than widget()->show() ensures correct
  128. /// display of the widget within the client area. The widget
  129. /// parameter should correspond to a widget that was previously used
  130. /// with the addWidget() function.
  131. /// Reimplement in derived classes.
  132. virtual void showWidget(QWidget* widget);
  133. protected:
  134. ///
  135. /// Add a widget to a new page of the client area, with a page label
  136. /// that may or may not be considered by the derived class
  137. /// Reimplement this function in derived classes
  138. virtual void addWidgetToClientArea(QWidget* widget, const QString& label) = 0;
  139. ///
  140. /// Set the current widget to that of the page containing the given
  141. /// widget
  142. /// Reimplement this function in derived classes
  143. virtual void setCurrentWidget(QWidget* widget) = 0;
  144. private:
  145. CTK_DECLARE_PRIVATE(ctkWorkflowAbstractPagedWidget);
  146. };
  147. #endif