1 /***************************************************************************
2 * Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef DOLPHIN_TAB_WIDGET_H
21 #define DOLPHIN_TAB_WIDGET_H
26 class DolphinViewContainer
;
30 class DolphinTabWidget
: public QTabWidget
36 * @brief Controls where tabs are placed
40 * The new tab is placed after the current tab
44 * The new tab is placed after the last tab
48 explicit DolphinTabWidget(QWidget
* parent
);
51 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
53 DolphinTabPage
* currentTabPage() const;
56 * @return the next tab page. If the current active tab is the last tab,
57 * it returns the first tab. If there is only one tab, returns nullptr
59 DolphinTabPage
* nextTabPage() const;
62 * @return the previous tab page. If the current active tab is the first tab,
63 * it returns the last tab. If there is only one tab, returns nullptr
65 DolphinTabPage
* prevTabPage() const;
68 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
70 DolphinTabPage
* tabPageAt(const int index
) const;
72 void saveProperties(KConfigGroup
& group
) const;
73 void readProperties(const KConfigGroup
& group
);
76 * Refreshes the views of the main window by recreating them according to
77 * the given Dolphin settings.
82 * @param url The URL that we would like
83 * @return a QPair with first containing the index of the tab with the
84 * desired URL or -1 if not found. Second says true if URL is in primary
85 * view container, false otherwise. False means the URL is in the secondary
86 * view container, unless first == -1. In that case the value of second
89 QPair
<int, bool> getIndexByUrl(const QUrl
& url
) const;
93 * Is emitted when the active view has been changed, by changing the current
94 * tab or by activating another view when split view is enabled in the current
97 void activeViewChanged(DolphinViewContainer
* viewContainer
);
100 * Is emitted when the number of open tabs has changed (e.g. by opening or
103 void tabCountChanged(int count
);
106 * Is emitted when a tab has been closed.
108 void rememberClosedTab(const QUrl
& url
, const QByteArray
& state
);
111 * Is emitted when the url of the current tab has been changed. This signal
112 * is also emitted when the active view has been changed.
114 void currentUrlChanged(const QUrl
& url
);
118 * Opens a new view with the current URL that is part of a tab and activates
121 void openNewActivatedTab();
124 * Opens a new tab showing the URL \a primaryUrl and the optional URL
125 * \a secondaryUrl and activates the tab.
127 void openNewActivatedTab(const QUrl
& primaryUrl
, const QUrl
& secondaryUrl
= QUrl());
130 * Opens a new tab in the background showing the URL \a primaryUrl and the
131 * optional URL \a secondaryUrl. \a tabPlacement controls where the new tab
134 void openNewTab(const QUrl
&primaryUrl
, const QUrl
&secondaryUrl
= QUrl(),
135 DolphinTabWidget::TabPlacement tabPlacement
= AfterLastTab
);
138 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
139 * 2 directories are collected within one tab.
140 * \pre \a dirs must contain at least one url.
142 void openDirectories(const QList
<QUrl
>& dirs
, bool splitView
);
145 * Opens the directories which contain the files \p files and selects all files.
146 * If \a splitView is set, 2 directories are collected within one tab.
147 * \pre \a files must contain at least one url.
149 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
152 * Closes the currently active tab.
157 * Closes the tab with the index \a index and activates the tab with index - 1.
159 void closeTab(const int index
);
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 invoked if the Places panel got visible/invisible and takes care
175 * that the places-selector of all views is only shown if the Places panel
178 void slotPlacesPanelVisibilityChanged(bool visible
);
181 * Is called when the user wants to reopen a previously closed tab from
182 * the recent tabs menu.
184 void restoreClosedTab(const QByteArray
& state
);
188 * Opens the tab with the index \a index in a new Dolphin instance and closes
191 void detachTab(int index
);
194 * Opens a new tab showing the url from tab at the given \a index and
197 void openNewActivatedTab(int index
);
200 * Is connected to the KTabBar signal receivedDropEvent.
201 * Allows dragging and dropping files onto tabs.
203 void tabDropEvent(int tab
, QDropEvent
* event
);
206 * The active view url of a tab has been changed so update the text and the
207 * icon of the corresponding tab.
209 void tabUrlChanged(const QUrl
& url
);
211 void currentTabChanged(int index
);
214 void tabInserted(int index
) override
;
215 void tabRemoved(int index
) override
;
219 * @param tabPage The tab page to get the name of
220 * @return The name of the tab page
222 QString
tabName(DolphinTabPage
* tabPage
) const;
225 /** Caches the (negated) places panel visibility */
226 bool m_placesSelectorVisible
;