ctkFlowLayout.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.commontk.org/LICENSE
  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 __ctkFlowLayout_h
  15. #define __ctkFlowLayout_h
  16. // Qt includes
  17. #include <QLayout>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkFlowLayoutPrivate;
  21. /// Acts like a QBoxLayout but if the space is horizontally/vertically limited,
  22. /// it displays items ona a new row/column based on the orientation.
  23. /// Please note that using a Qt::Vertical orientation without the property
  24. /// alignItems set to true might result to weird layout behavior.
  25. class CTK_WIDGETS_EXPORT ctkFlowLayout : public QLayout
  26. {
  27. Q_OBJECT
  28. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  29. Q_PROPERTY(int horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
  30. Q_PROPERTY(int verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
  31. Q_PROPERTY(bool alignItems READ alignItems WRITE setAlignItems)
  32. Q_PROPERTY(Qt::Orientations preferredExpandingDirections READ preferredExpandingDirections WRITE setPreferredExpandingDirections)
  33. public:
  34. typedef QLayout Superclass;
  35. explicit ctkFlowLayout(Qt::Orientation orientation, QWidget* parent = 0);
  36. explicit ctkFlowLayout(QWidget* parent);
  37. explicit ctkFlowLayout();
  38. virtual ~ctkFlowLayout();
  39. /// If orientation is Qt::Horizontal, items are layed out from left to right
  40. /// then top to bottom. If orientation is Qt::Vertical, items are layed out
  41. /// from top to bottom then left to right.
  42. void setOrientation(Qt::Orientation orientation);
  43. Qt::Orientation orientation()const;
  44. /// Indicates how the size hint of the layout should behave. The preferred
  45. /// expanding direction can be different than the orientation of the layout.
  46. /// It can be a combination of Qt::Horizontal and Qt::Vertical, in that case
  47. /// the layout will try to expand in a square shape (evenly distribute the
  48. /// number of rows and columns).
  49. void setPreferredExpandingDirections(Qt::Orientations directions);
  50. Qt::Orientations preferredExpandingDirections()const;
  51. /// Horizontal space between items, if the spacing is <0, a default spacing
  52. /// set on the parent/style will be used.
  53. int horizontalSpacing() const;
  54. void setHorizontalSpacing(int);
  55. /// Vertical space between items, if the spacing is <0, a default spacing
  56. /// set on the parent/style will be used.
  57. int verticalSpacing() const;
  58. void setVerticalSpacing(int);
  59. /// Force the items to be horizontally aligned based on the largest item
  60. /// to display.
  61. /// True by default.
  62. bool alignItems()const;
  63. void setAlignItems(bool);
  64. /// Reimplemented for internal reasons
  65. virtual void addItem(QLayoutItem *item);
  66. virtual Qt::Orientations expandingDirections() const;
  67. virtual bool hasHeightForWidth() const;
  68. virtual int heightForWidth(int) const;
  69. virtual int count() const;
  70. virtual QLayoutItem *itemAt(int index) const;
  71. virtual QSize minimumSize() const;
  72. virtual void setGeometry(const QRect &rect);
  73. virtual QSize sizeHint() const;
  74. virtual QLayoutItem *takeAt(int index);
  75. protected:
  76. QScopedPointer<ctkFlowLayoutPrivate> d_ptr;
  77. private:
  78. Q_DECLARE_PRIVATE(ctkFlowLayout);
  79. Q_DISABLE_COPY(ctkFlowLayout);
  80. };
  81. #endif