]> 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 /**
89 * Notify the connected DolphinNavigatorsWidgetAction of geometry changes which it
90 * needs for visual alignment.
91 */
92 void resizeNavigators() const;
93
94 /**
95 * Marks the items indicated by \p urls to get selected after the
96 * directory DolphinView::url() has been loaded. Note that nothing
97 * gets selected if no loading of a directory has been triggered
98 * by DolphinView::setUrl() or DolphinView::reload().
99 */
100 void markUrlsAsSelected(const QList<QUrl> &urls);
101
102 /**
103 * Marks the item indicated by \p url to be scrolled to and as the
104 * current item after directory DolphinView::url() has been loaded.
105 */
106 void markUrlAsCurrent(const QUrl& url);
107
108 /**
109 * Refreshes the views of the main window by recreating them according to
110 * the given Dolphin settings.
111 */
112 void refreshViews();
113
114 /**
115 * Saves all tab related properties (urls, splitter layout, ...).
116 *
117 * @return A byte-array which contains all properties.
118 */
119 QByteArray saveState() const;
120
121 /**
122 * Restores all tab related properties (urls, splitter layout, ...) from
123 * the given \a state.
124 */
125 void restoreState(const QByteArray& state);
126
127 /**
128 * Restores all tab related properties (urls, splitter layout, ...) from
129 * the given \a state.
130 *
131 * @deprecated The first tab state version has no version number, we keep
132 * this method to restore old states (<= Dolphin 4.14.x).
133 */
134 Q_DECL_DEPRECATED void restoreStateV1(const QByteArray& state);
135
136 /**
137 * Set whether the tab page is active
138 *
139 */
140 void setActive(bool active);
141
142 signals:
143 void activeViewChanged(DolphinViewContainer* viewContainer);
144 void activeViewUrlChanged(const QUrl& url);
145 void splitterMoved(int pos, int index);
146
147 private slots:
148 /**
149 * Handles the view activated event.
150 *
151 * It sets the previous active view to inactive, updates the current
152 * active view type and triggers the activeViewChanged event.
153 */
154 void slotViewActivated();
155
156 /**
157 * Handles the view url redirection event.
158 *
159 * It emits the activeViewUrlChanged signal with the url \a newUrl.
160 */
161 void slotViewUrlRedirection(const QUrl& oldUrl, const QUrl& newUrl);
162
163 void switchActiveView();
164
165 private:
166 /**
167 * Creates a new view container and does the default initialization.
168 */
169 DolphinViewContainer* createViewContainer(const QUrl& url) const;
170
171 private:
172 QSplitter* m_splitter;
173
174 QPointer<DolphinNavigatorsWidgetAction> m_navigatorsWidget;
175 QPointer<DolphinViewContainer> m_primaryViewContainer;
176 QPointer<DolphinViewContainer> m_secondaryViewContainer;
177
178 bool m_primaryViewActive;
179 bool m_splitViewEnabled;
180 bool m_active;
181 };
182
183 #endif // DOLPHIN_TAB_PAGE_H