]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabwidget.h
Unify window and tab title
[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 explicit DolphinTabWidget(QWidget* parent);
36
37 /**
38 * @return Tab page at the current index (can be 0 if tabs count is smaller than 1)
39 */
40 DolphinTabPage* currentTabPage() const;
41
42 /**
43 * @return the next tab page. If the current active tab is the last tab,
44 * it returns the first tab. If there is only one tab, returns nullptr
45 */
46 DolphinTabPage* nextTabPage() const;
47
48 /**
49 * @return the previous tab page. If the current active tab is the first tab,
50 * it returns the last tab. If there is only one tab, returns nullptr
51 */
52 DolphinTabPage* prevTabPage() const;
53
54 /**
55 * @return Tab page at the given \a index (can be 0 if the index is out-of-range)
56 */
57 DolphinTabPage* tabPageAt(const int index) const;
58
59 void saveProperties(KConfigGroup& group) const;
60 void readProperties(const KConfigGroup& group);
61
62 /**
63 * Refreshes the views of the main window by recreating them according to
64 * the given Dolphin settings.
65 */
66 void refreshViews();
67
68 signals:
69 /**
70 * Is emitted when the active view has been changed, by changing the current
71 * tab or by activating another view when split view is enabled in the current
72 * tab.
73 */
74 void activeViewChanged(DolphinViewContainer* viewContainer);
75
76 /**
77 * Is emitted when the number of open tabs has changed (e.g. by opening or
78 * closing a tab)
79 */
80 void tabCountChanged(int count);
81
82 /**
83 * Is emitted when a tab has been closed.
84 */
85 void rememberClosedTab(const QUrl& url, const QByteArray& state);
86
87 /**
88 * Is emitted when the url of the current tab has been changed. This signal
89 * is also emitted when the active view has been changed.
90 */
91 void currentUrlChanged(const QUrl& url);
92
93 public slots:
94 /**
95 * Opens a new view with the current URL that is part of a tab and activates
96 * the tab.
97 */
98 void openNewActivatedTab();
99
100 /**
101 * Opens a new tab showing the URL \a primaryUrl and the optional URL
102 * \a secondaryUrl and activates the tab.
103 */
104 void openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl = QUrl());
105
106 /**
107 * Opens a new tab in the background showing the URL \a primaryUrl and the
108 * optional URL \a secondaryUrl.
109 */
110 void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl());
111
112 /**
113 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
114 * 2 directories are collected within one tab.
115 * \pre \a dirs must contain at least one url.
116 */
117 void openDirectories(const QList<QUrl>& dirs, bool splitView);
118
119 /**
120 * Opens the directories which contain the files \p files and selects all files.
121 * If \a splitView is set, 2 directories are collected within one tab.
122 * \pre \a files must contain at least one url.
123 */
124 void openFiles(const QList<QUrl> &files, bool splitView);
125
126 /**
127 * Closes the currently active tab.
128 */
129 void closeTab();
130
131 /**
132 * Closes the tab with the index \a index and activates the tab with index - 1.
133 */
134 void closeTab(const int index);
135
136 /**
137 * Activates the next tab in the tab bar.
138 * If the current active tab is the last tab, it activates the first tab.
139 */
140 void activateNextTab();
141
142 /**
143 * Activates the previous tab in the tab bar.
144 * If the current active tab is the first tab, it activates the last tab.
145 */
146 void activatePrevTab();
147
148 /**
149 * Is invoked if the Places panel got visible/invisible and takes care
150 * that the places-selector of all views is only shown if the Places panel
151 * is invisible.
152 */
153 void slotPlacesPanelVisibilityChanged(bool visible);
154
155 /**
156 * Is called when the user wants to reopen a previously closed tab from
157 * the recent tabs menu.
158 */
159 void restoreClosedTab(const QByteArray& state);
160
161 private slots:
162 /**
163 * Opens the tab with the index \a index in a new Dolphin instance and closes
164 * this tab.
165 */
166 void detachTab(int index);
167
168 /**
169 * Opens a new tab showing the url from tab at the given \a index and
170 * activates the tab.
171 */
172 void openNewActivatedTab(int index);
173
174 /**
175 * Is connected to the KTabBar signal receivedDropEvent.
176 * Allows dragging and dropping files onto tabs.
177 */
178 void tabDropEvent(int tab, QDropEvent* event);
179
180 /**
181 * The active view url of a tab has been changed so update the text and the
182 * icon of the corresponding tab.
183 */
184 void tabUrlChanged(const QUrl& url);
185
186 void currentTabChanged(int index);
187
188 protected:
189 void tabInserted(int index) override;
190 void tabRemoved(int index) override;
191
192 private:
193 /**
194 * Returns the name of the tab for the URL \a url.
195 */
196 QString tabName() const;
197
198 private:
199 /** Caches the (negated) places panel visibility */
200 bool m_placesSelectorVisible;
201
202 int m_lastViewedTab;
203 };
204
205 #endif