]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabwidget.h
Merge branch 'release/20.12'
[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 contains @p url in their primary
64 * or secondary view.
65 */
66 bool isUrlOpen(const QUrl& url) const;
67
68 signals:
69 /**
70 * Is emitted when the active view has been changed, by changing the current
71 * tab or by activating another view when split view is enabled in the current
72 * tab.
73 */
74 void activeViewChanged(DolphinViewContainer* viewContainer);
75
76 /**
77 * Is emitted when the number of open tabs has changed (e.g. by opening or
78 * closing a tab)
79 */
80 void tabCountChanged(int count);
81
82 /**
83 * Is emitted when a tab has been closed.
84 */
85 void rememberClosedTab(const QUrl& url, const QByteArray& state);
86
87 /**
88 * Is emitted when the url of the current tab has been changed. This signal
89 * is also emitted when the active view has been changed.
90 */
91 void currentUrlChanged(const QUrl& url);
92
93 public slots:
94 /**
95 * Opens a new view with the current URL that is part of a tab and activates
96 * the tab.
97 */
98 void openNewActivatedTab();
99
100 /**
101 * Opens a new tab showing the URL \a primaryUrl and the optional URL
102 * \a secondaryUrl and activates the tab.
103 */
104 void openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl = QUrl());
105
106 /**
107 * Opens a new tab in the background showing the URL \a primaryUrl and the
108 * optional URL \a secondaryUrl.
109 */
110 void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl());
111
112 /**
113 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
114 * 2 directories are collected within one tab.
115 * \pre \a dirs must contain at least one url.
116 */
117 void openDirectories(const QList<QUrl>& dirs, bool splitView);
118
119 /**
120 * Opens the directories which contain the files \p files and selects all files.
121 * If \a splitView is set, 2 directories are collected within one tab.
122 * \pre \a files must contain at least one url.
123 */
124 void openFiles(const QList<QUrl> &files, bool splitView);
125
126 /**
127 * Closes the currently active tab.
128 */
129 void closeTab();
130
131 /**
132 * Closes the tab with the index \a index and activates the tab with index - 1.
133 */
134 void closeTab(const int index);
135
136 /**
137 * Activates the tab with the index \a index.
138 */
139 void activateTab(const int index);
140
141 /**
142 * Activates the last tab in the tab bar.
143 */
144 void activateLastTab();
145
146 /**
147 * Activates the next tab in the tab bar.
148 * If the current active tab is the last tab, it activates the first tab.
149 */
150 void activateNextTab();
151
152 /**
153 * Activates the previous tab in the tab bar.
154 * If the current active tab is the first tab, it activates the last tab.
155 */
156 void activatePrevTab();
157
158 /**
159 * Is called when the user wants to reopen a previously closed tab from
160 * the recent tabs menu.
161 */
162 void restoreClosedTab(const QByteArray& state);
163
164 /** Copies all selected items to the inactive view. */
165 void copyToInactiveSplitView();
166
167 /** Moves all selected items to the inactive view. */
168 void moveToInactiveSplitView();
169
170 private slots:
171 /**
172 * Opens the tab with the index \a index in a new Dolphin instance and closes
173 * this tab.
174 */
175 void detachTab(int index);
176
177 /**
178 * Opens a new tab showing the url from tab at the given \a index and
179 * activates the tab.
180 */
181 void openNewActivatedTab(int index);
182
183 /**
184 * Is connected to the KTabBar signal receivedDropEvent.
185 * Allows dragging and dropping files onto tabs.
186 */
187 void tabDropEvent(int tab, QDropEvent* event);
188
189 /**
190 * The active view url of a tab has been changed so update the text and the
191 * icon of the corresponding tab.
192 */
193 void tabUrlChanged(const QUrl& url);
194
195 void currentTabChanged(int index);
196
197 protected:
198 void tabInserted(int index) override;
199 void tabRemoved(int index) override;
200
201 private:
202 /**
203 * @param tabPage The tab page to get the name of
204 * @return The name of the tab page
205 */
206 QString tabName(DolphinTabPage* tabPage) const;
207
208 /**
209 * @param url The URL that we would like
210 * @return a QPair with first containing the index of the tab with the
211 * desired URL or -1 if not found. Second says true if URL is in primary
212 * view container, false otherwise. False means the URL is in the secondary
213 * view container, unless first == -1. In that case the value of second
214 * is meaningless.
215 */
216 QPair<int, bool> indexByUrl(const QUrl& url) const;
217
218 private:
219 QPointer<DolphinTabPage> m_lastViewedTab;
220 QPointer<DolphinNavigatorsWidgetAction> m_navigatorsWidget;
221 };
222
223 #endif