Changeset View
Changeset View
Standalone View
Standalone View
src/ViewSplitter.h
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #ifndef VIEWSPLITTER_H | 22 | #ifndef VIEWSPLITTER_H | ||
23 | #define VIEWSPLITTER_H | 23 | #define VIEWSPLITTER_H | ||
24 | 24 | | |||
25 | // Qt | 25 | // Qt | ||
26 | #include <QList> | 26 | #include <QList> | ||
27 | #include <QSplitter> | 27 | #include <QSplitter> | ||
28 | 28 | | |||
29 | // Konsole | ||||
30 | #include "konsoleprivate_export.h" | ||||
31 | | ||||
29 | class QFocusEvent; | 32 | class QFocusEvent; | ||
30 | 33 | | |||
31 | namespace Konsole { | 34 | namespace Konsole { | ||
32 | class TabbedViewContainer; | 35 | class TerminalDisplay; | ||
33 | 36 | | |||
34 | /** | 37 | /** | ||
35 | * A splitter which holds a number of ViewContainer objects and allows | 38 | * A splitter which holds a number of ViewContainer objects and allows | ||
36 | * the user to control the size of each view container by dragging a splitter | 39 | * the user to control the size of each view container by dragging a splitter | ||
37 | * bar between them. | 40 | * bar between them. | ||
38 | * | 41 | * | ||
39 | * Each splitter can also contain child ViewSplitter widgets, allowing | 42 | * Each splitter can also contain child ViewSplitter widgets, allowing | ||
40 | * for a hierarchy of view splitters and containers. | 43 | * for a hierarchy of view splitters and containers. | ||
41 | * | 44 | * | ||
42 | * The addContainer() method is used to split the existing view and | 45 | * The addContainer() method is used to split the existing view and | ||
43 | * insert a new view container. | 46 | * insert a new view container. | ||
44 | * Containers can only be removed from the hierarchy by deleting them. | 47 | * Containers can only be removed from the hierarchy by deleting them. | ||
45 | */ | 48 | */ | ||
46 | class ViewSplitter : public QSplitter | 49 | class KONSOLEPRIVATE_EXPORT ViewSplitter : public QSplitter | ||
47 | { | 50 | { | ||
48 | Q_OBJECT | 51 | Q_OBJECT | ||
49 | 52 | | |||
50 | public: | 53 | public: | ||
51 | explicit ViewSplitter(QWidget *parent = nullptr); | 54 | explicit ViewSplitter(QWidget *parent = nullptr); | ||
52 | 55 | | |||
53 | /** | 56 | /** | ||
54 | * Locates the child ViewSplitter widget which currently has the focus | 57 | * Locates the child ViewSplitter widget which currently has the focus | ||
55 | * and inserts the container into it. | 58 | * and inserts the container into it. | ||
56 | * | 59 | * | ||
57 | * @param container The container to insert | 60 | * @param container The container to insert | ||
58 | * @param orientation Specifies whether the view should be split | 61 | * @param orientation Specifies whether the view should be split | ||
59 | * horizontally or vertically. If the orientation | 62 | * horizontally or vertically. If the orientation | ||
60 | * is the same as the ViewSplitter into which the | 63 | * is the same as the ViewSplitter into which the | ||
61 | * container is to be inserted, or if the splitter | 64 | * container is to be inserted, or if the splitter | ||
62 | * has fewer than two child widgets then the container | 65 | * has fewer than two child widgets then the container | ||
63 | * will be added to that splitter. If the orientation | 66 | * will be added to that splitter. If the orientation | ||
64 | * is different, then a new child splitter | 67 | * is different, then a new child splitter | ||
65 | * will be created, into which the container will | 68 | * will be created, into which the container will | ||
66 | * be inserted. | 69 | * be inserted. | ||
67 | */ | 70 | */ | ||
68 | void addContainer(TabbedViewContainer *container, Qt::Orientation orientation); | 71 | void addTerminalDisplay(TerminalDisplay *terminalDisplay, Qt::Orientation orientation); | ||
69 | 72 | | |||
70 | /** Removes a container from the splitter. The container is not deleted. */ | 73 | /** Removes a container from the splitter. The container is not deleted. */ | ||
71 | void removeContainer(TabbedViewContainer *container); | 74 | void removeTerminalDisplay(TerminalDisplay *terminalDisplay); | ||
72 | 75 | | |||
73 | /** Returns the child ViewSplitter widget which currently has the focus */ | 76 | /** Returns the child ViewSplitter widget which currently has the focus */ | ||
74 | ViewSplitter *activeSplitter(); | 77 | ViewSplitter *activeSplitter(); | ||
75 | 78 | | |||
76 | /** | 79 | /** | ||
77 | * Returns the container which currently has the focus or 0 if none | 80 | * Returns the container which currently has the focus or 0 if none | ||
78 | * of the immediate child containers have the focus. This does not | 81 | * of the immediate child containers have the focus. This does not | ||
79 | * search through child splitters. activeSplitter() can be used | 82 | * search through child splitters. activeSplitter() can be used | ||
80 | * to search recursively through child splitters for the splitter | 83 | * to search recursively through child splitters for the splitter | ||
81 | * which currently has the focus. | 84 | * which currently has the focus. | ||
82 | * | 85 | * | ||
83 | * To find the currently active container, use | 86 | * To find the currently active container, use | ||
84 | * mySplitter->activeSplitter()->activeContainer() where mySplitter | 87 | * mySplitter->activeSplitter()->activeContainer() where mySplitter | ||
85 | * is the ViewSplitter widget at the top of the hierarchy. | 88 | * is the ViewSplitter widget at the top of the hierarchy. | ||
86 | */ | 89 | */ | ||
87 | TabbedViewContainer *activeContainer() const; | 90 | TerminalDisplay *activeTerminalDisplay() const; | ||
88 | 91 | | |||
89 | /** | 92 | /** Makes the current TerminalDisplay expanded to 100% of the view | ||
90 | * Gives the focus to the active view in the specified container | | |||
91 | */ | 93 | */ | ||
92 | void setActiveContainer(TabbedViewContainer *container); | 94 | void maximizeCurrentTerminal(); | ||
93 | 95 | | |||
94 | /** | 96 | /** Restore the sizes of the terminals. | ||
95 | * Returns a list of the containers held by this splitter | | |||
96 | */ | 97 | */ | ||
97 | QList<TabbedViewContainer *> containers() const | 98 | void restoreOtherTerminals(); | ||
98 | { | 99 | | ||
99 | return _containers; | 100 | void handleMinimizeMaximize(bool maximize); | ||
100 | } | 101 | | ||
102 | /** returns the splitter that has no splitter as a parent. */ | ||||
103 | ViewSplitter *getToplevelSplitter(); | ||||
101 | 104 | | |||
102 | /** | 105 | /** | ||
103 | * Gives the focus to the active view in the next container | 106 | * Gives the focus to the active view in the specified container | ||
104 | */ | 107 | */ | ||
105 | void activateNextContainer(); | 108 | void setActiveTerminalDisplay(TerminalDisplay *container); | ||
106 | 109 | | |||
107 | /** | 110 | /** | ||
108 | * Changes the size of the specified @p container by a given @p percentage. | 111 | * Changes the size of the specified @p container by a given @p percentage. | ||
109 | * @p percentage may be positive ( in which case the size of the container | 112 | * @p percentage may be positive ( in which case the size of the container | ||
110 | * is increased ) or negative ( in which case the size of the container | 113 | * is increased ) or negative ( in which case the size of the container | ||
111 | * is decreased ). | 114 | * is decreased ). | ||
112 | * | 115 | * | ||
113 | * The sizes of the remaining containers are increased or decreased | 116 | * The sizes of the remaining containers are increased or decreased | ||
114 | * uniformly to maintain the width of the splitter. | 117 | * uniformly to maintain the width of the splitter. | ||
115 | */ | 118 | */ | ||
116 | void adjustContainerSize(TabbedViewContainer *container, int percentage); | 119 | void adjustActiveTerminalDisplaySize(int percentage); | ||
117 | | ||||
118 | /** | | |||
119 | * Gives the focus to the active view in the previous container | | |||
120 | */ | | |||
121 | void activatePreviousContainer(); | | |||
122 | | ||||
123 | /** | | |||
124 | * Specifies whether the view may be split recursively. | | |||
125 | * | | |||
126 | * If this is false, all containers will be placed into the same | | |||
127 | * top-level splitter. Adding a container with an orientation | | |||
128 | * which is different to that specified when adding the previous | | |||
129 | * containers will change the orientation for all dividers | | |||
130 | * between containers. | | |||
131 | * | | |||
132 | * If this is true, adding a container to the view splitter with | | |||
133 | * an orientation different to the orientation of the previous | | |||
134 | * area will result in the previously active container being | | |||
135 | * replaced with a new splitter containing the active container | | |||
136 | * and the newly added container. | | |||
137 | */ | | |||
138 | void setRecursiveSplitting(bool recursive); | | |||
139 | 120 | | |||
140 | /** | 121 | void focusUp(); | ||
141 | * Returns whether the view may be split recursively. | 122 | void focusDown(); | ||
142 | * See setRecursiveSplitting() | 123 | void focusLeft(); | ||
143 | */ | 124 | void focusRight(); | ||
144 | bool recursiveSplitting() const; | | |||
145 | 125 | | |||
146 | Q_SIGNALS: | 126 | void handleFocusDirection(Qt::Orientation orientation, int direction); | ||
147 | /** Signal emitted when the last child widget is removed from the splitter */ | | |||
148 | void empty(ViewSplitter *splitter); | | |||
149 | 127 | | |||
150 | /** | 128 | void childEvent(QChildEvent* event) override; | ||
151 | * Signal emitted when the containers held by this splitter become empty, this | | |||
152 | * differs from the empty() signal which is only emitted when all of the containers | | |||
153 | * are deleted. This signal is emitted even if there are still container widgets. | | |||
154 | * | | |||
155 | * TODO: This does not yet work recursively (ie. when splitters inside splitters have empty containers) | | |||
156 | */ | | |||
157 | void allContainersEmpty(); | | |||
158 | 129 | | |||
159 | protected: | 130 | QList<TerminalDisplay*> getTerminalDisplays(); | ||
160 | //virtual void focusEvent(QFocusEvent* event); | | |||
161 | 131 | | |||
162 | private: | 132 | private: | ||
163 | // Adds container to splitter's internal list and | | |||
164 | // connects signals and slots | | |||
165 | void registerContainer(TabbedViewContainer *container); | | |||
166 | // Removes container from splitter's internal list and | | |||
167 | // removes signals and slots | | |||
168 | void unregisterContainer(TabbedViewContainer *container); | | |||
169 | | ||||
170 | void updateSizes(); | 133 | void updateSizes(); | ||
171 | | ||||
172 | private Q_SLOTS: | | |||
173 | // Called to indicate that a child ViewContainer is empty | | |||
174 | void containerEmpty(TabbedViewContainer *container); | | |||
175 | | ||||
176 | // Called to indicate that a child ViewSplitter is empty | | |||
177 | // (ie. all child widgets have been deleted) | | |||
178 | void childEmpty(ViewSplitter *splitter); | | |||
179 | | ||||
180 | private: | | |||
181 | QList<TabbedViewContainer *> _containers; | | |||
182 | bool _recursiveSplitting; | | |||
183 | }; | 134 | }; | ||
184 | } | 135 | } | ||
185 | #endif //VIEWSPLITTER_H | 136 | #endif //VIEWSPLITTER_H |