2 Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <QtCore/QHash>
25 #include <QtCore/QObject>
26 #include <QtCore/QPointer>
33 class KActionCollection
;
39 class IncrementalSearchBar
;
41 class TerminalDisplay
;
44 class SessionController
;
50 * Manages the terminal display widgets in a Konsole window or part.
52 * When a view manager is created, it constructs a splitter widget ( accessed via
53 * widget() ) to hold one or more view containers. Each view container holds
54 * one or more terminal displays and a navigation widget ( eg. tabs or a list )
55 * to allow the user to navigate between the displays in that container.
57 * The view manager provides menu actions ( defined in the 'konsoleui.rc' XML file )
58 * to manipulate the views and view containers - for example, actions to split the view
59 * left/right or top/bottom, detach a view from the current window and navigate between
60 * views and containers. These actions are added to the collection specified in the
61 * ViewManager's constructor.
63 * The view manager provides facilities to construct display widgets for a terminal
64 * session and also to construct the SessionController which provides the menus and other
65 * user interface elements specific to each display/session pair.
68 class ViewManager
: public QObject
74 * Constructs a new view manager with the specified @p parent.
75 * View-related actions defined in 'konsoleui.rc' are created
76 * and added to the specified @p collection.
78 ViewManager(QObject
* parent
, KActionCollection
* collection
);
82 * Creates a new view to display the outout from and deliver input to @p session.
83 * Constructs a new container to hold the views if no container has yet been created.
85 void createView(Session
* session
);
88 * Applies the view-specific settings associated with specified @p profile
89 * to the terminal display @p view. If @p applyContainerSettings is true then
90 * tab bar settings in the profile will also be applied
92 void applyProfile(TerminalDisplay
* view
, const Profile::Ptr profile
93 , bool applyContainerSettings
);
96 * Return the main widget for the view manager which
97 * holds all of the views managed by this ViewManager instance.
99 QWidget
* widget() const;
102 * Returns the view manager's active view.
104 QWidget
* activeView() const;
107 * Returns the list of view properties for views in the active container.
108 * Each view widget is associated with a ViewProperties instance which
109 * provides access to basic information about the session being
110 * displayed in the view, such as title, current directory and
113 QList
<ViewProperties
*> viewProperties() const;
116 * This enum describes the available types of navigation widget
117 * which newly created containers can provide to allow navigation
118 * between open sessions.
120 enum NavigationMethod
123 * Each container has a row of tabs (one per session) which the user
124 * can click on to navigate between open sessions.
127 /** The container has no navigation widget. */
132 * Sets the type of widget provided to navigate between open sessions
133 * in a container. The changes will only apply to newly created containers.
135 * The default method is TabbedNavigation. To disable navigation widgets, call
136 * setNavigationMethod(ViewManager::NoNavigation) before creating any sessions.
138 void setNavigationMethod(NavigationMethod method
);
141 * Returns the type of navigation widget created in new containers.
142 * See setNavigationMethod()
144 NavigationMethod
navigationMethod() const;
147 * Returns the controller for the active view. activeViewChanged() is
148 * emitted when this changes.
150 SessionController
* activeViewController() const;
153 * Returns the search bar.
155 IncrementalSearchBar
* searchBar() const;
160 void saveSessions(KConfigGroup
& group
);
161 void restoreSessions(const KConfigGroup
& group
);
164 /** Emitted when the last view is removed from the view manager */
167 /** Emitted when a session is detached from a view owned by this ViewManager */
168 void viewDetached(Session
* session
);
171 * Emitted when the active view changes.
172 * @param controller The controller associated with the active view
174 void activeViewChanged(SessionController
* controller
);
177 * Emitted when the list of view properties ( as returned by viewProperties() ) changes.
178 * This occurs when views are added to or removed from the active container, or
179 * if the active container is changed.
181 void viewPropertiesChanged(const QList
<ViewProperties
*>& propertiesList
);
184 * Emitted when the number of views containers changes. This is used to disable or
185 * enable menu items which can only be used when there are one or multiple containers
188 * @param multipleViews True if there are multiple view containers open or false if there is
189 * just a single view.
191 void splitViewToggle(bool multipleViews
);
194 * Emitted when menu bar visibility changes because a profile that requires so is
197 void setMenuBarVisibleRequest(bool);
199 /** Requests creation of a new view with the default profile. */
200 void newViewRequest();
201 /** Requests creation of a new view, with the selected profile. */
202 void newViewRequest(Profile::Ptr
);
205 // called when the "Split View Left/Right" menu item is selected
206 void splitLeftRight();
207 void splitTopBottom();
208 void closeActiveView();
209 void closeOtherViews();
210 void expandActiveView();
211 void shrinkActiveView();
213 // called when the "Detach View" menu item is selected
214 void detachActiveView();
215 void updateDetachViewState();
217 // called when a session terminates - the view manager will delete any
218 // views associated with the session
219 void sessionFinished();
220 // called when the container requests to close a particular view
221 void viewCloseRequest(QWidget
* widget
);
223 // controller detects when an associated view is given the focus
224 // and emits a signal. ViewManager listens for that signal
225 // and then plugs the action into the UI
226 //void viewFocused( SessionController* controller );
228 // called when the active view in a ViewContainer changes, so
229 // that we can plug the appropriate actions into the UI
230 void viewActivated( QWidget
* view
);
232 // called when "Next View" shortcut is activated
235 // called when "Previous View" shortcut is activated
238 // called when "Next View Container" shortcut is activated
239 void nextContainer();
241 // called when the views in a container owned by this view manager
243 void containerViewsChanged(QObject
* container
);
245 // called when a profile changes
246 void profileChanged(Profile::Ptr profile
);
248 void updateViewsForSession(Session
* session
);
250 // moves active view to the left
251 void moveActiveViewLeft();
252 // moves active view to the right
253 void moveActiveViewRight();
254 // switches to the view at visual position 'index'
255 // in the current container
256 void switchToView(int index
);
258 // called when a SessionController gains focus
259 void controllerChanged(SessionController
* controller
);
261 // called when a ViewContainer requests a view be
263 void containerMoveViewRequest(int index
, int id
, bool& success
);
266 void createView(Session
* session
, ViewContainer
* container
, int index
);
267 const ColorScheme
* colorSchemeForProfile(const Profile::Ptr profile
) const;
270 void focusActiveView();
271 void registerView(TerminalDisplay
* view
);
272 void unregisterView(TerminalDisplay
* view
);
274 // takes a view from a view container owned by a different manager and places it in
275 // newContainer owned by this manager
276 void takeView(ViewManager
* otherManager
, ViewContainer
* otherContainer
, ViewContainer
* newContainer
, TerminalDisplay
* view
);
277 void splitView(Qt::Orientation orientation
);
279 // creates a new container which can hold terminal displays
280 // 'profile' specifies the profile to use to get initial
281 // settings (eg. navigation position) for the container
282 ViewContainer
* createContainer(const Profile::Ptr profile
);
283 // removes a container and emits appropriate signals
284 void removeContainer(ViewContainer
* container
);
286 // creates a new terminal display
287 // the 'session' is used so that the terminal display's random seed
288 // can be set to something which depends uniquely on that session
289 TerminalDisplay
* createTerminalDisplay(Session
* session
= 0);
291 // creates a new controller for a session/display pair which provides the menu
292 // actions associated with that view, and exposes basic information
293 // about the session ( such as title and associated icon ) to the display.
294 SessionController
* createController(Session
* session
, TerminalDisplay
* display
);
296 // create menu for 'new tab' button
297 QMenu
* createNewViewMenu();
299 QPointer
<ViewSplitter
> _viewSplitter
;
300 QPointer
<SessionController
> _pluggedController
;
302 QHash
<TerminalDisplay
*,Session
*> _sessionMap
;
304 KActionCollection
* _actionCollection
;
305 QSignalMapper
* _containerSignalMapper
;
306 NavigationMethod _navigationMethod
;
318 c-file-style: "stroustrup"
319 indent-tabs-mode: nil