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