]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabwidget.h
New tab should be placed after the current tab
[dolphin.git] / src / dolphintabwidget.h
1 /***************************************************************************
2 * Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef DOLPHIN_TAB_WIDGET_H
21 #define DOLPHIN_TAB_WIDGET_H
22
23 #include <QTabWidget>
24 #include <QUrl>
25
26 class DolphinViewContainer;
27 class DolphinTabPage;
28 class KConfigGroup;
29
30 class DolphinTabWidget : public QTabWidget
31 {
32 Q_OBJECT
33
34 public:
35 /**
36 * @brief Controls where tabs are placed
37 */
38 enum TabPlacement {
39 /**
40 * The new tab is placed after the current tab
41 */
42 AfterCurrentTab,
43 /**
44 * The new tab is placed after the last tab
45 */
46 AfterLastTab
47 };
48 explicit DolphinTabWidget(QWidget* parent);
49
50 /**
51 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
52 */
53 DolphinTabPage* currentTabPage() const;
54
55 /**
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
58 */
59 DolphinTabPage* nextTabPage() const;
60
61 /**
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
64 */
65 DolphinTabPage* prevTabPage() const;
66
67 /**
68 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
69 */
70 DolphinTabPage* tabPageAt(const int index) const;
71
72 void saveProperties(KConfigGroup& group) const;
73 void readProperties(const KConfigGroup& group);
74
75 /**
76 * Refreshes the views of the main window by recreating them according to
77 * the given Dolphin settings.
78 */
79 void refreshViews();
80
81 signals:
82 /**
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
85 * tab.
86 */
87 void activeViewChanged(DolphinViewContainer* viewContainer);
88
89 /**
90 * Is emitted when the number of open tabs has changed (e.g. by opening or
91 * closing a tab)
92 */
93 void tabCountChanged(int count);
94
95 /**
96 * Is emitted when a tab has been closed.
97 */
98 void rememberClosedTab(const QUrl& url, const QByteArray& state);
99
100 /**
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.
103 */
104 void currentUrlChanged(const QUrl& url);
105
106 public slots:
107 /**
108 * Opens a new view with the current URL that is part of a tab and activates
109 * the tab.
110 */
111 void openNewActivatedTab();
112
113 /**
114 * Opens a new tab showing the URL \a primaryUrl and the optional URL
115 * \a secondaryUrl and activates the tab.
116 */
117 void openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl = QUrl());
118
119 /**
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
122 * is placed.
123 */
124 void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl(),
125 TabPlacement tabPlacement = AfterLastTab);
126
127 /**
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.
131 */
132 void openDirectories(const QList<QUrl>& dirs, bool splitView);
133
134 /**
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.
138 */
139 void openFiles(const QList<QUrl> &files, bool splitView);
140
141 /**
142 * Closes the currently active tab.
143 */
144 void closeTab();
145
146 /**
147 * Closes the tab with the index \a index and activates the tab with index - 1.
148 */
149 void closeTab(const int index);
150
151 /**
152 * Activates the next tab in the tab bar.
153 * If the current active tab is the last tab, it activates the first tab.
154 */
155 void activateNextTab();
156
157 /**
158 * Activates the previous tab in the tab bar.
159 * If the current active tab is the first tab, it activates the last tab.
160 */
161 void activatePrevTab();
162
163 /**
164 * Is invoked if the Places panel got visible/invisible and takes care
165 * that the places-selector of all views is only shown if the Places panel
166 * is invisible.
167 */
168 void slotPlacesPanelVisibilityChanged(bool visible);
169
170 /**
171 * Is called when the user wants to reopen a previously closed tab from
172 * the recent tabs menu.
173 */
174 void restoreClosedTab(const QByteArray& state);
175
176 private slots:
177 /**
178 * Opens the tab with the index \a index in a new Dolphin instance and closes
179 * this tab.
180 */
181 void detachTab(int index);
182
183 /**
184 * Opens a new tab showing the url from tab at the given \a index and
185 * activates the tab.
186 */
187 void openNewActivatedTab(int index);
188
189 /**
190 * Is connected to the KTabBar signal receivedDropEvent.
191 * Allows dragging and dropping files onto tabs.
192 */
193 void tabDropEvent(int tab, QDropEvent* event);
194
195 /**
196 * The active view url of a tab has been changed so update the text and the
197 * icon of the corresponding tab.
198 */
199 void tabUrlChanged(const QUrl& url);
200
201 void currentTabChanged(int index);
202
203 protected:
204 void tabInserted(int index) override;
205 void tabRemoved(int index) override;
206
207 private:
208 /**
209 * @param tabPage The tab page to get the name of
210 * @return The name of the tab page
211 */
212 QString tabName(DolphinTabPage* tabPage) const;
213
214 private:
215 /** Caches the (negated) places panel visibility */
216 bool m_placesSelectorVisible;
217
218 int m_lastViewedTab;
219 };
220
221 #endif