ctkWorkflowButtonBoxWidget.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.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 __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. ///
  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. Q_PROPERTY(QString backButtonDefaultText
  42. READ backButtonDefaultText WRITE setBackButtonDefaultText)
  43. Q_PROPERTY(QString nextButtonDefaultText
  44. READ nextButtonDefaultText WRITE setNextButtonDefaultText)
  45. Q_PROPERTY(bool hideInvalidButtons READ hideInvalidButtons WRITE setHideInvalidButtons)
  46. public:
  47. typedef QWidget Superclass;
  48. explicit ctkWorkflowButtonBoxWidget(ctkWorkflow* newWorkflow, QWidget* newParent = 0);
  49. explicit ctkWorkflowButtonBoxWidget(QWidget* newParent = 0);
  50. virtual ~ctkWorkflowButtonBoxWidget();
  51. /// Get the workflow associated with the widget
  52. ctkWorkflow* workflow()const;
  53. /// Set the workflow associated with the widget
  54. void setWorkflow(ctkWorkflow * newWorkflow);
  55. /// Get the 'back' button
  56. QPushButton* backButton()const;
  57. /// Get 'back' button default text
  58. QString backButtonDefaultText()const;
  59. /// \brief Set 'back' button \a defaultText
  60. /// \a defaultText is used if the text associated with the current step is empty
  61. void setBackButtonDefaultText(const QString& defaultText);
  62. /// Get the 'next' button
  63. QPushButton* nextButton()const;
  64. /// Get 'next' button default text
  65. QString nextButtonDefaultText()const;
  66. /// \brief Set 'next' button \a defaultText
  67. /// \a defaultText is used if the text associated with the current step is empty
  68. void setNextButtonDefaultText(const QString& defaultText);
  69. /// Get a list of the 'goTo' buttons
  70. QList<QPushButton*> goToButtons()const;
  71. /// Sets the direction of the QBoxLayout that manages this widget (default is
  72. /// QBoxLayout::LeftToRight)
  73. QBoxLayout::Direction direction()const;
  74. void setDirection(const QBoxLayout::Direction& newDirection);
  75. /// If true, invalid buttons are hidden. If false, invalid buttons are shown but disabled.
  76. /// Default is false.
  77. bool hideInvalidButtons()const;
  78. void setHideInvalidButtons(bool newHide);
  79. public slots:
  80. /// Updates the buttons to reflect the current status of the workflow, and should be called
  81. /// whenever the workflow's current step has changed
  82. virtual void updateButtons(ctkWorkflowStep* currentStep);
  83. protected slots:
  84. /// is called when a 'goTo' button is clicked, and retrieves the corresponding goTo step's id to
  85. /// send to the workflow
  86. virtual void prepareGoToStep();
  87. protected:
  88. QScopedPointer<ctkWorkflowButtonBoxWidgetPrivate> d_ptr;
  89. private:
  90. Q_DECLARE_PRIVATE(ctkWorkflowButtonBoxWidget);
  91. Q_DISABLE_COPY(ctkWorkflowButtonBoxWidget);
  92. };
  93. #endif