add more spacing
[personal-kdebase.git] / apps / konsole / src / ViewSplitter.h
blob7924d2393054e89b477cdbeaf0c776eb2e23b33c
1 /*
2 This file is part of the Konsole Terminal.
4 Copyright 2006-2008 Robert Knight <robertknight@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
22 #ifndef VIEWSPLITTER_H
23 #define VIEWSPLITTER_H
25 #include <QtCore/QList>
26 #include <QtGui/QSplitter>
28 class QFocusEvent;
30 namespace Konsole
33 class ViewContainer;
35 /**
36 * A splitter which holds a number of ViewContainer objects and allows
37 * the user to control the size of each view container by dragging a splitter
38 * bar between them.
40 * Each splitter can also contain child ViewSplitter widgets, allowing
41 * for a hierarchy of view splitters and containers.
43 * The addContainer() method is used to split the existing view and
44 * insert a new view container.
45 * Containers can only be removed from the hierarchy by deleting them.
47 class ViewSplitter : public QSplitter
49 Q_OBJECT
51 public:
52 ViewSplitter(QWidget* parent = 0);
54 /**
55 * Locates the child ViewSplitter widget which currently has the focus
56 * and inserts the container into it.
58 * @param container The container to insert
59 * @param orientation Specifies whether the view should be split
60 * horizontally or vertically. If the orientation
61 * is the same as the ViewSplitter into which the
62 * container is to be inserted, or if the splitter
63 * has fewer than two child widgets then the container
64 * will be added to that splitter. If the orientation
65 * is different, then a new child splitter
66 * will be created, into which the container will
67 * be inserted.
69 void addContainer( ViewContainer* container , Qt::Orientation orientation );
71 /** Removes a container from the splitter. The container is not deleted. */
72 void removeContainer( ViewContainer* container );
74 /** Returns the child ViewSplitter widget which currently has the focus */
75 ViewSplitter* activeSplitter() ;
77 /**
78 * Returns the container which currently has the focus or 0 if none
79 * of the immediate child containers have the focus. This does not
80 * search through child splitters. activeSplitter() can be used
81 * to search recursively through child splitters for the splitter
82 * which currently has the focus.
84 * To find the currently active container, use
85 * mySplitter->activeSplitter()->activeContainer() where mySplitter
86 * is the ViewSplitter widget at the top of the hierarchy.
88 ViewContainer* activeContainer() const;
90 /**
91 * Gives the focus to the active view in the specified container
93 void setActiveContainer(ViewContainer* container);
95 /**
96 * Returns a list of the containers held by this splitter
98 QList<ViewContainer*> containers() const {return _containers;}
101 * Gives the focus to the active view in the next container
103 void activateNextContainer();
106 * Changes the size of the specified @p container by a given @p percentage.
107 * @p percentage may be positive ( in which case the size of the container
108 * is increased ) or negative ( in which case the size of the container
109 * is decreased ).
111 * The sizes of the remaining containers are increased or decreased
112 * uniformly to maintain the width of the splitter.
114 void adjustContainerSize(ViewContainer* container , int percentage);
117 * Gives the focus to the active view in the previous container
119 void activatePreviousContainer();
122 * Specifies whether the view may be split recursively.
124 * If this is false, all containers will be placed into the same
125 * top-level splitter. Adding a container with an orientation
126 * which is different to that specified when adding the previous
127 * containers will change the orientation for all dividers
128 * between containers.
130 * If this is true, adding a container to the view splitter with
131 * an orientation different to the orientation of the previous
132 * area will result in the previously active container being
133 * replaced with a new splitter containing the active container
134 * and the newly added container.
136 void setRecursiveSplitting(bool recursive);
138 /**
139 * Returns whether the view may be split recursively.
140 * See setRecursiveSplitting()
142 bool recursiveSplitting() const;
144 signals:
145 /** Signal emitted when the last child widget is removed from the splitter */
146 void empty(ViewSplitter* splitter);
148 /**
149 * Signal emitted when the containers held by this splitter become empty, this
150 * differs from the empty() signal which is only emitted when all of the containers
151 * are deleted. This signal is emitted even if there are still container widgets.
153 * TODO: This does not yet work recursively (ie. when splitters inside splitters have empty containers)
155 void allContainersEmpty();
157 protected:
158 //virtual void focusEvent(QFocusEvent* event);
160 private:
161 // Adds container to splitter's internal list and
162 // connects signals and slots
163 void registerContainer( ViewContainer* container );
164 // Removes container from splitter's internal list and
165 // removes signals and slots
166 void unregisterContainer( ViewContainer* container );
168 void updateSizes();
170 private slots:
171 // Called to indicate that a child ViewContainer has been deleted
172 void containerDestroyed( ViewContainer* object );
174 // Called to indicate that a child ViewContainer is empty
175 void containerEmpty( ViewContainer* object );
177 // Called to indicate that a child ViewSplitter is empty
178 // (ie. all child widgets have been deleted)
179 void childEmpty( ViewSplitter* splitter );
181 private:
182 QList<ViewContainer*> _containers;
183 bool _recursiveSplitting;
187 #endif //VIEWSPLITTER_H