Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / sublime / areaindex.h
blobf8c3eeb82817ba7592525f5ec70ed6ed75fe5701
1 /***************************************************************************
2 * Copyright 2006-2007 Alexander Dymo <adymo@kdevelop.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU Library General Public License as *
6 * published by the Free Software Foundation; either version 2 of the *
7 * License, or (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Library General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19 #ifndef SUBLIMEAREAINDEX_H
20 #define SUBLIMEAREAINDEX_H
22 #include <QtCore/Qt>
23 #include <QtCore/QList>
25 #include <KConfigGroup>
27 #include "sublimeexport.h"
29 namespace Sublime {
31 class View;
33 /**
34 @short Index denotes the position of the view in the splitted area.
36 B-Tree alike structure is used to represent an area with splitted
37 views. Area has a root index which can either contain one view or contain
38 two child nodes (@p first and @p second). In the later case area
39 is considered to be splitted into two parts. Each of those parts can
40 in turn contain a view or be splitted (with first/second children).
42 When a view at given index is splitted, then its index becomes an index of the splitter
43 and the original view goes into the @p first part of the splitter. The new view goes as
44 @p second part.
46 For example, consider an area which was splitted once horizontally
47 and then the second part of it was splitted vertically:
48 @code
49 1. initial state: one view in the area
50 |----------------|
51 | |
52 | 1 |
53 | |
54 |----------------|
56 Indices:
57 root_index (view 1)
59 2. the view is splitted horizontally
60 |----------------|
61 | | |
62 | 1 | 2 |
63 | | |
64 |----------------|
66 Indices:
67 root_index (no view)
69 ----------------
70 | |
71 view 1 view 2
73 3. the second view is splitted vertically
74 |----------------|
75 | | 2 |
76 | 1 |--------|
77 | | 3 |
78 |----------------|
80 Indices:
81 root_index (horizontal splitter)
83 ----------------
84 | |
85 view 1 vertical_splitter
87 -----------------
88 | |
89 view 2 view 3
90 @endcode
92 It is possible that several "stacked" views will have the same area index.
93 Those views can be considered as the view stack from which only one view
94 is visible at the time.
95 @code
96 |----------------|
97 | |
98 | 1,2,3,4 |
99 | |
100 |----------------|
102 Indices:
103 root_index (view1, view2, view3, view4)
104 @endcode
106 class SUBLIME_EXPORT AreaIndex {
107 public:
108 ~AreaIndex();
109 AreaIndex(const AreaIndex &index);
111 /**@return the parent index, returns 0 for root index.*/
112 AreaIndex *parent() const;
114 /**@return the first child index if there're any.*/
115 AreaIndex *first() const;
116 /**@return the second child index if there're any.*/
117 AreaIndex *second() const;
118 /**@return true if the index is splitted.*/
119 bool isSplitted() const;
120 /**@return the orientation of the splitter for this index.*/
121 Qt::Orientation orientation() const;
122 /**Set the orientation of the splitter for this index.*/
123 void setOrientation(Qt::Orientation orientation) const;
125 /**Adds view to the list of views in this position.
126 Does nothing if the view is already splitted.
127 @param after if not 0, new view will be placed after this one.
128 @param view the view to be added.*/
129 void add(View *view, View *after = 0);
130 /**Removes view and unsplits the parent index when no views
131 are left at the current index.*/
132 void remove(View *view);
133 /**Splits the view in this position by given @p orientation
134 and adds the @p newView into the splitter.
135 Does nothing if the view is already splitted.*/
136 void split(View *newView, Qt::Orientation orientation);
137 /**Splits the view in this position by given @p orientation.
138 Does nothing if the view is already splitted.*/
139 void split(Qt::Orientation orientation);
141 /**@return the stacked view in @p position,
142 returns 0 for splitter's indices and when there's no view at the @p position.*/
143 View *viewAt(int position) const;
144 /**@return the number of stacked views.*/
145 int viewCount() const;
146 /**@return true if there's a stacked @p view at this index.*/
147 bool hasView(View *view) const;
148 /**@return the list of views at this index.*/
149 QList<View*> &views() const;
151 protected:
152 /**Constructor for Root index.*/
153 AreaIndex();
155 private:
156 /**Constructor for indices other than root.*/
157 AreaIndex(AreaIndex *parent);
159 /**Sets the parent for this index.*/
160 void setParent(AreaIndex *parent);
162 /**Copies the data from this index to @p target.*/
163 void copyTo(AreaIndex *target);
164 /**Copies the children indices from this index to @p target.*/
165 void copyChildrenTo(AreaIndex *target);
166 /**Unsplits the index removing the given @p child and moving the contents
167 of another child to this index.*/
168 void unsplit(AreaIndex *childToRemove);
170 struct AreaIndexPrivate * const d;
175 @short Root Area Index
177 This is the special index class returned by @ref Area::rootIndex().
178 Doesn't provide any additional functionality beyond AreaIndex.
180 class SUBLIME_EXPORT RootAreaIndex: public AreaIndex {
181 public:
182 RootAreaIndex();
183 private:
184 class RootAreaIndexPrivate* const d;
189 #endif