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