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
10 #include "dolphinnavigatorswidgetaction.h"
11 #include "dolphintabpage.h"
16 class DolphinViewContainer
;
19 class DolphinTabWidget
: public QTabWidget
25 * @brief Controls where tabs are placed
29 * The new tab is placed after the current tab
33 * The new tab is placed after the last tab
39 * @param navigatorsWidget The navigatorsWidget which is always going to be connected
40 * to the active tabPage.
42 explicit DolphinTabWidget(DolphinNavigatorsWidgetAction
*navigatorsWidget
, QWidget
*parent
);
45 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
47 DolphinTabPage
* currentTabPage() const;
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
53 DolphinTabPage
* nextTabPage() const;
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
59 DolphinTabPage
* prevTabPage() const;
62 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
64 DolphinTabPage
* tabPageAt(const int index
) const;
66 void saveProperties(KConfigGroup
& group
) const;
67 void readProperties(const KConfigGroup
& group
);
70 * Refreshes the views of the main window by recreating them according to
71 * the given Dolphin settings.
76 * @return Whether any of the tab pages contains @p url in their primary
79 bool isUrlOpen(const QUrl
& url
) const;
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
87 void activeViewChanged(DolphinViewContainer
* viewContainer
);
90 * Is emitted when the number of open tabs has changed (e.g. by opening or
93 void tabCountChanged(int count
);
96 * Is emitted when a tab has been closed.
98 void rememberClosedTab(const QUrl
& url
, const QByteArray
& state
);
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.
104 void currentUrlChanged(const QUrl
& url
);
108 * Opens a new view with the current URL that is part of a tab and activates
111 void openNewActivatedTab();
114 * Opens a new tab showing the URL \a primaryUrl and the optional URL
115 * \a secondaryUrl and activates the tab.
117 void openNewActivatedTab(const QUrl
& primaryUrl
, const QUrl
& secondaryUrl
= QUrl());
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
124 void openNewTab(const QUrl
&primaryUrl
, const QUrl
&secondaryUrl
= QUrl(),
125 DolphinTabWidget::TabPlacement tabPlacement
= AfterLastTab
);
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.
132 void openDirectories(const QList
<QUrl
>& dirs
, bool splitView
);
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.
139 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
142 * Closes the currently active tab.
147 * Closes the tab with the index \a index and activates the tab with index - 1.
149 void closeTab(const int index
);
152 * Activates the tab with the index \a index.
154 void activateTab(const int index
);
157 * Activates the last tab in the tab bar.
159 void activateLastTab();
162 * Activates the next tab in the tab bar.
163 * If the current active tab is the last tab, it activates the first tab.
165 void activateNextTab();
168 * Activates the previous tab in the tab bar.
169 * If the current active tab is the first tab, it activates the last tab.
171 void activatePrevTab();
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 QPointer
<DolphinTabPage
> m_lastViewedTab
;
235 QPointer
<DolphinNavigatorsWidgetAction
> m_navigatorsWidget
;