ctkSizeGrip.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 __ctkSizeGrip_h
  15. #define __ctkSizeGrip_h
  16. // Qt includes
  17. #include <QWidget>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkSizeGripPrivate;
  21. /// \ingroup Widgets
  22. /// \brief ctkSizeGrip is a utility widget that allows widget in a layout to be
  23. /// manually resized.
  24. /// It is not meant to be used as is but with a third party that can change the
  25. /// size hint of a widget such as a container widget (e.g. ctkExpandableWidget).
  26. /// To resize a widget, the user must left click on the size grip and drag
  27. /// left/right to control the width and/or up/bottom to control the height.
  28. /// Left button double-click resets the size hint of the target widget to its
  29. /// default.
  30. /// \sa ctkExpandableWidget
  31. class CTK_WIDGETS_EXPORT ctkSizeGrip
  32. : public QWidget
  33. {
  34. Q_OBJECT
  35. /// This property describes the movement of freedom of the sizeGrip.
  36. /// There are 3 supported orientations: Qt::Vertical, Qt::Horizontal and
  37. /// Qt::Horizontal|Qt::Vertical.
  38. /// If the orientation is solely Qt::Horizontal, the size grip only allows
  39. /// vertical resize. If the orientation is solely Qt::Vertical, only
  40. /// horizontal resizes are supported.
  41. /// Note that the orientations change the look of the widget. And it also
  42. /// probably means that the position of the widget should be changed: bottom
  43. /// side for Qt::Vertical, right side for Qt::Horizontal and bottom
  44. /// right corner for Qt::Horizontal|Qt::Vertical.
  45. /// Qt::Horizontal|Qt::Vertical by default.
  46. Q_PROPERTY(Qt::Orientations orientations READ orientations WRITE setOrientations)
  47. /// This property holds the sizeHint set by the user via the size grip or
  48. /// programatically using \a setWidgetSizeHint().
  49. /// If width or/and height is 0, it means the sizeHint has not been touched
  50. /// and the default widget sizeHint should be used instead.
  51. /// For example, if \a orientations is solely vertical (not also
  52. /// horizontal), the width component of the widget sizeHint is 0.
  53. /// If \a orientations is solely horizontal, the widgets izeHint height is 0.
  54. /// (0,0) by default (meaning the default widget sizehint should be used).
  55. Q_PROPERTY(QSize widgetSizeHint READ widgetSizeHint WRITE setWidgetSizeHint)
  56. /// This property holds whether the size grip resizes the widget or not.
  57. /// If the size grip doesn't resize the widget, it still returns a valid
  58. /// \a widgetSizeHint that can be used by a third party.
  59. /// By default, the widget is resized.
  60. /// \tbd it is experimental and not really working.
  61. Q_PROPERTY(bool resizeWidget READ resizeWidget WRITE setResizeWidget)
  62. public:
  63. typedef QWidget Superclass;
  64. explicit ctkSizeGrip(QWidget *parent);
  65. explicit ctkSizeGrip(QWidget* widgetToResize, QWidget *parent);
  66. virtual ~ctkSizeGrip();
  67. void setOrientations(Qt::Orientations orientations);
  68. Qt::Orientations orientations()const;
  69. /// Set the widget to resize.
  70. /// Note that the widget is not resized by ctkSizeGrip if resizeWidget is false.
  71. /// It should be a third party that should resize the widget
  72. /// (e.g. ctkExpandableWidget).
  73. /// \sa widgetSizeHint()
  74. QWidget* widgetToResize()const;
  75. void setWidgetToResize(QWidget* target);
  76. /// Return the sizeHint set by the user or programatically using
  77. /// \a setWidgetSizeHint().
  78. /// If width or/and height is 0, it means the sizeHint has not been touched
  79. /// and the original widget sizeHint should be used instead.
  80. /// When the orientation is solely vertical, the returned width component of
  81. /// the sizeHint is 0. If the orientations is solely horizontal, the sizeHint
  82. /// height is 0.
  83. QSize widgetSizeHint()const;
  84. void setResizeWidget(bool resize);
  85. bool resizeWidget()const;
  86. /// SizeHint of the size grip. It depends on the style in use, but it is
  87. /// typically a small (e.g. 13x13) square sizehint for
  88. /// Qt::Horizontal|Qt::Vertical \a orientations and a narrow rectangle for
  89. /// Qt::Horizontal or Qt::Vertical orientations.
  90. virtual QSize sizeHint() const;
  91. public Q_SLOTS:
  92. /// Expressively change the sizeHint of the widget to resize.
  93. /// \sa widgetSizeHint()
  94. void setWidgetSizeHint(QSize sizeHint);
  95. Q_SIGNALS:
  96. void widgetSizeHintChanged(QSize sizeHint);
  97. protected:
  98. QScopedPointer<ctkSizeGripPrivate> d_ptr;
  99. virtual void paintEvent(QPaintEvent* paintEvent);
  100. virtual bool event(QEvent* event);
  101. virtual void mousePressEvent(QMouseEvent* mouseEvent);
  102. virtual void mouseMoveEvent(QMouseEvent* mouseEvent);
  103. virtual void mouseReleaseEvent(QMouseEvent* mouseEvent);
  104. virtual void mouseDoubleClickEvent(QMouseEvent* mouseEvent);
  105. private:
  106. Q_DECLARE_PRIVATE(ctkSizeGrip)
  107. Q_DISABLE_COPY(ctkSizeGrip)
  108. };
  109. #endif // __ctkSizeGrip_h