]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphintabpage.h
Merge branch 'Applications/18.08'
[dolphin.git] / src / dolphintabpage.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_PAGE_H
21 #define DOLPHIN_TAB_PAGE_H
22
23 #include <QPointer>
24 #include <QUrl>
25 #include <QWidget>
26
27 class QSplitter;
28 class DolphinViewContainer;
29 class KFileItemList;
30
31 class DolphinTabPage : public QWidget
32 {
33 Q_OBJECT
34
35 public:
36 explicit DolphinTabPage(const QUrl& primaryUrl, const QUrl& secondaryUrl = QUrl(), QWidget* parent = nullptr);
37
38 /**
39 * @return True if primary view is the active view in this tab.
40 */
41 bool primaryViewActive() const;
42
43 /**
44 * @return True if split view is enabled.
45 */
46 bool splitViewEnabled() const;
47
48 /**
49 * Enables or disables the split view mode.
50 *
51 * If \a enabled is true, it creates a secondary view with the url of the primary view.
52 */
53 void setSplitViewEnabled(bool enabled, const QUrl &secondaryUrl = QUrl());
54
55 /**
56 * @return The primary view container.
57 */
58 DolphinViewContainer* primaryViewContainer() const;
59
60 /**
61 * @return The secondary view container, can be 0 if split view is disabled.
62 */
63 DolphinViewContainer* secondaryViewContainer() const;
64
65 /**
66 * @return DolphinViewContainer of the active view
67 */
68 DolphinViewContainer* activeViewContainer() const;
69
70 /**
71 * Returns the selected items. The list is empty if no item has been
72 * selected.
73 */
74 KFileItemList selectedItems() const;
75
76 /**
77 * Returns the number of selected items (this is faster than
78 * invoking selectedItems().count()).
79 */
80 int selectedItemsCount() const;
81
82 /**
83 * Marks the items indicated by \p urls to get selected after the
84 * directory DolphinView::url() has been loaded. Note that nothing
85 * gets selected if no loading of a directory has been triggered
86 * by DolphinView::setUrl() or DolphinView::reload().
87 */
88 void markUrlsAsSelected(const QList<QUrl> &urls);
89
90 /**
91 * Marks the item indicated by \p url to be scrolled to and as the
92 * current item after directory DolphinView::url() has been loaded.
93 */
94 void markUrlAsCurrent(const QUrl& url);
95
96 /**
97 * Sets the places selector visible, if \a visible is true.
98 * The places selector allows to select the places provided
99 * by the places model passed in the constructor. Per default
100 * the places selector is visible.
101 */
102 void setPlacesSelectorVisible(bool visible);
103
104 /**
105 * Refreshes the views of the main window by recreating them according to
106 * the given Dolphin settings.
107 */
108 void refreshViews();
109
110 /**
111 * Saves all tab related properties (urls, splitter layout, ...).
112 *
113 * @return A byte-array which contains all properties.
114 */
115 QByteArray saveState() const;
116
117 /**
118 * Restores all tab related properties (urls, splitter layout, ...) from
119 * the given \a state.
120 */
121 void restoreState(const QByteArray& state);
122
123 /**
124 * Restores all tab related properties (urls, splitter layout, ...) from
125 * the given \a state.
126 *
127 * @deprecated The first tab state version has no version number, we keep
128 * this method to restore old states (<= Dolphin 4.14.x).
129 */
130 Q_DECL_DEPRECATED void restoreStateV1(const QByteArray& state);
131
132 /**
133 * Set whether the tab page is active
134 *
135 */
136 void setActive(bool active);
137
138 signals:
139 void activeViewChanged(DolphinViewContainer* viewContainer);
140 void activeViewUrlChanged(const QUrl& url);
141
142 private slots:
143 /**
144 * Handles the view activated event.
145 *
146 * It sets the previous active view to inactive, updates the current
147 * active view type and triggers the activeViewChanged event.
148 */
149 void slotViewActivated();
150
151 /**
152 * Handles the view url redirection event.
153 *
154 * It emits the activeViewUrlChanged signal with the url \a newUrl.
155 */
156 void slotViewUrlRedirection(const QUrl& oldUrl, const QUrl& newUrl);
157
158 void switchActiveView();
159
160 private:
161 /**
162 * Creates a new view container and does the default initialization.
163 */
164 DolphinViewContainer* createViewContainer(const QUrl& url) const;
165
166 private:
167 QSplitter* m_splitter;
168
169 QPointer<DolphinViewContainer> m_primaryViewContainer;
170 QPointer<DolphinViewContainer> m_secondaryViewContainer;
171
172 bool m_primaryViewActive;
173 bool m_splitViewEnabled;
174 bool m_active;
175 };
176
177 #endif // DOLPHIN_TAB_PAGE_H