]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabwidget.h
Merge branch 'release/20.08' into master
[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 invoked if the Places panel got visible/invisible and takes care
168 * that the places-selector of all views is only shown if the Places panel
169 * is invisible.
170 */
171 void slotPlacesPanelVisibilityChanged(bool visible);
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 /** Caches the (negated) places panel visibility */
235 bool m_placesSelectorVisible;
236
237 int m_lastViewedTab;
238 };
239
240 #endif