]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabpage.h
Animate split view mode toggling
[dolphin.git] / src / dolphintabpage.h
1 /*
2 * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
3 * SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #ifndef DOLPHIN_TAB_PAGE_H
9 #define DOLPHIN_TAB_PAGE_H
10
11 #include <QPointer>
12 #include <QUrl>
13 #include <QWidget>
14
15 class DolphinNavigatorsWidgetAction;
16 class DolphinViewContainer;
17 class QSplitter;
18 class QVariantAnimation;
19 class KFileItemList;
20
21 enum Animated {
22 WithAnimation,
23 WithoutAnimation
24 };
25
26 class DolphinTabPage : public QWidget
27 {
28 Q_OBJECT
29
30 public:
31 explicit DolphinTabPage(const QUrl& primaryUrl, const QUrl& secondaryUrl = QUrl(), QWidget* parent = nullptr);
32
33 /**
34 * @return True if primary view is the active view in this tab.
35 */
36 bool primaryViewActive() const;
37
38 /**
39 * @return True if split view is enabled.
40 */
41 bool splitViewEnabled() const;
42
43 /**
44 * Enables or disables the split view mode.
45 *
46 * @param enabled If true, creates a secondary viewContainer in this tab.
47 * Otherwise deletes it.
48 * @param animated Decides wether the effects of this method call should
49 * happen instantly or be transitioned to smoothly.
50 * @param secondaryUrl If \p enabled is true, the new viewContainer will be opened at this
51 * parameter. The default value will set the Url of the new viewContainer
52 * to be the same as the existing one.
53 */
54 void setSplitViewEnabled(bool enabled, Animated animated, const QUrl &secondaryUrl = QUrl());
55
56 /**
57 * @return The primary view container.
58 */
59 DolphinViewContainer* primaryViewContainer() const;
60
61 /**
62 * @return The secondary view container, can be 0 if split view is disabled.
63 */
64 DolphinViewContainer* secondaryViewContainer() const;
65
66 /**
67 * @return DolphinViewContainer of the active view
68 */
69 DolphinViewContainer* activeViewContainer() const;
70
71 /**
72 * Returns the selected items. The list is empty if no item has been
73 * selected.
74 */
75 KFileItemList selectedItems() const;
76
77 /**
78 * Returns the number of selected items (this is faster than
79 * invoking selectedItems().count()).
80 */
81 int selectedItemsCount() const;
82
83 /**
84 * Connects a navigatorsWidget to this. It will be connected to the DolphinViewContainers
85 * managed by this tab. For alignment purposes this will from now on notify the
86 * navigatorsWidget when this tab or its viewContainers are resized.
87 */
88 void connectNavigators(DolphinNavigatorsWidgetAction *navigatorsWidget);
89
90 /**
91 * Makes it so this tab and its DolphinViewContainers aren't controlled by any
92 * UrlNavigators anymore.
93 */
94 void disconnectNavigators();
95
96 /**
97 * Calls resizeNavigators() when a watched object is resized.
98 */
99 bool eventFilter(QObject *watched, QEvent *event) override;
100
101 void insertNavigatorsWidget(DolphinNavigatorsWidgetAction *navigatorsWidget);
102
103 /**
104 * Notify the connected DolphinNavigatorsWidgetAction of geometry changes which it
105 * needs for visual alignment.
106 */
107 void resizeNavigators() const;
108
109 /**
110 * Marks the items indicated by \p urls to get selected after the
111 * directory DolphinView::url() has been loaded. Note that nothing
112 * gets selected if no loading of a directory has been triggered
113 * by DolphinView::setUrl() or DolphinView::reload().
114 */
115 void markUrlsAsSelected(const QList<QUrl> &urls);
116
117 /**
118 * Marks the item indicated by \p url to be scrolled to and as the
119 * current item after directory DolphinView::url() has been loaded.
120 */
121 void markUrlAsCurrent(const QUrl& url);
122
123 /**
124 * Refreshes the views of the main window by recreating them according to
125 * the given Dolphin settings.
126 */
127 void refreshViews();
128
129 /**
130 * Saves all tab related properties (urls, splitter layout, ...).
131 *
132 * @return A byte-array which contains all properties.
133 */
134 QByteArray saveState() const;
135
136 /**
137 * Restores all tab related properties (urls, splitter layout, ...) from
138 * the given \a state.
139 */
140 void restoreState(const QByteArray& state);
141
142 /**
143 * Restores all tab related properties (urls, splitter layout, ...) from
144 * the given \a state.
145 *
146 * @deprecated The first tab state version has no version number, we keep
147 * this method to restore old states (<= Dolphin 4.14.x).
148 */
149 Q_DECL_DEPRECATED void restoreStateV1(const QByteArray& state);
150
151 /**
152 * Set whether the tab page is active
153 *
154 */
155 void setActive(bool active);
156
157 signals:
158 void activeViewChanged(DolphinViewContainer* viewContainer);
159 void activeViewUrlChanged(const QUrl& url);
160 void splitterMoved(int pos, int index);
161
162 private slots:
163 /**
164 * Deletes all zombie viewContainers that were used for the animation
165 * and resets the minimum size of the others to a sane value.
166 */
167 void slotAnimationFinished();
168
169 /**
170 * This method is called for every frame of the m_expandViewAnimation.
171 */
172 void slotAnimationValueChanged(const QVariant &value);
173
174 /**
175 * Handles the view activated event.
176 *
177 * It sets the previous active view to inactive, updates the current
178 * active view type and triggers the activeViewChanged event.
179 */
180 void slotViewActivated();
181
182 /**
183 * Handles the view url redirection event.
184 *
185 * It emits the activeViewUrlChanged signal with the url \a newUrl.
186 */
187 void slotViewUrlRedirection(const QUrl& oldUrl, const QUrl& newUrl);
188
189 void switchActiveView();
190
191 private:
192 /**
193 * Creates a new view container and does the default initialization.
194 */
195 DolphinViewContainer* createViewContainer(const QUrl& url) const;
196
197 /**
198 * Starts an animation that transitions between split view mode states.
199 *
200 * One of the viewContainers is always being expanded when toggling so
201 * this method can animate both opening and closing of viewContainers.
202 * @param expandingContainer The container that will increase in size
203 * over the course of the animation.
204 */
205 void startExpandViewAnimation(DolphinViewContainer *expandingContainer);
206
207 private:
208 QSplitter* m_splitter;
209
210 QPointer<DolphinNavigatorsWidgetAction> m_navigatorsWidget;
211 QPointer<DolphinViewContainer> m_primaryViewContainer;
212 QPointer<DolphinViewContainer> m_secondaryViewContainer;
213
214 DolphinViewContainer *m_expandingContainer;
215 QPointer<QVariantAnimation> m_expandViewAnimation;
216
217 bool m_primaryViewActive;
218 bool m_splitViewEnabled;
219 bool m_active;
220 };
221
222 #endif // DOLPHIN_TAB_PAGE_H