]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabpage.h
5dafcd5dc528d205e6914af383e4871708463556
[dolphin.git] / src / dolphintabpage.h
1 /*
2 * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
3 * SPDX-FileCopyrightText: 2020 Felix Ernst <felixernst@kde.org>
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 "global.h"
12
13 #include <QPointer>
14 #include <QSplitter>
15 #include <QUrl>
16 #include <QUuid>
17 #include <QWidget>
18 #include <quuid.h>
19
20 class DolphinNavigatorsWidgetAction;
21 class DolphinViewContainer;
22 class QVariantAnimation;
23 class KFileItemList;
24 class DolphinTabPageSplitter;
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 whether 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 * @return DolphinViewContainer of the inactive view
73 * if split view is enabled, or nullptr otherwise.
74 */
75 DolphinViewContainer *inactiveViewContainer() const;
76
77 /**
78 * Returns the selected items. The list is empty if no item has been
79 * selected.
80 */
81 KFileItemList selectedItems() const;
82
83 /**
84 * Returns the number of selected items (this is faster than
85 * invoking selectedItems().count()).
86 */
87 int selectedItemsCount() const;
88
89 /**
90 * Connects a navigatorsWidget to this. It will be connected to the DolphinViewContainers
91 * managed by this tab. For alignment purposes this will from now on notify the
92 * navigatorsWidget when this tab or its viewContainers are resized.
93 */
94 void connectNavigators(DolphinNavigatorsWidgetAction *navigatorsWidget);
95
96 /**
97 * Makes it so this tab and its DolphinViewContainers aren't controlled by any
98 * UrlNavigators anymore.
99 */
100 void disconnectNavigators();
101
102 void insertNavigatorsWidget(DolphinNavigatorsWidgetAction *navigatorsWidget);
103
104 /**
105 * Marks the items indicated by \p urls to get selected after the
106 * directory DolphinView::url() has been loaded. Note that nothing
107 * gets selected if no loading of a directory has been triggered
108 * by DolphinView::setUrl() or DolphinView::reload().
109 */
110 void markUrlsAsSelected(const QList<QUrl> &urls);
111
112 /**
113 * Marks the item indicated by \p url to be scrolled to and as the
114 * current item after directory DolphinView::url() has been loaded.
115 */
116 void markUrlAsCurrent(const QUrl &url);
117
118 /**
119 * Refreshes the views of the main window by recreating them according to
120 * the given Dolphin settings.
121 */
122 void refreshViews();
123
124 /**
125 * Saves all tab related properties (urls, splitter layout, ...).
126 *
127 * @return A byte-array which contains all properties.
128 */
129 QByteArray saveState() const;
130
131 /**
132 * Restores all tab related properties (urls, splitter layout, ...) from
133 * the given \a state.
134 */
135 void restoreState(const QByteArray &state);
136
137 /**
138 * Set whether the tab page is active
139 *
140 */
141 void setActive(bool active);
142
143 void switchActiveView();
144
145 void setTitle(const QString &name);
146
147 QString title();
148
149 Q_SIGNALS:
150 void activeViewChanged(DolphinViewContainer *viewContainer);
151 void activeViewUrlChanged(const QUrl &url);
152 void splitterMoved(int pos, int index);
153
154 private Q_SLOTS:
155 /**
156 * Deletes all zombie viewContainers that were used for the animation
157 * and resets the minimum size of the others to a sane value.
158 */
159 void slotAnimationFinished();
160
161 /**
162 * This method is called for every frame of the m_expandViewAnimation.
163 */
164 void slotAnimationValueChanged(const QVariant &value);
165
166 /**
167 * Handles the view activated event.
168 *
169 * It sets the previous active view to inactive, updates the current
170 * active view type and triggers the activeViewChanged event.
171 */
172 void slotViewActivated();
173
174 /**
175 * Handles the view url redirection event.
176 *
177 * It emits the activeViewUrlChanged signal with the url \a newUrl.
178 */
179 void slotViewUrlRedirection(const QUrl &oldUrl, const QUrl &newUrl);
180
181 private:
182 /**
183 * Creates a new view container and does the default initialization.
184 */
185 DolphinViewContainer *createViewContainer(const QUrl &url) const;
186
187 /**
188 * Starts an animation that transitions between split view mode states.
189 *
190 * One of the viewContainers is always being expanded when toggling so
191 * this method can animate both opening and closing of viewContainers.
192 * @param expandingContainer The container that will increase in size
193 * over the course of the animation.
194 */
195 void startExpandViewAnimation(DolphinViewContainer *expandingContainer);
196
197 private:
198 DolphinTabPageSplitter *m_splitter;
199
200 QPointer<DolphinNavigatorsWidgetAction> m_navigatorsWidget;
201 QPointer<DolphinViewContainer> m_primaryViewContainer;
202 QPointer<DolphinViewContainer> m_secondaryViewContainer;
203
204 DolphinViewContainer *m_expandingContainer;
205 QPointer<QVariantAnimation> m_expandViewAnimation;
206
207 bool m_primaryViewActive;
208 bool m_splitViewEnabled;
209 bool m_active;
210 QString m_title;
211 };
212
213 class DolphinTabPageSplitterHandle : public QSplitterHandle
214 {
215 Q_OBJECT
216
217 public:
218 explicit DolphinTabPageSplitterHandle(Qt::Orientation orientation, QSplitter *parent);
219
220 protected:
221 bool event(QEvent *event) override;
222
223 private:
224 void resetSplitterSizes();
225
226 // Sometimes QSplitterHandle doesn't receive MouseButtonDblClick event.
227 // We can detect that MouseButtonDblClick event should have been
228 // received if we receive two MouseButtonRelease events in a row.
229 bool m_mouseReleaseWasReceived;
230 };
231
232 class DolphinTabPageSplitter : public QSplitter
233 {
234 Q_OBJECT
235
236 public:
237 explicit DolphinTabPageSplitter(Qt::Orientation orientation, QWidget *parent);
238
239 protected:
240 QSplitterHandle *createHandle() override;
241 };
242
243 #endif // DOLPHIN_TAB_PAGE_H