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
28 * @param navigatorsWidget The navigatorsWidget which is always going to be connected
29 * to the active tabPage.
31 explicit DolphinTabWidget(DolphinNavigatorsWidgetAction
*navigatorsWidget
, QWidget
*parent
);
34 * Where a newly opened tab should be placed.
36 enum class NewTabPosition
{
37 FollowSetting
, ///< Honor openNewTabAfterLastTab setting
38 AfterCurrent
, ///< After the current tab
39 AtEnd
, ///< At the end of the tab bar
43 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
45 DolphinTabPage
* currentTabPage() const;
48 * @return the next tab page. If the current active tab is the last tab,
49 * it returns the first tab. If there is only one tab, returns nullptr
51 DolphinTabPage
* nextTabPage() const;
54 * @return the previous tab page. If the current active tab is the first tab,
55 * it returns the last tab. If there is only one tab, returns nullptr
57 DolphinTabPage
* prevTabPage() const;
60 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
62 DolphinTabPage
* tabPageAt(const int index
) const;
64 void saveProperties(KConfigGroup
& group
) const;
65 void readProperties(const KConfigGroup
& group
);
68 * Refreshes the views of the main window by recreating them according to
69 * the given Dolphin settings.
74 * @return Whether any of the tab pages has @p url opened
75 * in their primary or secondary view.
77 bool isUrlOpen(const QUrl
& url
) const;
80 * @return Whether the item with @p url can be found in any view only by switching
81 * between already open tabs and scrolling in their primary or secondary view.
83 bool isItemVisibleInAnyView(const QUrl
& urlOfItem
) const;
87 * Is emitted when the active view has been changed, by changing the current
88 * tab or by activating another view when split view is enabled in the current
91 void activeViewChanged(DolphinViewContainer
* viewContainer
);
94 * Is emitted when the number of open tabs has changed (e.g. by opening or
97 void tabCountChanged(int count
);
100 * Is emitted when a tab has been closed.
102 void rememberClosedTab(const QUrl
& url
, const QByteArray
& state
);
105 * Is emitted when the url of the current tab has been changed. This signal
106 * is also emitted when the active view has been changed.
108 void currentUrlChanged(const QUrl
& url
);
112 * Opens a new view with the current URL that is part of a tab and activates
115 void openNewActivatedTab();
118 * Opens a new tab showing the URL \a primaryUrl and the optional URL
119 * \a secondaryUrl and activates the tab.
121 void openNewActivatedTab(const QUrl
& primaryUrl
, const QUrl
& secondaryUrl
= QUrl());
124 * Opens a new tab in the background showing the URL \a primaryUrl and the
125 * optional URL \a secondaryUrl.
127 void openNewTab(const QUrl
&primaryUrl
, const QUrl
&secondaryUrl
= QUrl(), NewTabPosition position
= NewTabPosition::FollowSetting
);
130 * Opens each directory in \p dirs in a separate tab unless it is already open.
131 * If \a splitView is set, 2 directories are collected within one tab.
132 * \pre \a dirs must contain at least one url.
134 void openDirectories(const QList
<QUrl
>& dirs
, bool splitView
);
137 * Opens the directories which contain the files \p files and selects all files.
138 * If \a splitView is set, 2 directories are collected within one tab.
139 * \pre \a files must contain at least one url.
141 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
144 * Closes the currently active tab.
149 * Closes the tab with the index \a index and activates the tab with index - 1.
151 void closeTab(const int index
);
154 * Activates the tab with the index \a index.
156 void activateTab(const int index
);
159 * Activates the last tab in the tab bar.
161 void activateLastTab();
164 * Activates the next tab in the tab bar.
165 * If the current active tab is the last tab, it activates the first tab.
167 void activateNextTab();
170 * Activates the previous tab in the tab bar.
171 * If the current active tab is the first tab, it activates the last tab.
173 void activatePrevTab();
176 * Is called when the user wants to reopen a previously closed tab from
177 * the recent tabs menu.
179 void restoreClosedTab(const QByteArray
& state
);
181 /** Copies all selected items to the inactive view. */
182 void copyToInactiveSplitView();
184 /** Moves all selected items to the inactive view. */
185 void moveToInactiveSplitView();
189 * Opens the tab with the index \a index in a new Dolphin instance and closes
192 void detachTab(int index
);
195 * Opens a new tab showing the url from tab at the given \a index and
198 void openNewActivatedTab(int index
);
201 * Is connected to the KTabBar signal receivedDropEvent.
202 * Allows dragging and dropping files onto tabs.
204 void tabDropEvent(int tab
, QDropEvent
* event
);
207 * The active view url of a tab has been changed so update the text and the
208 * icon of the corresponding tab.
210 void tabUrlChanged(const QUrl
& url
);
212 void currentTabChanged(int index
);
215 void tabInserted(int index
) override
;
216 void tabRemoved(int index
) override
;
220 * @param tabPage The tab page to get the name of
221 * @return The name of the tab page
223 QString
tabName(DolphinTabPage
* tabPage
) const;
227 const bool isInPrimaryView
;
230 * Get the position of the view within this widget that is open at @p directory.
231 * @param directory The URL of the directory we want to find.
232 * @return a small struct containing the tab index of the view and whether it is
233 * in the primary view. A std::nullopt is returned if there is no view open for @p directory.
235 const std::optional
<const ViewIndex
> viewOpenAtDirectory(const QUrl
& directory
) const;
238 * Get the position of the view within this widget that has @p item in the view.
239 * This means that the item can be seen by the user in that view when scrolled to the right position.
240 * If the view has folders expanded and @p item is one of them, the view will also be returned.
241 * @param item The URL of the item we want to find.
242 * @return a small struct containing the tab index of the view and whether it is
243 * in the primary view. A std::nullopt is returned if there is no view open that has @p item visible anywhere.
245 const std::optional
<const ViewIndex
> viewShowingItem(const QUrl
& item
) const;
248 QPointer
<DolphinTabPage
> m_lastViewedTab
;
249 QPointer
<DolphinNavigatorsWidgetAction
> m_navigatorsWidget
;