2 * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef DOLPHIN_TAB_WIDGET_H
8 #define DOLPHIN_TAB_WIDGET_H
13 class DolphinViewContainer
;
17 class DolphinTabWidget
: public QTabWidget
23 * @brief Controls where tabs are placed
27 * The new tab is placed after the current tab
31 * The new tab is placed after the last tab
35 explicit DolphinTabWidget(QWidget
* parent
);
38 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
40 DolphinTabPage
* currentTabPage() const;
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
46 DolphinTabPage
* nextTabPage() const;
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
52 DolphinTabPage
* prevTabPage() const;
55 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
57 DolphinTabPage
* tabPageAt(const int index
) const;
59 void saveProperties(KConfigGroup
& group
) const;
60 void readProperties(const KConfigGroup
& group
);
63 * Refreshes the views of the main window by recreating them according to
64 * the given Dolphin settings.
69 * @return Whether any of the tab pages contains @p url in their primary
72 bool isUrlOpen(const QUrl
& url
) const;
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
80 void activeViewChanged(DolphinViewContainer
* viewContainer
);
83 * Is emitted when the number of open tabs has changed (e.g. by opening or
86 void tabCountChanged(int count
);
89 * Is emitted when a tab has been closed.
91 void rememberClosedTab(const QUrl
& url
, const QByteArray
& state
);
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.
97 void currentUrlChanged(const QUrl
& url
);
101 * Opens a new view with the current URL that is part of a tab and activates
104 void openNewActivatedTab();
107 * Opens a new tab showing the URL \a primaryUrl and the optional URL
108 * \a secondaryUrl and activates the tab.
110 void openNewActivatedTab(const QUrl
& primaryUrl
, const QUrl
& secondaryUrl
= QUrl());
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
117 void openNewTab(const QUrl
&primaryUrl
, const QUrl
&secondaryUrl
= QUrl(),
118 DolphinTabWidget::TabPlacement tabPlacement
= AfterLastTab
);
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.
125 void openDirectories(const QList
<QUrl
>& dirs
, bool splitView
);
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.
132 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
135 * Closes the currently active tab.
140 * Closes the tab with the index \a index and activates the tab with index - 1.
142 void closeTab(const int index
);
145 * Activates the tab with the index \a index.
147 void activateTab(const int index
);
150 * Activates the last tab in the tab bar.
152 void activateLastTab();
155 * Activates the next tab in the tab bar.
156 * If the current active tab is the last tab, it activates the first tab.
158 void activateNextTab();
161 * Activates the previous tab in the tab bar.
162 * If the current active tab is the first tab, it activates the last tab.
164 void activatePrevTab();
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
171 void slotPlacesPanelVisibilityChanged(bool visible
);
174 * Is called when the user wants to reopen a previously closed tab from
175 * the recent tabs menu.
177 void restoreClosedTab(const QByteArray
& state
);
179 /** Copies all selected items to the inactive view. */
180 void copyToInactiveSplitView();
182 /** Moves all selected items to the inactive view. */
183 void moveToInactiveSplitView();
187 * Opens the tab with the index \a index in a new Dolphin instance and closes
190 void detachTab(int index
);
193 * Opens a new tab showing the url from tab at the given \a index and
196 void openNewActivatedTab(int index
);
199 * Is connected to the KTabBar signal receivedDropEvent.
200 * Allows dragging and dropping files onto tabs.
202 void tabDropEvent(int tab
, QDropEvent
* event
);
205 * The active view url of a tab has been changed so update the text and the
206 * icon of the corresponding tab.
208 void tabUrlChanged(const QUrl
& url
);
210 void currentTabChanged(int index
);
213 void tabInserted(int index
) override
;
214 void tabRemoved(int index
) override
;
218 * @param tabPage The tab page to get the name of
219 * @return The name of the tab page
221 QString
tabName(DolphinTabPage
* tabPage
) const;
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
231 QPair
<int, bool> indexByUrl(const QUrl
& url
) const;
234 /** Caches the (negated) places panel visibility */
235 bool m_placesSelectorVisible
;