ctkWorkflowButtonBoxWidget.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /// This property controls the text of the back button when the step text is empty.
  43. /// "Back" by default.
  44. /// \sa nextButtonDefaultText, goToButtonDefaultText
  45. Q_PROPERTY(QString backButtonDefaultText
  46. READ backButtonDefaultText WRITE setBackButtonDefaultText)
  47. /// This property controls the text of the next button when the step text is empty.
  48. /// "Next" by default.
  49. /// \sa backButtonDefaultText, goToButtonDefaultText
  50. Q_PROPERTY(QString nextButtonDefaultText
  51. READ nextButtonDefaultText WRITE setNextButtonDefaultText)
  52. /// This property controls whether the goTo buttons are visible or hidden.
  53. /// False (visible) by default.
  54. /// \sa hideInvalidButtons
  55. Q_PROPERTY(bool hideGoToButtons READ hideGoToButtons WRITE setHideGoToButtons)
  56. /// This property controls whether the back, next or goTo buttons are hidden when disabled.
  57. /// Note that buttons can also be hidden via ctkWorkflowWidgetStep::buttonHints.
  58. /// \sa ctkWofklowWidgetStep::buttonBoxHints
  59. Q_PROPERTY(bool hideInvalidButtons READ hideInvalidButtons WRITE setHideInvalidButtons)
  60. public:
  61. typedef QWidget Superclass;
  62. explicit ctkWorkflowButtonBoxWidget(ctkWorkflow* newWorkflow, QWidget* newParent = 0);
  63. explicit ctkWorkflowButtonBoxWidget(QWidget* newParent = 0);
  64. virtual ~ctkWorkflowButtonBoxWidget();
  65. /// Get the workflow associated with the widget
  66. ctkWorkflow* workflow()const;
  67. /// Set the workflow associated with the widget
  68. void setWorkflow(ctkWorkflow * newWorkflow);
  69. /// Get the 'back' button
  70. QPushButton* backButton()const;
  71. /// Get 'back' button default text
  72. QString backButtonDefaultText()const;
  73. /// \brief Set 'back' button \a defaultText
  74. /// \a defaultText is used if the text associated with the current step is empty
  75. void setBackButtonDefaultText(const QString& defaultText);
  76. /// Get the 'next' button
  77. QPushButton* nextButton()const;
  78. /// Get 'next' button default text
  79. QString nextButtonDefaultText()const;
  80. /// \brief Set 'next' button \a defaultText
  81. /// \a defaultText is used if the text associated with the current step is empty
  82. void setNextButtonDefaultText(const QString& defaultText);
  83. /// Get a list of the 'goTo' buttons
  84. QList<QPushButton*> goToButtons()const;
  85. /// Sets the direction of the QBoxLayout that manages this widget (default is
  86. /// QBoxLayout::LeftToRight)
  87. QBoxLayout::Direction direction()const;
  88. void setDirection(const QBoxLayout::Direction& newDirection);
  89. /// Return the hideGoToButtons property value.
  90. /// \sa hideGoToButtons
  91. bool hideGoToButtons()const;
  92. /// Set the hideGoToButtons property value.
  93. /// \sa hideGoToButtons
  94. void setHideGoToButtons(bool hide);
  95. /// If true, invalid buttons are hidden. If false, invalid buttons are shown but disabled.
  96. /// Default is false.
  97. bool hideInvalidButtons()const;
  98. void setHideInvalidButtons(bool newHide);
  99. public Q_SLOTS:
  100. /// Updates the buttons to reflect the current status of the workflow, and should be called
  101. /// whenever the workflow's current step has changed
  102. virtual void updateButtons(ctkWorkflowStep* currentStep);
  103. protected Q_SLOTS:
  104. /// is called when a 'goTo' button is clicked, and retrieves the corresponding goTo step's id to
  105. /// send to the workflow
  106. virtual void prepareGoToStep();
  107. protected:
  108. QScopedPointer<ctkWorkflowButtonBoxWidgetPrivate> d_ptr;
  109. private:
  110. Q_DECLARE_PRIVATE(ctkWorkflowButtonBoxWidget);
  111. Q_DISABLE_COPY(ctkWorkflowButtonBoxWidget);
  112. };
  113. #endif