ctkExpandableWidget.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 __ctkExpandableWidget_h
  15. #define __ctkExpandableWidget_h
  16. // Qt includes
  17. #include <QFrame>
  18. class QResizeEvent;
  19. // CTK includes
  20. #include "ctkWidgetsExport.h"
  21. class ctkExpandableWidgetPrivate;
  22. /// \ingroup Widgets
  23. /// \brief Widget that can be resized by the user using a corner size grip.
  24. /// ctkExpandableWidget is a container widget that has a user customizable
  25. /// sizeHint.
  26. /// \note If the widget fails to be resized, consider tweaking the size
  27. /// policy of the parents and children widgets.
  28. /// \sa ctkSizeGrip
  29. class CTK_WIDGETS_EXPORT ctkExpandableWidget: public QFrame
  30. {
  31. Q_OBJECT
  32. /// This property controls the movement of freedom allowed to resize the widget.
  33. /// The location of the size grip widget depends on the orientations:
  34. /// - bottom of the widget if Qt::Vertical
  35. /// - right of the widget if Qt::Horizontal
  36. /// - bottom right corner of the widget if Qt::Horizontal|Qt::Vertical.
  37. /// Bottom right corner of the widget with a Qt::Horizontal|Qt::Vertical resize
  38. /// movements of freedom by default.
  39. /// \sa ctkSizeGrip::orientations, sizeGripInside, sizeGripMargins
  40. Q_PROPERTY(Qt::Orientations orientations READ orientations WRITE setOrientations)
  41. /// This property controls whether the size grip widget overlays the children
  42. /// widgets or it is moved into its own margin.
  43. /// Please note that QWidget::setContentsMargins is controlled by
  44. /// ctkExpandableWidget, any value set will be overwritten. You can still set
  45. /// the layout contents margins though.
  46. /// true by default.
  47. /// \sa sizeGripMargins, orientations
  48. Q_PROPERTY(bool sizeGripInside READ isSizeGripInside WRITE setSizeGripInside)
  49. /// This property controls the extra padding to give to the size grip widget.
  50. /// Depending on the contents of ctkExpandableWidget, the location of the size
  51. /// grip widget could look off and would benefit from being moved from a few
  52. /// pixels.
  53. /// When tweaking this property, you may want to make sure it works for all
  54. /// styles and platforms.
  55. /// \sa sizeGripInside, orientations
  56. Q_PROPERTY(QSize sizeGripMargins READ sizeGripMargins WRITE setSizeGripMargins)
  57. public:
  58. typedef QFrame Superclass;
  59. ctkExpandableWidget(QWidget *parent=0);
  60. virtual ~ctkExpandableWidget();
  61. void setOrientations(Qt::Orientations orientations);
  62. Qt::Orientations orientations()const;
  63. void setSizeGripInside(bool);
  64. bool isSizeGripInside()const;
  65. void setSizeGripMargins(QSize margins);
  66. QSize sizeGripMargins()const;
  67. virtual QSize minimumSizeHint()const;
  68. virtual QSize sizeHint()const;
  69. public Q_SLOTS:
  70. /// Recompute the size hint of the widget and resize with regard to the
  71. /// layout.
  72. void updateSizeHint();
  73. protected:
  74. QScopedPointer<ctkExpandableWidgetPrivate> d_ptr;
  75. virtual void resizeEvent(QResizeEvent* event);
  76. virtual bool event(QEvent* event);
  77. private:
  78. Q_DECLARE_PRIVATE(ctkExpandableWidget);
  79. Q_DISABLE_COPY(ctkExpandableWidget);
  80. };
  81. #endif // __ctkExpandableWidget_h