2 * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
3 * SPDX-FileCopyrightText: 2020 Felix Ernst <felixernst@kde.org>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #ifndef DOLPHIN_TAB_PAGE_H
9 #define DOLPHIN_TAB_PAGE_H
18 class DolphinNavigatorsWidgetAction
;
19 class DolphinViewContainer
;
20 class QVariantAnimation
;
22 class DolphinTabPageSplitter
;
24 class DolphinTabPage
: public QWidget
29 explicit DolphinTabPage(const QUrl
&primaryUrl
, const QUrl
&secondaryUrl
= QUrl(), QWidget
*parent
= nullptr);
32 * @return True if primary view is the active view in this tab.
34 bool primaryViewActive() const;
37 * @return True if split view is enabled.
39 bool splitViewEnabled() const;
42 * Enables or disables the split view mode.
44 * @param enabled If true, creates a secondary viewContainer in this tab.
45 * Otherwise deletes it.
46 * @param animated Decides whether the effects of this method call should
47 * happen instantly or be transitioned to smoothly.
48 * @param secondaryUrl If \p enabled is true, the new viewContainer will be opened at this
49 * parameter. The default value will set the Url of the new viewContainer
50 * to be the same as the existing one.
52 void setSplitViewEnabled(bool enabled
, Animated animated
, const QUrl
&secondaryUrl
= QUrl());
55 * @return The primary view container.
57 DolphinViewContainer
*primaryViewContainer() const;
60 * @return The secondary view container, can be 0 if split view is disabled.
62 DolphinViewContainer
*secondaryViewContainer() const;
65 * @return DolphinViewContainer of the active view
67 DolphinViewContainer
*activeViewContainer() const;
70 * @return DolphinViewContainer of the inactive view
71 * if split view is enabled, or nullptr otherwise.
73 DolphinViewContainer
*inactiveViewContainer() const;
76 * Returns the selected items. The list is empty if no item has been
79 KFileItemList
selectedItems() const;
82 * Returns the number of selected items (this is faster than
83 * invoking selectedItems().count()).
85 int selectedItemsCount() const;
88 * Connects a navigatorsWidget to this. It will be connected to the DolphinViewContainers
89 * managed by this tab. For alignment purposes this will from now on notify the
90 * navigatorsWidget when this tab or its viewContainers are resized.
92 void connectNavigators(DolphinNavigatorsWidgetAction
*navigatorsWidget
);
95 * Makes it so this tab and its DolphinViewContainers aren't controlled by any
96 * UrlNavigators anymore.
98 void disconnectNavigators();
100 void insertNavigatorsWidget(DolphinNavigatorsWidgetAction
*navigatorsWidget
);
103 * Marks the items indicated by \p urls to get selected after the
104 * directory DolphinView::url() has been loaded. Note that nothing
105 * gets selected if no loading of a directory has been triggered
106 * by DolphinView::setUrl() or DolphinView::reload().
108 void markUrlsAsSelected(const QList
<QUrl
> &urls
);
111 * Marks the item indicated by \p url to be scrolled to and as the
112 * current item after directory DolphinView::url() has been loaded.
114 void markUrlAsCurrent(const QUrl
&url
);
117 * Refreshes the views of the main window by recreating them according to
118 * the given Dolphin settings.
123 * Saves all tab related properties (urls, splitter layout, ...).
125 * @return A byte-array which contains all properties.
127 QByteArray
saveState() const;
130 * Restores all tab related properties (urls, splitter layout, ...) from
131 * the given \a state.
133 void restoreState(const QByteArray
&state
);
136 * Set whether the tab page is active
139 void setActive(bool active
);
141 void switchActiveView();
144 * Overwrites the automatically generated label of this tab with @p label.
145 * This @p label will be kept until it is overwritten by calling this method again.
146 * Calling this with an empty string will restore the automatic labelling.
148 void setCustomLabel(const QString
&label
);
151 * @see setCustomLabel.
153 QString
customLabel() const;
156 void activeViewChanged(DolphinViewContainer
*viewContainer
);
157 void activeViewUrlChanged(const QUrl
&url
);
158 void splitterMoved(int pos
, int index
);
162 * Deletes all zombie viewContainers that were used for the animation
163 * and resets the minimum size of the others to a sane value.
165 void slotAnimationFinished();
168 * This method is called for every frame of the m_expandViewAnimation.
170 void slotAnimationValueChanged(const QVariant
&value
);
173 * Handles the view activated event.
175 * It sets the previous active view to inactive, updates the current
176 * active view type and triggers the activeViewChanged event.
178 void slotViewActivated();
181 * Handles the view url redirection event.
183 * It emits the activeViewUrlChanged signal with the url \a newUrl.
185 void slotViewUrlRedirection(const QUrl
&oldUrl
, const QUrl
&newUrl
);
189 * Creates a new view container and does the default initialization.
191 DolphinViewContainer
*createViewContainer(const QUrl
&url
) const;
194 * Starts an animation that transitions between split view mode states.
196 * One of the viewContainers is always being expanded when toggling so
197 * this method can animate both opening and closing of viewContainers.
198 * @param expandingContainer The container that will increase in size
199 * over the course of the animation.
201 void startExpandViewAnimation(DolphinViewContainer
*expandingContainer
);
204 DolphinTabPageSplitter
*m_splitter
;
206 QPointer
<DolphinNavigatorsWidgetAction
> m_navigatorsWidget
;
207 QPointer
<DolphinViewContainer
> m_primaryViewContainer
;
208 QPointer
<DolphinViewContainer
> m_secondaryViewContainer
;
210 DolphinViewContainer
*m_expandingContainer
;
211 QPointer
<QVariantAnimation
> m_expandViewAnimation
;
213 bool m_primaryViewActive
;
214 bool m_splitViewEnabled
;
216 /** @see setCustomLabel(). */
217 QString m_customLabel
;
220 class DolphinTabPageSplitterHandle
: public QSplitterHandle
225 explicit DolphinTabPageSplitterHandle(Qt::Orientation orientation
, QSplitter
*parent
);
228 bool event(QEvent
*event
) override
;
231 void resetSplitterSizes();
233 // Sometimes QSplitterHandle doesn't receive MouseButtonDblClick event.
234 // We can detect that MouseButtonDblClick event should have been
235 // received if we receive two MouseButtonRelease events in a row.
236 bool m_mouseReleaseWasReceived
;
239 class DolphinTabPageSplitter
: public QSplitter
244 explicit DolphinTabPageSplitter(Qt::Orientation orientation
, QWidget
*parent
);
247 QSplitterHandle
*createHandle() override
;
250 #endif // DOLPHIN_TAB_PAGE_H