ctkWorkflowButtonBoxWidget.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 <QBoxLayout>
  18. #include <QWidget>
  19. // CTK includes
  20. #include "ctkPimpl.h"
  21. #include "ctkWidgetsExport.h"
  22. class ctkPushButton;
  23. class ctkWorkflow;
  24. class ctkWorkflowStep;
  25. class ctkWorkflowButtonBoxWidgetPrivate;
  26. /// \ingroup Widgets
  27. ///
  28. /// \brief A widget that controls a workflow
  29. ///
  30. /// Creates:
  31. /// - a 'back' button to go to the previous step
  32. /// - a 'next' button to go the next step
  33. /// - 'goTo' buttons to go to finish steps, i.e. those steps in the workflow that do not have any
  34. /// steps following them
  35. ///
  36. /// The updateButtons() slot updates the buttons to reflect the current status of the workflow, and
  37. /// should be called whenever the workflow's current step has changed
  38. class CTK_WIDGETS_EXPORT ctkWorkflowButtonBoxWidget : public QWidget
  39. {
  40. Q_OBJECT
  41. /// This property controls the text, icon and tooltip of the back button.
  42. /// "[<-]{backButtonText|\"Back\"}(back:description)" by default.
  43. /// \sa backButtonFormat(), setBackButtonFormat(),
  44. /// ctkWorkflow::formatButton(), nextButtonFormat, goToButtonFormat
  45. Q_PROPERTY(QString backButtonFormat
  46. READ backButtonFormat WRITE setBackButtonFormat)
  47. /// This property controls the text, icon and tooltip of the next button.
  48. /// "{nextButtonText|\"Next\"}(next:description)[->]" by default.
  49. /// \sa nextButtonFormat(), setNextButtonFormat(),
  50. /// ctkWorkflow::formatButton(), backButtonFormat, goToButtonFormat
  51. Q_PROPERTY(QString nextButtonFormat
  52. READ nextButtonFormat WRITE setNextButtonFormat)
  53. /// This property controls the text, icon and tooltip of the goTo/finish
  54. /// button.
  55. /// "[icon]{stepid|\"Finish\"}" by default.
  56. /// \sa goToButtonsFormat(), setGoToButtonsFormat(),
  57. /// ctkWorkflow::formatButton(), backButtonFormat, nextButtonFormat
  58. Q_PROPERTY(QString goToButtonsFormat
  59. READ goToButtonsFormat WRITE setGoToButtonsFormat)
  60. /// This property controls whether the goTo buttons are visible or hidden.
  61. /// False (visible) by default.
  62. /// \sa hideInvalidButtons
  63. Q_PROPERTY(bool hideGoToButtons READ hideGoToButtons WRITE setHideGoToButtons)
  64. /// This property controls whether the back, next or goTo buttons are hidden when disabled.
  65. /// Note that buttons can also be hidden via ctkWorkflowWidgetStep::buttonHints.
  66. /// \sa ctkWofklowWidgetStep::buttonBoxHints
  67. Q_PROPERTY(bool hideInvalidButtons READ hideInvalidButtons WRITE setHideInvalidButtons)
  68. public:
  69. typedef QWidget Superclass;
  70. explicit ctkWorkflowButtonBoxWidget(ctkWorkflow* newWorkflow, QWidget* newParent = 0);
  71. explicit ctkWorkflowButtonBoxWidget(QWidget* newParent = 0);
  72. virtual ~ctkWorkflowButtonBoxWidget();
  73. /// Get the workflow associated with the widget
  74. ctkWorkflow* workflow()const;
  75. /// Set the workflow associated with the widget
  76. void setWorkflow(ctkWorkflow * newWorkflow);
  77. /// Get the 'back' button
  78. Q_INVOKABLE ctkPushButton* backButton()const;
  79. /// Return the backButtonFormat property value.
  80. /// \sa backButtonFormat, setBackButtonFormat()
  81. QString backButtonFormat()const;
  82. /// Set the backButtonFormat property value.
  83. /// \sa backButtonFormat, backButtonFormat()
  84. void setBackButtonFormat(const QString& format);
  85. /// Get the 'next' button
  86. Q_INVOKABLE ctkPushButton* nextButton()const;
  87. /// Return the nextButtonFormat property value.
  88. /// \sa nextButtonFormat, setNextButtonFormat()
  89. QString nextButtonFormat()const;
  90. /// Set the nextButtonFormat property value.
  91. /// \sa nextButtonFormat, nextButtonFormat()
  92. void setNextButtonFormat(const QString& format);
  93. /// Return the goToButtonsFormat property value.
  94. /// \sa goToButtonsFormat, setGoToButtonsFormat()
  95. QString goToButtonsFormat()const;
  96. /// Set the goToButtonsFormat property value.
  97. /// \sa goToButtonsFormat, goToButtonsFormat()
  98. void setGoToButtonsFormat(const QString& format);
  99. /// Get a list of the 'goTo' buttons
  100. QList<ctkPushButton*> goToButtons()const;
  101. /// Sets the direction of the QBoxLayout that manages this widget (default is
  102. /// QBoxLayout::LeftToRight)
  103. QBoxLayout::Direction direction()const;
  104. void setDirection(const QBoxLayout::Direction& newDirection);
  105. /// Return the hideGoToButtons property value.
  106. /// \sa hideGoToButtons
  107. bool hideGoToButtons()const;
  108. /// Set the hideGoToButtons property value.
  109. /// \sa hideGoToButtons
  110. void setHideGoToButtons(bool hide);
  111. /// If true, invalid buttons are hidden. If false, invalid buttons are shown but disabled.
  112. /// Default is false.
  113. bool hideInvalidButtons()const;
  114. void setHideInvalidButtons(bool newHide);
  115. public Q_SLOTS:
  116. /// Updates the buttons to reflect the current status of the workflow, and should be called
  117. /// whenever the workflow's current step has changed
  118. virtual void updateButtons(ctkWorkflowStep* currentStep);
  119. protected Q_SLOTS:
  120. /// is called when a 'goTo' button is clicked, and retrieves the corresponding goTo step's id to
  121. /// send to the workflow
  122. virtual void prepareGoToStep();
  123. protected:
  124. QScopedPointer<ctkWorkflowButtonBoxWidgetPrivate> d_ptr;
  125. private:
  126. Q_DECLARE_PRIVATE(ctkWorkflowButtonBoxWidget);
  127. Q_DISABLE_COPY(ctkWorkflowButtonBoxWidget);
  128. };
  129. #endif