ctkButtonGroup.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 __ctkButtonGroup_h
  15. #define __ctkButtonGroup_h
  16. // Qt includes
  17. #include <QButtonGroup>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "ctkWidgetsExport.h"
  21. class ctkButtonGroupPrivate;
  22. /// \ingroup Widgets
  23. ///
  24. /// ctkButtonGroup is a QButtonGroup with a different behavior when exclusive.
  25. /// An exclusive ctkButtonGroup switches off the previously checked button when
  26. /// a new button is checked. ctkButtonGroup doesn't enforce that 1 button is
  27. /// checked at all time (contrary to QButtonGroup). If a button is checked it is
  28. /// possible to uncheck it without having to check another button.
  29. /// Use ctkButtonGroup the same way than QButtonGroup.
  30. /// \code
  31. /// ctkButtonGroup* buttonGroup = new ctkButtonGroup(parent);
  32. /// buttonGroup->addButton(button1);
  33. /// buttonGroup->addButton(button2);
  34. /// \endcode
  35. /// By default ctkButtonGroup is exclusive.
  36. /// \sa QButtonGroup
  37. class CTK_WIDGETS_EXPORT ctkButtonGroup : public QButtonGroup
  38. {
  39. Q_OBJECT
  40. public:
  41. explicit ctkButtonGroup(QObject *_parent = 0);
  42. virtual ~ctkButtonGroup();
  43. public Q_SLOTS:
  44. /// Check or uncheck the button.
  45. void setChecked(QAbstractButton* button, bool checked = true);
  46. protected Q_SLOTS:
  47. void onButtonClicked(int button);
  48. void onButtonPressed(int button);
  49. protected:
  50. QScopedPointer<ctkButtonGroupPrivate> d_ptr;
  51. private:
  52. Q_DECLARE_PRIVATE(ctkButtonGroup);
  53. Q_DISABLE_COPY(ctkButtonGroup);
  54. };
  55. #endif