ctkWorkflowButtonBoxWidget.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
  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 __ctkWorkflowButtonBoxWidget_h
  15. #define __ctkWorkflowButtonBoxWidget_h
  16. // QT includes
  17. #include <QWidget>
  18. //class QList;
  19. class QPushButton;
  20. #include <QBoxLayout>
  21. // CTK includes
  22. #include "ctkPimpl.h"
  23. #include "ctkWidgetsExport.h"
  24. class ctkWorkflow;
  25. class ctkWorkflowStep;
  26. class ctkWorkflowButtonBoxWidgetPrivate;
  27. /// \ingroup Widgets
  28. ///
  29. /// \brief A widget that controls a workflow
  30. ///
  31. /// Creates:
  32. /// - a 'back' button to go to the previous step
  33. /// - a 'next' button to go the next step
  34. /// - 'goTo' buttons to go to finish steps, i.e. those steps in the workflow that do not have any
  35. /// steps following them
  36. ///
  37. /// The updateButtons() slot updates the buttons to reflect the current status of the workflow, and
  38. /// should be called whenever the workflow's current step has changed
  39. class CTK_WIDGETS_EXPORT ctkWorkflowButtonBoxWidget : public QWidget
  40. {
  41. Q_OBJECT
  42. Q_PROPERTY(QString backButtonDefaultText
  43. READ backButtonDefaultText WRITE setBackButtonDefaultText)
  44. Q_PROPERTY(QString nextButtonDefaultText
  45. READ nextButtonDefaultText WRITE setNextButtonDefaultText)
  46. Q_PROPERTY(bool hideInvalidButtons READ hideInvalidButtons WRITE setHideInvalidButtons)
  47. public:
  48. typedef QWidget Superclass;
  49. explicit ctkWorkflowButtonBoxWidget(ctkWorkflow* newWorkflow, QWidget* newParent = 0);
  50. explicit ctkWorkflowButtonBoxWidget(QWidget* newParent = 0);
  51. virtual ~ctkWorkflowButtonBoxWidget();
  52. /// Get the workflow associated with the widget
  53. ctkWorkflow* workflow()const;
  54. /// Set the workflow associated with the widget
  55. void setWorkflow(ctkWorkflow * newWorkflow);
  56. /// Get the 'back' button
  57. QPushButton* backButton()const;
  58. /// Get 'back' button default text
  59. QString backButtonDefaultText()const;
  60. /// \brief Set 'back' button \a defaultText
  61. /// \a defaultText is used if the text associated with the current step is empty
  62. void setBackButtonDefaultText(const QString& defaultText);
  63. /// Get the 'next' button
  64. QPushButton* nextButton()const;
  65. /// Get 'next' button default text
  66. QString nextButtonDefaultText()const;
  67. /// \brief Set 'next' button \a defaultText
  68. /// \a defaultText is used if the text associated with the current step is empty
  69. void setNextButtonDefaultText(const QString& defaultText);
  70. /// Get a list of the 'goTo' buttons
  71. QList<QPushButton*> goToButtons()const;
  72. /// Sets the direction of the QBoxLayout that manages this widget (default is
  73. /// QBoxLayout::LeftToRight)
  74. QBoxLayout::Direction direction()const;
  75. void setDirection(const QBoxLayout::Direction& newDirection);
  76. /// If true, invalid buttons are hidden. If false, invalid buttons are shown but disabled.
  77. /// Default is false.
  78. bool hideInvalidButtons()const;
  79. void setHideInvalidButtons(bool newHide);
  80. public Q_SLOTS:
  81. /// Updates the buttons to reflect the current status of the workflow, and should be called
  82. /// whenever the workflow's current step has changed
  83. virtual void updateButtons(ctkWorkflowStep* currentStep);
  84. protected Q_SLOTS:
  85. /// is called when a 'goTo' button is clicked, and retrieves the corresponding goTo step's id to
  86. /// send to the workflow
  87. virtual void prepareGoToStep();
  88. protected:
  89. QScopedPointer<ctkWorkflowButtonBoxWidgetPrivate> d_ptr;
  90. private:
  91. Q_DECLARE_PRIVATE(ctkWorkflowButtonBoxWidget);
  92. Q_DISABLE_COPY(ctkWorkflowButtonBoxWidget);
  93. };
  94. #endif