Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / sublime / areaindex.cpp
bloba8f73affdfc594f8c51a108a73a807b9f3631f38
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 #include "areaindex.h"
21 #include <QList>
23 #include <kdebug.h>
25 #include "view.h"
26 #include "document.h"
28 namespace Sublime {
30 // struct AreaIndexPrivate
32 struct AreaIndexPrivate {
33 AreaIndexPrivate()
34 :parent(0), first(0), second(0), orientation(Qt::Horizontal)
37 ~AreaIndexPrivate()
39 delete first;
40 delete second;
42 AreaIndexPrivate(const AreaIndexPrivate &p)
44 parent = 0;
45 orientation = p.orientation;
46 first = p.first ? new AreaIndex(*(p.first)) : 0;
47 second = p.second ? new AreaIndex(*(p.second)) : 0;
50 bool isSplitted() const
52 return first || second;
55 QList<View*> views;
57 AreaIndex *parent;
58 AreaIndex *first;
59 AreaIndex *second;
60 Qt::Orientation orientation;
65 // class AreaIndex
67 AreaIndex::AreaIndex() : d(new AreaIndexPrivate)
71 AreaIndex::AreaIndex(AreaIndex *parent) : d(new AreaIndexPrivate)
73 d->parent = parent;
76 AreaIndex::AreaIndex(const AreaIndex &index) : d(new AreaIndexPrivate( *(index.d) ) )
78 kDebug() << "copying area index";
79 if (d->first)
80 d->first->setParent(this);
81 if (d->second)
82 d->second->setParent(this);
83 //clone views in this index
84 d->views.clear();
85 foreach (View *view, index.views())
86 add(view->document()->createView());
89 AreaIndex::~AreaIndex()
91 delete d;
94 void AreaIndex::add(View *view, View *after)
96 //we can not add views to the areas that have already been splitted
97 if (d->isSplitted())
98 return;
100 if (after)
101 d->views.insert(d->views.indexOf(after), view);
102 else
103 d->views.append(view);
106 void AreaIndex::remove(View *view)
108 if (d->isSplitted())
109 return;
111 d->views.removeAll(view);
112 if (d->parent && (d->views.count() == 0))
113 d->parent->unsplit(this);
116 void Sublime::AreaIndex::split(Qt::Orientation orientation)
118 //we can not split areas that have already been splitted
119 if (d->isSplitted())
120 return;
122 d->first = new AreaIndex(this);
123 d->second = new AreaIndex(this);
124 d->orientation = orientation;
126 //assign current views to the first part of splitter
127 copyTo(d->first);
130 void AreaIndex::split(View *newView, Qt::Orientation orientation)
132 split(orientation);
134 //make new view as second widget in splitter
135 d->second->add(newView);
138 void AreaIndex::unsplit(AreaIndex *childToRemove)
140 if (!d->isSplitted())
141 return;
143 AreaIndex *other = d->first == childToRemove ? d->second : d->first;
144 other->copyTo(this);
145 d->orientation = other->orientation();
146 d->first = 0;
147 d->second = 0;
148 other->copyChildrenTo(this);
150 delete other;
151 delete childToRemove;
154 void AreaIndex::copyChildrenTo(AreaIndex *target)
156 if (!d->first || !d->second)
157 return;
158 target->d->first = d->first;
159 target->d->second = d->second;
160 target->d->first->setParent(target);
161 target->d->second->setParent(target);
163 d->first = 0;
164 d->second = 0;
167 void AreaIndex::copyTo(AreaIndex *target)
169 target->d->views = d->views;
170 d->views.clear();
173 QList<View*> &AreaIndex::views() const
175 return d->views;
178 View *AreaIndex::viewAt(int position) const
180 return d->views.value(position, 0);
183 int AreaIndex::viewCount() const
185 return d->views.count();
188 bool AreaIndex::hasView(View *view) const
190 return d->views.contains(view);
193 AreaIndex *AreaIndex::parent() const
195 return d->parent;
198 void AreaIndex::setParent(AreaIndex *parent)
200 d->parent = parent;
203 AreaIndex *AreaIndex::first() const
205 return d->first;
208 AreaIndex *AreaIndex::second() const
210 return d->second;
213 Qt::Orientation AreaIndex::orientation() const
215 return d->orientation;
218 bool Sublime::AreaIndex::isSplitted() const
220 return d->isSplitted();
223 void Sublime::AreaIndex::setOrientation(Qt::Orientation orientation) const
225 d->orientation = orientation;
228 // class RootAreaIndex
230 RootAreaIndex::RootAreaIndex()
231 :AreaIndex(), d(0)