CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkLayoutManager.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkLayoutManager_h
22 #define __ctkLayoutManager_h
23 
24 // Qt includes
25 #include <QObject>
26 #include <QDomDocument>
27 class QLayoutItem;
28 class QWidgetItem;
29 
30 // CTK includes
31 #include "ctkWidgetsExport.h"
32 class ctkLayoutManagerPrivate;
34 
74 class CTK_WIDGETS_EXPORT ctkLayoutManager: public QObject
75 {
76  Q_OBJECT
79  Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
80 public:
82  ctkLayoutManager(QObject* parent = 0);
83  explicit ctkLayoutManager(QWidget* viewport, QObject* parent);
84 
86  virtual ~ctkLayoutManager();
87 
88  void setViewport(QWidget* widget);
89  Q_INVOKABLE QWidget* viewport()const;
90 
93  int spacing()const;
96  void setSpacing(int spacing);
97 
98  void refresh();
99 
100 public Q_SLOTS:
101 
102 Q_SIGNALS:
103  void layoutChanged();
104 
105 protected:
106  QScopedPointer<ctkLayoutManagerPrivate> d_ptr;
107  ctkLayoutManager(ctkLayoutManagerPrivate* ptr, QWidget* viewport, QObject* parent);
108 
109  virtual void onViewportChanged();
110  void clearLayout();
111  virtual void setupLayout();
112 
113  virtual void setLayout(const QDomDocument& newLayout);
114  const QDomDocument layout()const;
115 
119  virtual QLayoutItem* processElement(QDomElement element);
122  virtual QLayoutItem* processLayoutElement(QDomElement layoutElement);
125  virtual QLayoutItem* layoutFromXML(QDomElement layoutElement);
128  void processItemElement(QDomElement layoutElement, QLayoutItem* layoutItem);
131  virtual void addChildItemToLayout(QDomElement itemElement, QLayoutItem* childItem, QLayoutItem* layoutItem);
135  QWidgetItem* widgetItemFromXML(QDomElement layoutElement);
140  virtual void setupView(QDomElement layoutElement, QWidget* view);
143  QList<QLayoutItem*> widgetItemsFromXML(QDomElement layoutElement);
149  virtual QWidget* viewFromXML(QDomElement layoutElement) = 0;
159  virtual QList<QWidget*> viewsFromXML(QDomElement layoutElement);
160 
161 private:
162  Q_DECLARE_PRIVATE(ctkLayoutManager);
163  Q_DISABLE_COPY(ctkLayoutManager);
164 };
165 
166 #endif
QScopedPointer< ctkLayoutManagerPrivate > d_ptr