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