ctkWorkflowWidgetStep.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 __ctkWorkflowWidgetStep_h
  15. #define __ctkWorkflowWidgetStep_h
  16. // Qt includes
  17. #include <QWidget>
  18. #include <QBoxLayout>
  19. #include <QFlags>
  20. #include <QIcon>
  21. // CTK includes
  22. #include "ctkPimpl.h"
  23. #include "ctkWidgetsExport.h"
  24. #include "ctkWorkflowStep.h"
  25. #include "ctkWorkflowTransitions.h"
  26. class ctkWorkflowGroupBox;
  27. class ctkWorkflowWidgetStepPrivate;
  28. /// \ingroup Widgets
  29. ///
  30. /// \brief ctkWorkflowWidgetStep is a convienience class to quickly
  31. /// construct a ctkWorkflowStep with a user interface.
  32. ///
  33. /// It embeds a QWidget* stepArea, onto which step-specific widgets can be placed.
  34. /// The showUserInterface() and hideUserInterface() commands of ctkWorkflowStep are
  35. /// written for you, and, if you desire, the step's "Next" and/or "Back" buttons are
  36. /// added with the appropriate signals and slots.
  37. /// To create a custom step, you can derive from this class and
  38. /// implement only two functions:
  39. /// 1) ctkWorkflowWidgetStep::populateStepWidgetsList(), to define the
  40. /// step-specific widgets;
  41. /// 2) ctkWorkflowWidgetStep::validate(const QString&), to validate the processing
  42. /// state associated with this step.
  43. /// For additional customization, you can reimplement
  44. /// showUserInterface() and hideUserInterface() in derived classes.
  45. /// \sa showUserInterface() hideUserInterface()
  46. class CTK_WIDGETS_EXPORT ctkWorkflowWidgetStep : public QWidget, public ctkWorkflowStep
  47. {
  48. Q_OBJECT
  49. Q_PROPERTY(QString stepid READ id WRITE setId)
  50. Q_PROPERTY(QString name READ name WRITE setName)
  51. Q_PROPERTY(QString description READ description WRITE setDescription)
  52. Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
  53. Q_PROPERTY(QString statusText READ statusText)
  54. Q_PROPERTY(QString backButtonText READ backButtonText WRITE setBackButtonText)
  55. Q_PROPERTY(QString nextButtonText READ nextButtonText WRITE setNextButtonText)
  56. Q_FLAGS(ButtonBoxHint ButtonBoxHints)
  57. Q_ENUMS(ButtonBoxHint)
  58. Q_PROPERTY(ButtonBoxHints buttonBoxHints READ buttonBoxHints WRITE setButtonBoxHints)
  59. public:
  60. enum ButtonBoxHint {
  61. NoHints = 0x0,
  62. BackButtonHidden = 0x1,
  63. BackButtonDisabled = 0x2,
  64. NextButtonHidden = 0x4,
  65. NextButtonDisabled = 0x8,
  66. ButtonBoxHidden = 0x10
  67. };
  68. Q_DECLARE_FLAGS(ButtonBoxHints, ButtonBoxHint)
  69. explicit ctkWorkflowWidgetStep(QWidget* newParent = 0);
  70. explicit ctkWorkflowWidgetStep(const QString& newId, QWidget* newParent = 0);
  71. virtual ~ctkWorkflowWidgetStep();
  72. /// \brief Override the back button text of any ctkWorkflowButtonBox when this step
  73. /// is the current step
  74. virtual QString backButtonText()const;
  75. virtual void setBackButtonText(const QString& name);
  76. /// \brief Override the next button text of any ctkWorkflowButtonBox when this step
  77. /// is the current step
  78. virtual QString nextButtonText()const;
  79. virtual void setNextButtonText(const QString& name);
  80. /// \brief Override the button visibility of any ctkWorkflowButtonBox when this step is the
  81. /// current step
  82. void setButtonBoxHints(ButtonBoxHints buttonBoxHints);
  83. ButtonBoxHints buttonBoxHints()const;
  84. /// \brief Associate an icon with this step (ex. used by ctkWorkflowButtonBox to display an icon
  85. /// on 'goTo' buttons).
  86. QIcon icon()const;
  87. void setIcon(const QIcon& newIcon);
  88. /// Returns the QWidget onto which this step's user interface elements are placed.
  89. virtual QWidget* stepArea();
  90. /// Set/get whether a showUserInterfaceCommand has been provided in
  91. /// a separate QObject (see method 2 described for
  92. /// showUserInterface())
  93. virtual bool hasShowUserInterfaceCommand()const;
  94. virtual void setHasShowUserInterfaceCommand(bool flag);
  95. /// Set/get whether a createUserInterfaceCommand has been provided in
  96. /// a separate QObject (see method 2 described for
  97. /// createUserInterface())
  98. virtual bool hasCreateUserInterfaceCommand()const;
  99. virtual void setHasCreateUserInterfaceCommand(bool flag);
  100. protected:
  101. /// Creates the user interface associated with this step.
  102. virtual void createUserInterface(){}
  103. /// Prepares the step to be shown.
  104. virtual void showUserInterface();
  105. /// \brief Signal (emitted by the private implementation) indicating that the step's
  106. /// createUserInterface() method should be called.
  107. /// \sa createUserInterface()
  108. void invokeCreateUserInterfaceCommand()const;
  109. /// \brief Signal (emitted by the private implementation) indicating that the step's
  110. /// createUserInterface() method has completed.
  111. /// \sa createUserInterface()
  112. void createUserInterfaceComplete()const;
  113. /// \brief Signal (emitted by the private implementation) indicating that the step's
  114. /// 'showUserInterface() method should be called.
  115. /// \sa showUserInterface()
  116. void invokeShowUserInterfaceCommand()const;
  117. /// \brief Signal (emitted by the private implementation) indicating that the step's
  118. /// showUserInterface() method has completed.
  119. /// \sa showUserInterface()
  120. void showUserInterfaceComplete()const;
  121. private:
  122. //Q_DECLARE_PRIVATE(ctkWorkflowWidgetStep);
  123. // Since this class derives from both QWidget and ctkWorkflowStep,
  124. // let's specify which 'd_ptr' to use to avoid ambiguous reference
  125. inline ctkWorkflowWidgetStepPrivate* d_func() { return reinterpret_cast<ctkWorkflowWidgetStepPrivate *>(qGetPtrHelper(ctkWorkflowStep::d_ptr)); }
  126. inline const ctkWorkflowWidgetStepPrivate* d_func() const { return reinterpret_cast<const ctkWorkflowWidgetStepPrivate *>(qGetPtrHelper(ctkWorkflowStep::d_ptr)); }
  127. friend class ctkWorkflowWidgetStepPrivate;
  128. Q_DISABLE_COPY(ctkWorkflowWidgetStep);
  129. friend class ctkWorkflowGroupBox; // For access to showUserInterface()
  130. };
  131. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkWorkflowWidgetStep::ButtonBoxHints)
  132. #endif