Add line for debugging
[kdevelopdvcssupport.git] / sublime / ideallayout.h
blobc425a706a64ab1db1bb6334f7775e1e18d4fcac7
1 /*
2 Copyright 2007 Roberto Raggi <roberto@kdevelop.org>
3 Copyright 2007 Hamish Rodda <rodda@kde.org>
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef SUBLIME_IDEALLAYOUT_H
23 #define SUBLIME_IDEALLAYOUT_H
25 #include <QtGui/QLayout>
26 #include <QtCore/QPointer>
27 #include <QtCore/QMap>
28 #include <QtCore/QHash>
30 #include "sublimedefs.h"
32 class KAction;
33 class KActionCollection;
35 namespace Sublime {
37 class IdealDockWidget;
39 class IdealButtonBarLayout: public QLayout
41 Q_OBJECT
43 public:
44 IdealButtonBarLayout(Qt::Orientation orientation, QWidget *parent = 0);
46 virtual ~IdealButtonBarLayout();
48 void setHeight(int height);
50 inline Qt::Orientation orientation() const;
52 virtual Qt::Orientations expandingDirections() const;
54 virtual QSize minimumSize() const;
56 virtual QSize sizeHint() const;
58 virtual void setGeometry(const QRect &rect);
60 virtual void addItem(QLayoutItem *item);
62 virtual QLayoutItem* itemAt(int index) const;
64 virtual QLayoutItem* takeAt(int index);
66 virtual int count() const;
68 virtual void invalidate();
70 protected:
71 int doVerticalLayout(const QRect &rect, bool updateGeometry = true) const;
73 int doHorizontalLayout(const QRect &rect, bool updateGeometry = true) const;
75 private:
76 QList<QLayoutItem *> _items;
77 Qt::Orientation _orientation;
78 int _height;
79 mutable bool m_minSizeDirty : 1;
80 mutable bool m_sizeHintDirty : 1;
81 mutable bool m_layoutDirty : 1;
82 mutable QSize m_min;
83 mutable QSize m_hint;
86 class IdealMainLayout : public QLayout
88 Q_OBJECT
90 public:
91 enum Role {
92 Left /**< aligning left */,
93 Right /**< aligning right */,
94 Bottom /**< aligning bottom */,
95 Top /**< aligning top */,
96 Central /**< aligning central */
99 IdealMainLayout(QWidget *parent = 0);
101 virtual ~IdealMainLayout();
103 void addWidget(QWidget* widget, Role role);
104 void addButtonBar(QWidget* widget, Role role);
105 void removeWidgets(Role role);
106 void removeWidget(QWidget* widget, Role role);
107 void removeUnanchored();
109 int splitterWidth() const;
110 int widthForRole(Role role) const;
111 void setWidthForRole(Role role, int width);
113 bool isAreaAnchored(Role role) const;
116 * Maximize the given \a widget, or disable any maximized widget if \a widget is null.
118 void maximizeWidget(QWidget* widget);
120 virtual QSize minimumSize() const;
122 virtual QSize sizeHint() const;
124 virtual void setGeometry(const QRect &rect);
126 virtual void addItem(QLayoutItem *item);
128 virtual QLayoutItem* itemAt(int index) const;
130 virtual QLayoutItem* takeAt(int index);
132 virtual int count() const;
134 virtual void invalidate();
136 IdealDockWidget* lastDockWidget() const;
137 IdealDockWidget* lastDockWidget(Role role) const;
138 Role lastDockWidgetRole() const;
140 class IdealMainWidget* mainWidget() const;
142 static Sublime::Position positionForRole(Role role);
144 public Q_SLOTS:
145 void resizeWidget(int thickness, IdealMainLayout::Role role);
146 void anchorWidget(bool anchor, IdealMainLayout::Role role);
148 void loadSettings();
150 Q_SIGNALS:
151 /* Reports that a dock widget for role now occupies 'thickness'
152 pixels from the corresponding window edge, if shown. */
153 void widgetResized(IdealMainLayout::Role role, int thickness);
155 protected:
156 using QLayout::layout;
158 void doLayout(QRect rect) const;
159 void layout(Role role1, Role role2, Role role3, Role role4, QRect& rect) const;
160 void layoutItem(Role role, QRect& rect) const;
161 void minimumSize(Role role, int& minWidth, int& softMinWidth, int& minHeight, int& softMinHeight) const;
163 private:
164 void createArea(Role role);
165 class IdealSplitterHandle* createSplitter(Role role, bool reverse = false);
167 class DockArea {
168 public:
169 DockArea(IdealMainLayout* layout, Role role);
170 ~DockArea();
172 int count() const;
173 QLayoutItem* itemAt(int index, int& at) const;
175 const QList<QWidgetItem*> items() const;
176 QWidgetItem* first() const;
177 void addWidget(QWidget* widget);
178 void removeWidget(QWidget* widget);
179 void removeWidgets();
181 QWidgetItem* mainSplitter() const;
182 void setMainSplitter(QWidget* splitter);
184 QWidgetItem* buttonBar() const;
185 void setButtonBar(QWidget* buttonBar);
186 void removeButtonBar();
188 void setVisible(bool visible, bool showMainSplitter = false, QWidget* maximizedWidget = 0);
189 void raise();
191 int width;
192 bool anchored;
193 QPointer<QWidget> last;
195 private:
196 void removeMainSplitter();
198 IdealMainLayout* m_layout;
199 Role m_role;
200 QList<QWidgetItem*> m_items;
201 QList<int> m_heights;
202 QWidgetItem* m_mainSplitter;
203 QList<QWidgetItem*> m_subSplitters;
204 QWidgetItem* m_buttonBarItem;
207 QMap<Role, DockArea*> m_items;
208 mutable bool m_layoutDirty, m_minDirty;
209 mutable QSize m_min;
210 int m_splitterWidth;
211 QPointer<QWidget> m_lastDockWidget;
212 Role m_lastDockWidgetRole;
213 int m_topOwnsTopLeft;
214 int m_topOwnsTopRight;
215 int m_bottomOwnsBottomLeft;
216 int m_bottomOwnsBottomRight;
217 Role m_maximizedRole;
218 QWidget* m_maximizedWidget;
221 IdealMainLayout::Role roleForArea(Qt::DockWidgetArea area);
223 Qt::DockWidgetArea areaForRole(IdealMainLayout::Role role);
227 #endif