ctkWorkflowAbstractPagedWidget.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. public:
  35. typedef ctkWorkflowWidget Superclass;
  36. explicit ctkWorkflowAbstractPagedWidget(QWidget* newParent = 0);
  37. virtual ~ctkWorkflowAbstractPagedWidget(){}
  38. /// only need to do if you're specifying an index/label, otherwise
  39. /// the workflow's steps will be added automatically
  40. virtual void addStepArea(ctkWorkflowWidgetStep* step, const QString& label);
  41. virtual void addStepArea(ctkWorkflowWidgetStep* step, int index);
  42. virtual void addStepArea(ctkWorkflowWidgetStep* step, int index, const QString& label);
  43. /// Add a widget to the client area, which is the area where
  44. /// custom-step content should be placed. If you are adding
  45. /// ctkWorkflowWidgetSteps to this workflow, you will probably want
  46. /// to use ctkWorkflowWidget::addNextStep() or
  47. /// ctkWorkflowWidget::addStep() instead.
  48. /// A workflow containing a user interface is made up of steps
  49. /// (ctkWorkflowWidgetStep). Each step should either:
  50. /// 1) reimplement ctkWorkflowWidgetStep::populateStepWidgetsList or
  51. /// set its populateStepWidgetsListCommand to point to a method that
  52. /// will add the custom-step's widgets to the list; or
  53. /// 2) reimplement ctkWorkflowWidgetStep::showUserInterface or set
  54. /// its showUserInterfaceCommand to point to a method that will
  55. /// display the step's user interface. Within that method, each of
  56. /// the custom step's widgets should be added to the workflow
  57. /// widget's clientArea using the addWidget() function.
  58. /// If not given an index: creates a new page on the client area.
  59. /// If given an index: adds a widget to a previously created page on
  60. /// the client area, as denoted by the page's index. If the given
  61. /// index does not correspond to a previously created page, then a
  62. /// new page will be created.
  63. /// The optional label may or may not be considered by the concrete
  64. /// implementation of this class.
  65. using ctkWorkflowWidget::addWidget;
  66. virtual void addWidget(QWidget* widget);
  67. virtual void addWidget(QWidget* widget, const QString& label);
  68. virtual void addWidget(QWidget* widget, int index);
  69. virtual void addWidget(QWidget* widget, int index, const QString& label);
  70. /// Sets the direction of the QBoxLayout that manages this widget's
  71. /// client area, i.e. the layout manager for the area onto which the
  72. /// step's widgets should be placed (default
  73. /// QBoxLayout::TopToBottom)
  74. /// To change the layout for a specific page, provide its index.
  75. /// Calling ctkPagedWorkflowWidget::setClientAreaDirect() without an
  76. /// index changes the layout direction for all previously created
  77. /// and future pages.
  78. virtual void setClientAreaDirection(const QBoxLayout::Direction& direction, int index = -1);
  79. /// Provided for advanced customization: get the client area.
  80. /// A workflow containing a user interface is made up of steps
  81. /// (ctkWorkflowWidgetStep). Each step should either:
  82. /// 1) reimplement ctkWorkflowWidgetStep::populateStepWidgetsList or
  83. /// set its populateStepWidgetsListCommand to point to a method that
  84. /// will add the custom-step's widgets to the list; or
  85. /// 2) reimplement ctkWorkflowWidgetStep::showUserInterface or set
  86. /// its showUserInterfaceCommand to point to a method that will
  87. /// display the step's user interface. Within that method, each of
  88. /// the custom step's widgets should be added to the workflow
  89. /// widget's clientArea using the addWidget() function.
  90. /// If you do not associate a layout manager with the clientArea,
  91. /// the default layout manager is a QBoxLayout with direction
  92. /// QBoxLayout::TopToBottom. Use the function
  93. /// setClientAreaDirection() to change the direction.
  94. /// For additional customization of layouts, note that
  95. /// ctkWorkflowAbstractPagedWidget()->clientArea()->setLayout() will
  96. /// likely not allow you to customize the client area layout.
  97. /// Customize specific pages instead using
  98. /// ctkWorkflowAbstractPagedWidget::getWidgetFromIndex(index)->setLayout()
  99. virtual QWidget* clientArea() = 0;
  100. /// Provided for advanced customization: get the widget
  101. /// corresponding to the page of the given index
  102. virtual QWidget* getWidgetFromIndex(int index) = 0;
  103. /// Provided for advanced customization: shows a given widget within
  104. /// the client area.
  105. /// A workflow containing a user interface is made up of steps
  106. /// (ctkWorkflowWidgetStep). Each step should either:
  107. /// 1) reimplement ctkWorkflowWidgetStep::populateStepWidgetsList or
  108. /// set its populateStepWidgetsListCommand to point to a method that
  109. /// will add the custom-step's widgets to the list; or
  110. /// 2) reimplement ctkWorkflowWidgetStep::showUserInterface or set
  111. /// its showUserInterfaceCommand to point to a method that will
  112. /// display the step's user interface. Within that method, each of
  113. /// the custom step's widgets should be added to the workflow
  114. /// widget's clientArea using the addWidget() function.
  115. /// Using showWidget() rather than widget()->show() ensures correct
  116. /// display of the widget within the client area. The widget
  117. /// parameter should correspond to a widget that was previously used
  118. /// with the addWidget() function.
  119. /// Reimplement in derived classes.
  120. virtual void showWidget(QWidget* widget);
  121. protected:
  122. /// Add a widget to a new page of the client area, with a page label
  123. /// that may or may not be considered by the derived class
  124. virtual void addWidgetToClientArea(QWidget* widget, const QString& label) = 0;
  125. /// Set the current widget to that of the page containing the given widget
  126. virtual void setCurrentWidget(QWidget* widget) = 0;
  127. private:
  128. CTK_DECLARE_PRIVATE(ctkWorkflowAbstractPagedWidget);
  129. };
  130. #endif