]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabwidget.h
GIT_SILENT: Terminal=false is default value. Not necessary to keep it in desktop...
[dolphin.git] / src / dolphintabwidget.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_WIDGET_H
8 #define DOLPHIN_TAB_WIDGET_H
9
10 #include "dolphinnavigatorswidgetaction.h"
11 #include "dolphintabpage.h"
12
13 #include <QTabWidget>
14 #include <QUrl>
15
16 class DolphinViewContainer;
17 class KConfigGroup;
18
19 class DolphinTabWidget : public QTabWidget
20 {
21 Q_OBJECT
22
23 public:
24
25 /**
26 * @param navigatorsWidget The navigatorsWidget which is always going to be connected
27 * to the active tabPage.
28 */
29 explicit DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidget, QWidget *parent);
30
31 /**
32 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
33 */
34 DolphinTabPage* currentTabPage() const;
35
36 /**
37 * @return the next tab page. If the current active tab is the last tab,
38 * it returns the first tab. If there is only one tab, returns nullptr
39 */
40 DolphinTabPage* nextTabPage() const;
41
42 /**
43 * @return the previous tab page. If the current active tab is the first tab,
44 * it returns the last tab. If there is only one tab, returns nullptr
45 */
46 DolphinTabPage* prevTabPage() const;
47
48 /**
49 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
50 */
51 DolphinTabPage* tabPageAt(const int index) const;
52
53 void saveProperties(KConfigGroup& group) const;
54 void readProperties(const KConfigGroup& group);
55
56 /**
57 * Refreshes the views of the main window by recreating them according to
58 * the given Dolphin settings.
59 */
60 void refreshViews();
61
62 /**
63 * @return Whether any of the tab pages has @p url opened
64 * in their primary or secondary view.
65 */
66 bool isUrlOpen(const QUrl& url) const;
67
68 /**
69 * @return Whether any of the tab pages has @p url or it's parent opened
70 * in their primary or secondary view.
71 */
72 bool isUrlOrParentOpen(const QUrl& url) const;
73
74 Q_SIGNALS:
75 /**
76 * Is emitted when the active view has been changed, by changing the current
77 * tab or by activating another view when split view is enabled in the current
78 * tab.
79 */
80 void activeViewChanged(DolphinViewContainer* viewContainer);
81
82 /**
83 * Is emitted when the number of open tabs has changed (e.g. by opening or
84 * closing a tab)
85 */
86 void tabCountChanged(int count);
87
88 /**
89 * Is emitted when a tab has been closed.
90 */
91 void rememberClosedTab(const QUrl& url, const QByteArray& state);
92
93 /**
94 * Is emitted when the url of the current tab has been changed. This signal
95 * is also emitted when the active view has been changed.
96 */
97 void currentUrlChanged(const QUrl& url);
98
99 public Q_SLOTS:
100 /**
101 * Opens a new view with the current URL that is part of a tab and activates
102 * the tab.
103 */
104 void openNewActivatedTab();
105
106 /**
107 * Opens a new tab showing the URL \a primaryUrl and the optional URL
108 * \a secondaryUrl and activates the tab.
109 */
110 void openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl = QUrl());
111
112 /**
113 * Opens a new tab in the background showing the URL \a primaryUrl and the
114 * optional URL \a secondaryUrl.
115 */
116 void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl());
117
118 /**
119 * Opens each directory in \p dirs in a separate tab unless it is already open.
120 * If \a splitView is set, 2 directories are collected within one tab.
121 * If \a skipChildUrls is set, do not open a directory if it's parent is already open.
122 * \pre \a dirs must contain at least one url.
123 */
124 void openDirectories(const QList<QUrl>& dirs, bool splitView, bool skipChildUrls = false);
125
126 /**
127 * Opens the directories which contain the files \p files and selects all files.
128 * If \a splitView is set, 2 directories are collected within one tab.
129 * \pre \a files must contain at least one url.
130 */
131 void openFiles(const QList<QUrl> &files, bool splitView);
132
133 /**
134 * Closes the currently active tab.
135 */
136 void closeTab();
137
138 /**
139 * Closes the tab with the index \a index and activates the tab with index - 1.
140 */
141 void closeTab(const int index);
142
143 /**
144 * Activates the tab with the index \a index.
145 */
146 void activateTab(const int index);
147
148 /**
149 * Activates the last tab in the tab bar.
150 */
151 void activateLastTab();
152
153 /**
154 * Activates the next tab in the tab bar.
155 * If the current active tab is the last tab, it activates the first tab.
156 */
157 void activateNextTab();
158
159 /**
160 * Activates the previous tab in the tab bar.
161 * If the current active tab is the first tab, it activates the last tab.
162 */
163 void activatePrevTab();
164
165 /**
166 * Is called when the user wants to reopen a previously closed tab from
167 * the recent tabs menu.
168 */
169 void restoreClosedTab(const QByteArray& state);
170
171 /** Copies all selected items to the inactive view. */
172 void copyToInactiveSplitView();
173
174 /** Moves all selected items to the inactive view. */
175 void moveToInactiveSplitView();
176
177 private Q_SLOTS:
178 /**
179 * Opens the tab with the index \a index in a new Dolphin instance and closes
180 * this tab.
181 */
182 void detachTab(int index);
183
184 /**
185 * Opens a new tab showing the url from tab at the given \a index and
186 * activates the tab.
187 */
188 void openNewActivatedTab(int index);
189
190 /**
191 * Is connected to the KTabBar signal receivedDropEvent.
192 * Allows dragging and dropping files onto tabs.
193 */
194 void tabDropEvent(int tab, QDropEvent* event);
195
196 /**
197 * The active view url of a tab has been changed so update the text and the
198 * icon of the corresponding tab.
199 */
200 void tabUrlChanged(const QUrl& url);
201
202 void currentTabChanged(int index);
203
204 protected:
205 void tabInserted(int index) override;
206 void tabRemoved(int index) override;
207
208 private:
209 /**
210 * @param tabPage The tab page to get the name of
211 * @return The name of the tab page
212 */
213 QString tabName(DolphinTabPage* tabPage) const;
214
215 enum ChildUrlBehavior {
216 ReturnIndexForOpenedUrlOnly,
217 ReturnIndexForOpenedParentAlso
218 };
219
220 /**
221 * @param url The URL that we would like
222 * @param childUrlBehavior Whether a tab with opened parent of the URL can be returned too
223 * @return a QPair with:
224 * First containing the index of the tab with the desired URL or -1 if not found.
225 * Second says true if URL is in primary view container, false otherwise.
226 * False means the URL is in the secondary view container, unless first == -1.
227 * In that case the value of second is meaningless.
228 */
229 QPair<int, bool> indexByUrl(const QUrl& url, ChildUrlBehavior childUrlBehavior = ReturnIndexForOpenedUrlOnly) const;
230
231 private:
232 QPointer<DolphinTabPage> m_lastViewedTab;
233 QPointer<DolphinNavigatorsWidgetAction> m_navigatorsWidget;
234 };
235
236 #endif