]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabwidget.h
Add an option to use an UrlNavigator in the toolbar instead
[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 <QTabWidget>
11 #include <QUrl>
12
13 class DolphinViewContainer;
14 class DolphinTabPage;
15 class KConfigGroup;
16
17 class DolphinTabWidget : public QTabWidget
18 {
19 Q_OBJECT
20
21 public:
22 /**
23 * @brief Controls where tabs are placed
24 */
25 enum TabPlacement {
26 /**
27 * The new tab is placed after the current tab
28 */
29 AfterCurrentTab,
30 /**
31 * The new tab is placed after the last tab
32 */
33 AfterLastTab
34 };
35 explicit DolphinTabWidget(QWidget* parent);
36
37 /**
38 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
39 */
40 DolphinTabPage* currentTabPage() const;
41
42 /**
43 * @return the next tab page. If the current active tab is the last tab,
44 * it returns the first tab. If there is only one tab, returns nullptr
45 */
46 DolphinTabPage* nextTabPage() const;
47
48 /**
49 * @return the previous tab page. If the current active tab is the first tab,
50 * it returns the last tab. If there is only one tab, returns nullptr
51 */
52 DolphinTabPage* prevTabPage() const;
53
54 /**
55 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
56 */
57 DolphinTabPage* tabPageAt(const int index) const;
58
59 void saveProperties(KConfigGroup& group) const;
60 void readProperties(const KConfigGroup& group);
61
62 /**
63 * Refreshes the views of the main window by recreating them according to
64 * the given Dolphin settings.
65 */
66 void refreshViews();
67
68 /**
69 * @return Whether any of the tab pages contains @p url in their primary
70 * or secondary view.
71 */
72 bool isUrlOpen(const QUrl& url) const;
73
74 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 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. \a tabPlacement controls where the new tab
115 * is placed.
116 */
117 void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl(),
118 DolphinTabWidget::TabPlacement tabPlacement = AfterLastTab);
119
120 /**
121 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
122 * 2 directories are collected within one tab.
123 * \pre \a dirs must contain at least one url.
124 */
125 void openDirectories(const QList<QUrl>& dirs, bool splitView);
126
127 /**
128 * Opens the directories which contain the files \p files and selects all files.
129 * If \a splitView is set, 2 directories are collected within one tab.
130 * \pre \a files must contain at least one url.
131 */
132 void openFiles(const QList<QUrl> &files, bool splitView);
133
134 /**
135 * Closes the currently active tab.
136 */
137 void closeTab();
138
139 /**
140 * Closes the tab with the index \a index and activates the tab with index - 1.
141 */
142 void closeTab(const int index);
143
144 /**
145 * Activates the tab with the index \a index.
146 */
147 void activateTab(const int index);
148
149 /**
150 * Activates the last tab in the tab bar.
151 */
152 void activateLastTab();
153
154 /**
155 * Activates the next tab in the tab bar.
156 * If the current active tab is the last tab, it activates the first tab.
157 */
158 void activateNextTab();
159
160 /**
161 * Activates the previous tab in the tab bar.
162 * If the current active tab is the first tab, it activates the last tab.
163 */
164 void activatePrevTab();
165
166 /**
167 * Is called when the user wants to reopen a previously closed tab from
168 * the recent tabs menu.
169 */
170 void restoreClosedTab(const QByteArray& state);
171
172 /** Copies all selected items to the inactive view. */
173 void copyToInactiveSplitView();
174
175 /** Moves all selected items to the inactive view. */
176 void moveToInactiveSplitView();
177
178 private slots:
179 /**
180 * Opens the tab with the index \a index in a new Dolphin instance and closes
181 * this tab.
182 */
183 void detachTab(int index);
184
185 /**
186 * Opens a new tab showing the url from tab at the given \a index and
187 * activates the tab.
188 */
189 void openNewActivatedTab(int index);
190
191 /**
192 * Is connected to the KTabBar signal receivedDropEvent.
193 * Allows dragging and dropping files onto tabs.
194 */
195 void tabDropEvent(int tab, QDropEvent* event);
196
197 /**
198 * The active view url of a tab has been changed so update the text and the
199 * icon of the corresponding tab.
200 */
201 void tabUrlChanged(const QUrl& url);
202
203 void currentTabChanged(int index);
204
205 protected:
206 void tabInserted(int index) override;
207 void tabRemoved(int index) override;
208
209 private:
210 /**
211 * @param tabPage The tab page to get the name of
212 * @return The name of the tab page
213 */
214 QString tabName(DolphinTabPage* tabPage) const;
215
216 /**
217 * @param url The URL that we would like
218 * @return a QPair with first containing the index of the tab with the
219 * desired URL or -1 if not found. Second says true if URL is in primary
220 * view container, false otherwise. False means the URL is in the secondary
221 * view container, unless first == -1. In that case the value of second
222 * is meaningless.
223 */
224 QPair<int, bool> indexByUrl(const QUrl& url) const;
225
226 private:
227 int m_lastViewedTab;
228 };
229
230 #endif