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
26 * @param navigatorsWidget The navigatorsWidget which is always going to be connected
27 * to the active tabPage.
29 explicit DolphinTabWidget(DolphinNavigatorsWidgetAction
*navigatorsWidget
, QWidget
*parent
);
32 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
34 DolphinTabPage
* currentTabPage() const;
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
40 DolphinTabPage
* nextTabPage() const;
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
46 DolphinTabPage
* prevTabPage() const;
49 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
51 DolphinTabPage
* tabPageAt(const int index
) const;
53 void saveProperties(KConfigGroup
& group
) const;
54 void readProperties(const KConfigGroup
& group
);
57 * Refreshes the views of the main window by recreating them according to
58 * the given Dolphin settings.
63 * @return Whether any of the tab pages has @p url opened
64 * in their primary or secondary view.
66 bool isUrlOpen(const QUrl
& url
) const;
69 * @return Whether any of the tab pages has @p url or it's parent opened
70 * in their primary or secondary view.
72 bool isUrlOrParentOpen(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.
116 void openNewTab(const QUrl
&primaryUrl
, const QUrl
&secondaryUrl
= QUrl());
119 * Opens each directory in \p dirs in a separate tab unless it is already open.
120 * If \a splitView is set, 2 directories are collected within one tab.
121 * If \a skipChildUrls is set, do not open a directory if it's parent is already open.
122 * \pre \a dirs must contain at least one url.
124 void openDirectories(const QList
<QUrl
>& dirs
, bool splitView
, bool skipChildUrls
= false);
127 * Opens the directories which contain the files \p files and selects all files.
128 * If \a splitView is set, 2 directories are collected within one tab.
129 * \pre \a files must contain at least one url.
131 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
134 * Closes the currently active tab.
139 * Closes the tab with the index \a index and activates the tab with index - 1.
141 void closeTab(const int index
);
144 * Activates the tab with the index \a index.
146 void activateTab(const int index
);
149 * Activates the last tab in the tab bar.
151 void activateLastTab();
154 * Activates the next tab in the tab bar.
155 * If the current active tab is the last tab, it activates the first tab.
157 void activateNextTab();
160 * Activates the previous tab in the tab bar.
161 * If the current active tab is the first tab, it activates the last tab.
163 void activatePrevTab();
166 * Is called when the user wants to reopen a previously closed tab from
167 * the recent tabs menu.
169 void restoreClosedTab(const QByteArray
& state
);
171 /** Copies all selected items to the inactive view. */
172 void copyToInactiveSplitView();
174 /** Moves all selected items to the inactive view. */
175 void moveToInactiveSplitView();
179 * Opens the tab with the index \a index in a new Dolphin instance and closes
182 void detachTab(int index
);
185 * Opens a new tab showing the url from tab at the given \a index and
188 void openNewActivatedTab(int index
);
191 * Is connected to the KTabBar signal receivedDropEvent.
192 * Allows dragging and dropping files onto tabs.
194 void tabDropEvent(int tab
, QDropEvent
* event
);
197 * The active view url of a tab has been changed so update the text and the
198 * icon of the corresponding tab.
200 void tabUrlChanged(const QUrl
& url
);
202 void currentTabChanged(int index
);
205 void tabInserted(int index
) override
;
206 void tabRemoved(int index
) override
;
210 * @param tabPage The tab page to get the name of
211 * @return The name of the tab page
213 QString
tabName(DolphinTabPage
* tabPage
) const;
215 enum ChildUrlBehavior
{
216 ReturnIndexForOpenedUrlOnly
,
217 ReturnIndexForOpenedParentAlso
221 * @param url The URL that we would like
222 * @param childUrlBehavior Whether a tab with opened parent of the URL can be returned too
223 * @return a QPair with:
224 * First containing the index of the tab with the desired URL or -1 if not found.
225 * Second says true if URL is in primary view container, false otherwise.
226 * False means the URL is in the secondary view container, unless first == -1.
227 * In that case the value of second is meaningless.
229 QPair
<int, bool> indexByUrl(const QUrl
& url
, ChildUrlBehavior childUrlBehavior
= ReturnIndexForOpenedUrlOnly
) const;
232 QPointer
<DolphinTabPage
> m_lastViewedTab
;
233 QPointer
<DolphinNavigatorsWidgetAction
> m_navigatorsWidget
;