ctkWorkflowWidgetStep.h 6.1 KB

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