ctkCheckablePushButton.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 __ctkCheckablePushButton_h
  15. #define __ctkCheckablePushButton_h
  16. // CTK includes
  17. #include <ctkPimpl.h>
  18. #include "ctkPushButton.h"
  19. #include "ctkWidgetsExport.h"
  20. class ctkCheckablePushButtonPrivate;
  21. /// \ingroup Widgets
  22. /// Description
  23. /// ctkCheckablePushButton is a QPushButton with a checkbox. By default
  24. /// the checkbox is connected to the checkable property of the push button.
  25. /// You can change this behaviour by clearing the "checkBoxControlsButton"
  26. /// property.
  27. /// The checkBoxUserCheckable property determines if the state of the
  28. /// checkbox can be changed interactively by the user by clicking on the
  29. /// checkbox.
  30. /// \note In checkBoxControlsButton mode, calling setCheckable instead of
  31. /// setCheckState may not refresh the button automatically. Use setCheckState
  32. /// instead.
  33. /// \note You can automatically check the button when the user checks the
  34. /// checkbox by connecting the checkBoxToggled(bool) signal with the
  35. /// setChecked(bool) slot.
  36. /// \warning The checkbox is drawn in place of the pushbuton icon, any icon
  37. /// will then be ignored.
  38. class CTK_WIDGETS_EXPORT ctkCheckablePushButton : public ctkPushButton
  39. {
  40. Q_OBJECT
  41. /// This property controls the location of the checkbox with regard to the text.
  42. /// Qt::AlignLeft|Qt::AlignVCenter by default
  43. Q_PROPERTY(Qt::Alignment indicatorAlignment READ indicatorAlignment WRITE setIndicatorAlignment)
  44. Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged)
  45. Q_PROPERTY(bool checkBoxControlsButton READ checkBoxControlsButton WRITE setCheckBoxControlsButton)
  46. Q_PROPERTY(bool checkBoxUserCheckable READ isCheckBoxUserCheckable WRITE setCheckBoxUserCheckable)
  47. public:
  48. ctkCheckablePushButton(QWidget *parent = 0);
  49. ctkCheckablePushButton(const QString& text, QWidget *parent = 0);
  50. virtual ~ctkCheckablePushButton();
  51. /// Set the alignment of the indicator (arrow) on the button,
  52. /// Qt::AlignLeft|Qt::AlignVCenter by default.
  53. void setIndicatorAlignment(Qt::Alignment indicatorAlignment);
  54. Qt::Alignment indicatorAlignment()const;
  55. virtual Qt::CheckState checkState()const;
  56. virtual void setCheckState(Qt::CheckState checkState);
  57. virtual bool checkBoxControlsButton()const;
  58. virtual void setCheckBoxControlsButton(bool b);
  59. virtual bool isCheckBoxUserCheckable()const;
  60. virtual void setCheckBoxUserCheckable(bool b);
  61. Q_SIGNALS:
  62. /// Fired anytime the checkbox change of state
  63. void checkBoxToggled(bool);
  64. /// Fired anytime the checkbox change of state
  65. void checkStateChanged(Qt::CheckState newCheckState);
  66. protected:
  67. /// Reimplemented for internal reasons
  68. virtual void mousePressEvent(QMouseEvent* event);
  69. /// Reimplemented for internal reasons
  70. virtual bool hitButton(const QPoint & pos) const;
  71. private:
  72. Q_DECLARE_PRIVATE(ctkCheckablePushButton);
  73. Q_DISABLE_COPY(ctkCheckablePushButton);
  74. };
  75. #endif