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"
18 class DolphinViewContainer
;
21 class DolphinTabWidget
: public QTabWidget
27 * @param navigatorsWidget The navigatorsWidget which is always going to be connected
28 * to the active tabPage.
30 explicit DolphinTabWidget(DolphinNavigatorsWidgetAction
*navigatorsWidget
, QWidget
*parent
);
33 * Where a newly opened tab should be placed.
35 enum class NewTabPosition
{
36 FollowSetting
, ///< Honor openNewTabAfterLastTab setting
37 AfterCurrent
, ///< After the current tab
38 AtEnd
, ///< At the end of the tab bar
42 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
44 DolphinTabPage
*currentTabPage() const;
47 * @return the next tab page. If the current active tab is the last tab,
48 * it returns the first tab. If there is only one tab, returns nullptr
50 DolphinTabPage
*nextTabPage() const;
53 * @return the previous tab page. If the current active tab is the first tab,
54 * it returns the last tab. If there is only one tab, returns nullptr
56 DolphinTabPage
*prevTabPage() const;
59 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
61 DolphinTabPage
*tabPageAt(const int index
) const;
63 void saveProperties(KConfigGroup
&group
) const;
64 void readProperties(const KConfigGroup
&group
);
67 * Refreshes the views of the main window by recreating them according to
68 * the given Dolphin settings.
73 * @return Whether any of the tab pages has @p url opened
74 * in their primary or secondary view.
76 bool isUrlOpen(const QUrl
&url
) const;
79 * @return Whether the item with @p url can be found in any view only by switching
80 * between already open tabs and scrolling in their primary or secondary view.
82 bool isItemVisibleInAnyView(const QUrl
&urlOfItem
) const;
86 * Is emitted when the active view has been changed, by changing the current
87 * tab or by activating another view when split view is enabled in the current
90 void activeViewChanged(DolphinViewContainer
*viewContainer
);
93 * Is emitted when the number of open tabs has changed (e.g. by opening or
96 void tabCountChanged(int count
);
99 * Is emitted when a tab has been closed.
101 void rememberClosedTab(const QUrl
&url
, const QByteArray
&state
);
104 * Is emitted when the url of the current tab has been changed. This signal
105 * is also emitted when the active view has been changed.
107 void currentUrlChanged(const QUrl
&url
);
111 * Opens a new view with the current URL that is part of a tab and activates
114 void openNewActivatedTab();
117 * Opens a new tab showing the URL \a primaryUrl and the optional URL
118 * \a secondaryUrl and activates the tab.
120 void openNewActivatedTab(const QUrl
&primaryUrl
, const QUrl
&secondaryUrl
= QUrl());
123 * Opens a new tab in the background showing the URL \a primaryUrl and the
124 * optional URL \a secondaryUrl.
126 void openNewTab(const QUrl
&primaryUrl
,
127 const QUrl
&secondaryUrl
= QUrl(),
128 DolphinTabWidget::NewTabPosition position
= DolphinTabWidget::NewTabPosition::FollowSetting
);
131 * Opens each directory in \p dirs in a separate tab unless it is already open.
132 * If \a splitView is set, 2 directories are collected within one tab.
133 * \pre \a dirs must contain at least one url.
135 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
138 * Opens the directories which contain the files \p files and selects all files.
139 * If \a splitView is set, 2 directories are collected within one tab.
140 * \pre \a files must contain at least one url.
142 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
145 * Closes the currently active tab.
150 * Closes the tab with the index \a index and activates the tab with index - 1.
152 void closeTab(const int index
);
155 * Activates the tab with the index \a index.
157 void activateTab(const int index
);
160 * Activates the last tab in the tab bar.
162 void activateLastTab();
165 * Activates the next tab in the tab bar.
166 * If the current active tab is the last tab, it activates the first tab.
168 void activateNextTab();
171 * Activates the previous tab in the tab bar.
172 * If the current active tab is the first tab, it activates the last tab.
174 void activatePrevTab();
177 * Is called when the user wants to reopen a previously closed tab from
178 * the recent tabs menu.
180 void restoreClosedTab(const QByteArray
&state
);
182 /** Copies all selected items to the inactive view. */
183 void copyToInactiveSplitView();
185 /** Moves all selected items to the inactive view. */
186 void moveToInactiveSplitView();
190 * Opens the tab with the index \a index in a new Dolphin instance and closes
193 void detachTab(int index
);
196 * Opens a new tab showing the url from tab at the given \a index and
199 void openNewActivatedTab(int index
);
202 * Is connected to the KTabBar signal receivedDropEvent.
203 * Allows dragging and dropping files onto tabs.
205 void tabDropEvent(int tab
, QDropEvent
*event
);
208 * The active view url of a tab has been changed so update the text and the
209 * icon of the corresponding tab.
211 void tabUrlChanged(const QUrl
&url
);
213 void currentTabChanged(int index
);
216 void tabInserted(int index
) override
;
217 void tabRemoved(int index
) override
;
221 * @param tabPage The tab page to get the name of
222 * @return The name of the tab page
224 QString
tabName(DolphinTabPage
*tabPage
) const;
228 const bool isInPrimaryView
;
232 * Getter for a view container.
233 * @param viewIndex specifies the tab and the view within that tab.
234 * @return the view container specified in @p viewIndex or nullptr if it doesn't exist.
236 DolphinViewContainer
*viewContainerAt(ViewIndex viewIndex
) const;
239 * Makes the view container specified in @p viewIndex become the active view container within this tab widget.
240 * @param viewIndex Specifies the tab to activate and the view container within the tab to activate.
241 * @return the freshly activated view container or nullptr if there is no view container at @p viewIndex.
243 DolphinViewContainer
*activateViewContainerAt(ViewIndex viewIndex
);
246 * Get the position of the view within this widget that is open at @p directory.
247 * @param directory The URL of the directory we want to find.
248 * @return a small struct containing the tab index of the view and whether it is
249 * in the primary view. A std::nullopt is returned if there is no view open for @p directory.
251 const std::optional
<const ViewIndex
> viewOpenAtDirectory(const QUrl
&directory
) const;
254 * Get the position of the view within this widget that has @p item in the view.
255 * This means that the item can be seen by the user in that view when scrolled to the right position.
256 * If the view has folders expanded and @p item is one of them, the view will also be returned.
257 * @param item The URL of the item we want to find.
258 * @return a small struct containing the tab index of the view and whether it is
259 * in the primary view. A std::nullopt is returned if there is no view open that has @p item visible anywhere.
261 const std::optional
<const ViewIndex
> viewShowingItem(const QUrl
&item
) const;
264 QPointer
<DolphinTabPage
> m_lastViewedTab
;
265 QPointer
<DolphinNavigatorsWidgetAction
> m_navigatorsWidget
;