ctkLayoutManager.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 __ctkLayoutManager_h
  15. #define __ctkLayoutManager_h
  16. // Qt includes
  17. #include <QObject>
  18. #include <QDomDocument>
  19. class QLayoutItem;
  20. class QWidgetItem;
  21. // CTK includes
  22. #include "ctkWidgetsExport.h"
  23. class ctkLayoutManagerPrivate;
  24. /// \ingroup Widgets
  25. /// ctkLayoutManager is
  26. class CTK_WIDGETS_EXPORT ctkLayoutManager: public QObject
  27. {
  28. Q_OBJECT
  29. /// Spacing between the widgets in a layout
  30. Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
  31. public:
  32. /// Constructor
  33. ctkLayoutManager(QObject* parent = 0);
  34. explicit ctkLayoutManager(QWidget* viewport, QObject* parent);
  35. /// Destructor
  36. virtual ~ctkLayoutManager();
  37. void setViewport(QWidget* widget);
  38. QWidget* viewport()const;
  39. int spacing()const;
  40. void setSpacing(int spacing);
  41. void refresh();
  42. public Q_SLOTS:
  43. Q_SIGNALS:
  44. void layoutChanged();
  45. protected:
  46. QScopedPointer<ctkLayoutManagerPrivate> d_ptr;
  47. ctkLayoutManager(ctkLayoutManagerPrivate* ptr, QWidget* viewport, QObject* parent);
  48. virtual void onViewportChanged();
  49. void clearLayout();
  50. void setupLayout();
  51. virtual void setLayout(const QDomDocument& newLayout);
  52. const QDomDocument layout()const;
  53. virtual QLayoutItem* processElement(QDomElement element);
  54. virtual QLayoutItem* processLayoutElement(QDomElement layoutElement);
  55. virtual QLayoutItem* layoutFromXML(QDomElement layoutElement);
  56. void processItemElement(QDomElement layoutElement, QLayoutItem* layoutItem);
  57. virtual void addChildItemToLayout(QDomElement itemElement, QLayoutItem* childItem, QLayoutItem* layoutItem);
  58. QWidgetItem* widgetItemFromXML(QDomElement layoutElement);
  59. virtual void setupView(QDomElement layoutElement, QWidget* view);
  60. QList<QLayoutItem*> widgetItemsFromXML(QDomElement layoutElement);
  61. virtual QWidget* viewFromXML(QDomElement layoutElement);
  62. virtual QList<QWidget*> viewsFromXML(QDomElement layoutElement);
  63. private:
  64. Q_DECLARE_PRIVATE(ctkLayoutManager);
  65. Q_DISABLE_COPY(ctkLayoutManager);
  66. };
  67. #endif